diff --git a/simulator-starter/pom.xml b/simulator-starter/pom.xml
index a0e38c6d6..d07e0426c 100644
--- a/simulator-starter/pom.xml
+++ b/simulator-starter/pom.xml
@@ -150,11 +150,6 @@
spring-boot-starter-test
test
-
- org.testng
- testng
- test
-
diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/InboundXmlDataDictionaryTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/InboundXmlDataDictionaryTest.java
index 5a4ef412a..8dc2991d9 100644
--- a/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/InboundXmlDataDictionaryTest.java
+++ b/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/InboundXmlDataDictionaryTest.java
@@ -1,46 +1,55 @@
package org.citrusframework.simulator.dictionary;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.when;
-
-import org.mockito.Mockito;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
import org.citrusframework.context.TestContext;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
import org.citrusframework.simulator.config.SimulatorConfigurationProperties;
import org.citrusframework.util.SpringBeanTypeConverter;
import org.citrusframework.xml.namespace.NamespaceContextBuilder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
/**
* @author Christoph Deppisch
*/
-public class InboundXmlDataDictionaryTest {
+@ExtendWith(MockitoExtension.class)
+class InboundXmlDataDictionaryTest {
- private TestContext context = Mockito.mock(TestContext.class);
-
- private String input = String.format("%n" +
+ private static final String MESSAGE_INPUT = String.format("%n" +
" string%n" +
" 100%n" +
" true%n" +
" stringstri%n" +
"");
- @Test
- public void testInboundDictionary() throws Exception {
- InboundXmlDataDictionary dictionary = new InboundXmlDataDictionary(new SimulatorConfigurationProperties());
- dictionary.initialize();
+ @Mock
+ private TestContext testContextMock;
+
+ private InboundXmlDataDictionary fixture;
- when(context.getTypeConverter()).thenReturn(SpringBeanTypeConverter.INSTANCE);
- when(context.getNamespaceContextBuilder()).thenReturn(new NamespaceContextBuilder());
- when(context.replaceDynamicContentInString(anyString())).thenAnswer(invocation -> invocation.getArguments()[0]);
+ @BeforeEach
+ void beforEachSetup() {
+ fixture = new InboundXmlDataDictionary(new SimulatorConfigurationProperties());
+ fixture.initialize();
+ }
+
+ @Test
+ void testInboundDictionary() {
+ when(testContextMock.getTypeConverter()).thenReturn(SpringBeanTypeConverter.INSTANCE);
+ when(testContextMock.getNamespaceContextBuilder()).thenReturn(new NamespaceContextBuilder());
+ when(testContextMock.replaceDynamicContentInString(anyString())).thenAnswer(invocation -> invocation.getArguments()[0]);
- Message request = new DefaultMessage(input);
- Message translated = dictionary.transform(request, context);
+ Message request = new DefaultMessage(MESSAGE_INPUT);
+ Message translated = fixture.transform(request, testContextMock);
- Assert.assertEquals(translated.getPayload(String.class), String.format("" +
+ assertEquals(translated.getPayload(String.class), String.format("" +
"%n" +
" @ignore@%n" +
" @ignore@%n" +
diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/OutboundXmlDataDictionaryTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/OutboundXmlDataDictionaryTest.java
index c466f91e0..b56e73636 100644
--- a/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/OutboundXmlDataDictionaryTest.java
+++ b/simulator-starter/src/test/java/org/citrusframework/simulator/dictionary/OutboundXmlDataDictionaryTest.java
@@ -1,39 +1,49 @@
package org.citrusframework.simulator.dictionary;
import org.citrusframework.context.TestContext;
-import org.citrusframework.message.*;
+import org.citrusframework.message.DefaultMessage;
+import org.citrusframework.message.Message;
import org.citrusframework.simulator.config.SimulatorConfigurationProperties;
import org.citrusframework.util.XMLUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
-import org.mockito.Mockito;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.when;
/**
* @author Christoph Deppisch
*/
-public class OutboundXmlDataDictionaryTest {
+@ExtendWith(MockitoExtension.class)
+class OutboundXmlDataDictionaryTest {
- private TestContext context = Mockito.mock(TestContext.class);
+ private static final String MESSAGE_INPUT = String.format("%n" +
+ " string%n" +
+ " 100%n" +
+ " true%n" +
+ " stringstri%n" +
+ "");
- private String input = String.format("%n" +
- " string%n" +
- " 100%n" +
- " true%n" +
- " stringstri%n" +
- "");
+ @Mock
+ private TestContext testContextMock;
- @Test
- public void testInboundDictionary() {
- OutboundXmlDataDictionary dictionary = new OutboundXmlDataDictionary(new SimulatorConfigurationProperties());
+ private OutboundXmlDataDictionary fixture;
- when(context.replaceDynamicContentInString(anyString())).thenAnswer(invocation -> invocation.getArguments()[0]);
+ @BeforeEach
+ void beforeEachSetup() {
+ fixture = new OutboundXmlDataDictionary(new SimulatorConfigurationProperties());
+ }
- Message request = new DefaultMessage(input);
- Message translated = dictionary.transform(request, context);
+ @Test
+ void testInboundDictionary() {
+ when(testContextMock.replaceDynamicContentInString(anyString())).thenAnswer(invocation -> invocation.getArguments()[0]);
+
+ Message request = new DefaultMessage(MESSAGE_INPUT);
+ Message translated = fixture.transform(request, testContextMock);
String payload = XMLUtils.prettyPrint(translated.getPayload(String.class));
String controlPayload = XMLUtils.prettyPrint(String.format("" +
@@ -43,8 +53,7 @@ public void testInboundDictionary() {
" true%n" +
" citrus:randomString(10)%n" +
"%n"));
-
- Assert.assertEquals(payload, controlPayload);
- }
+ assertEquals(payload, controlPayload);
+ }
}
diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationMatcherTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationMatcherTest.java
index 55ebaf0ed..5e332a27f 100644
--- a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationMatcherTest.java
+++ b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationMatcherTest.java
@@ -4,13 +4,14 @@
import org.citrusframework.simulator.scenario.AbstractSimulatorScenario;
import org.citrusframework.simulator.scenario.Scenario;
import org.citrusframework.simulator.scenario.SimulatorScenario;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import org.testng.Assert;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
import java.util.Collection;
import java.util.Collections;
@@ -18,11 +19,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
-public class HttpRequestAnnotationMatcherTest {
-
- HttpRequestAnnotationMatcher cut = HttpRequestAnnotationMatcher.instance();
+class HttpRequestAnnotationMatcherTest {
private static final RequestMapping REQ_MAP_WITH_PATH_NAME = getRequestMapping(new ScenarioWithPathName());
private static final RequestMapping REQ_MAP_WITH_PATH_VALUE = getRequestMapping(new ScenarioWithPathValue());
@@ -32,192 +32,194 @@ public class HttpRequestAnnotationMatcherTest {
private static final RequestMapping REQ_MAP_WITH_QUERY_PARAMS = getRequestMapping(new ScenarioWithQueryParams());
private static final RequestMapping REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS = getRequestMapping(new ScenarioWithAllSupportedRestrictions());
- @DataProvider
- public Object[][] dpScenarios() {
- return new Object[][]{
- new Object[]{
+ HttpRequestAnnotationMatcher fixture;
+
+ @BeforeEach
+ void beforeEachSetup() {
+ fixture = HttpRequestAnnotationMatcher.instance();
+ }
+
+ static Stream checkRequestPathSupported() {
+ return Stream.of(
+ Arguments.of(
REQ_MAP_WITH_PATH_NAME,
setupHttpMessage("/path/name", RequestMethod.GET, Collections.emptyMap()),
true,
true
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_NAME,
setupHttpMessage("/path/name", RequestMethod.GET, Collections.emptyMap()),
false,
true
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_NAME,
setupHttpMessage("/path/wrong-path", RequestMethod.GET, Collections.emptyMap()),
true,
false
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_NAME,
setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()),
true,
false
- },
-
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_VALUE,
setupHttpMessage("/path/value", RequestMethod.GET, Collections.emptyMap()),
true,
true
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_VALUE,
setupHttpMessage("/path/wrong-path", RequestMethod.GET, Collections.emptyMap()),
true,
false
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_VALUE,
setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()),
true,
false
- },
-
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_PLACEHOLDER,
setupHttpMessage("/path/place-holder/123", RequestMethod.GET, Collections.emptyMap()),
false,
true
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_PLACEHOLDER,
setupHttpMessage("/path/place-holder/123", RequestMethod.GET, Collections.emptyMap()),
true,
false
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_PLACEHOLDER,
setupHttpMessage("/path/wrong-path", RequestMethod.GET, Collections.emptyMap()),
true,
false
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_PLACEHOLDER,
setupHttpMessage("/path/wrong-path", RequestMethod.GET, Collections.emptyMap()),
false,
false
- },
-
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_PATTERN,
setupHttpMessage("/path/pattern/match-me", RequestMethod.GET, Collections.emptyMap()),
true,
false
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_PATTERN,
setupHttpMessage("/path/pattern/match-me", RequestMethod.GET, Collections.emptyMap()),
false,
true
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_PATTERN,
setupHttpMessage("/path/wrong-pattern", RequestMethod.GET, Collections.emptyMap()),
true,
false
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_PATTERN,
setupHttpMessage("/path/wrong-pattern", RequestMethod.GET, Collections.emptyMap()),
false,
false
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_PATTERN,
setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()),
true,
false
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PATH_PATTERN,
setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()),
false,
false
- },
-
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PUT_METHOD,
setupHttpMessage("/any-path", RequestMethod.PUT, Collections.emptyMap()),
true,
true
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_PUT_METHOD,
setupHttpMessage("", RequestMethod.GET, Collections.emptyMap()),
true,
false
- },
-
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_QUERY_PARAMS,
setupHttpMessage("/any-path", RequestMethod.GET, Collections.singletonMap("a", Collections.singleton("1"))),
true,
true
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_QUERY_PARAMS,
setupHttpMessage("/any-path", RequestMethod.GET, Collections.singletonMap("a", Collections.emptySet())),
true,
true
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_QUERY_PARAMS,
setupHttpMessage("/any-path", RequestMethod.GET, Stream.of("a=1","b=2").map(item -> item.split("=")).collect(Collectors.toMap(keyValuePair -> keyValuePair[0], keyValuePair -> Collections.singleton(keyValuePair[1])))),
true,
false
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_QUERY_PARAMS,
setupHttpMessage("/any-path", RequestMethod.GET, Collections.singletonMap("c", Collections.singleton("3"))),
true,
false
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_QUERY_PARAMS,
setupHttpMessage("/any-path", RequestMethod.GET, Collections.emptyMap()),
true,
false
- },
+ ),
- new Object[]{
+ Arguments.of(
REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS,
setupHttpMessage("/path/value", RequestMethod.GET, Collections.singletonMap("a", Collections.singleton("1"))),
true,
true
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS,
setupHttpMessage("/wrong-path", RequestMethod.GET, Collections.singletonMap("a", Collections.singleton("1"))),
true,
false
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS,
setupHttpMessage("/path/value", RequestMethod.PUT, Collections.singletonMap("a", Collections.singleton("1"))),
true,
false
- },
- new Object[]{
+ ),
+ Arguments.of(
REQ_MAP_WITH_ALL_SUPPORTED_RESTRICTIONS,
setupHttpMessage("/path/value", RequestMethod.GET, Collections.emptyMap()),
true,
false
- },
- };
+ )
+ );
}
- @Test(dataProvider = "dpScenarios")
- public void testCheckRequestSupported(RequestMapping requestMapping, HttpMessage httpMessage, boolean exactMatch, boolean expectedResult) throws Exception {
- boolean actual = cut.checkRequestPathSupported(httpMessage, requestMapping, exactMatch)
- && cut.checkRequestMethodSupported(httpMessage, requestMapping)
- && cut.checkRequestQueryParamsSupported(httpMessage, requestMapping);
- Assert.assertEquals(actual, expectedResult);
+ @MethodSource
+ @ParameterizedTest
+ void checkRequestPathSupported(RequestMapping requestMapping, HttpMessage httpMessage, boolean exactMatch, boolean expectedResult) throws Exception {
+ boolean actual = fixture.checkRequestPathSupported(httpMessage, requestMapping, exactMatch)
+ && fixture.checkRequestMethodSupported(httpMessage, requestMapping)
+ && fixture.checkRequestQueryParamsSupported(httpMessage, requestMapping);
+ assertEquals(actual, expectedResult);
}
@Scenario("ScenarioWithPathName")
@@ -259,7 +261,7 @@ private static RequestMapping getRequestMapping(SimulatorScenario scenario) {
return AnnotationUtils.findAnnotation(scenario.getClass(), RequestMapping.class);
}
- private HttpMessage setupHttpMessage(String path, RequestMethod method, Map> queryParams) {
+ private static HttpMessage setupHttpMessage(String path, RequestMethod method, Map> queryParams) {
final HttpMessage httpMessage = Mockito.mock(HttpMessage.class);
when(httpMessage.getPath()).thenReturn(path);
when(httpMessage.getRequestMethod()).thenReturn(method);
diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationScenarioMapperTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationScenarioMapperTest.java
index 77369f74e..3b9590912 100644
--- a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationScenarioMapperTest.java
+++ b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestAnnotationScenarioMapperTest.java
@@ -1,64 +1,67 @@
package org.citrusframework.simulator.http;
-import java.util.Arrays;
-
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.http.message.HttpMessage;
import org.citrusframework.simulator.config.SimulatorConfigurationProperties;
import org.citrusframework.simulator.scenario.AbstractSimulatorScenario;
import org.citrusframework.simulator.scenario.Scenario;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;
/**
* @author Christoph Deppisch
*/
-public class HttpRequestAnnotationScenarioMapperTest {
-
- private final HttpRequestAnnotationScenarioMapper scenarioMapper = new HttpRequestAnnotationScenarioMapper();
+@ExtendWith(MockitoExtension.class)
+class HttpRequestAnnotationScenarioMapperTest {
@Mock
private SimulatorConfigurationProperties simulatorConfiguration;
- @BeforeClass
- public void setup() {
- MockitoAnnotations.initMocks(this);
- scenarioMapper.setConfiguration(simulatorConfiguration);
+ private HttpRequestAnnotationScenarioMapper fixture;
+
+ @BeforeEach
+ void beforeEachSetup() {
+ fixture = new HttpRequestAnnotationScenarioMapper();
+ fixture.setConfiguration(simulatorConfiguration);
when(simulatorConfiguration.getDefaultScenario()).thenReturn("default");
}
@Test
- public void testGetMappingKey() {
- scenarioMapper.setScenarioList(Arrays.asList(new IssueScenario(),
+ void testGetMappingKey() {
+ fixture.setScenarioList(Arrays.asList(new IssueScenario(),
new FooScenario(),
new GetFooScenario(),
new PutFooScenario(),
new OtherScenario()));
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/foo")), "FooScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/foo").method(HttpMethod.GET)), "GetFooScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/foo").method(HttpMethod.PUT)), "PutFooScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/other")), "OtherScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.GET)), "IssueScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.DELETE)), "IssueScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.PUT)), "default");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar")), "default");
- Assert.assertEquals(scenarioMapper.getMappingKey(null), "default");
-
- scenarioMapper.setUseDefaultMapping(false);
-
- Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.PUT)));
- Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar")));
- Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(null));
+ assertEquals(fixture.getMappingKey(new HttpMessage().path("/issues/foo")), "FooScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().path("/issues/foo").method(HttpMethod.GET)), "GetFooScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().path("/issues/foo").method(HttpMethod.PUT)), "PutFooScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().path("/issues/other")), "OtherScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.GET)), "IssueScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.DELETE)), "IssueScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.PUT)), "default");
+ assertEquals(fixture.getMappingKey(new HttpMessage().path("/issues/bar")), "default");
+ assertEquals(fixture.getMappingKey(null), "default");
+
+ fixture.setUseDefaultMapping(false);
+
+ assertThrows(CitrusRuntimeException.class, () -> fixture.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.PUT)));
+ assertThrows(CitrusRuntimeException.class, () -> fixture.getMappingKey(new HttpMessage().path("/issues/bar")));
+ assertThrows(CitrusRuntimeException.class, () -> fixture.getMappingKey(null));
}
@Scenario("FooScenario")
diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestPathScenarioMapperTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestPathScenarioMapperTest.java
index e9ae5f50d..524a1dc69 100644
--- a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestPathScenarioMapperTest.java
+++ b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpRequestPathScenarioMapperTest.java
@@ -1,45 +1,49 @@
package org.citrusframework.simulator.http;
-import java.util.Arrays;
-import java.util.Collections;
-
+import io.swagger.models.Operation;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.http.message.HttpMessage;
import org.citrusframework.simulator.config.SimulatorConfigurationProperties;
-import io.swagger.models.Operation;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMethod;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;
/**
* @author Christoph Deppisch
*/
-public class HttpRequestPathScenarioMapperTest {
- private HttpRequestPathScenarioMapper scenarioMapper = new HttpRequestPathScenarioMapper();
+@ExtendWith(MockitoExtension.class)
+class HttpRequestPathScenarioMapperTest {
@Mock
- private SimulatorConfigurationProperties simulatorConfiguration;
+ private SimulatorConfigurationProperties simulatorConfigurationMock;
+
+ private HttpRequestPathScenarioMapper fixture;
- @BeforeClass
- public void setup() {
- MockitoAnnotations.initMocks(this);
- scenarioMapper.setConfiguration(simulatorConfiguration);
+ @BeforeEach
+ void beforeEachSetup() {
+ fixture = new HttpRequestPathScenarioMapper();
+ fixture.setConfiguration(simulatorConfigurationMock);
- when(simulatorConfiguration.getDefaultScenario()).thenReturn("default");
+ when(simulatorConfigurationMock.getDefaultScenario()).thenReturn("default");
}
@Test
- public void testGetMappingKey() {
+ void testGetMappingKey() {
Operation operation = Mockito.mock(Operation.class);
- scenarioMapper.setScenarioList(Arrays.asList(new HttpOperationScenario("/issues/foos", RequestMethod.GET, operation, Collections.emptyMap()),
+ fixture.setScenarioList(Arrays.asList(new HttpOperationScenario("/issues/foos", RequestMethod.GET, operation, Collections.emptyMap()),
new HttpOperationScenario("/issues/foos", RequestMethod.POST, operation, Collections.emptyMap()),
new HttpOperationScenario("/issues/foo/{id}", RequestMethod.GET, operation, Collections.emptyMap()),
new HttpOperationScenario("/issues/foo/detail", RequestMethod.GET, operation, Collections.emptyMap()),
@@ -56,23 +60,23 @@ public void testGetMappingKey() {
.thenReturn("fooDetailScenario")
.thenReturn("barDetailScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET)), "default");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.POST)), "default");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues")), "default");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/foos")), "fooListScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.POST).path("/issues/foos")), "fooListPostScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.PUT).path("/issues/foos")), "default");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/bars")), "barListScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.DELETE).path("/issues/bars")), "default");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/foo/1")), "fooScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/bar/1")), "barScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/foo/detail")), "fooDetailScenario");
- Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/bar/detail")), "barDetailScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.GET)), "default");
+ assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.POST)), "default");
+ assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues")), "default");
+ assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/foos")), "fooListScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.POST).path("/issues/foos")), "fooListPostScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.PUT).path("/issues/foos")), "default");
+ assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/bars")), "barListScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.DELETE).path("/issues/bars")), "default");
+ assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/foo/1")), "fooScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/bar/1")), "barScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/foo/detail")), "fooDetailScenario");
+ assertEquals(fixture.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/bar/detail")), "barDetailScenario");
- scenarioMapper.setUseDefaultMapping(false);
+ fixture.setUseDefaultMapping(false);
- Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET)));
- Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues")));
+ assertThrows(CitrusRuntimeException.class, () -> fixture.getMappingKey(new HttpMessage().method(HttpMethod.GET)));
+ assertThrows(CitrusRuntimeException.class, () -> fixture.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues")));
}
}
diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpScenarioGeneratorTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpScenarioGeneratorTest.java
index 94f5b6844..f93147d31 100644
--- a/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpScenarioGeneratorTest.java
+++ b/simulator-starter/src/test/java/org/citrusframework/simulator/http/HttpScenarioGeneratorTest.java
@@ -1,177 +1,174 @@
package org.citrusframework.simulator.http;
import io.swagger.models.Operation;
-import org.mockito.Mockito;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.RequestMethod;
-import org.testng.Assert;
-import org.testng.annotations.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* @author Christoph Deppisch
*/
-public class HttpScenarioGeneratorTest {
+@ExtendWith(MockitoExtension.class)
+class HttpScenarioGeneratorTest {
- private final ConfigurableListableBeanFactory beanFactory = Mockito.mock(ConfigurableListableBeanFactory.class);
- private final DefaultListableBeanFactory beanRegistry = Mockito.mock(DefaultListableBeanFactory.class);
+ @Mock
+ private ConfigurableListableBeanFactory beanFactoryMock;
- @Test
- public void testGenerateScenarios() {
- HttpScenarioGenerator scenarioGenerator = new HttpScenarioGenerator(new ClassPathResource("swagger/swagger-api.json"));
+ @Mock
+ private DefaultListableBeanFactory beanRegistryMock;
+
+ private HttpScenarioGenerator fixture;
- reset(beanFactory);
+ @BeforeEach
+ void beforeEachSetup() {
+ fixture = new HttpScenarioGenerator(new ClassPathResource("swagger/swagger-api.json"));
+ }
+ @Test
+ void generateHttpScenarios() {
doAnswer(invocation -> {
HttpOperationScenario scenario = (HttpOperationScenario) invocation.getArguments()[1];
- Assert.assertNotNull(scenario.getOperation());
- Assert.assertEquals(scenario.getPath(), "/v2/pet");
- Assert.assertEquals(scenario.getMethod(), RequestMethod.POST);
+ assertNotNull(scenario.getOperation());
+ assertEquals(scenario.getPath(), "/v2/pet");
+ assertEquals(scenario.getMethod(), RequestMethod.POST);
return null;
- }).when(beanFactory).registerSingleton(eq("addPet"), any(HttpOperationScenario.class));
+ }).when(beanFactoryMock).registerSingleton(eq("addPet"), any(HttpOperationScenario.class));
doAnswer(invocation -> {
HttpOperationScenario scenario = (HttpOperationScenario) invocation.getArguments()[1];
- Assert.assertNotNull(scenario.getOperation());
- Assert.assertEquals(scenario.getPath(), "/v2/pet/{petId}");
- Assert.assertEquals(scenario.getMethod(), RequestMethod.GET);
+ assertNotNull(scenario.getOperation());
+ assertEquals(scenario.getPath(), "/v2/pet/{petId}");
+ assertEquals(scenario.getMethod(), RequestMethod.GET);
return null;
- }).when(beanFactory).registerSingleton(eq("getPetById"), any(HttpOperationScenario.class));
+ }).when(beanFactoryMock).registerSingleton(eq("getPetById"), any(HttpOperationScenario.class));
doAnswer(invocation -> {
HttpOperationScenario scenario = (HttpOperationScenario) invocation.getArguments()[1];
- Assert.assertNotNull(scenario.getOperation());
- Assert.assertEquals(scenario.getPath(), "/v2/pet/{petId}");
- Assert.assertEquals(scenario.getMethod(), RequestMethod.DELETE);
+ assertNotNull(scenario.getOperation());
+ assertEquals(scenario.getPath(), "/v2/pet/{petId}");
+ assertEquals(scenario.getMethod(), RequestMethod.DELETE);
return null;
- }).when(beanFactory).registerSingleton(eq("deletePet"), any(HttpOperationScenario.class));
+ }).when(beanFactoryMock).registerSingleton(eq("deletePet"), any(HttpOperationScenario.class));
- scenarioGenerator.postProcessBeanFactory(beanFactory);
+ fixture.postProcessBeanFactory(beanFactoryMock);
- verify(beanFactory).registerSingleton(eq("addPet"), any(HttpOperationScenario.class));
- verify(beanFactory).registerSingleton(eq("getPetById"), any(HttpOperationScenario.class));
- verify(beanFactory).registerSingleton(eq("deletePet"), any(HttpOperationScenario.class));
+ verify(beanFactoryMock).registerSingleton(eq("addPet"), any(HttpOperationScenario.class));
+ verify(beanFactoryMock).registerSingleton(eq("getPetById"), any(HttpOperationScenario.class));
+ verify(beanFactoryMock).registerSingleton(eq("deletePet"), any(HttpOperationScenario.class));
}
@Test
- public void testGenerateScenariosWithBeandDefinitionRegistry() {
- HttpScenarioGenerator scenarioGenerator = new HttpScenarioGenerator(new ClassPathResource("swagger/swagger-api.json"));
-
- reset(beanRegistry);
-
+ void testGenerateScenariosWithBeandDefinitionRegistry() {
doAnswer(invocation -> {
BeanDefinition scenario = (BeanDefinition) invocation.getArguments()[1];
- Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet");
- Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, RequestMethod.class).getValue(), RequestMethod.POST);
- Assert.assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue());
- Assert.assertNull(scenario.getPropertyValues().get("inboundDataDictionary"));
- Assert.assertNull(scenario.getPropertyValues().get("outboundDataDictionary"));
+ assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet");
+ assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, RequestMethod.class).getValue(), RequestMethod.POST);
+ assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue());
+ assertNull(scenario.getPropertyValues().get("inboundDataDictionary"));
+ assertNull(scenario.getPropertyValues().get("outboundDataDictionary"));
return null;
- }).when(beanRegistry).registerBeanDefinition(eq("addPet"), any(BeanDefinition.class));
+ }).when(beanRegistryMock).registerBeanDefinition(eq("addPet"), any(BeanDefinition.class));
doAnswer(invocation -> {
BeanDefinition scenario = (BeanDefinition) invocation.getArguments()[1];
- Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet/{petId}");
- Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, RequestMethod.class).getValue(), RequestMethod.GET);
- Assert.assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue());
- Assert.assertNull(scenario.getPropertyValues().get("inboundDataDictionary"));
- Assert.assertNull(scenario.getPropertyValues().get("outboundDataDictionary"));
+ assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet/{petId}");
+ assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, RequestMethod.class).getValue(), RequestMethod.GET);
+ assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue());
+ assertNull(scenario.getPropertyValues().get("inboundDataDictionary"));
+ assertNull(scenario.getPropertyValues().get("outboundDataDictionary"));
return null;
- }).when(beanRegistry).registerBeanDefinition(eq("getPetById"), any(BeanDefinition.class));
+ }).when(beanRegistryMock).registerBeanDefinition(eq("getPetById"), any(BeanDefinition.class));
doAnswer(invocation -> {
BeanDefinition scenario = (BeanDefinition) invocation.getArguments()[1];
- Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet/{petId}");
- Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, RequestMethod.class).getValue(), RequestMethod.DELETE);
- Assert.assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue());
- Assert.assertNull(scenario.getPropertyValues().get("inboundDataDictionary"));
- Assert.assertNull(scenario.getPropertyValues().get("outboundDataDictionary"));
+ assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet/{petId}");
+ assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, RequestMethod.class).getValue(), RequestMethod.DELETE);
+ assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue());
+ assertNull(scenario.getPropertyValues().get("inboundDataDictionary"));
+ assertNull(scenario.getPropertyValues().get("outboundDataDictionary"));
return null;
- }).when(beanRegistry).registerBeanDefinition(eq("deletePet"), any(BeanDefinition.class));
+ }).when(beanRegistryMock).registerBeanDefinition(eq("deletePet"), any(BeanDefinition.class));
- scenarioGenerator.postProcessBeanFactory(beanRegistry);
+ fixture.postProcessBeanFactory(beanRegistryMock);
- verify(beanRegistry).registerBeanDefinition(eq("addPet"), any(BeanDefinition.class));
- verify(beanRegistry).registerBeanDefinition(eq("getPetById"), any(BeanDefinition.class));
- verify(beanRegistry).registerBeanDefinition(eq("deletePet"), any(BeanDefinition.class));
+ verify(beanRegistryMock).registerBeanDefinition(eq("addPet"), any(BeanDefinition.class));
+ verify(beanRegistryMock).registerBeanDefinition(eq("getPetById"), any(BeanDefinition.class));
+ verify(beanRegistryMock).registerBeanDefinition(eq("deletePet"), any(BeanDefinition.class));
}
@Test
- public void testGenerateScenariosWithDataDictionaries() {
- HttpScenarioGenerator scenarioGenerator = new HttpScenarioGenerator(new ClassPathResource("swagger/swagger-api.json"));
-
- reset(beanRegistry);
-
- BeanDefinition inboundJsonDataDictionary = Mockito.mock(BeanDefinition.class);
- BeanDefinition outboundJsonDataDictionary = Mockito.mock(BeanDefinition.class);
-
- when(beanRegistry.containsBeanDefinition("inboundJsonDataDictionary")).thenReturn(true);
- when(beanRegistry.containsBeanDefinition("outboundJsonDataDictionary")).thenReturn(true);
-
- when(beanRegistry.getBeanDefinition("inboundJsonDataDictionary")).thenReturn(inboundJsonDataDictionary);
- when(beanRegistry.getBeanDefinition("outboundJsonDataDictionary")).thenReturn(outboundJsonDataDictionary);
+ void testGenerateScenariosWithDataDictionaries() {
+ when(beanRegistryMock.containsBeanDefinition("inboundJsonDataDictionary")).thenReturn(true);
+ when(beanRegistryMock.containsBeanDefinition("outboundJsonDataDictionary")).thenReturn(true);
doAnswer(invocation -> {
BeanDefinition scenario = (BeanDefinition) invocation.getArguments()[1];
- Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet");
- Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, RequestMethod.class).getValue(), RequestMethod.POST);
- Assert.assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue());
- Assert.assertNotNull(scenario.getPropertyValues().get("inboundDataDictionary"));
- Assert.assertNotNull(scenario.getPropertyValues().get("outboundDataDictionary"));
+ assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet");
+ assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, RequestMethod.class).getValue(), RequestMethod.POST);
+ assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue());
+ assertNotNull(scenario.getPropertyValues().get("inboundDataDictionary"));
+ assertNotNull(scenario.getPropertyValues().get("outboundDataDictionary"));
return null;
- }).when(beanRegistry).registerBeanDefinition(eq("addPet"), any(BeanDefinition.class));
+ }).when(beanRegistryMock).registerBeanDefinition(eq("addPet"), any(BeanDefinition.class));
doAnswer(invocation -> {
BeanDefinition scenario = (BeanDefinition) invocation.getArguments()[1];
- Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet/{petId}");
- Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, RequestMethod.class).getValue(), RequestMethod.GET);
- Assert.assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue());
- Assert.assertNotNull(scenario.getPropertyValues().get("inboundDataDictionary"));
- Assert.assertNotNull(scenario.getPropertyValues().get("outboundDataDictionary"));
+ assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet/{petId}");
+ assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, RequestMethod.class).getValue(), RequestMethod.GET);
+ assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue());
+ assertNotNull(scenario.getPropertyValues().get("inboundDataDictionary"));
+ assertNotNull(scenario.getPropertyValues().get("outboundDataDictionary"));
return null;
- }).when(beanRegistry).registerBeanDefinition(eq("getPetById"), any(BeanDefinition.class));
+ }).when(beanRegistryMock).registerBeanDefinition(eq("getPetById"), any(BeanDefinition.class));
doAnswer(invocation -> {
BeanDefinition scenario = (BeanDefinition) invocation.getArguments()[1];
- Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet/{petId}");
- Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, RequestMethod.class).getValue(), RequestMethod.DELETE);
- Assert.assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue());
- Assert.assertNotNull(scenario.getPropertyValues().get("inboundDataDictionary"));
- Assert.assertNotNull(scenario.getPropertyValues().get("outboundDataDictionary"));
+ assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet/{petId}");
+ assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, RequestMethod.class).getValue(), RequestMethod.DELETE);
+ assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue());
+ assertNotNull(scenario.getPropertyValues().get("inboundDataDictionary"));
+ assertNotNull(scenario.getPropertyValues().get("outboundDataDictionary"));
return null;
- }).when(beanRegistry).registerBeanDefinition(eq("deletePet"), any(BeanDefinition.class));
+ }).when(beanRegistryMock).registerBeanDefinition(eq("deletePet"), any(BeanDefinition.class));
- scenarioGenerator.postProcessBeanFactory(beanRegistry);
+ fixture.postProcessBeanFactory(beanRegistryMock);
- verify(beanRegistry).registerBeanDefinition(eq("addPet"), any(BeanDefinition.class));
- verify(beanRegistry).registerBeanDefinition(eq("getPetById"), any(BeanDefinition.class));
- verify(beanRegistry).registerBeanDefinition(eq("deletePet"), any(BeanDefinition.class));
+ verify(beanRegistryMock).registerBeanDefinition(eq("addPet"), any(BeanDefinition.class));
+ verify(beanRegistryMock).registerBeanDefinition(eq("getPetById"), any(BeanDefinition.class));
+ verify(beanRegistryMock).registerBeanDefinition(eq("deletePet"), any(BeanDefinition.class));
}
}
diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/http/SimulatorHttpMessageConverterTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/http/SimulatorHttpMessageConverterTest.java
index a9fd4e3fa..ff9ab0e1f 100644
--- a/simulator-starter/src/test/java/org/citrusframework/simulator/http/SimulatorHttpMessageConverterTest.java
+++ b/simulator-starter/src/test/java/org/citrusframework/simulator/http/SimulatorHttpMessageConverterTest.java
@@ -1,45 +1,53 @@
package org.citrusframework.simulator.http;
-import java.io.IOException;
-import java.nio.charset.Charset;
-
import org.citrusframework.http.controller.HttpMessageController;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.mock.http.MockHttpInputMessage;
import org.springframework.mock.http.MockHttpOutputMessage;
-import org.testng.Assert;
-import org.testng.annotations.Test;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* @author Christoph Deppisch
*/
-public class SimulatorHttpMessageConverterTest {
+class SimulatorHttpMessageConverterTest {
- private SimulatorHttpMessageConverter converter = new SimulatorHttpMessageConverter();
+ private SimulatorHttpMessageConverter fixture;
+
+ @BeforeEach
+ void beforeEachSetup() {
+ fixture = new SimulatorHttpMessageConverter();
+ }
@Test
- public void testSimulatorMessageConverter() throws IOException {
- Assert.assertFalse(converter.canRead(Object.class, Object.class, MediaType.ALL));
- Assert.assertFalse(converter.canRead(Object.class, MediaType.ALL));
- Assert.assertFalse(converter.canWrite(Object.class, Object.class, MediaType.ALL));
- Assert.assertFalse(converter.canWrite(Object.class, MediaType.ALL));
+ void testSimulatorMessageConverter() throws IOException {
+ assertFalse(fixture.canRead(Object.class, Object.class, MediaType.ALL));
+ assertFalse(fixture.canRead(Object.class, MediaType.ALL));
+ assertFalse(fixture.canWrite(Object.class, Object.class, MediaType.ALL));
+ assertFalse(fixture.canWrite(Object.class, MediaType.ALL));
- Assert.assertEquals(converter.read(String.class, HttpMessageController.class, new MockHttpInputMessage("Hello".getBytes(Charset.forName("UTF-8")))), "Hello");
+ assertEquals(fixture.read(String.class, HttpMessageController.class, new MockHttpInputMessage("Hello".getBytes(StandardCharsets.UTF_8))), "Hello");
}
- @Test(expectedExceptions = IllegalStateException.class)
- public void testUnsupportedRead() throws IOException {
- converter.read(Object.class, new MockHttpInputMessage("Hello".getBytes(Charset.forName("UTF-8"))));
+ @Test
+ void testUnsupportedRead() {
+ assertThrows(IllegalStateException.class, () -> fixture.read(Object.class, new MockHttpInputMessage("Hello".getBytes(StandardCharsets.UTF_8))));
}
- @Test(expectedExceptions = IllegalStateException.class)
- public void testUnsupportedWrite() {
- converter.write("Hello", MediaType.TEXT_PLAIN, new MockHttpOutputMessage());
+ @Test
+ void testUnsupportedWrite() {
+ assertThrows(IllegalStateException.class, () -> fixture.write("Hello", MediaType.TEXT_PLAIN, new MockHttpOutputMessage()));
}
- @Test(expectedExceptions = IllegalStateException.class)
- public void testUnsupportedGenericWrite() {
- converter.write("Hello", String.class, MediaType.TEXT_PLAIN, new MockHttpOutputMessage());
+ @Test
+ void testUnsupportedGenericWrite() {
+ assertThrows(IllegalStateException.class, () -> fixture.write("Hello", String.class, MediaType.TEXT_PLAIN, new MockHttpOutputMessage()));
}
-
}
diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/scenario/mapper/ScenarioMappersTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/scenario/mapper/ScenarioMappersTest.java
index b0d3c7e80..94a1eea5e 100644
--- a/simulator-starter/src/test/java/org/citrusframework/simulator/scenario/mapper/ScenarioMappersTest.java
+++ b/simulator-starter/src/test/java/org/citrusframework/simulator/scenario/mapper/ScenarioMappersTest.java
@@ -28,21 +28,23 @@
import org.citrusframework.simulator.http.HttpRequestPathScenarioMapper;
import org.citrusframework.simulator.scenario.AbstractSimulatorScenario;
import org.citrusframework.simulator.scenario.Scenario;
+import org.junit.jupiter.api.Test;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import org.testng.Assert;
-import org.testng.annotations.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* @author Christoph Deppisch
*/
-public class ScenarioMappersTest {
+class ScenarioMappersTest {
private static final String DEFAULT_SCENARIO = "default";
@Test
- public void testMappingChain() throws Exception {
+ void testMappingChain() throws Exception {
ScenarioMappers mapperChain = ScenarioMappers.of(new HeaderMapper("foo"),
new ContentBasedXPathScenarioMapper().addXPathExpression("/foo"),
new ContentBasedJsonPathScenarioMapper().addJsonPathExpression("$.foo"),
@@ -57,48 +59,48 @@ public void testMappingChain() throws Exception {
mapperChain.setScenarioList(Arrays.asList(new FooScenario(), new BarScenario(), new OtherScenario()));
mapperChain.afterPropertiesSet();
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage()), DEFAULT_SCENARIO);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("foo").setHeader("foo", "something")), DEFAULT_SCENARIO);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage().setHeader("foo", FooScenario.SCENARIO_NAME)), FooScenario.SCENARIO_NAME);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage().setHeader("foo", FooScenario.SCENARIO_NAME)
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage()), DEFAULT_SCENARIO);
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage("foo").setHeader("foo", "something")), DEFAULT_SCENARIO);
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage().setHeader("foo", FooScenario.SCENARIO_NAME)), FooScenario.SCENARIO_NAME);
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage().setHeader("foo", FooScenario.SCENARIO_NAME)
.setHeader("bar", BarScenario.SCENARIO_NAME)), FooScenario.SCENARIO_NAME);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage().setHeader("foo", "something")
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage().setHeader("foo", "something")
.setHeader("bar", BarScenario.SCENARIO_NAME)), BarScenario.SCENARIO_NAME);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage().setHeader("bar", BarScenario.SCENARIO_NAME)), BarScenario.SCENARIO_NAME);
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage().setHeader("bar", BarScenario.SCENARIO_NAME)), BarScenario.SCENARIO_NAME);
- Assert.assertEquals(mapperChain.getMappingKey(new HttpMessage().path("/other").method(HttpMethod.GET).setHeader("foo", FooScenario.SCENARIO_NAME)), FooScenario.SCENARIO_NAME);
- Assert.assertEquals(mapperChain.getMappingKey(new HttpMessage().path("/other").method(HttpMethod.GET).setHeader("foo", "something")), OtherScenario.SCENARIO_NAME);
- Assert.assertEquals(mapperChain.getMappingKey(new HttpMessage().path("/other").method(HttpMethod.GET).setHeader("bar", BarScenario.SCENARIO_NAME)), OtherScenario.SCENARIO_NAME);
+ assertEquals(mapperChain.getMappingKey(new HttpMessage().path("/other").method(HttpMethod.GET).setHeader("foo", FooScenario.SCENARIO_NAME)), FooScenario.SCENARIO_NAME);
+ assertEquals(mapperChain.getMappingKey(new HttpMessage().path("/other").method(HttpMethod.GET).setHeader("foo", "something")), OtherScenario.SCENARIO_NAME);
+ assertEquals(mapperChain.getMappingKey(new HttpMessage().path("/other").method(HttpMethod.GET).setHeader("bar", BarScenario.SCENARIO_NAME)), OtherScenario.SCENARIO_NAME);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("{ \"foo\": \"something\" }")), DEFAULT_SCENARIO);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("{ \"foo\": \"something\" }")), DEFAULT_SCENARIO);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("{ \"bar\": \"" + FooScenario.SCENARIO_NAME + "\" }")), DEFAULT_SCENARIO);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("{ \"foo\": \"" + FooScenario.SCENARIO_NAME + "\" }")), FooScenario.SCENARIO_NAME);
- Assert.assertEquals(mapperChain.getMappingKey(new HttpMessage("{ \"foo\": \"" + FooScenario.SCENARIO_NAME + "\" }").path("/other").method(HttpMethod.GET)), FooScenario.SCENARIO_NAME);
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage("{ \"foo\": \"something\" }")), DEFAULT_SCENARIO);
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage("{ \"foo\": \"something\" }")), DEFAULT_SCENARIO);
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage("{ \"bar\": \"" + FooScenario.SCENARIO_NAME + "\" }")), DEFAULT_SCENARIO);
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage("{ \"foo\": \"" + FooScenario.SCENARIO_NAME + "\" }")), FooScenario.SCENARIO_NAME);
+ assertEquals(mapperChain.getMappingKey(new HttpMessage("{ \"foo\": \"" + FooScenario.SCENARIO_NAME + "\" }").path("/other").method(HttpMethod.GET)), FooScenario.SCENARIO_NAME);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("something")), DEFAULT_SCENARIO);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("" + FooScenario.SCENARIO_NAME + "")), DEFAULT_SCENARIO);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("" + FooScenario.SCENARIO_NAME + "")), FooScenario.SCENARIO_NAME);
- Assert.assertEquals(mapperChain.getMappingKey(new HttpMessage("" + FooScenario.SCENARIO_NAME + "").path("/other").method(HttpMethod.GET)), FooScenario.SCENARIO_NAME);
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage("something")), DEFAULT_SCENARIO);
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage("" + FooScenario.SCENARIO_NAME + "")), DEFAULT_SCENARIO);
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage("" + FooScenario.SCENARIO_NAME + "")), FooScenario.SCENARIO_NAME);
+ assertEquals(mapperChain.getMappingKey(new HttpMessage("" + FooScenario.SCENARIO_NAME + "").path("/other").method(HttpMethod.GET)), FooScenario.SCENARIO_NAME);
mapperChain.setUseDefaultMapping(false);
- Assert.assertThrows(CitrusRuntimeException.class, () -> mapperChain.getMappingKey(new DefaultMessage()));
- Assert.assertThrows(CitrusRuntimeException.class, () -> mapperChain.getMappingKey(new DefaultMessage().setHeader("foo", "something")));
+ assertThrows(CitrusRuntimeException.class, () -> mapperChain.getMappingKey(new DefaultMessage()));
+ assertThrows(CitrusRuntimeException.class, () -> mapperChain.getMappingKey(new DefaultMessage().setHeader("foo", "something")));
}
@Test
- public void testDefaultMapping() {
+ void testDefaultMapping() {
ScenarioMappers mapperChain = ScenarioMappers.of(new HeaderMapper("foo"));
- Assert.assertThrows(CitrusRuntimeException.class, () -> mapperChain.getMappingKey(new DefaultMessage()));
+ assertThrows(CitrusRuntimeException.class, () -> mapperChain.getMappingKey(new DefaultMessage()));
SimulatorConfigurationProperties configurationProperties = new SimulatorConfigurationProperties();
configurationProperties.setDefaultScenario(DEFAULT_SCENARIO);
mapperChain.setSimulatorConfigurationProperties(configurationProperties);
- Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage()), DEFAULT_SCENARIO);
+ assertEquals(mapperChain.getMappingKey(new DefaultMessage()), DEFAULT_SCENARIO);
mapperChain.setUseDefaultMapping(false);
- Assert.assertThrows(CitrusRuntimeException.class, () -> mapperChain.getMappingKey(new DefaultMessage()));
+ assertThrows(CitrusRuntimeException.class, () -> mapperChain.getMappingKey(new DefaultMessage()));
}
private class HeaderMapper implements ScenarioMapper {
diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/service/MessageServiceTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/service/MessageServiceTest.java
index f1d79ff54..3e584b3fa 100644
--- a/simulator-starter/src/test/java/org/citrusframework/simulator/service/MessageServiceTest.java
+++ b/simulator-starter/src/test/java/org/citrusframework/simulator/service/MessageServiceTest.java
@@ -22,54 +22,50 @@
import org.citrusframework.simulator.repository.MessageRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
-import org.mockito.Mockito;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
-public class MessageServiceTest {
+@ExtendWith(MockitoExtension.class)
+class MessageServiceTest {
- private QueryFilterAdapterFactory queryFilterAdapterFactory = new QueryFilterAdapterFactory(
- new SimulatorConfigurationProperties());
+ private final QueryFilterAdapterFactory queryFilterAdapterFactory = new QueryFilterAdapterFactory(new SimulatorConfigurationProperties());
- private MessageRepository messageRepository;
+ @Mock
+ private MessageRepository messageRepositoryMock;
- private MessageService sut;
private ArgumentCaptor messageFilterCaptor;
- @SuppressWarnings("unchecked")
+ private MessageService fixture;
+
@BeforeEach
- public void init() {
+ void beforeEachSetup() {
messageFilterCaptor = ArgumentCaptor.forClass(MessageFilter.class);
- messageRepository = Mockito.mock(MessageRepository.class);
- sut = new MessageService(messageRepository, queryFilterAdapterFactory);
- }
-
- @AfterMethod
- public void clear() {
- Mockito.reset(messageRepository);
+ fixture = new MessageService(messageRepositoryMock, queryFilterAdapterFactory);
}
@Test
- public void shouldGetMessagesUsingDefaults() throws Exception {
+ void shouldGetMessagesUsingDefaults() {
MessageFilter filter = new MessageFilter();
- when(messageRepository.find(messageFilterCaptor.capture())).thenReturn(singleResult());
+ when(messageRepositoryMock.find(messageFilterCaptor.capture())).thenReturn(singleResult());
- assertHasSingleResult(sut.getMessagesMatchingFilter(filter));
+ assertHasSingleResult(fixture.getMessagesMatchingFilter(filter));
assertPagingMatches(0, 25);
assertDirectionMatches(true, true);
}
@Test
- public void shouldGetMessagesUsingNoDefaults() throws Exception {
+ void shouldGetMessagesUsingNoDefaults() {
Instant dateFrom = Instant.now();
Instant dateTo = Instant.now();
int pageNumber = 10;
@@ -85,9 +81,9 @@ public void shouldGetMessagesUsingNoDefaults() throws Exception {
filter.setDirectionOutbound(false);
filter.setContainingText(text);
- when(messageRepository.find(messageFilterCaptor.capture())).thenReturn(singleResult());
+ when(messageRepositoryMock.find(messageFilterCaptor.capture())).thenReturn(singleResult());
- assertHasSingleResult(sut.getMessagesMatchingFilter(filter));
+ assertHasSingleResult(fixture.getMessagesMatchingFilter(filter));
assertPagingMatches(pageNumber, pageSize);
assertDirectionMatches(false, false);
@@ -98,16 +94,16 @@ private List singleResult() {
}
private void assertHasSingleResult(List messages) {
- Assert.assertEquals(messages.size(), 1);
+ assertEquals(messages.size(), 1);
}
private void assertPagingMatches(int pageNumber, int pageSize) {
- Assert.assertEquals(messageFilterCaptor.getValue().getPageNumber(), (Integer) pageNumber);
- Assert.assertEquals(messageFilterCaptor.getValue().getPageSize(), (Integer) pageSize);
+ assertEquals(messageFilterCaptor.getValue().getPageNumber(), (Integer) pageNumber);
+ assertEquals(messageFilterCaptor.getValue().getPageSize(), (Integer) pageSize);
}
private void assertDirectionMatches(boolean inbound, boolean outbound) {
- Assert.assertEquals(messageFilterCaptor.getValue().getDirectionInbound(), (Boolean) inbound);
- Assert.assertEquals(messageFilterCaptor.getValue().getDirectionOutbound(), (Boolean) outbound);
+ assertEquals(messageFilterCaptor.getValue().getDirectionInbound(), (Boolean) inbound);
+ assertEquals(messageFilterCaptor.getValue().getDirectionOutbound(), (Boolean) outbound);
}
}
diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/template/TemplateHelperTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/template/TemplateHelperTest.java
index 670585470..dc1f41e13 100644
--- a/simulator-starter/src/test/java/org/citrusframework/simulator/template/TemplateHelperTest.java
+++ b/simulator-starter/src/test/java/org/citrusframework/simulator/template/TemplateHelperTest.java
@@ -1,80 +1,87 @@
package org.citrusframework.simulator.template;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.core.io.Resource;
-import org.testng.Assert;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
+
+import java.util.stream.Stream;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class TemplateHelperTest {
-public class TemplateHelperTest {
private static final String CONTENT = "Some text containing funny characters üöäß";
- @DataProvider
- private Object[][] fileResourceDP() {
- return new Object[][]{
- {"", "test", ".xml", false},
- {"/", "test", ".xml", false},
- {"/template", "test", ".xml", false},
- {"/template/xml", "test", ".xml", true},
- {"/template/xml/", "test", ".xml", true},
- {"/template/xml/", "test", "xml", true},
- {"/template/xml/", "aaaa", "xml", false}
- };
+ static Stream getFileResource() {
+ return Stream.of(
+ Arguments.of("", "test", ".xml", false),
+ Arguments.of("/", "test", ".xml", false),
+ Arguments.of("/template", "test", ".xml", false),
+ Arguments.of("/template/xml", "test", ".xml", true),
+ Arguments.of("/template/xml/", "test", ".xml", true),
+ Arguments.of("/template/xml/", "test", "xml", true),
+ Arguments.of("/template/xml/", "aaaa", "xml", false)
+ );
}
- @Test(dataProvider = "fileResourceDP")
- public void testGetFileResource(String basePath, String fileName, String fileExtension, boolean shouldExist) throws Exception {
+ @MethodSource
+ @ParameterizedTest
+ void getFileResource(String basePath, String fileName, String fileExtension, boolean shouldExist) throws Exception {
final TemplateHelper testling = TemplateHelper.instance(basePath, UTF_8);
final Resource fileResource = testling.getFileResource(fileName, fileExtension);
- Assert.assertEquals(shouldExist, fileResource.exists());
+
+ assertEquals(shouldExist, fileResource.exists());
}
- @DataProvider
- private Object[][] xmlTemplateDP() {
- return new Object[][]{
- {"", "test.xml", null},
- {"/", "test.xml", null},
- {"/template", "test.xml", null},
- {"/template/xml", "test.xml", CONTENT},
- {"/template/xml/", "test.xml", CONTENT},
- {"/template/xml/", "test", CONTENT},
- {"/template/xml/", "aaaa", null}
- };
+ static Stream getXmlMessageTemplate() {
+ return Stream.of(
+ Arguments.of("", "test.xml", null),
+ Arguments.of("/", "test.xml", null),
+ Arguments.of("/template", "test.xml", null),
+ Arguments.of("/template/xml", "test.xml", CONTENT),
+ Arguments.of("/template/xml/", "test.xml", CONTENT),
+ Arguments.of("/template/xml/", "test", CONTENT),
+ Arguments.of("/template/xml/", "aaaa", null)
+ );
}
- @Test(dataProvider = "xmlTemplateDP")
- public void testGetXmlMessageTemplate(String basePath, String fileName, String expectedContent) throws Exception {
+ @MethodSource
+ @ParameterizedTest
+ void getXmlMessageTemplate(String basePath, String fileName, String expectedContent) throws Exception {
final TemplateHelper testling = TemplateHelper.instance(basePath, UTF_8);
try {
final String content = testling.getXmlMessageTemplate(fileName);
- Assert.assertTrue(content.contains(expectedContent));
+ assertTrue(content.contains(expectedContent));
} catch (Exception e) {
- Assert.assertNull(expectedContent);
+ assertNull(expectedContent);
}
}
- @DataProvider
- private Object[][] jsonTemplateDP() {
- return new Object[][]{
- {"", "test.json", null},
- {"/", "test.json", null},
- {"/template", "test.json", null},
- {"/template/json", "test.json", CONTENT},
- {"/template/json/", "test.json", CONTENT},
- {"/template/json/", "test", CONTENT},
- {"/template/json/", "aaaa", null}
- };
+ static Stream getJsonMessageTemplate() {
+ return Stream.of(
+ Arguments.of("", "test.json", null),
+ Arguments.of("/", "test.json", null),
+ Arguments.of("/template", "test.json", null),
+ Arguments.of("/template/json", "test.json", CONTENT),
+ Arguments.of("/template/json/", "test.json", CONTENT),
+ Arguments.of("/template/json/", "test", CONTENT),
+ Arguments.of("/template/json/", "aaaa", null)
+ );
}
- @Test(dataProvider = "jsonTemplateDP")
- public void testGetJsonMessageTemplate(String basePath, String fileName, String expectedContent) throws Exception {
+ @MethodSource
+ @ParameterizedTest
+ void getJsonMessageTemplate(String basePath, String fileName, String expectedContent) throws Exception {
final TemplateHelper testling = TemplateHelper.instance(basePath, UTF_8);
try {
final String content = testling.getJsonMessageTemplate(fileName);
- Assert.assertTrue(content.contains(expectedContent));
+ assertTrue(content.contains(expectedContent));
} catch (Exception e) {
- Assert.assertNull(expectedContent);
+ assertNull(expectedContent);
}
}
}
diff --git a/simulator-starter/src/test/java/org/citrusframework/simulator/ws/WsdlScenarioGeneratorTest.java b/simulator-starter/src/test/java/org/citrusframework/simulator/ws/WsdlScenarioGeneratorTest.java
index a0f242064..527d3c05e 100644
--- a/simulator-starter/src/test/java/org/citrusframework/simulator/ws/WsdlScenarioGeneratorTest.java
+++ b/simulator-starter/src/test/java/org/citrusframework/simulator/ws/WsdlScenarioGeneratorTest.java
@@ -1,125 +1,140 @@
package org.citrusframework.simulator.ws;
-import org.mockito.Mockito;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
-import org.testng.Assert;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-import static org.mockito.Mockito.*;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
/**
* @author Christoph Deppisch
*/
-public class WsdlScenarioGeneratorTest {
+@ExtendWith(MockitoExtension.class)
+class WsdlScenarioGeneratorTest {
+
+ private static final String SCENARIO_INPUT = String.format("%n" +
+ " string%n" +
+ " 100%n" +
+ " true%n" +
+ " stringstri%n" +
+ "");
+
+ private static final String SCENARIO_OUTPUT = String.format("%n" +
+ " string%n" +
+ " 100%n" +
+ " true%n" +
+ " stringstri%n" +
+ "");
+
+
+ static Stream testGenerateScenarios() {
+ return data();
+ }
- private ConfigurableListableBeanFactory beanFactory = Mockito.mock(ConfigurableListableBeanFactory.class);
- private DefaultListableBeanFactory beanRegistry = Mockito.mock(DefaultListableBeanFactory.class);
+ static Stream testGenerateScenariosWithRegistry() {
+ return data();
+ }
- private String input = String.format("%n" +
- " string%n" +
- " 100%n" +
- " true%n" +
- " stringstri%n" +
- "");
+ static Stream data() {
+ return Stream.of(
+ Arguments.of("TestRequest", WsdlScenarioGenerator.WsdlScenarioNamingStrategy.INPUT, "/TestService/test", SCENARIO_INPUT, SCENARIO_OUTPUT),
+ Arguments.of("test", WsdlScenarioGenerator.WsdlScenarioNamingStrategy.OPERATION, "/TestService/test", SCENARIO_INPUT, SCENARIO_OUTPUT),
+ Arguments.of("/TestService/test", WsdlScenarioGenerator.WsdlScenarioNamingStrategy.SOAP_ACTION, "/TestService/test", SCENARIO_INPUT, SCENARIO_OUTPUT)
+ );
+ }
- private String output = String.format("%n" +
- " string%n" +
- " 100%n" +
- " true%n" +
- " stringstri%n" +
- "");
+ @Mock
+ private ConfigurableListableBeanFactory beanFactoryMock;
- @Test(dataProvider = "wsdlDataProvider")
- public void testGenerateScenarios(String scenarioName, WsdlScenarioGenerator.WsdlScenarioNamingStrategy namingStrategy, String soapAction, String input, String output) {
- WsdlScenarioGenerator scenarioGenerator = new WsdlScenarioGenerator(new ClassPathResource("schema/TestService.wsdl"));
+ @Mock
+ private DefaultListableBeanFactory beanRegistryMock;
- reset(beanFactory);
+ private WsdlScenarioGenerator fixture;
- scenarioGenerator.setNamingStrategy(namingStrategy);
+ @BeforeEach
+ void beforeEachSetup() {
+ fixture = new WsdlScenarioGenerator(new ClassPathResource("schema/TestService.wsdl"));
+ }
+
+ @MethodSource
+ @ParameterizedTest
+ void testGenerateScenarios(String scenarioName, WsdlScenarioGenerator.WsdlScenarioNamingStrategy namingStrategy, String soapAction, String input, String output) {
+ fixture.setNamingStrategy(namingStrategy);
doAnswer(invocation -> {
WsdlOperationScenario scenario = (WsdlOperationScenario) invocation.getArguments()[1];
- Assert.assertEquals(scenario.getSoapAction(), soapAction);
- Assert.assertEquals(scenario.getInput(), input);
- Assert.assertEquals(scenario.getOutput(), output);
+ assertEquals(scenario.getSoapAction(), soapAction);
+ assertEquals(scenario.getInput(), input);
+ assertEquals(scenario.getOutput(), output);
return null;
- }).when(beanFactory).registerSingleton(eq(scenarioName), any(WsdlOperationScenario.class));
+ }).when(beanFactoryMock).registerSingleton(eq(scenarioName), any(WsdlOperationScenario.class));
- scenarioGenerator.postProcessBeanFactory(beanFactory);
+ fixture.postProcessBeanFactory(beanFactoryMock);
- verify(beanFactory).registerSingleton(eq(scenarioName), any(WsdlOperationScenario.class));
+ verify(beanFactoryMock).registerSingleton(eq(scenarioName), any(WsdlOperationScenario.class));
}
- @Test(dataProvider = "wsdlDataProvider")
- public void testGenerateScenariosWithRegistry(String scenarioName, WsdlScenarioGenerator.WsdlScenarioNamingStrategy namingStrategy, String soapAction, String input, String output) {
- WsdlScenarioGenerator scenarioGenerator = new WsdlScenarioGenerator(new ClassPathResource("schema/TestService.wsdl"));
-
- reset(beanRegistry);
-
- scenarioGenerator.setNamingStrategy(namingStrategy);
+ @MethodSource
+ @ParameterizedTest
+ void testGenerateScenariosWithRegistry(String scenarioName, WsdlScenarioGenerator.WsdlScenarioNamingStrategy namingStrategy, String soapAction, String input, String output) {
+ fixture.setNamingStrategy(namingStrategy);
doAnswer(invocation -> {
BeanDefinition scenario = (BeanDefinition) invocation.getArguments()[1];
- Assert.assertEquals(scenario.getPropertyValues().get("soapAction"), soapAction);
- Assert.assertEquals(scenario.getPropertyValues().get("input"), input);
- Assert.assertEquals(scenario.getPropertyValues().get("output"), output);
- Assert.assertNull(scenario.getPropertyValues().get("inboundDataDictionary"));
- Assert.assertNull(scenario.getPropertyValues().get("outboundDataDictionary"));
+ assertEquals(scenario.getPropertyValues().get("soapAction"), soapAction);
+ assertEquals(scenario.getPropertyValues().get("input"), input);
+ assertEquals(scenario.getPropertyValues().get("output"), output);
+ assertNull(scenario.getPropertyValues().get("inboundDataDictionary"));
+ assertNull(scenario.getPropertyValues().get("outboundDataDictionary"));
return null;
- }).when(beanRegistry).registerBeanDefinition(eq(scenarioName), any(BeanDefinition.class));
+ }).when(beanRegistryMock).registerBeanDefinition(eq(scenarioName), any(BeanDefinition.class));
- scenarioGenerator.postProcessBeanFactory(beanRegistry);
+ fixture.postProcessBeanFactory(beanRegistryMock);
- verify(beanRegistry).registerBeanDefinition(eq(scenarioName), any(BeanDefinition.class));
+ verify(beanRegistryMock).registerBeanDefinition(eq(scenarioName), any(BeanDefinition.class));
}
@Test
- public void testGenerateScenariosWithDataDictionaries() {
- WsdlScenarioGenerator scenarioGenerator = new WsdlScenarioGenerator(new ClassPathResource("schema/TestService.wsdl"));
-
- reset(beanRegistry);
-
- BeanDefinition inboundXmlDataDictionary = Mockito.mock(BeanDefinition.class);
- BeanDefinition outboundXmlDataDictionary = Mockito.mock(BeanDefinition.class);
-
- when(beanRegistry.containsBeanDefinition("inboundXmlDataDictionary")).thenReturn(true);
- when(beanRegistry.containsBeanDefinition("outboundXmlDataDictionary")).thenReturn(true);
-
- when(beanRegistry.getBeanDefinition("inboundXmlDataDictionary")).thenReturn(inboundXmlDataDictionary);
- when(beanRegistry.getBeanDefinition("outboundXmlDataDictionary")).thenReturn(outboundXmlDataDictionary);
+ void generateScenariosWithDataDictionaries() {
+ when(beanRegistryMock.containsBeanDefinition("inboundXmlDataDictionary")).thenReturn(true);
+ when(beanRegistryMock.containsBeanDefinition("outboundXmlDataDictionary")).thenReturn(true);
doAnswer(invocation -> {
BeanDefinition scenario = (BeanDefinition) invocation.getArguments()[1];
- Assert.assertEquals(scenario.getPropertyValues().get("soapAction"), "/TestService/test");
- Assert.assertEquals(scenario.getPropertyValues().get("input"), input);
- Assert.assertEquals(scenario.getPropertyValues().get("output"), output);
- Assert.assertNotNull(scenario.getPropertyValues().get("inboundDataDictionary"));
- Assert.assertNotNull(scenario.getPropertyValues().get("outboundDataDictionary"));
+ assertEquals(scenario.getPropertyValues().get("soapAction"), "/TestService/test");
+ assertEquals(scenario.getPropertyValues().get("input"), SCENARIO_INPUT);
+ assertEquals(scenario.getPropertyValues().get("output"), SCENARIO_OUTPUT);
+ assertNotNull(scenario.getPropertyValues().get("inboundDataDictionary"));
+ assertNotNull(scenario.getPropertyValues().get("outboundDataDictionary"));
return null;
- }).when(beanRegistry).registerBeanDefinition(eq("TestRequest"), any(BeanDefinition.class));
+ }).when(beanRegistryMock).registerBeanDefinition(eq("TestRequest"), any(BeanDefinition.class));
- scenarioGenerator.postProcessBeanFactory(beanRegistry);
+ fixture.postProcessBeanFactory(beanRegistryMock);
- verify(beanRegistry).registerBeanDefinition(eq("TestRequest"), any(BeanDefinition.class));
+ verify(beanRegistryMock).registerBeanDefinition(eq("TestRequest"), any(BeanDefinition.class));
}
-
- @DataProvider
- public Object[][] wsdlDataProvider() {
- return new Object[][] {
- new Object[] { "TestRequest", WsdlScenarioGenerator.WsdlScenarioNamingStrategy.INPUT, "/TestService/test", input, output },
- new Object[] { "test", WsdlScenarioGenerator.WsdlScenarioNamingStrategy.OPERATION, "/TestService/test", input, output },
- new Object[] { "/TestService/test", WsdlScenarioGenerator.WsdlScenarioNamingStrategy.SOAP_ACTION, "/TestService/test", input, output }
- };
- }
-
}