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