1 |
|
package org.europa.together.application; |
2 |
|
|
3 |
|
import org.europa.together.JUnit5Preperator; |
4 |
|
import org.europa.together.business.JsonTools; |
5 |
|
import org.europa.together.business.Logger; |
6 |
|
import org.europa.together.domain.LogLevel; |
7 |
|
import org.europa.together.domain.JacksonObjectTest; |
8 |
|
import org.junit.jupiter.api.AfterAll; |
9 |
|
import org.junit.jupiter.api.AfterEach; |
10 |
|
import org.junit.jupiter.api.BeforeAll; |
11 |
|
import org.junit.jupiter.api.BeforeEach; |
12 |
|
import org.junit.jupiter.api.extension.ExtendWith; |
13 |
|
import org.springframework.test.context.ContextConfiguration; |
14 |
|
import org.springframework.test.context.junit.jupiter.SpringExtension; |
15 |
|
import org.junit.jupiter.api.Test; |
16 |
|
import static org.junit.jupiter.api.Assertions.*; |
17 |
|
import org.junit.jupiter.api.Assumptions; |
18 |
|
import org.springframework.beans.factory.annotation.Autowired; |
19 |
|
|
20 |
|
@SuppressWarnings("unchecked") |
21 |
|
@ExtendWith({JUnit5Preperator.class}) |
22 |
|
@ExtendWith(SpringExtension.class) |
23 |
|
@ContextConfiguration(locations = {"/applicationContext.xml"}) |
|
|
| 100% |
Uncovered Elements: 0 (43) |
Complexity: 10 |
Complexity Density: 0.3 |
|
24 |
|
public class JacksonJsonToolsTest { |
25 |
|
|
26 |
|
private static final Logger LOGGER = new LogbackLogger(JacksonJsonToolsTest.class); |
27 |
|
|
28 |
|
@Autowired |
29 |
|
private JsonTools<JacksonObjectTest> jsonTools; |
30 |
|
|
31 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
32 |
1 |
@BeforeAll... |
33 |
|
static void setUp() { |
34 |
1 |
Assumptions.assumeTrue(true, "Assumtion failed."); |
35 |
|
|
36 |
1 |
LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG); |
37 |
|
} |
38 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
39 |
1 |
@AfterAll... |
40 |
|
static void tearDown() { |
41 |
|
} |
42 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
43 |
6 |
@BeforeEach... |
44 |
|
void testCaseInitialization() { |
45 |
|
} |
46 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
47 |
6 |
@AfterEach... |
48 |
|
void testCaseTermination() { |
49 |
|
} |
50 |
|
|
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
52 |
1 |
@Test... |
53 |
|
void serializeObjectToJson() throws Exception { |
54 |
1 |
LOGGER.log("TEST CASE: serializeObjectToJson", LogLevel.DEBUG); |
55 |
|
|
56 |
1 |
JacksonObjectTest domainObject = new JacksonObjectTest(); |
57 |
1 |
domainObject.setId("identifier"); |
58 |
1 |
domainObject.setKey("key"); |
59 |
1 |
domainObject.setValue(12345); |
60 |
1 |
domainObject.setActivation(true); |
61 |
|
|
62 |
1 |
String json = "{\"id\":\"identifier\",\"key\":\"key\",\"value\":12345,\"activation\":true}"; |
63 |
1 |
assertEquals(json, jsonTools.serializeAsJsonObject(domainObject)); |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
66 |
1 |
@Test... |
67 |
|
void failSerializeObjectToJson() throws Exception { |
68 |
1 |
LOGGER.log("TEST CASE: failSerializeObjectToJson", LogLevel.DEBUG); |
69 |
|
|
70 |
1 |
assertThrows(Exception.class, () -> { |
71 |
1 |
jsonTools.serializeAsJsonObject(null); |
72 |
|
}); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
75 |
1 |
@Test... |
76 |
|
void deserializeJsonToObject() throws Exception { |
77 |
1 |
LOGGER.log("TEST CASE: deserializeJsonToObject", LogLevel.DEBUG); |
78 |
|
|
79 |
1 |
JacksonObjectTest domainObject = new JacksonObjectTest(); |
80 |
1 |
domainObject.setId("identifier"); |
81 |
1 |
domainObject.setKey("key"); |
82 |
1 |
domainObject.setValue(12345); |
83 |
1 |
domainObject.setActivation(true); |
84 |
|
|
85 |
1 |
String json = "{\"id\":\"identifier\",\"key\":\"key\",\"value\":12345,\"activation\":true}"; |
86 |
1 |
JacksonObjectTest deserializion = jsonTools.deserializeJsonAsObject(json, JacksonObjectTest.class); |
87 |
1 |
assertEquals("JacksonObjectTest{id=identifier, key=key, value=12345, activation=true}", |
88 |
|
deserializion.toString()); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
91 |
1 |
@Test... |
92 |
|
void failDeserializeJsonToObject() throws Exception { |
93 |
1 |
LOGGER.log("TEST CASE: failDeserializeJsonToObject", LogLevel.DEBUG); |
94 |
|
|
95 |
1 |
String json = "{\"xx\":\"identifier01\",\"key\":\"key\",\"value\":'123',\"activation\":false}"; |
96 |
1 |
assertThrows(Exception.class, () -> { |
97 |
1 |
jsonTools.deserializeJsonAsObject(json, JacksonObjectTest.class); |
98 |
|
}); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
101 |
1 |
@Test... |
102 |
|
void deserializeJsonAsObjectList() throws Exception { |
103 |
1 |
LOGGER.log("TEST CASE: deserializeJsonAsObjectList", LogLevel.DEBUG); |
104 |
|
|
105 |
1 |
String json = "[" |
106 |
|
+ "{\"id\":\"identifier00\",\"key\":\"low.number\",\"value\":12345,\"activation\":true}, " |
107 |
|
+ "{\"id\":\"identifier01\",\"key\":\"high.number\",\"value\":67890,\"activation\":false}, " |
108 |
|
+ "{\"id\":\"identifier02\",\"key\":\"amount\",\"value\":100,\"activation\":false}, " |
109 |
|
+ "{\"id\":\"identifier03\",\"key\":\"key\",\"value\":99099,\"activation\":true}" |
110 |
|
+ "]"; |
111 |
1 |
assertEquals(4, jsonTools.deserializeJsonAsList(json).size()); |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
114 |
1 |
@Test... |
115 |
|
void failDeserializeJsonAsObjectList() throws Exception { |
116 |
1 |
LOGGER.log("TEST CASE: failDeserializeJsonAsObjectList", LogLevel.DEBUG); |
117 |
|
|
118 |
1 |
String json = "{" |
119 |
|
+ "{\"id\":\"identifier00\",\"key\":\"low.number\",\"value\":12345,\"activation\":true}" |
120 |
|
+ "{\"id\":\"identifier01\",\"key\":\"high.number\",\"value\":67890,\"activation\":false}" |
121 |
|
+ "}"; |
122 |
1 |
assertThrows(Exception.class, () -> { |
123 |
1 |
jsonTools.deserializeJsonAsList(json); |
124 |
|
}); |
125 |
|
} |
126 |
|
} |