Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangoerdes committed Nov 13, 2023
1 parent 432a82f commit 0f89a0b
Showing 1 changed file with 19 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package com.predic8.membrane.examples.tests;

import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import static com.predic8.membrane.test.AssertUtils.getAndAssert200;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertTrue;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class SampleSoapServiceTest extends AbstractSampleMembraneStartStopTestcase {
Expand All @@ -23,11 +19,11 @@ protected String getExampleDirName() {
return "soap/sampleSoapService";
}

private final String soapWsdl = "<wsdl:definitions xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/";

private final HashMap<String, String> methodGETmap = new HashMap<>() {{
put("/foo?wsdl", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><wsdl:definitions xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:tns=\"https://predic8.de/cities\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" targetNamespace=\"https://predic8.de/cities\" name=\"cities\">\n" +
" <wsdl:types>");
put("/foo/bar?wSdL", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><wsdl:definitions xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:tns=\"https://predic8.de/cities\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" targetNamespace=\"https://predic8.de/cities\" name=\"cities\">\n" +
" <wsdl:types>");
put("/foo?wsdl", soapWsdl);
put("/foo/bar?wSdL", soapWsdl);
put("/foo", "<faultstring>Method Not Allowed</faultstring>");

}};
Expand All @@ -47,34 +43,27 @@ public void testMethod(String query) throws Exception {

}

@Test
public void testPostBonn() throws IOException {
given()
.body(readFileFromBaseDir("request.xml"))
.when()
.post("http://localhost:2000/")
.then()
.body(containsString("<population>327000</population>"));

private final HashMap<String, String> cityMap = new HashMap<>() {{
put("Bonn", "<population>327000</population>");
put("London", "<population>8980000</population>");
put("Berlin", "<errorcode>404</errorcode>");

}};

final List<String> cityMap() {
return cityMap.keySet().stream().toList();
}

@Test
public void testPostLondon() throws IOException {
@ParameterizedTest
@MethodSource("cityMap")
public void testCity(String city) throws Exception {
given()
.body(readFileFromBaseDir("request.xml").replace("Bonn", "London"))
.body(readFileFromBaseDir("request.xml").replace("Bonn", city))
.when()
.post("http://localhost:2000/")
.then()
.body(containsString("<population>8980000</population>"));
}
.body(containsString(cityMap.get(city)));

@Test
public void testNotFound() throws IOException {
given()
.body(readFileFromBaseDir("request.xml").replace("Bonn", "Berlin"))
.when()
.post("http://localhost:2000/")
.then()
.body(containsString("<errorcode>404</errorcode>"));
}

}

0 comments on commit 0f89a0b

Please sign in to comment.