Commit ebba72ad authored by Simon Reis's avatar Simon Reis
Browse files

SI-158 Tests update

parent 91e5c3cf
......@@ -127,6 +127,10 @@
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
......
......@@ -15,31 +15,21 @@
package org.eclipse.openk.gridfailureinformation.controller;
import org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication;
import org.eclipse.openk.gridfailureinformation.exceptions.InternalServerErrorException;
import org.eclipse.openk.gridfailureinformation.service.EmailService;
import org.eclipse.openk.gridfailureinformation.service.StatusService;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
import org.eclipse.openk.gridfailureinformation.viewmodel.StatusDto;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import javax.mail.MessagingException;
import java.util.List;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = GridFailureInformationApplication.class)
@AutoConfigureMockMvc
@ActiveProfiles("test")
......
......@@ -19,28 +19,22 @@ import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.ServerSetup;
import org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication;
import org.eclipse.openk.gridfailureinformation.config.EmailConfig;
import org.eclipse.openk.gridfailureinformation.config.TestConfiguration;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.mail.MessagingException;
import java.io.IOException;
import java.net.ServerSocket;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = GridFailureInformationApplication.class)
@ContextConfiguration(classes = {TestConfiguration.class})
@ActiveProfiles("test")
public class EmailManagerTest {
......@@ -65,19 +59,19 @@ public class EmailManagerTest {
@Autowired
private EmailConfig emailConfig;
@BeforeClass
public static void beforeAll() throws IOException {
@BeforeAll
public static void beforeAll() {
ServerSetup serverSetup = new ServerSetup(3025 , "localhost", ServerSetup.PROTOCOL_SMTP);
serverSetup.setServerStartupTimeout(3000);
mailServer = new GreenMail(serverSetup);
}
@Before
@BeforeEach
public void beforeTest() {
mailServer.start();
}
@After
@AfterEach
public void afterTest() {
mailServer.stop();
}
......@@ -89,27 +83,27 @@ public class EmailManagerTest {
assertTrue(emailSent);
}
@Test (expected = MessagingException.class)
@Test
public void testSendMail_nok() throws Exception {
mailServer.stop();
EmailManager emailManager = new GfiEmail(null, "emailConfigurationTest/emailTemplates/appliedEmailTemplateTest.txt", false, this.emailConfig);
emailManager.sendEmail();
assertThrows(MessagingException.class, emailManager::sendEmail);
}
@Test (expected = MessagingException.class)
@Test
public void testSendMail_invalidRecipient() throws Exception {
EmailManager emailManager = new GfiEmail(null, "emailConfigurationTest/emailTemplates/emailTemplateTestFehlerRecipient.txt", false, this.emailConfig);
emailManager.sendEmail();
assertThrows(MessagingException.class, emailManager::sendEmail);
}
@Test (expected = MessagingException.class)
@Test
public void testSendMail_invalidSender() throws Exception {
EmailConfig emailConfig = new EmailConfig();
emailConfig.setSmtpHost("localhost");
emailConfig.setEmailPort("3025");
emailConfig.setSender("testCaseSendertest.de");
EmailManager emailManager = new GfiEmail(null, "emailConfigurationTest/emailTemplates/emailTemplateTestFehlerRecipient.txt", false, emailConfig);
emailManager.sendEmail();
assertThrows(MessagingException.class, emailManager::sendEmail);
}
}
......@@ -16,38 +16,20 @@ package org.eclipse.openk.gridfailureinformation.service;
import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.ServerSetup;
import com.icegreen.greenmail.util.ServerSetupTest;
import org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication;
import org.eclipse.openk.gridfailureinformation.config.TestConfiguration;
import org.eclipse.openk.gridfailureinformation.model.RefBranch;
import org.eclipse.openk.gridfailureinformation.repository.BranchRepository;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
import org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.mail.MessagingException;
import java.io.IOException;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = GridFailureInformationApplication.class)
@ContextConfiguration(classes = {TestConfiguration.class})
@ActiveProfiles("test")
public class EmailServiceTest {
......@@ -56,19 +38,19 @@ public class EmailServiceTest {
private static GreenMail mailServer;
@BeforeClass
public static void beforeAll() throws IOException {
@BeforeAll
public static void beforeAll() {
ServerSetup serverSetup = new ServerSetup(3025 , "localhost", ServerSetup.PROTOCOL_SMTP);
serverSetup.setServerStartupTimeout(3000);
mailServer = new GreenMail(serverSetup);
}
@Before
@BeforeEach
public void beforeTest() {
mailServer.start();
}
@After
@AfterEach
public void afterTest() {
mailServer.stop();
}
......
......@@ -15,7 +15,8 @@
package org.eclipse.openk.gridfailureinformation.util;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment