1. Project Clover database Wed Jan 17 2024 23:40:18 CST
  2. Package org.europa.together.domain

File ConfigurationDOTest.java

 

Code metrics

0
84
9
1
186
149
9
0.11
9.33
9
1

Classes

Class Line # Actions
ConfigurationDOTest 18 84 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 9 tests. .

Source view

1    package org.europa.together.domain;
2   
3    import static com.google.code.beanmatchers.BeanMatchers.*;
4    import jakarta.validation.ConstraintViolation;
5    import jakarta.validation.Validation;
6    import jakarta.validation.Validator;
7    import java.util.Set;
8    import org.europa.together.JUnit5Preperator;
9    import org.europa.together.application.LogbackLogger;
10    import org.europa.together.business.Logger;
11    import static org.hamcrest.MatcherAssert.assertThat;
12    import static org.junit.jupiter.api.Assertions.*;
13    import org.junit.jupiter.api.Test;
14    import org.junit.jupiter.api.extension.ExtendWith;
15   
16    @SuppressWarnings("unchecked")
17    @ExtendWith({JUnit5Preperator.class})
 
18    public class ConfigurationDOTest {
19   
20    private static final Logger LOGGER = new LogbackLogger(ConfigurationDOTest.class);
21   
22    private static Validator validate
23    = Validation.buildDefaultValidatorFactory().getValidator();
24   
25    private String key = "key";
26    private String value = "value";
27    private String defaultValue = "default";
28    private String modulName = "module";
29    private String configSet = "configuration";
30    private String version = "1.0";
31    private boolean deprecated = true;
32    private boolean mandatory = false;
33    private String comment = "no comment";
34   
 
35  1 toggle @Test
36    void prePersist() {
37  1 LOGGER.log("TEST CASE: prePersist", LogLevel.DEBUG);
38   
39  1 ConfigurationDO domainObject = new ConfigurationDO();
40  1 domainObject.prePersist();
41   
42  1 assertNotNull(domainObject);
43  1 assertEquals("default", domainObject.getConfigurationSet());
44  1 assertEquals("NIL", domainObject.getDefaultValue());
45  1 assertEquals(false, domainObject.isDeprecated());
46  1 assertEquals(false, domainObject.isMandatory());
47    }
48   
 
49  1 toggle @Test
50    void domainObject() {
51  1 LOGGER.log("TEST CASE: domainObject", LogLevel.DEBUG);
52   
53  1 assertThat(ConfigurationDO.class, hasValidBeanConstructor());
54  1 assertThat(ConfigurationDO.class, hasValidBeanToString());
55  1 assertThat(ConfigurationDO.class, hasValidBeanHashCodeFor("key", "modulName", "version"));
56  1 assertThat(ConfigurationDO.class, hasValidBeanEqualsFor("key", "modulName", "version"));
57    }
58   
 
59  1 toggle @Test
60    void hasValidGetter() {
61  1 LOGGER.log("TEST CASE: hasValidGetter", LogLevel.DEBUG);
62   
63  1 ConfigurationDO domainObject = new ConfigurationDO();
64  1 domainObject.setComment("comment");
65  1 domainObject.setConfigurationSet(configSet);
66  1 domainObject.setDefaultValue(defaultValue);
67  1 domainObject.setKey(key);
68  1 domainObject.setModulName(modulName);
69  1 domainObject.setValue(value);
70  1 domainObject.setVersion(version);
71   
72  1 assertEquals("comment", domainObject.getComment());
73  1 assertEquals(configSet, domainObject.getConfigurationSet());
74  1 assertEquals(defaultValue, domainObject.getDefaultValue());
75  1 assertEquals(key, domainObject.getKey());
76  1 assertEquals(modulName, domainObject.getModulName());
77  1 assertNotNull(domainObject.getUuid());
78  1 assertEquals(value, domainObject.getValue());
79  1 assertEquals(version, domainObject.getVersion());
80    }
81   
 
82  1 toggle @Test
83    void createDomainObjectBySetter() {
84  1 LOGGER.log("TEST CASE: createDomainObjectBySetter", LogLevel.DEBUG);
85   
86  1 ConfigurationDO domainObject = new ConfigurationDO();
87  1 domainObject.setKey(key);
88  1 domainObject.setModulName(modulName);
89  1 domainObject.setVersion(version);
90  1 domainObject.setConfigurationSet(configSet);
91  1 domainObject.setDefaultValue(defaultValue);
92  1 domainObject.setValue(value);
93   
94  1 assertNotNull(domainObject);
95   
96  1 Set<ConstraintViolation<ConfigurationDO>> result
97    = validate.validate(domainObject);
98   
99  1 assertTrue(result.isEmpty());
100  1 assertEquals(0, result.size());
101    }
102   
 
103  1 toggle @Test
104    void correctBeanConstruction() {
105  1 LOGGER.log("TEST CASE: correctBeanConstruction", LogLevel.DEBUG);
106   
107  1 ConfigurationDO domainObject;
108   
109  1 domainObject = new ConfigurationDO(key, value, modulName, version);
110  1 domainObject.prePersist();
111  1 assertNotNull(domainObject);
112  1 assertEquals(0, validate.validate(domainObject).size());
113  1 assertTrue(validate.validate(domainObject).isEmpty());
114   
115  1 domainObject = new ConfigurationDO(key, null, modulName, version);
116  1 domainObject.prePersist();
117  1 assertNotNull(domainObject);
118  1 assertEquals(0, validate.validate(domainObject).size());
119  1 assertTrue(validate.validate(domainObject).isEmpty());
120    }
121   
 
122  1 toggle @Test
123    void isEqual() {
124  1 LOGGER.log("TEST CASE: isEqual", LogLevel.DEBUG);
125   
126  1 ConfigurationDO A
127    = new ConfigurationDO(key, "111", modulName, version);
128  1 ConfigurationDO B
129    = new ConfigurationDO(key, "000", modulName, version);
130   
131  1 assertTrue(A.equals(B));
132  1 assertTrue(B.equals(A));
133    }
134   
 
135  1 toggle @Test
136    void isNotEqual() {
137  1 LOGGER.log("TEST CASE: isNotEqual", LogLevel.DEBUG);
138   
139  1 ConfigurationDO A
140    = new ConfigurationDO("AAA", "000", "test", "1.0.1");
141  1 ConfigurationDO B
142    = new ConfigurationDO("BBB", "001", "test", "1.0.1");
143  1 ConfigurationDO C
144    = new ConfigurationDO("BBB", "010", "module", "1.0.1");
145  1 ConfigurationDO D
146    = new ConfigurationDO("BBB", "011", "test", "2.0");
147   
148    //KEY
149  1 assertFalse(A.equals(B));
150  1 assertFalse(B.equals(A));
151    //MODULE
152  1 assertFalse(B.equals(C));
153    //VERION
154  1 assertFalse(B.equals(D));
155    }
156   
 
157  1 toggle @Test
158    void validationEmptyComment() {
159  1 LOGGER.log("TEST CASE: validationEmptyComment", LogLevel.DEBUG);
160   
161  1 ConfigurationDO domainObject
162    = new ConfigurationDO(key, value, modulName, version);
163  1 domainObject.prePersist();
164  1 assertNotNull(domainObject);
165  1 assertEquals("", domainObject.getComment());
166  1 assertEquals(0, validate.validate(domainObject).size());
167  1 assertTrue(validate.validate(domainObject).isEmpty());
168    }
169   
 
170  1 toggle @Test
171    void validationEmptyValue() {
172  1 LOGGER.log("TEST CASE: validationEmptyValue", LogLevel.DEBUG);
173   
174  1 ConfigurationDO domainObject
175    = new ConfigurationDO(key, null, modulName, version);
176  1 domainObject.prePersist();
177  1 assertNotNull(domainObject);
178  1 assertNull(domainObject.getValue());
179  1 assertEquals(0, validate.validate(domainObject).size());
180  1 assertTrue(validate.validate(domainObject).isEmpty());
181   
182  1 domainObject.setValue("");
183  1 assertEquals("", domainObject.getValue());
184    }
185   
186    }