Skip to content

Commit

Permalink
ci: migrate simulator-starter tests to junit
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Oct 12, 2023
1 parent 7f841d0 commit 60660d3
Show file tree
Hide file tree
Showing 12 changed files with 529 additions and 482 deletions.
5 changes: 0 additions & 5 deletions simulator-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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("<v1:TestRequest xmlns:v1=\"http://www.citrusframework.org/schema/samples/TestService/v1\" flag=\"false\" id=\"100\" name=\"string\">%n" +
private static final String MESSAGE_INPUT = String.format("<v1:TestRequest xmlns:v1=\"http://www.citrusframework.org/schema/samples/TestService/v1\" flag=\"false\" id=\"100\" name=\"string\">%n" +
" <v1:name>string</v1:name>%n" +
" <v1:id>100</v1:id>%n" +
" <v1:flag>true</v1:flag>%n" +
" <v1:restricted>stringstri</v1:restricted>%n" +
"</v1:TestRequest>");

@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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
assertEquals(translated.getPayload(String.class), String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<v1:TestRequest xmlns:v1=\"http://www.citrusframework.org/schema/samples/TestService/v1\" flag=\"@ignore@\" id=\"@ignore@\" name=\"@ignore@\">%n" +
" <v1:name>@ignore@</v1:name>%n" +
" <v1:id>@ignore@</v1:id>%n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -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("<v1:TestResponse xmlns:v1=\"http://www.citrusframework.org/schema/samples/TestService/v1\" flag=\"false\" id=\"100\" name=\"string\">%n" +
" <v1:name>string</v1:name>%n" +
" <v1:id>100</v1:id>%n" +
" <v1:flag>true</v1:flag>%n" +
" <v1:restricted>stringstri</v1:restricted>%n" +
"</v1:TestResponse>");

private String input = String.format("<v1:TestResponse xmlns:v1=\"http://www.citrusframework.org/schema/samples/TestService/v1\" flag=\"false\" id=\"100\" name=\"string\">%n" +
" <v1:name>string</v1:name>%n" +
" <v1:id>100</v1:id>%n" +
" <v1:flag>true</v1:flag>%n" +
" <v1:restricted>stringstri</v1:restricted>%n" +
"</v1:TestResponse>");
@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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
Expand All @@ -43,8 +53,7 @@ public void testInboundDictionary() {
" <v1:flag>true</v1:flag>%n" +
" <v1:restricted>citrus:randomString(10)</v1:restricted>%n" +
"</v1:TestResponse>%n"));

Assert.assertEquals(payload, controlPayload);
}

assertEquals(payload, controlPayload);
}
}
Loading

0 comments on commit 60660d3

Please sign in to comment.