1. Project Clover database Wed Jan 17 2024 23:40:18 CST
  2. Package org.europa.together.service

File MailClientServiceTest.java

 

Code metrics

0
39
9
1
138
112
11
0.28
4.33
9
1.22

Classes

Class Line # Actions
MailClientServiceTest 32 39 0% 11 20
0.583333358.3%
 

Contributing tests

This file is covered by 3 tests. .

Source view

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"})
 
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    //<editor-fold defaultstate="collapsed" desc="Test Preparation">
 
45  1 toggle @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   
 
52  1 toggle @AfterAll
53    static void tearDown() {
54    }
55   
 
56  3 toggle @BeforeEach
57    void testCaseInitialization() {
58  3 CONNECTION.executeSqlFromClasspath(SQL_FILE);
59    }
60   
 
61  3 toggle @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    //</editor-fold>
71   
 
72  1 toggle @Test
73    void constructor() {
74  1 LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG);
75  1 assertThat(MailClientService.class, hasValidBeanConstructor());
76    }
77   
 
78  1 toggle @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   
 
90  1 toggle @Test
91    void updateConfiguration() {
92  1 LOGGER.log("TEST CASE: updateConfiguration", LogLevel.DEBUG);
93   
94    //Arrage
95  1 Map<String, String> config = new HashMap<>();
96  1 config.put("mailer.port", "9999");
97    //Act
98  1 try {
99  1 mailClientService.updateConfiguration(config);
100    } catch (Exception ex) {
101  0 LOGGER.catchException(ex);
102    }
103    //Assume
104  1 Map<String, String> newConfig
105    = mailClientService.loadConfiguration();
106  1 assertEquals("9999", newConfig.get("mailer.port"));
107    }
108   
 
109  0 toggle @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   
 
122  0 toggle @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    }