diff --git a/src/mokka/pom.xml b/src/mokka/pom.xml
index 28c2b74..87895f7 100644
--- a/src/mokka/pom.xml
+++ b/src/mokka/pom.xml
@@ -157,6 +157,13 @@
org.springframework.boot
spring-boot-starter-test
test
+
+
+
+ org.junit.vintage
+ junit-vintage-engine
+
+
com.h2database
@@ -260,15 +267,9 @@
-
org.apache.maven.plugins
maven-surefire-plugin
-
- false
-
diff --git a/src/mokka/src/main/java/pl/hycom/mokka/core/InitialSetupCommandLineRunner.java b/src/mokka/src/main/java/pl/hycom/mokka/core/InitialSetupCommandLineRunner.java
index ee663bc..2c7e9a3 100644
--- a/src/mokka/src/main/java/pl/hycom/mokka/core/InitialSetupCommandLineRunner.java
+++ b/src/mokka/src/main/java/pl/hycom/mokka/core/InitialSetupCommandLineRunner.java
@@ -1,10 +1,11 @@
package pl.hycom.mokka.core;
+import lombok.RequiredArgsConstructor;
+import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
-import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
import pl.hycom.mokka.security.UserManager;
/**
@@ -18,12 +19,13 @@
* @author Piotr Kulasek-Szwed
*/
@Slf4j
-@Component
+@Service
+@RequiredArgsConstructor
public class InitialSetupCommandLineRunner implements CommandLineRunner {
- @Autowired
- private UserManager userManager;
+ private final UserManager userManager;
+ @Setter
@Value("${setup.initial.enabled}")
private boolean initialSetupEnabled;
diff --git a/src/mokka/src/test/java/pl/hycom/mokka/AbstractTest.java b/src/mokka/src/test/java/pl/hycom/mokka/AbstractTest.java
index d94b57f..0115857 100644
--- a/src/mokka/src/test/java/pl/hycom/mokka/AbstractTest.java
+++ b/src/mokka/src/test/java/pl/hycom/mokka/AbstractTest.java
@@ -1,15 +1,15 @@
package pl.hycom.mokka;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* @author Mariusz Krysztofowicz (mariusz.krysztofowicz@hycom.pl)
*/
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Application.class)
@AutoConfigureTestDatabase
@TestPropertySource(locations = "classpath:test.properties")
diff --git a/src/mokka/src/test/java/pl/hycom/mokka/core/InitialSetupCommandLineRunnerTest.java b/src/mokka/src/test/java/pl/hycom/mokka/core/InitialSetupCommandLineRunnerTest.java
new file mode 100644
index 0000000..f470616
--- /dev/null
+++ b/src/mokka/src/test/java/pl/hycom/mokka/core/InitialSetupCommandLineRunnerTest.java
@@ -0,0 +1,61 @@
+package pl.hycom.mokka.core;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import pl.hycom.mokka.security.UserManager;
+
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Piotr Kulasek-Szwed
+ */
+@ExtendWith(MockitoExtension.class)
+public class InitialSetupCommandLineRunnerTest {
+
+ @Mock
+ private UserManager userManager;
+
+ @InjectMocks
+ private InitialSetupCommandLineRunner initialSetupCommandLineRunner;
+
+ @Test
+ public void shouldSkipInitialConfig(){
+ // given
+ when(userManager.numberOfAdmins()).thenReturn(1);
+ initialSetupCommandLineRunner.setInitialSetupEnabled(true);
+
+ // when
+ try {
+ initialSetupCommandLineRunner.run("");
+ } catch (Exception e) {
+ Assertions.fail();
+ }
+
+ // then
+ verify(userManager, atLeastOnce()).numberOfAdmins();
+ }
+
+ @Test
+ public void shouldExecuteInitialConfig(){
+ // given
+ when(userManager.numberOfAdmins()).thenReturn(0);
+ initialSetupCommandLineRunner.setInitialSetupEnabled(true);
+
+ // when
+ try {
+ initialSetupCommandLineRunner.run("");
+ } catch (Exception e) {
+ Assertions.fail();
+ }
+
+ // then
+ verify(userManager, atLeastOnce()).createAdminUser();
+ }
+
+}
diff --git a/src/mokka/src/test/java/pl/hycom/mokka/endpoint/FileControllerTest.java b/src/mokka/src/test/java/pl/hycom/mokka/endpoint/FileControllerTest.java
index 24a8981..791070b 100644
--- a/src/mokka/src/test/java/pl/hycom/mokka/endpoint/FileControllerTest.java
+++ b/src/mokka/src/test/java/pl/hycom/mokka/endpoint/FileControllerTest.java
@@ -2,8 +2,8 @@
import io.restassured.RestAssured;
import org.hamcrest.Matchers;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@ -21,7 +21,7 @@ public class FileControllerTest extends AbstractTest {
@Value("${local.server.port}")
protected int serverPort;
- @Before
+ @BeforeEach
public void setUp() {
RestAssured.port = serverPort;
}
diff --git a/src/mokka/src/test/java/pl/hycom/mokka/service/file/DefaultFileServiceTest.java b/src/mokka/src/test/java/pl/hycom/mokka/service/file/DefaultFileServiceTest.java
index 3588bae..8d4c88a 100644
--- a/src/mokka/src/test/java/pl/hycom/mokka/service/file/DefaultFileServiceTest.java
+++ b/src/mokka/src/test/java/pl/hycom/mokka/service/file/DefaultFileServiceTest.java
@@ -1,7 +1,8 @@
package pl.hycom.mokka.service.file;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.FileNotFoundException;
@@ -12,25 +13,31 @@
*/
public class DefaultFileServiceTest {
- DefaultFileService fileService = new DefaultFileService();
+ private DefaultFileService fileService;
+
+ @BeforeEach
+ public void init() {
+ fileService = new DefaultFileService();
+ }
@Test
public void testFetchFileSuccess() throws FileNotFoundException {
fileService.setSourceDirectory("src/test/resources/files/");
File file = fileService.fetchFile("samplefile.txt");
- Assert.assertNotNull(file);
+ Assertions.assertNotNull(file);
}
- @Test(expected = FileNotFoundException.class)
+ @Test
public void testFetchFileFileNotFoundException() throws FileNotFoundException {
- fileService.setSourceDirectory("src/test/resources/files/");
- fileService.fetchFile("samplefile1.txt");
-
+ Assertions.assertThrows(FileNotFoundException.class, () -> {
+ fileService.setSourceDirectory("src/test/resources/files/");
+ fileService.fetchFile("samplefile1.txt");
+ });
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testFetchFileIllegalArgumentException() throws FileNotFoundException {
- fileService.fetchFile(null);
+ Assertions.assertThrows(IllegalArgumentException.class, () -> fileService.fetchFile(null));
}
@@ -38,16 +45,16 @@ public void testFetchFileIllegalArgumentException() throws FileNotFoundException
public void testFetchAllFileSuccess() {
fileService.setSourceDirectory("src/test/resources/files/");
List files = fileService.fetchAllFiles();
- Assert.assertNotNull(files);
- Assert.assertEquals(1, files.size());
+ Assertions.assertNotNull(files);
+ Assertions.assertEquals(1, files.size());
}
@Test
public void testFetchAllFileWithoutFiles() {
fileService.setSourceDirectory("src/test/resources/files/dummy-directory/");
List files = fileService.fetchAllFiles();
- Assert.assertNotNull(files);
- Assert.assertEquals(0, files.size());
+ Assertions.assertNotNull(files);
+ Assertions.assertEquals(0, files.size());
}
}
diff --git a/src/mokka/src/test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceTest.java b/src/mokka/src/test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceTest.java
index badd670..51deb0a 100644
--- a/src/mokka/src/test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceTest.java
+++ b/src/mokka/src/test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceTest.java
@@ -1,51 +1,49 @@
package pl.hycom.mokka.service.impl;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import pl.hycom.mokka.AbstractTest;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.client.MockRestServiceServer;
+import pl.hycom.mokka.service.payment.DefaultPaymentStatusService;
import pl.hycom.mokka.service.payment.pojo.BlueMediaPayment;
-import pl.hycom.mokka.service.payment.PaymentStatusService;
-import javax.annotation.Resource;
-
-import static com.github.tomakehurst.wiremock.client.WireMock.*;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
+import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
/**
* @author Mariusz Krysztofowicz (mariusz.krysztofowicz@hycom.pl)
*/
-@Ignore
-public class DefaultPaymentStatusServiceTest extends AbstractTest {
+@Disabled
+public class DefaultPaymentStatusServiceTest{
- @Resource
- private PaymentStatusService paymentStatusService;
+ private DefaultPaymentStatusService defaultPaymentStatusService;
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(48080);
+ @Autowired
+ private MockRestServiceServer server;
- @Before
+ @BeforeEach
public void init() {
- wireMockRule.stubFor(post(urlPathMatching("/soap/webservice-http/payment")).willReturn(aResponse().withHeader("Content-Type", "text/plain")
- .withBody("OK")
- .withStatus(200)));
+ defaultPaymentStatusService = new DefaultPaymentStatusService();//new DefaultHashGenerator());
+ this.server.expect(requestTo("/soap/webservice-http/payment"))
+ .andRespond(withSuccess("OK", MediaType.TEXT_PLAIN));
}
@Test
- public void TestSuccess() {
- paymentStatusService.paymentStatusSuccessUpdate(createSampleBlueMediaPayment());
+ public void shouldSendSuccess() {
+ defaultPaymentStatusService.paymentStatusSuccessUpdate(createSampleBlueMediaPayment());
}
@Test
- public void TestPending() {
- paymentStatusService.paymentStatusPendingUpdate(createSampleBlueMediaPayment());
+ public void shouldSendPending() {
+ defaultPaymentStatusService.paymentStatusPendingUpdate(createSampleBlueMediaPayment());
}
@Test
- public void TestFailure() {
- paymentStatusService.paymentStatusFailureUpdate(createSampleBlueMediaPayment());
+ public void shouldSendFailure() {
+ defaultPaymentStatusService.paymentStatusFailureUpdate(createSampleBlueMediaPayment());
}
private BlueMediaPayment createSampleBlueMediaPayment() {
diff --git a/src/mokka/src/test/java/pl/hycom/mokka/ui/payment/PaymentControllerTest.java b/src/mokka/src/test/java/pl/hycom/mokka/ui/payment/PaymentControllerTest.java
index f497e79..c5f583d 100644
--- a/src/mokka/src/test/java/pl/hycom/mokka/ui/payment/PaymentControllerTest.java
+++ b/src/mokka/src/test/java/pl/hycom/mokka/ui/payment/PaymentControllerTest.java
@@ -1,7 +1,10 @@
package pl.hycom.mokka.ui.payment;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
-import org.junit.*;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.springframework.ui.ExtendedModelMap;
import org.springframework.ui.Model;
import pl.hycom.mokka.AbstractTest;
@@ -14,7 +17,7 @@
/**
* @author Jakub Muras
*/
-@Ignore
+@Disabled
public class PaymentControllerTest extends AbstractTest{
private static final String REDIRECT = "redirect:";
private static final String ORDER_ID = "&OrderID=";
@@ -22,65 +25,67 @@ public class PaymentControllerTest extends AbstractTest{
private static final String SERVICE_ID = "?ServiceID=";
@Resource
private PaymentController paymentController;
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(48080);
- @Before
+// TODO
+// @Rule
+// public WireMockRule wireMockRule = new WireMockRule(48080);
+
+ @BeforeEach
public void init() {
- wireMockRule.stubFor(post(urlPathMatching("/soap/webservice-http/payment")).willReturn(aResponse().withHeader("Content-Type", "text/plain")
- .withBody("OK")
- .withStatus(200)));
+// wireMockRule.stubFor(post(urlPathMatching("/soap/webservice-http/payment")).willReturn(aResponse().withHeader("Content-Type", "text/plain")
+// .withBody("OK")
+// .withStatus(200)));
}
@Test
public void testGet(){
Model model = new ExtendedModelMap();
paymentController.get(" ", " ", "0.0","", "a", "asd", model);
- Assert.assertNotNull(model.asMap().get("ServiceIDerror"));
- Assert.assertEquals(PaymentController.SERVICE_ID_EMPTY, model.asMap().get("ServiceIDerror"));
- Assert.assertNotNull(model.asMap().get("OrderIDerror"));
- Assert.assertEquals(PaymentController.ORDER_ID_CANNOT_BE_EMPTY, model.asMap().get("OrderIDerror"));
- Assert.assertNotNull(model.asMap().get("Emailerror"));
+ Assertions.assertNotNull(model.asMap().get("ServiceIDerror"));
+ Assertions.assertEquals(PaymentController.SERVICE_ID_EMPTY, model.asMap().get("ServiceIDerror"));
+ Assertions.assertNotNull(model.asMap().get("OrderIDerror"));
+ Assertions.assertEquals(PaymentController.ORDER_ID_CANNOT_BE_EMPTY, model.asMap().get("OrderIDerror"));
+ Assertions.assertNotNull(model.asMap().get("Emailerror"));
model = new ExtendedModelMap();
paymentController.get("12312312311", "123123123111231231231112312312311", "-10.0","", "a" ,"asd", model);
- Assert.assertEquals(PaymentController.SERVICE_ID_TOO_LONG_MAXIMUM_10_SIGNS, model.asMap().get("ServiceIDerror"));
- Assert.assertNotNull(model.asMap().get("OrderIDerror"));
- Assert.assertEquals(PaymentController.ORDER_ID_TOO_LONG_MAXIMUM_32_SIGNS, model.asMap().get("OrderIDerror"));
+ Assertions.assertEquals(PaymentController.SERVICE_ID_TOO_LONG_MAXIMUM_10_SIGNS, model.asMap().get("ServiceIDerror"));
+ Assertions.assertNotNull(model.asMap().get("OrderIDerror"));
+ Assertions.assertEquals(PaymentController.ORDER_ID_TOO_LONG_MAXIMUM_32_SIGNS, model.asMap().get("OrderIDerror"));
paymentController.get("1231s2311", "1231231+=1231231231112312312311", "-10.0", "", "a","", model);
- Assert.assertEquals(PaymentController.ONLY_INTEGERS_ARE_ALLOWED, model.asMap().get("ServiceIDerror"));
- Assert.assertEquals(PaymentController.ONLY_ALFANUMERIC_SIGNS_ARE_ALLOWED, model.asMap().get("OrderIDerror"));
- Assert.assertEquals(PaymentController.HASH_COULDNT_BE_NULL, model.asMap().get("Hasherror"));
+ Assertions.assertEquals(PaymentController.ONLY_INTEGERS_ARE_ALLOWED, model.asMap().get("ServiceIDerror"));
+ Assertions.assertEquals(PaymentController.ONLY_ALFANUMERIC_SIGNS_ARE_ALLOWED, model.asMap().get("OrderIDerror"));
+ Assertions.assertEquals(PaymentController.HASH_COULDNT_BE_NULL, model.asMap().get("Hasherror"));
model = new ExtendedModelMap();
paymentController.get("123123111", "1231231231112231231112312312311", "-10.0","", "as@as.as", "asd", model);
- Assert.assertNull(model.asMap().get("ServiceIDerror"));
- Assert.assertNull(model.asMap().get("OrderIDerror"));
- Assert.assertNull(model.asMap().get("Emailerror"));
+ Assertions.assertNull(model.asMap().get("ServiceIDerror"));
+ Assertions.assertNull(model.asMap().get("OrderIDerror"));
+ Assertions.assertNull(model.asMap().get("Emailerror"));
paymentController.get(null, null, "0.0", "","a", null, model);
- Assert.assertNotNull(model.asMap().get("ServiceIDerror"));
- Assert.assertEquals(PaymentController.SERVICE_ID_EMPTY, model.asMap().get("ServiceIDerror"));
- Assert.assertNotNull(model.asMap().get("OrderIDerror"));
- Assert.assertEquals(PaymentController.ORDER_ID_CANNOT_BE_EMPTY, model.asMap().get("OrderIDerror"));
- Assert.assertEquals(PaymentController.HASH_COULDNT_BE_NULL, model.asMap().get("Hasherror"));
- Assert.assertNotNull(model.asMap().get("Emailerror"));
+ Assertions.assertNotNull(model.asMap().get("ServiceIDerror"));
+ Assertions.assertEquals(PaymentController.SERVICE_ID_EMPTY, model.asMap().get("ServiceIDerror"));
+ Assertions.assertNotNull(model.asMap().get("OrderIDerror"));
+ Assertions.assertEquals(PaymentController.ORDER_ID_CANNOT_BE_EMPTY, model.asMap().get("OrderIDerror"));
+ Assertions.assertEquals(PaymentController.HASH_COULDNT_BE_NULL, model.asMap().get("Hasherror"));
+ Assertions.assertNotNull(model.asMap().get("Emailerror"));
}
@Test
public void testSuccessRedirect() {
BlueMediaPayment blueMediaPayment = createSampleBlueMediaPayment();
String result=paymentController.successRedirect(blueMediaPayment);
- Assert.assertEquals(redirectUrl(blueMediaPayment),result);
+ Assertions.assertEquals(redirectUrl(blueMediaPayment),result);
}
@Test
public void testPendingRedirect() {
String result=paymentController.pendingRedirect(createSampleBlueMediaPayment());
- Assert.assertEquals("OK",result);
+ Assertions.assertEquals("OK",result);
}
@Test
public void testErrorRedirect() {
BlueMediaPayment blueMediaPayment = createSampleBlueMediaPayment();
String result=paymentController.errorRedirect(blueMediaPayment);
- Assert.assertEquals(redirectUrl(blueMediaPayment),result);
+ Assertions.assertEquals(redirectUrl(blueMediaPayment),result);
}
private BlueMediaPayment createSampleBlueMediaPayment() {