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