1 |
|
package org.europa.together.service; |
2 |
|
|
3 |
|
import static com.google.code.beanmatchers.BeanMatchers.*; |
4 |
|
import java.util.HashMap; |
5 |
|
import java.util.Map; |
6 |
|
import org.europa.together.JUnit5Preperator; |
7 |
|
import org.europa.together.application.JdbcActions; |
8 |
|
import org.europa.together.application.LogbackLogger; |
9 |
|
import org.europa.together.business.DatabaseActions; |
10 |
|
import org.europa.together.business.Logger; |
11 |
|
import org.europa.together.domain.LogLevel; |
12 |
|
import org.europa.together.domain.Mail; |
13 |
|
import org.europa.together.utils.StringUtils; |
14 |
|
import static org.hamcrest.MatcherAssert.*; |
15 |
|
import static org.junit.jupiter.api.Assertions.*; |
16 |
|
import org.junit.jupiter.api.AfterAll; |
17 |
|
import org.junit.jupiter.api.AfterEach; |
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.Disabled; |
22 |
|
import org.junit.jupiter.api.Test; |
23 |
|
import org.junit.jupiter.api.extension.ExtendWith; |
24 |
|
import org.springframework.beans.factory.annotation.Autowired; |
25 |
|
import org.springframework.test.context.ContextConfiguration; |
26 |
|
import org.springframework.test.context.junit.jupiter.SpringExtension; |
27 |
|
|
28 |
|
@SuppressWarnings("unchecked") |
29 |
|
@ExtendWith({JUnit5Preperator.class}) |
30 |
|
@ExtendWith(SpringExtension.class) |
31 |
|
@ContextConfiguration(locations = {"/applicationContext.xml"}) |
|
|
| 58.3% |
Uncovered Elements: 20 (48) |
Complexity: 11 |
Complexity Density: 0.28 |
|
32 |
|
public class MailClientServiceTest { |
33 |
|
|
34 |
|
private static final Logger LOGGER |
35 |
|
= new LogbackLogger(MailClientServiceTest.class); |
36 |
|
private static final String SQL_FILE |
37 |
|
= "/org/europa/together/sql/email-config-test.sql"; |
38 |
|
public static DatabaseActions CONNECTION |
39 |
|
= new JdbcActions(); |
40 |
|
|
41 |
|
@Autowired |
42 |
|
private MailClientService mailClientService; |
43 |
|
|
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
45 |
1 |
@BeforeAll... |
46 |
|
static void setUp() { |
47 |
1 |
Assumptions.assumeTrue(CONNECTION.connect("test"), "JDBC DBMS Connection failed."); |
48 |
|
|
49 |
1 |
LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG); |
50 |
|
} |
51 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
52 |
1 |
@AfterAll... |
53 |
|
static void tearDown() { |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
3 |
@BeforeEach... |
57 |
|
void testCaseInitialization() { |
58 |
3 |
CONNECTION.executeSqlFromClasspath(SQL_FILE); |
59 |
|
} |
60 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
61 |
3 |
@AfterEach... |
62 |
|
void testCaseTermination() throws Exception { |
63 |
3 |
LOGGER.log("CleanUp Test Suite.", LogLevel.DEBUG); |
64 |
3 |
try { |
65 |
3 |
CONNECTION.executeQuery("TRUNCATE TABLE APP_CONFIG;"); |
66 |
|
} catch (Exception ex) { |
67 |
0 |
LOGGER.catchException(ex); |
68 |
|
} |
69 |
|
} |
70 |
|
|
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
72 |
1 |
@Test... |
73 |
|
void constructor() { |
74 |
1 |
LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG); |
75 |
1 |
assertThat(MailClientService.class, hasValidBeanConstructor()); |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
78 |
1 |
@Test... |
79 |
|
void loadInitConfiguration() { |
80 |
1 |
LOGGER.log("TEST CASE: loadConfiguration", LogLevel.DEBUG); |
81 |
|
|
82 |
1 |
Map<String, String> config = mailClientService.loadConfiguration(); |
83 |
1 |
LOGGER.log("Mail Config: " + config.toString(), LogLevel.DEBUG); |
84 |
|
|
85 |
1 |
assertNotNull(config); |
86 |
1 |
assertEquals(10, config.size()); |
87 |
1 |
assertEquals("smtp.sample.org", config.get("mailer.host")); |
88 |
|
} |
89 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
1PASS
|
|
90 |
1 |
@Test... |
91 |
|
void updateConfiguration() { |
92 |
1 |
LOGGER.log("TEST CASE: updateConfiguration", LogLevel.DEBUG); |
93 |
|
|
94 |
|
|
95 |
1 |
Map<String, String> config = new HashMap<>(); |
96 |
1 |
config.put("mailer.port", "9999"); |
97 |
|
|
98 |
1 |
try { |
99 |
1 |
mailClientService.updateConfiguration(config); |
100 |
|
} catch (Exception ex) { |
101 |
0 |
LOGGER.catchException(ex); |
102 |
|
} |
103 |
|
|
104 |
1 |
Map<String, String> newConfig |
105 |
|
= mailClientService.loadConfiguration(); |
106 |
1 |
assertEquals("9999", newConfig.get("mailer.port")); |
107 |
|
} |
108 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
109 |
0 |
@Test... |
110 |
|
@Disabled |
111 |
|
void sendMail() throws Exception { |
112 |
0 |
LOGGER.log("TEST CASE: sendMail", LogLevel.DEBUG); |
113 |
|
|
114 |
0 |
Mail mail = new Mail(); |
115 |
0 |
mail.setSubject("JGiven Test E-Mail"); |
116 |
0 |
mail.setMessage(StringUtils.generateLoremIpsum(0)); |
117 |
0 |
mail.addRecipent("recipient_01@sample.org"); |
118 |
|
|
119 |
0 |
mailClientService.sendEmail(mail); |
120 |
|
} |
121 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
122 |
0 |
@Test... |
123 |
|
@Disabled |
124 |
|
void sendBulkMail() throws Exception { |
125 |
0 |
LOGGER.log("TEST CASE: sendBulkMail", LogLevel.DEBUG); |
126 |
|
|
127 |
0 |
Mail mail = new Mail(); |
128 |
0 |
mail.setSubject("JGiven Test E-Mail"); |
129 |
0 |
mail.setMessage(StringUtils.generateLoremIpsum(0)); |
130 |
0 |
mail.addRecipent("recipient_01@sample.org"); |
131 |
0 |
mail.addRecipent("recipient_02@sample.org"); |
132 |
0 |
mail.addRecipent("recipient_03@sample.org"); |
133 |
0 |
mail.addRecipent("recipient_04@sample.org"); |
134 |
0 |
mail.addRecipent("recipient_05@sample.org"); |
135 |
|
|
136 |
0 |
mailClientService.sendBulkMail(mail); |
137 |
|
} |
138 |
|
} |