From 0f89a0bd203c93f16e2f8c79f522ce765b91a76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6rdes?= Date: Mon, 13 Nov 2023 14:07:39 +0100 Subject: [PATCH] refactoring --- .../examples/tests/SampleSoapServiceTest.java | 49 +++++++------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/distribution/src/test/java/com/predic8/membrane/examples/tests/SampleSoapServiceTest.java b/distribution/src/test/java/com/predic8/membrane/examples/tests/SampleSoapServiceTest.java index f5990d25fb..886f463e6b 100644 --- a/distribution/src/test/java/com/predic8/membrane/examples/tests/SampleSoapServiceTest.java +++ b/distribution/src/test/java/com/predic8/membrane/examples/tests/SampleSoapServiceTest.java @@ -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 { @@ -23,11 +19,11 @@ protected String getExampleDirName() { return "soap/sampleSoapService"; } + private final String soapWsdl = " methodGETmap = new HashMap<>() {{ - put("/foo?wsdl", "\n" + - " "); - put("/foo/bar?wSdL", "\n" + - " "); + put("/foo?wsdl", soapWsdl); + put("/foo/bar?wSdL", soapWsdl); put("/foo", "Method Not Allowed"); }}; @@ -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("327000")); + + private final HashMap cityMap = new HashMap<>() {{ + put("Bonn", "327000"); + put("London", "8980000"); + put("Berlin", "404"); + + }}; + + final List 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("8980000")); - } + .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("404")); } - }