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}) |
|
|
| 100% |
Uncovered Elements: 0 (93) |
Complexity: 9 |
Complexity Density: 0.11 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
35 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
49 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
59 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
82 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
103 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
122 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
135 |
1 |
@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 |
|
|
149 |
1 |
assertFalse(A.equals(B)); |
150 |
1 |
assertFalse(B.equals(A)); |
151 |
|
|
152 |
1 |
assertFalse(B.equals(C)); |
153 |
|
|
154 |
1 |
assertFalse(B.equals(D)); |
155 |
|
} |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
157 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
170 |
1 |
@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 |
|
} |