1 |
|
package org.europa.together.application; |
2 |
|
|
3 |
|
import static com.google.code.beanmatchers.BeanMatchers.*; |
4 |
|
import java.io.File; |
5 |
|
import java.time.ZoneId; |
6 |
|
import java.time.ZonedDateTime; |
7 |
|
import java.util.HashMap; |
8 |
|
import java.util.Map; |
9 |
|
import org.europa.together.JUnit5Preperator; |
10 |
|
import org.europa.together.business.Logger; |
11 |
|
import org.europa.together.business.QrCodeGenerator; |
12 |
|
import org.europa.together.domain.LogLevel; |
13 |
|
import org.europa.together.utils.Constraints; |
14 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
15 |
|
import org.junit.jupiter.api.AfterAll; |
16 |
|
import org.junit.jupiter.api.AfterEach; |
17 |
|
import static org.junit.jupiter.api.Assertions.*; |
18 |
|
import org.junit.jupiter.api.Assumptions; |
19 |
|
import org.junit.jupiter.api.BeforeAll; |
20 |
|
import org.junit.jupiter.api.BeforeEach; |
21 |
|
import org.junit.jupiter.api.Test; |
22 |
|
import org.junit.jupiter.api.extension.ExtendWith; |
23 |
|
import org.springframework.test.context.ContextConfiguration; |
24 |
|
import org.springframework.test.context.junit.jupiter.SpringExtension; |
25 |
|
|
26 |
|
@SuppressWarnings("unchecked") |
27 |
|
@ExtendWith({JUnit5Preperator.class}) |
28 |
|
@ExtendWith(SpringExtension.class) |
29 |
|
@ContextConfiguration(locations = {"/applicationContext.xml"}) |
|
|
| 100% |
Uncovered Elements: 0 (77) |
Complexity: 13 |
Complexity Density: 0.2 |
|
30 |
|
public class ZxingGeneratorTest { |
31 |
|
|
32 |
|
private static final Logger LOGGER |
33 |
|
= new LogbackLogger(ZxingGeneratorTest.class); |
34 |
|
private static final String FILE_PATH |
35 |
|
= "org/europa/together/qr_codes"; |
36 |
|
private static final String DIRECTORY |
37 |
|
= Constraints.SYSTEM_APP_DIR + "/target/test-classes/" + FILE_PATH; |
38 |
|
|
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
40 |
1 |
@BeforeAll... |
41 |
|
static void setUp() { |
42 |
1 |
Assumptions.assumeTrue(true, "Assumtion failed."); |
43 |
|
|
44 |
1 |
LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG); |
45 |
|
} |
46 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
47 |
1 |
@AfterAll... |
48 |
|
static void tearDown() { |
49 |
|
} |
50 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
51 |
9 |
@BeforeEach... |
52 |
|
void testCaseInitialization() { |
53 |
|
} |
54 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
55 |
9 |
@AfterEach... |
56 |
|
void testCaseTermination() { |
57 |
|
} |
58 |
|
|
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
60 |
1 |
@Test... |
61 |
|
void constructor() { |
62 |
1 |
LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG); |
63 |
|
|
64 |
1 |
assertThat(ZxingGenerator.class, hasValidBeanConstructor()); |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
67 |
1 |
@Test... |
68 |
|
void qrCodeGenerator() { |
69 |
1 |
LOGGER.log("TEST CASE: qrCodeGenerator", LogLevel.DEBUG); |
70 |
|
|
71 |
1 |
String out = Constraints.SYSTEM_APP_DIR + "/target/test-classes/" + "QrCode-0000.png"; |
72 |
1 |
QrCodeGenerator generator = new ZxingGenerator(); |
73 |
1 |
generator.setup(out, 100); |
74 |
1 |
generator.encode("Test CODE."); |
75 |
|
|
76 |
1 |
assertEquals("Test CODE.", generator.decode(new File(out))); |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
79 |
1 |
@Test... |
80 |
|
void failEncode() { |
81 |
1 |
LOGGER.log("TEST CASE: failEncode", LogLevel.DEBUG); |
82 |
|
|
83 |
1 |
QrCodeGenerator generator = new ZxingGenerator(); |
84 |
1 |
generator.setup("/fail.png", 100); |
85 |
|
|
86 |
1 |
assertFalse(generator.encode(generator.generateDataForvCard(null))); |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
89 |
1 |
@Test... |
90 |
|
void failDecode() { |
91 |
1 |
LOGGER.log("TEST CASE: failDecode", LogLevel.DEBUG); |
92 |
|
|
93 |
1 |
QrCodeGenerator generator = new ZxingGenerator(); |
94 |
1 |
assertNull(generator.decode(null)); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
97 |
1 |
@Test... |
98 |
|
void vCard() { |
99 |
1 |
LOGGER.log("TEST CASE: vCard", LogLevel.DEBUG); |
100 |
|
|
101 |
1 |
Map<String, String> vCard = new HashMap<>(); |
102 |
1 |
vCard.put("gender", "Mr."); |
103 |
1 |
vCard.put("name", "Doe"); |
104 |
1 |
vCard.put("surname", "John"); |
105 |
1 |
vCard.put("title", "MSc"); |
106 |
1 |
vCard.put("organization", "org.europa"); |
107 |
1 |
vCard.put("role", "Developer"); |
108 |
1 |
vCard.put("home-street", "Poniente 15"); |
109 |
1 |
vCard.put("home-city", "Oaxaca"); |
110 |
1 |
vCard.put("home-zipcode", "12345"); |
111 |
1 |
vCard.put("home-state", "Oaxaca"); |
112 |
1 |
vCard.put("home-country", "Mexico"); |
113 |
1 |
vCard.put("home-phone", "(55) 22365014"); |
114 |
1 |
vCard.put("home-mobile", "1245 44548954"); |
115 |
1 |
vCard.put("work-street", "Poniente 15"); |
116 |
1 |
vCard.put("work-city", "Oaxaca"); |
117 |
1 |
vCard.put("work-zipcode", "12345"); |
118 |
1 |
vCard.put("work-state", "Oaxaca"); |
119 |
1 |
vCard.put("work-country", "Mexico"); |
120 |
1 |
vCard.put("work-phone", "(234) 12456457801"); |
121 |
1 |
vCard.put("work-mobile", "145 78457 54"); |
122 |
1 |
vCard.put("e-mail", "john.doe@sample.org"); |
123 |
1 |
vCard.put("homepage", "http://www.sample.org"); |
124 |
|
|
125 |
1 |
String out = Constraints.SYSTEM_APP_DIR + "/target/test-classes/" + "300_vCard.png"; |
126 |
1 |
QrCodeGenerator generator = new ZxingGenerator(); |
127 |
1 |
generator.setup(out, 300); |
128 |
1 |
assertTrue(generator.encode(generator.generateDataForvCard(vCard))); |
129 |
|
} |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
131 |
1 |
@Test... |
132 |
|
void emptyVCard() { |
133 |
1 |
LOGGER.log("TEST CASE: emptyVCard", LogLevel.DEBUG); |
134 |
|
|
135 |
1 |
QrCodeGenerator generator = new ZxingGenerator(); |
136 |
1 |
assertNull(generator.generateDataForvCard(new HashMap<>())); |
137 |
1 |
assertNull(generator.generateDataForvCard(null)); |
138 |
|
} |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
140 |
1 |
@Test... |
141 |
|
void geoInfo() { |
142 |
1 |
LOGGER.log("TEST CASE: geoInfo", LogLevel.DEBUG); |
143 |
|
|
144 |
1 |
String out = Constraints.SYSTEM_APP_DIR + "/target/test-classes/" + "100_geoInfo.png"; |
145 |
1 |
QrCodeGenerator generator = new ZxingGenerator(); |
146 |
1 |
generator.setup(out, 100); |
147 |
1 |
assertTrue(generator.encode( |
148 |
|
generator.generateDataForGeoLocation("40.71872", "-73.98905"))); |
149 |
|
} |
150 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
151 |
1 |
@Test... |
152 |
|
void url() { |
153 |
1 |
LOGGER.log("TEST CASE: url", LogLevel.DEBUG); |
154 |
|
|
155 |
1 |
String out = Constraints.SYSTEM_APP_DIR + "/target/test-classes/" + "100_url.png"; |
156 |
1 |
QrCodeGenerator generator = new ZxingGenerator(); |
157 |
1 |
generator.setup(out, 100); |
158 |
1 |
assertTrue(generator.encode( |
159 |
|
generator.generateDataForUrl("http://www.sample.org"))); |
160 |
|
} |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
162 |
1 |
@Test... |
163 |
|
void calendar() { |
164 |
1 |
LOGGER.log("TEST CASE: calendar", LogLevel.DEBUG); |
165 |
|
|
166 |
1 |
String out = Constraints.SYSTEM_APP_DIR + "/target/test-classes/" + "100_event.png"; |
167 |
1 |
QrCodeGenerator generator = new ZxingGenerator(); |
168 |
1 |
generator.setup(out, 100); |
169 |
|
|
170 |
1 |
assertTrue(generator.encode( |
171 |
|
generator.generateDataForCalendarEvent("Appointment", |
172 |
|
ZonedDateTime.of(2017, 1, 1, 1, 0, 0, 0, ZoneId.of("UTC")), |
173 |
|
ZonedDateTime.of(2017, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC")) |
174 |
|
) |
175 |
|
)); |
176 |
|
} |
177 |
|
} |