diff --git a/distribution/examples/offline/apis.yaml b/distribution/examples/configuration/offline.apis.yaml
similarity index 100%
rename from distribution/examples/offline/apis.yaml
rename to distribution/examples/configuration/offline.apis.yaml
diff --git a/distribution/examples/offline/membrane.cmd b/distribution/examples/offline/membrane.cmd
deleted file mode 100644
index 8d2d64e9cf..0000000000
--- a/distribution/examples/offline/membrane.cmd
+++ /dev/null
@@ -1,24 +0,0 @@
-@echo off
-setlocal EnableExtensions
-
-set "SCRIPT_DIR=%~dp0"
-if "%SCRIPT_DIR:~-1%"=="\" set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"
-
-set "dir=%SCRIPT_DIR%"
-
-:search_up
-if exist "%dir%\LICENSE.txt" if exist "%dir%\scripts\run-membrane.cmd" goto found
-for %%A in ("%dir%\..") do set "next=%%~fA"
-if /I "%next%"=="%dir%" goto notfound
-set "dir=%next%"
-goto search_up
-
-:found
-set "MEMBRANE_HOME=%dir%"
-set "MEMBRANE_CALLER_DIR=%SCRIPT_DIR%"
-call "%MEMBRANE_HOME%\scripts\run-membrane.cmd" %*
-exit /b %ERRORLEVEL%
-
-:notfound
->&2 echo Could not locate Membrane root. Ensure directory structure is correct.
-exit /b 1
diff --git a/distribution/examples/offline/membrane.sh b/distribution/examples/offline/membrane.sh
deleted file mode 100755
index 195dae51ec..0000000000
--- a/distribution/examples/offline/membrane.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/sh
-# Default: ./proxies.xml (next to this script); fallback -> $MEMBRANE_HOME/conf/proxies.xml
-# JAVA_OPTS: relative -D paths are auto-resolved against $MEMBRANE_HOME (absolute/URI unchanged).
-# Examples:
-# export JAVA_OPTS='-Dlog4j.configurationFile=examples/logging/access/log4j2_access.xml'
-# export JAVA_OPTS='-Dlog4j.configurationFile=/abs/path/log4j2.xml'
-
-SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
-
-dir="$SCRIPT_DIR"
-while [ "$dir" != "/" ]; do
- if [ -f "$dir/LICENSE.txt" ] && [ -f "$dir/scripts/run-membrane.sh" ]; then
- export MEMBRANE_HOME="$dir"
- export MEMBRANE_CALLER_DIR="$SCRIPT_DIR"
- exec sh "$dir/scripts/run-membrane.sh" "$@"
- fi
- dir=$(dirname "$dir")
-done
-
-echo "Could not locate Membrane root. Ensure directory structure is correct." >&2
-exit 1
\ No newline at end of file
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/util/DistributionExtractingTestcase.java b/distribution/src/test/java/com/predic8/membrane/examples/util/DistributionExtractingTestcase.java
index a87a2ca89e..46ddb9552e 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/util/DistributionExtractingTestcase.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/util/DistributionExtractingTestcase.java
@@ -43,8 +43,25 @@ public abstract class DistributionExtractingTestcase {
private static File membraneHome;
protected File baseDir;
+ /**
+ * The directory of the example relative to distribution/examples
+ */
protected abstract String getExampleDirName();
+ /**
+ * The parameters to start the script with
+ */
+ protected String getParameters() {
+ return "";
+ }
+
+ /**
+ * The environment variables for the script
+ */
+ protected Map getEnvs() {
+ return Map.of();
+ }
+
@BeforeAll
public static void beforeAll() throws Exception {
log.info("unzipping router distribution");
@@ -193,11 +210,6 @@ protected Process2 startServiceProxyScript() throws IOException, InterruptedExce
return startServiceProxyScript(null, "membrane");
}
- protected Process2 startServiceProxyScriptWithEnv(String env, String val) throws IOException, InterruptedException {
- Process2.Builder builder = new Process2.Builder().env(env, val).in(baseDir);
- return builder.script("membrane").waitForMembrane().start();
- }
-
protected Process2 startServiceProxyScript(ConsoleWatcher watch) throws IOException, InterruptedException {
return startServiceProxyScript(watch, "membrane");
}
@@ -206,7 +218,7 @@ protected Process2 startServiceProxyScript(ConsoleWatcher watch, String script)
Process2.Builder builder = new Process2.Builder().in(baseDir);
if (watch != null)
builder = builder.withWatcher(watch);
- return builder.script(script).waitForMembrane().start();
+ return builder.script(script).withParameters(getParameters()).withEnv(getEnvs()).waitForMembrane().start();
}
protected String readFile(String s) throws IOException {
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/util/Process2.java b/distribution/src/test/java/com/predic8/membrane/examples/util/Process2.java
index b0bca56079..582df1196f 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/util/Process2.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/util/Process2.java
@@ -61,11 +61,6 @@ public Builder in(File baseDir) {
return this;
}
- public Builder parameters(String parameters) {
- this.parameters = parameters;
- return this;
- }
-
public Builder executable(String line) {
if (id != null)
throw new IllegalStateException("executable or script is already set.");
@@ -82,8 +77,13 @@ public Builder script(String script) {
return this;
}
- public Builder env(String key, String value) {
- env.put(key, value);
+ public Builder withEnv(Map envs) {
+ env.putAll(envs);
+ return this;
+ }
+
+ public Builder withParameters(String parameters) {
+ this.parameters = parameters;
return this;
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/DistributionApisYamlExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/DistributionApisYamlExampleTest.java
index c5d71eb464..8df6c5fdfe 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/DistributionApisYamlExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/DistributionApisYamlExampleTest.java
@@ -32,9 +32,9 @@ protected String getExampleDirName() {
return "..";
}
- @BeforeEach
- void startMembrane() throws IOException, InterruptedException {
- process = new Process2.Builder().in(baseDir).script("membrane").parameters("-c conf/apis.yaml").waitForMembrane().start();
+ @Override
+ protected String getParameters() {
+ return "-c conf/apis.yaml";
}
// @formatter:off
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/config/ProxiesXMLExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/config/ProxiesXMLExampleTest.java
index 771eb37105..abaedef78d 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/config/ProxiesXMLExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/config/ProxiesXMLExampleTest.java
@@ -34,9 +34,9 @@ protected String getExampleDirName() {
return "..";
}
- @BeforeEach
- void startMembrane() throws IOException, InterruptedException {
- process = new Process2.Builder().in(baseDir).script("membrane").parameters("-c conf/proxies.inactive.xml").waitForMembrane().start();
+ @Override
+ protected String getParameters() {
+ return "-c conf/proxies.inactive.xml";
}
@SuppressWarnings("JsonSchemaCompliance")
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/rest2soap/Rest2SOAPTemplateExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/rest2soap/Rest2SOAPTemplateExampleTest.java
index 32c58be48b..3003a44482 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/rest2soap/Rest2SOAPTemplateExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/rest2soap/Rest2SOAPTemplateExampleTest.java
@@ -21,7 +21,7 @@
import static io.restassured.filter.log.LogDetail.*;
import static org.hamcrest.Matchers.*;
-public class Rest2SOAPTemplateExampleTest extends DistributionExtractingTestcase {
+public class Rest2SOAPTemplateExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -29,18 +29,15 @@ protected String getExampleDirName() {
}
@Test
- void test() throws Exception {
-
- try (Process2 ignored = startServiceProxyScript()) {
- // @formatter:off
- given()
- .get("http://localhost:2000/cities/Bielefeld")
- .then()
- .log().ifValidationFails(ALL)
- .statusCode(200)
- .contentType(APPLICATION_JSON)
- .body("population", equalTo(333000F));
- // @formatter:on
- }
+ void test() {
+ // @formatter:off
+ given()
+ .get("http://localhost:2000/cities/Bielefeld")
+ .then()
+ .log().ifValidationFails(ALL)
+ .statusCode(200)
+ .contentType(APPLICATION_JSON)
+ .body("population", equalTo(333000F));
+ // @formatter:on
}
}
\ No newline at end of file
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/ssl/ToBackendExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/ssl/ToBackendExampleTest.java
index 72254c1fe8..3802c6ec41 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/ssl/ToBackendExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/ssl/ToBackendExampleTest.java
@@ -14,17 +14,13 @@
package com.predic8.membrane.examples.withinternet.ssl;
-import com.predic8.membrane.examples.util.DistributionExtractingTestcase;
-import com.predic8.membrane.examples.util.Process2;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
import com.predic8.membrane.test.HttpAssertions;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import java.io.IOException;
-
import static com.predic8.membrane.test.StringAssertions.assertContains;
-public class ToBackendExampleTest extends DistributionExtractingTestcase {
+public class ToBackendExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -33,7 +29,7 @@ protected String getExampleDirName() {
@Test
public void test() throws Exception {
- try(Process2 ignore = startServiceProxyScript(); HttpAssertions ha = new HttpAssertions()) {
+ try(HttpAssertions ha = new HttpAssertions()) {
assertContains("shop", ha.getAndAssert200("http://localhost:2000/"));
}
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/ACLExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/ACLExampleTest.java
index 86864319a1..4828404e62 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/ACLExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/ACLExampleTest.java
@@ -14,12 +14,11 @@
package com.predic8.membrane.examples.withinternet.test;
-import com.predic8.membrane.examples.util.DistributionExtractingTestcase;
-import com.predic8.membrane.examples.util.Process2;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
import com.predic8.membrane.test.HttpAssertions;
import org.junit.jupiter.api.Test;
-public class ACLExampleTest extends DistributionExtractingTestcase {
+public class ACLExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -28,7 +27,7 @@ protected String getExampleDirName() {
@Test
public void test() throws Exception {
- try(Process2 ignored = startServiceProxyScript(); HttpAssertions ha = new HttpAssertions()) {
+ try(HttpAssertions ha = new HttpAssertions()) {
ha.getAndAssert200("http://localhost:2000/");
ha.getAndAssert(200, "http://localhost:2000/products/");
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/ConfigurationPropertiesTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/ConfigurationPropertiesTest.java
index ac623ee21f..176e1cd931 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/ConfigurationPropertiesTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/ConfigurationPropertiesTest.java
@@ -14,35 +14,41 @@
package com.predic8.membrane.examples.withinternet.test;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
import com.predic8.membrane.examples.util.DistributionExtractingTestcase;
import com.predic8.membrane.examples.util.Process2;
import org.junit.jupiter.api.Test;
+import java.util.Map;
+
import static io.restassured.RestAssured.given;
-public class ConfigurationPropertiesTest extends DistributionExtractingTestcase {
+public class ConfigurationPropertiesTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
return "extending-membrane/configuration-properties";
}
+ @Override
+ protected Map getEnvs() {
+ return Map.of("TARGET", "https://www.predic8.de/");
+ }
+
@Test
public void test() throws Exception {
- try (Process2 ignored = startServiceProxyScriptWithEnv("TARGET", "https://www.predic8.de/")) {
- // @formatter:off
- given()
- .redirects().follow(false)
- .get("http://localhost:2000/")
- .then()
- .statusCode(307);
-
- given()
- .redirects().follow(false)
- .get("http://localhost:2001/")
- .then()
- .statusCode(200);
- // @formatter:on
- }
+ // @formatter:off
+ given()
+ .redirects().follow(false)
+ .get("http://localhost:2000/")
+ .then()
+ .statusCode(307);
+
+ given()
+ .redirects().follow(false)
+ .get("http://localhost:2001/")
+ .then()
+ .statusCode(200);
+ // @formatter:on
}
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/FileExchangeStoreExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/FileExchangeStoreExampleTest.java
index f8670087de..0c234b7f9c 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/FileExchangeStoreExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/FileExchangeStoreExampleTest.java
@@ -29,7 +29,7 @@
import static java.util.Calendar.*;
import static org.junit.jupiter.api.Assertions.*;
-public class FileExchangeStoreExampleTest extends DistributionExtractingTestcase {
+public class FileExchangeStoreExampleTest extends AbstractSampleMembraneStartStopTestcase {
private static final Logger log = LoggerFactory.getLogger(FileExchangeStoreExampleTest.class.getName());
@@ -40,7 +40,7 @@ protected String getExampleDirName() {
@Test
void test() throws Exception {
- try (Process2 ignored = startServiceProxyScript(); HttpAssertions ha = new HttpAssertions()) {
+ try (HttpAssertions ha = new HttpAssertions()) {
ha.getAndAssert200("http://localhost:2000/");
sleep(300);
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/FormValidationExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/FormValidationExampleTest.java
index 512976ca23..88ec3660ea 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/FormValidationExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/FormValidationExampleTest.java
@@ -14,14 +14,16 @@
package com.predic8.membrane.examples.withinternet.test;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
import com.predic8.membrane.examples.util.DistributionExtractingTestcase;
import com.predic8.membrane.examples.util.Process2;
import com.predic8.membrane.test.HttpAssertions;
import org.junit.jupiter.api.Test;
+import static io.restassured.RestAssured.when;
import static java.io.File.separator;
-public class FormValidationExampleTest extends DistributionExtractingTestcase {
+public class FormValidationExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -30,9 +32,7 @@ protected String getExampleDirName() {
@Test
public void test() throws Exception {
- try(Process2 ignored = startServiceProxyScript(); HttpAssertions ha = new HttpAssertions()) {
- ha.getAndAssert(400, "http://localhost:2000/?name=banana0");
- ha.getAndAssert(200, "http://localhost:2000/?name=banana");
- }
+ when().get("http://localhost:2000/?name=banana0").then().statusCode(400);
+ when().get("http://localhost:2000/?name=banana").then().statusCode(200);
}
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/Loadbalancing4XmlSessionExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/Loadbalancing4XmlSessionExampleTest.java
index f717b1c098..9481e4af4b 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/Loadbalancing4XmlSessionExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/Loadbalancing4XmlSessionExampleTest.java
@@ -14,7 +14,7 @@
package com.predic8.membrane.examples.withinternet.test;
-import com.predic8.membrane.examples.util.DistributionExtractingTestcase;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
import com.predic8.membrane.examples.util.Process2;
import org.junit.jupiter.api.Test;
@@ -22,7 +22,7 @@
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;
-public class Loadbalancing4XmlSessionExampleTest extends DistributionExtractingTestcase {
+public class Loadbalancing4XmlSessionExampleTest extends AbstractSampleMembraneStartStopTestcase {
private static final String BODY_SESSION_1 = """
{"id":"SESSION1"}""";
@@ -36,70 +36,70 @@ protected String getExampleDirName() {
@Test
void test() throws Exception {
- try(Process2 ignored = startServiceProxyScript()) {
- given().when()
- .body(BODY_SESSION_1)
- .contentType(APPLICATION_JSON)
- .post("http://localhost:8080")
- .then()
- .statusCode(200)
- .body(containsString("Request count: 1"));
-
- given().when()
- .body(BODY_SESSION_1)
- .contentType(APPLICATION_JSON)
- .post("http://localhost:8080")
- .then()
- .statusCode(200)
- .body(containsString("Request count: 2"));
-
- given().when()
- .body(BODY_SESSION_1)
- .contentType(APPLICATION_JSON)
- .post("http://localhost:8080")
- .then()
- .statusCode(200)
- .body(containsString("Request count: 3"));
-
- given().when()
- .body(BODY_SESSION_1)
- .contentType(APPLICATION_JSON)
- .post("http://localhost:8080")
- .then()
- .statusCode(200)
- .body(containsString("Request count: 4"));
-
- given().when()
- .body(BODY_SESSION_2)
- .contentType(APPLICATION_JSON)
- .post("http://localhost:8080")
- .then()
- .statusCode(200)
- .body(containsString("Request count: 1"));
-
- given().when()
- .body(BODY_SESSION_2)
- .contentType(APPLICATION_JSON)
- .post("http://localhost:8080")
- .then()
- .statusCode(200)
- .body(containsString("Request count: 2"));
-
- given().when()
- .body(BODY_SESSION_2)
- .contentType(APPLICATION_JSON)
- .post("http://localhost:8080")
- .then()
- .statusCode(200)
- .body(containsString("Request count: 3"));
-
- given().when()
- .body(BODY_SESSION_2)
- .contentType(APPLICATION_JSON)
- .post("http://localhost:8080")
- .then()
- .statusCode(200)
- .body(containsString("Request count: 4"));
- }
+ // @formatter:off
+ given().when()
+ .body(BODY_SESSION_1)
+ .contentType(APPLICATION_JSON)
+ .post("http://localhost:8080")
+ .then()
+ .statusCode(200)
+ .body(containsString("Request count: 1"));
+
+ given().when()
+ .body(BODY_SESSION_1)
+ .contentType(APPLICATION_JSON)
+ .post("http://localhost:8080")
+ .then()
+ .statusCode(200)
+ .body(containsString("Request count: 2"));
+
+ given().when()
+ .body(BODY_SESSION_1)
+ .contentType(APPLICATION_JSON)
+ .post("http://localhost:8080")
+ .then()
+ .statusCode(200)
+ .body(containsString("Request count: 3"));
+
+ given().when()
+ .body(BODY_SESSION_1)
+ .contentType(APPLICATION_JSON)
+ .post("http://localhost:8080")
+ .then()
+ .statusCode(200)
+ .body(containsString("Request count: 4"));
+
+ given().when()
+ .body(BODY_SESSION_2)
+ .contentType(APPLICATION_JSON)
+ .post("http://localhost:8080")
+ .then()
+ .statusCode(200)
+ .body(containsString("Request count: 1"));
+
+ given().when()
+ .body(BODY_SESSION_2)
+ .contentType(APPLICATION_JSON)
+ .post("http://localhost:8080")
+ .then()
+ .statusCode(200)
+ .body(containsString("Request count: 2"));
+
+ given().when()
+ .body(BODY_SESSION_2)
+ .contentType(APPLICATION_JSON)
+ .post("http://localhost:8080")
+ .then()
+ .statusCode(200)
+ .body(containsString("Request count: 3"));
+
+ given().when()
+ .body(BODY_SESSION_2)
+ .contentType(APPLICATION_JSON)
+ .post("http://localhost:8080")
+ .then()
+ .statusCode(200)
+ .body(containsString("Request count: 4"));
+ // @formatter:on
}
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/LoggingCSVExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/LoggingCSVExampleTest.java
index e0589043d8..fd04fd32bd 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/LoggingCSVExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/LoggingCSVExampleTest.java
@@ -14,15 +14,16 @@
package com.predic8.membrane.examples.withinternet.test;
-import com.predic8.membrane.examples.util.DistributionExtractingTestcase;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
import com.predic8.membrane.examples.util.Process2;
import com.predic8.membrane.test.HttpAssertions;
import org.junit.jupiter.api.Test;
import static com.predic8.membrane.core.http.MimeType.APPLICATION_JSON;
import static com.predic8.membrane.test.StringAssertions.assertContains;
+import static io.restassured.RestAssured.when;
-public class LoggingCSVExampleTest extends DistributionExtractingTestcase {
+public class LoggingCSVExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -31,9 +32,8 @@ protected String getExampleDirName() {
@Test
public void test() throws Exception {
- try(Process2 ignored = startServiceProxyScript(); HttpAssertions ha = new HttpAssertions()) {
- ha.getAndAssert200("http://localhost:2000/");
- }
+ when().get("http://localhost:2000/").then().statusCode(200);
assertContains(APPLICATION_JSON, readFile("log.csv"));
}
+
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/LoggingJsonExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/LoggingJsonExampleTest.java
index 5f349ffd22..d4a5faaeab 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/LoggingJsonExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/LoggingJsonExampleTest.java
@@ -23,6 +23,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
+import java.util.Map;
import static java.lang.System.nanoTime;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -34,12 +35,17 @@ protected String getExampleDirName() {
return "logging/json";
}
+ @Override
+ protected Map getEnvs() {
+ return Map.of("JAVA_OPTS", "-Dlog4j.configurationFile=examples/logging/json/log4j2_json.xml -Dlog4j.debug=true");
+ }
+
@Test
public void test() throws Exception {
Path logFile = baseDir.toPath().resolve("membrane_json.log");
Files.deleteIfExists(logFile);
- try (Process2 sl = startServiceProxyScriptWithEnv("JAVA_OPTS", "-Dlog4j.configurationFile=examples/logging/json/log4j2_json.xml -Dlog4j.debug=true");
+ try (Process2 sl = startServiceProxyScript();
HttpAssertions ha = new HttpAssertions()) {
SubstringWaitableConsoleEvent logged = new SubstringWaitableConsoleEvent(sl, "HTTP/1.1");
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/OutgoingAPIGatewayExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/OutgoingAPIGatewayExampleTest.java
index ff8b862743..1280ace393 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/OutgoingAPIGatewayExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/OutgoingAPIGatewayExampleTest.java
@@ -14,13 +14,14 @@
package com.predic8.membrane.examples.withinternet.test;
-import com.predic8.membrane.examples.util.*;
-import org.junit.jupiter.api.*;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
+import org.junit.jupiter.api.Test;
-import static io.restassured.RestAssured.*;
-import static org.hamcrest.Matchers.*;
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.not;
-public class OutgoingAPIGatewayExampleTest extends DistributionExtractingTestcase {
+public class OutgoingAPIGatewayExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -29,24 +30,22 @@ protected String getExampleDirName() {
@Test
public void test() throws Exception {
- try (Process2 ignored = startServiceProxyScript()) {
- // @formatter:off
- given()
- .baseUri("http://localhost:2000")
- .header("X-Api-Key", "10430")
- .header("User-Agent", "secret")
- .header("Authorization", "secret")
- .when()
- .get("/")
- .then()
- .log().ifValidationFails()
- .statusCode(200)
- .body(containsString("X-Api-Key"))
- .body(not(containsString("User-Agent")))
- .body(not(containsString("Authorization")))
- .body(not(containsString("X-Forwarded")));
- // @formatter:on
- }
+ // @formatter:off
+ given()
+ .baseUri("http://localhost:2000")
+ .header("X-Api-Key", "10430")
+ .header("User-Agent", "secret")
+ .header("Authorization", "secret")
+ .when()
+ .get("/")
+ .then()
+ .log().ifValidationFails()
+ .statusCode(200)
+ .body(containsString("X-Api-Key"))
+ .body(not(containsString("User-Agent")))
+ .body(not(containsString("Authorization")))
+ .body(not(containsString("X-Forwarded")));
+ // @formatter:on
}
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/RewriterExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/RewriterExampleTest.java
index 8294b2e316..e474e62a60 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/RewriterExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/RewriterExampleTest.java
@@ -14,13 +14,13 @@
package com.predic8.membrane.examples.withinternet.test;
-import com.predic8.membrane.examples.util.*;
-import org.junit.jupiter.api.*;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
+import org.junit.jupiter.api.Test;
-import static io.restassured.RestAssured.*;
-import static org.hamcrest.Matchers.*;
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-public class RewriterExampleTest extends DistributionExtractingTestcase {
+public class RewriterExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -29,13 +29,12 @@ protected String getExampleDirName() {
@Test
public void test() throws Exception {
- try(Process2 ignore = startServiceProxyScript()) {
-
- given()
- .get("http://localhost:2000/store/products/")
- .then()
- .statusCode(200)
- .body("meta.count", greaterThanOrEqualTo(0));
- }
+ // @formatter:off
+ given()
+ .get("http://localhost:2000/store/products/")
+ .then()
+ .statusCode(200)
+ .body("meta.count", greaterThanOrEqualTo(0));
+ // @formatter:on
}
}
\ No newline at end of file
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/SpELExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/SpELExampleTest.java
index 2f145a7eb6..51726be58c 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/SpELExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/SpELExampleTest.java
@@ -14,12 +14,15 @@
package com.predic8.membrane.examples.withinternet.test;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
import com.predic8.membrane.examples.util.DistributionExtractingTestcase;
import com.predic8.membrane.examples.util.Process2;
import com.predic8.membrane.test.HttpAssertions;
import org.junit.jupiter.api.Test;
-public class SpELExampleTest extends DistributionExtractingTestcase {
+import static io.restassured.RestAssured.when;
+
+public class SpELExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -28,8 +31,6 @@ protected String getExampleDirName() {
@Test
public void test() throws Exception {
- try(Process2 ignored = startServiceProxyScript(); HttpAssertions ha = new HttpAssertions()) {
- ha.getAndAssert200("http://localhost:2000/");
- }
+ when().get("http://localhost:2000/").then().statusCode(200);
}
}
\ No newline at end of file
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/ThrottleExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/ThrottleExampleTest.java
index d308af5d21..33e26d84f1 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/ThrottleExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/ThrottleExampleTest.java
@@ -14,14 +14,14 @@
package com.predic8.membrane.examples.withinternet.test;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
import com.predic8.membrane.examples.util.DistributionExtractingTestcase;
-import com.predic8.membrane.examples.util.Process2;
-import com.predic8.membrane.test.HttpAssertions;
import org.junit.jupiter.api.Test;
+import static io.restassured.RestAssured.when;
import static org.junit.jupiter.api.Assertions.assertTrue;
-public class ThrottleExampleTest extends DistributionExtractingTestcase {
+public class ThrottleExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -30,12 +30,9 @@ protected String getExampleDirName() {
@Test
public void test() throws Exception {
- try(Process2 ignored = startServiceProxyScript(); HttpAssertions ha = new HttpAssertions()) {
- ha.getAndAssert200(LOCALHOST_2000);
- long start = System.currentTimeMillis();
- ha.getAndAssert200(LOCALHOST_2000);
- long elapsedMillis = System.currentTimeMillis() - start;
- assertTrue(elapsedMillis >= 1000);
- }
+ when().get(LOCALHOST_2000).then().statusCode(200);
+ long start = System.currentTimeMillis();
+ when().get(LOCALHOST_2000).then().statusCode(200);
+ assertTrue(System.currentTimeMillis() - start >= 1000);
}
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/VersioningSoapXsltExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/VersioningSoapXsltExampleTest.java
index 1c5b8d9488..f6961e7897 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/VersioningSoapXsltExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/VersioningSoapXsltExampleTest.java
@@ -22,7 +22,7 @@
import static io.restassured.filter.log.LogDetail.*;
import static org.hamcrest.Matchers.*;
-public class VersioningSoapXsltExampleTest extends DistributionExtractingTestcase {
+public class VersioningSoapXsltExampleTest extends AbstractSampleMembraneStartStopTestcase {
String request_old;
String request_new;
@@ -40,25 +40,22 @@ protected String getExampleDirName() {
@Test
public void test() throws Exception {
-
- try (Process2 ignored1 = startServiceProxyScript()) {
- // @formatter:off
- given()
- .body(request_new)
- .post("http://localhost:2000/city-service")
- .then()
- .statusCode(200)
- .body("Envelope.Body.getCityResponse.population", equalTo("327000"));
-
- given()
- .body(request_old)
- .post("http://localhost:2000/city-service")
- .then()
- .log().ifValidationFails(ALL)
- .statusCode(200)
- .body("Envelope.Body.getCityResponse.country", equalTo("Germany"));
- // @formatter:on
- }
+ // @formatter:off
+ given()
+ .body(request_new)
+ .post("http://localhost:2000/city-service")
+ .then()
+ .statusCode(200)
+ .body("Envelope.Body.getCityResponse.population", equalTo("327000"));
+
+ given()
+ .body(request_old)
+ .post("http://localhost:2000/city-service")
+ .then()
+ .log().ifValidationFails(ALL)
+ .statusCode(200)
+ .body("Envelope.Body.getCityResponse.country", equalTo("Germany"));
+ // @formatter:on
}
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/OfflineExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/OfflineExampleTest.java
index d6edbf6923..48f2777d41 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/OfflineExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/OfflineExampleTest.java
@@ -15,8 +15,12 @@
package com.predic8.membrane.examples.withoutinternet;
import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
+import com.predic8.membrane.examples.util.Process2;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.io.IOException;
+
import static io.restassured.RestAssured.when;
import static org.hamcrest.Matchers.*;
@@ -24,7 +28,12 @@ public class OfflineExampleTest extends AbstractSampleMembraneStartStopTestcase
@Override
protected String getExampleDirName() {
- return "/offline";
+ return "/configuration";
+ }
+
+ @Override
+ protected String getParameters() {
+ return "-c offline.apis.yaml";
}
@Test
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/message_transformation/Xml2JsonExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/message_transformation/Xml2JsonExampleTest.java
index 3d3ff5c531..a780368670 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/message_transformation/Xml2JsonExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/message_transformation/Xml2JsonExampleTest.java
@@ -38,8 +38,8 @@ public void test() throws Exception {
.body(readFileFromBaseDir("jobs.xml"))
.when()
.post(LOCALHOST_2000)
-.then()
- .statusCode(200);
+ .then()
+ .statusCode(200);
// @formatter:on
assertThat(logger.toString(), containsString("{\"jobs\":{\"job\":"));
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/openapi/OpenAPIValidationSimpleExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/openapi/OpenAPIValidationSimpleExampleTest.java
index e2de1b559e..342ab98461 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/openapi/OpenAPIValidationSimpleExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/openapi/OpenAPIValidationSimpleExampleTest.java
@@ -14,15 +14,15 @@
package com.predic8.membrane.examples.withoutinternet.openapi;
-import com.predic8.membrane.examples.util.*;
-import org.junit.jupiter.api.*;
-import org.skyscreamer.jsonassert.*;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
+import org.junit.jupiter.api.Test;
+import org.skyscreamer.jsonassert.JSONAssert;
import static io.restassured.RestAssured.given;
import static io.restassured.http.ContentType.JSON;
import static org.hamcrest.CoreMatchers.containsString;
-public class OpenAPIValidationSimpleExampleTest extends DistributionExtractingTestcase {
+public class OpenAPIValidationSimpleExampleTest extends AbstractSampleMembraneStartStopTestcase {
final String createPersonValid = """
{"name": "Johannes Gutenberg","age": 78}
@@ -57,31 +57,28 @@ protected String getExampleDirName() {
@Test
public void test() throws Exception {
+ // @formatter:off
+ // Test valid person creation
+ given()
+ .contentType(JSON)
+ .body(createPersonValid)
+ .when()
+ .post(LOCALHOST_2000 + "/persons")
+ .then()
+ .statusCode(201)
+ .body(containsString("success"));
- try(Process2 ignored = startServiceProxyScript()) {
- // @formatter:off
- // Test valid person creation
- given()
- .contentType(JSON)
- .body(createPersonValid)
- .when()
- .post(LOCALHOST_2000 + "/persons")
- .then()
- .statusCode(201)
- .body(containsString("success"));
+ // Test invalid person creation
+ String response =given()
+ .contentType(JSON)
+ .body(createPersonInvalid)
+ .when()
+ .post(LOCALHOST_2000 + "/persons")
+ .then()
+ .statusCode(400)
+ .extract().response().asString();
+ // @formatter:on
- // Test invalid person creation
- String response =given()
- .contentType(JSON)
- .body(createPersonInvalid)
- .when()
- .post(LOCALHOST_2000 + "/persons")
- .then()
- .statusCode(400)
- .extract().response().asString();
- // @formatter:on
-
- JSONAssert.assertEquals(validationResult, response, false);
- }
+ JSONAssert.assertEquals(validationResult, response, false);
}
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/AccessLogExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/AccessLogExampleTest.java
index 81f5f442a8..cef731a568 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/AccessLogExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/AccessLogExampleTest.java
@@ -23,7 +23,7 @@
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;
-public class AccessLogExampleTest extends DistributionExtractingTestcase {
+public class AccessLogExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -31,49 +31,31 @@ protected String getExampleDirName() {
}
@Test
- void console() throws Exception {
- try (var process = startServiceProxyScript()) {
-
- var console = new WaitableConsoleEvent(
- process,
- p -> p.contains("\"GET / HTTP/1.1\" 200 0 [application/json]")
- );
-
- given()
- .when()
- .get("http://localhost:2000")
- .then()
- .log().ifValidationFails()
- .statusCode(200);
-
- assertTrue(console.occurred());
- }
+ void console() {
+ var console = new WaitableConsoleEvent(
+ process,
+ p -> p.contains("\"GET / HTTP/1.1\" 200 0 [application/json]")
+ );
+
+ given()
+ .when()
+ .get("http://localhost:2000")
+ .then()
+ .log().ifValidationFails()
+ .statusCode(200);
+
+ assertTrue(console.occurred());
}
@Test
void rollingFile() throws Exception {
- try (var ignore = startServiceProxyScript()) {
- given()
- .when()
- .get("http://localhost:2000")
- .then()
- .statusCode(200);
- }
-
- var log = readFile("access.log");
- assertThat(log, containsString("\"GET / HTTP/1.1\" 200 0 [application/json]"));
+ when().get("http://localhost:2000").then().statusCode(200);
+ assertThat(readFile("access.log"), containsString("\"GET / HTTP/1.1\" 200 0 [application/json]"));
}
@Test
void header() throws Exception {
- try (var ignore = startServiceProxyScript()) {
- given()
- .when()
- .get("http://localhost:2000")
- .then()
- .statusCode(200);
- }
-
+ when().get("http://localhost:2000").then().statusCode(200);
assertThat(readFile("access.log"), containsString("X-Forwarded-For: 127.0.0.1"));
}
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/CBRXPathExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/CBRXPathExampleTest.java
index f589bd3a51..373565ce79 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/CBRXPathExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/CBRXPathExampleTest.java
@@ -21,7 +21,7 @@
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
-public class CBRXPathExampleTest extends DistributionExtractingTestcase {
+public class CBRXPathExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -30,31 +30,28 @@ protected String getExampleDirName() {
@Test
void test() throws Exception {
-
- try(Process2 ignored = startServiceProxyScript()) {
- // @formatter:off
- given()
- .body(readFile("order.xml"))
- .post(LOCALHOST_2000)
- .then()
- .statusCode(200)
- .body(containsString("Normal"));
-
- given()
- .contentType(APPLICATION_XML)
- .body(readFile("express.xml"))
- .post(LOCALHOST_2000)
+ // @formatter:off
+ given()
+ .body(readFile("order.xml"))
+ .post(LOCALHOST_2000)
+ .then()
+ .statusCode(200)
+ .body(containsString("Normal"));
+
+ given()
+ .contentType(APPLICATION_XML)
+ .body(readFile("express.xml"))
+ .post(LOCALHOST_2000)
+ .then()
+ .statusCode(200)
+ .body(containsString("Express"));
+
+ given()
+ .body(readFile("import.xml"))
+ .post(LOCALHOST_2000)
.then()
- .statusCode(200)
- .body(containsString("Express"));
-
- given()
- .body(readFile("import.xml"))
- .post(LOCALHOST_2000)
- .then()
- .statusCode(200)
- .body(containsString("import"));
- // @formatter:on
- }
+ .statusCode(200)
+ .body(containsString("import"));
+ // @formatter:on
}
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/InternalProxyExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/InternalProxyExampleTest.java
index caf4d1f2bb..aa159ec6a0 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/InternalProxyExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/InternalProxyExampleTest.java
@@ -13,14 +13,14 @@
limitations under the License. */
package com.predic8.membrane.examples.withoutinternet.test;
-import com.predic8.membrane.examples.util.*;
-import org.junit.jupiter.api.*;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
+import org.junit.jupiter.api.Test;
-import static io.restassured.RestAssured.*;
-import static io.restassured.http.ContentType.*;
-import static org.hamcrest.Matchers.*;
+import static io.restassured.RestAssured.given;
+import static io.restassured.http.ContentType.XML;
+import static org.hamcrest.Matchers.containsStringIgnoringCase;
-public class InternalProxyExampleTest extends DistributionExtractingTestcase {
+public class InternalProxyExampleTest extends AbstractSampleMembraneStartStopTestcase {
private static final String BASE_URL = "http://localhost:2000";
@@ -31,44 +31,42 @@ protected String getExampleDirName() {
@Test
void expressOrderRoutesToInternalProxy() throws Exception {
- try(Process2 ignored = startServiceProxyScript()) {
- // @formatter:off
- given()
- .contentType(XML)
- .body(readFileFromBaseDir("express.xml"))
- .when()
- .post(BASE_URL)
- .then()
- .statusCode(200)
- .body(containsStringIgnoringCase("Express"));
+ // @formatter:off
+ given()
+ .contentType(XML)
+ .body(readFileFromBaseDir("express.xml"))
+ .when()
+ .post(BASE_URL)
+ .then()
+ .statusCode(200)
+ .body(containsStringIgnoringCase("Express"));
- given()
- .when()
- .body(readFileFromBaseDir("normal.xml"))
- .post(BASE_URL)
- .then()
- .statusCode(200)
- .body(containsStringIgnoringCase("Normal"))
- .extract()
- .asString();
+ given()
+ .when()
+ .body(readFileFromBaseDir("normal.xml"))
+ .post(BASE_URL)
+ .then()
+ .statusCode(200)
+ .body(containsStringIgnoringCase("Normal"))
+ .extract()
+ .asString();
- given()
- .contentType(XML)
- .body("""
-
-
-
-
-
- """)
- .when()
- .post(BASE_URL)
- .then()
- .statusCode(200)
- .body(containsStringIgnoringCase("Normal"))
- .extract()
- .asString();
- // @formatter:on
- }
+ given()
+ .contentType(XML)
+ .body("""
+
+
+
+
+
+ """)
+ .when()
+ .post(BASE_URL)
+ .then()
+ .statusCode(200)
+ .body(containsStringIgnoringCase("Normal"))
+ .extract()
+ .asString();
+ // @formatter:on
}
}
\ No newline at end of file
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/Loadbalancing6HealthMonitorExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/Loadbalancing6HealthMonitorExampleTest.java
index 4891438524..917706ea25 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/Loadbalancing6HealthMonitorExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/Loadbalancing6HealthMonitorExampleTest.java
@@ -138,7 +138,7 @@ class https {
@Test
void https_backendsReachable() throws Exception {
ensureCertificates();
- try (Process2 ignored = builder.parameters(PROXIES_TLS_XML_OPTION).start()) {
+ try (Process2 ignored = builder.withParameters(PROXIES_TLS_XML_OPTION).start()) {
// @formatter:off
given()
.relaxedHTTPSValidation()
@@ -163,7 +163,7 @@ void https_backendsReachable() throws Exception {
@Test
void https_lbAlternates() throws Exception {
ensureCertificates();
- try (Process2 ignored = builder.parameters(PROXIES_TLS_XML_OPTION).start()) {
+ try (Process2 ignored = builder.withParameters(PROXIES_TLS_XML_OPTION).start()) {
Set seen = new HashSet<>();
for (int i = 0; i < 4; i++) {
// @formatter:off
@@ -188,7 +188,7 @@ void https_lbAlternates() throws Exception {
@Test
void https_adminShowsNodesUp() throws Exception {
ensureCertificates();
- try (Process2 ignored = builder.parameters(PROXIES_TLS_XML_OPTION).start()) {
+ try (Process2 ignored = builder.withParameters(PROXIES_TLS_XML_OPTION).start()) {
// @formatter:off
String html = given()
.relaxedHTTPSValidation()
@@ -211,7 +211,7 @@ void https_simulateNodeDown() throws Exception {
withBackedUpFile("proxies-tls.xml", () -> {
try {
setNode1Delay(baseDir.toPath().resolve("proxies-tls.xml"), 3000);
- try (Process2 ignored = builder.parameters(PROXIES_TLS_XML_OPTION).start()) {
+ try (Process2 ignored = builder.withParameters(PROXIES_TLS_XML_OPTION).start()) {
// @formatter:off
String html = given()
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/OAuth2APIExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/OAuth2APIExampleTest.java
index d94e8a7b8d..b878ed9c95 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/OAuth2APIExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/OAuth2APIExampleTest.java
@@ -57,7 +57,7 @@ void testIt() throws Exception {
.in(getExampleDir(getExampleDirName()))
.withWatcher(logger)
.script("client")
- .parameters("john password")
+ .withParameters("john password")
.waitAfterStartFor("true")
.start()) {
assertTrue(logger.contains("success"));
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/OAuth2CredentialsExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/OAuth2CredentialsExampleTest.java
index d9301ab33a..797f911306 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/OAuth2CredentialsExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/OAuth2CredentialsExampleTest.java
@@ -56,7 +56,7 @@ void testIt() throws Exception {
.in(getExampleDir( getExampleDirName()))
.withWatcher(logger)
.script("client")
- .parameters("john password")
+ .withParameters("john password")
.waitAfterStartFor("Ok")
.start()) {
assertTrue(true);
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/XMLValidationExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/XMLValidationExampleTest.java
index 802507f7c7..f6fd3d104d 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/XMLValidationExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/XMLValidationExampleTest.java
@@ -14,14 +14,14 @@
package com.predic8.membrane.examples.withoutinternet.test;
-import com.predic8.membrane.examples.util.*;
-import io.restassured.response.*;
-import org.junit.jupiter.api.*;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.Test;
-import static io.restassured.RestAssured.*;
-import static java.io.File.*;
+import static io.restassured.RestAssured.given;
+import static java.io.File.separator;
-public class XMLValidationExampleTest extends DistributionExtractingTestcase {
+public class XMLValidationExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -30,20 +30,18 @@ protected String getExampleDirName() {
@Test
public void test() throws Exception {
- try(Process2 ignored = startServiceProxyScript()) {
- // @formatter:off
- Response r = given()
- .body(readFileFromBaseDir("year.xml"))
- .post(LOCALHOST_2000);
- r.then()
- .statusCode(200);
-
- given()
- .body(readFileFromBaseDir("invalid-year.xml"))
- .post(LOCALHOST_2000)
- .then()
- .statusCode(400);
- // @formatter:on
- }
+ // @formatter:off
+ Response r = given()
+ .body(readFileFromBaseDir("year.xml"))
+ .post(LOCALHOST_2000);
+ r.then()
+ .statusCode(200);
+
+ given()
+ .body(readFileFromBaseDir("invalid-year.xml"))
+ .post(LOCALHOST_2000)
+ .then()
+ .statusCode(400);
+ // @formatter:on
}
}
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/validation/JSONSchemaValidationExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/validation/JSONSchemaValidationExampleTest.java
index 5c7ca6da7c..51651edfb1 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/validation/JSONSchemaValidationExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/validation/JSONSchemaValidationExampleTest.java
@@ -14,16 +14,17 @@
package com.predic8.membrane.examples.withoutinternet.validation;
-import com.predic8.membrane.examples.util.*;
-import org.junit.jupiter.api.*;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
+import org.junit.jupiter.api.Test;
-import static com.predic8.membrane.core.http.MimeType.*;
-import static io.restassured.RestAssured.*;
-import static io.restassured.http.ContentType.*;
-import static java.io.File.*;
-import static org.hamcrest.Matchers.*;
+import static com.predic8.membrane.core.http.MimeType.APPLICATION_PROBLEM_JSON;
+import static io.restassured.RestAssured.given;
+import static io.restassured.http.ContentType.JSON;
+import static java.io.File.separator;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
-public class JSONSchemaValidationExampleTest extends DistributionExtractingTestcase {
+public class JSONSchemaValidationExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -32,55 +33,48 @@ protected String getExampleDirName() {
@Test
void port2000() throws Exception {
- try(Process2 ignored = startServiceProxyScript()) {
+ // @formatter:off
+ // Test good JSON
+ given()
+ .contentType(JSON)
+ .body(readFileFromBaseDir("good2000.json"))
+ .when()
+ .post("http://localhost:2000")
+ .then()
+ .statusCode(200);
- // @formatter:off
- // Test good JSON
- given()
- .contentType(JSON)
- .body(readFileFromBaseDir("good2000.json"))
- .when()
- .post("http://localhost:2000")
- .then()
- .statusCode(200);
-
- // Test bad JSON
- given()
- .contentType(JSON)
- .body(readFileFromBaseDir("bad2000.json"))
- .when()
- .post("http://localhost:2000")
- .then()
- .statusCode(400)
- .contentType(APPLICATION_PROBLEM_JSON)
- .body("title", equalTo("JSON validation failed"))
- .body("type", equalTo("https://membrane-api.io/problems/user/validation"))
- .body(containsString("p1"))
- .body("errors.find { it.pointer == '/required' }.message", containsString("not found"));
- // @formatter:on
-
- }
+ // Test bad JSON
+ given()
+ .contentType(JSON)
+ .body(readFileFromBaseDir("bad2000.json"))
+ .when()
+ .post("http://localhost:2000")
+ .then()
+ .statusCode(400)
+ .contentType(APPLICATION_PROBLEM_JSON)
+ .body("title", equalTo("JSON validation failed"))
+ .body("type", equalTo("https://membrane-api.io/problems/user/validation"))
+ .body(containsString("p1"))
+ .body("errors.find { it.pointer == '/required' }.message", containsString("not found"));
+ // @formatter:on
}
@Test
void port2001() throws Exception {
- try(Process2 ignored = startServiceProxyScript()) {
- // @formatter:off
- given()
- .contentType(JSON)
- .body(readFileFromBaseDir("bad2001.json"))
- .when()
- .post("http://localhost:2001")
- .then()
- .statusCode(400)
- .contentType(APPLICATION_PROBLEM_JSON)
- .body("title", equalTo("JSON validation failed"))
- .body("type", equalTo("https://membrane-api.io/problems/user/validation"))
- .body("errors.find { it.pointer == '/properties/params/minItems' }.message", containsString("at least 2 items"))
- .body("errors.find { it.pointer == '/properties/meta/$ref/properties/source/minLength' }.message", containsString("at least 1"))
- .body("errors.find { it.pointer == '/properties/meta/$ref/additionalProperties' }.message", containsString("unexpected"));
- // @formatter:on
-
- }
+ // @formatter:off
+ given()
+ .contentType(JSON)
+ .body(readFileFromBaseDir("bad2001.json"))
+ .when()
+ .post("http://localhost:2001")
+ .then()
+ .statusCode(400)
+ .contentType(APPLICATION_PROBLEM_JSON)
+ .body("title", equalTo("JSON validation failed"))
+ .body("type", equalTo("https://membrane-api.io/problems/user/validation"))
+ .body("errors.find { it.pointer == '/properties/params/minItems' }.message", containsString("at least 2 items"))
+ .body("errors.find { it.pointer == '/properties/meta/$ref/properties/source/minLength' }.message", containsString("at least 1"))
+ .body("errors.find { it.pointer == '/properties/meta/$ref/additionalProperties' }.message", containsString("unexpected"));
+ // @formatter:on
}
}
\ No newline at end of file
diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/validation/SOAPProxyValidationExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/validation/SOAPProxyValidationExampleTest.java
index 411e84dac4..f1d4bca083 100644
--- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/validation/SOAPProxyValidationExampleTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/validation/SOAPProxyValidationExampleTest.java
@@ -14,17 +14,16 @@
package com.predic8.membrane.examples.withoutinternet.validation;
-import com.predic8.membrane.examples.util.*;
-import org.junit.jupiter.api.*;
+import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
+import org.junit.jupiter.api.Test;
-import java.io.*;
+import static com.predic8.membrane.core.http.MimeType.APPLICATION_SOAP_XML;
+import static io.restassured.RestAssured.given;
+import static java.io.File.separator;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.not;
-import static com.predic8.membrane.core.http.MimeType.*;
-import static io.restassured.RestAssured.*;
-import static java.io.File.*;
-import static org.hamcrest.CoreMatchers.*;
-
-public class SOAPProxyValidationExampleTest extends DistributionExtractingTestcase {
+public class SOAPProxyValidationExampleTest extends AbstractSampleMembraneStartStopTestcase {
@Override
protected String getExampleDirName() {
@@ -33,34 +32,30 @@ protected String getExampleDirName() {
@Test
void testValidCitySoapRequest() throws Exception {
- try (Process2 ignored = startServiceProxyScript()) {
- // @formatter:off
- given()
- .contentType(APPLICATION_SOAP_XML)
- .body(readFile("city-soap.xml"))
- .when()
- .post("http://localhost:2000/")
- .then()
- .body(not(containsString("faultcode")))
- .statusCode(200);
- // @formatter:on
- }
+ // @formatter:off
+ given()
+ .contentType(APPLICATION_SOAP_XML)
+ .body(readFile("city-soap.xml"))
+ .when()
+ .post("http://localhost:2000/")
+ .then()
+ .body(not(containsString("faultcode")))
+ .statusCode(200);
+ // @formatter:on
}
@Test
- void testInvalidCitySoapRequest() throws IOException, InterruptedException {
- try (Process2 ignored = startServiceProxyScript()) {
- // @formatter:off
- given()
- .contentType(APPLICATION_SOAP_XML)
- .body(readFile("invalid-city-soap.xml"))
- .when()
- .post("http://localhost:2000/")
- .then()
- .log().ifValidationFails()
- .body(containsString("faultcode"))
- .statusCode(200); // SOAP: even errors return 200 :-)
- // @formatter:on
- }
+ void testInvalidCitySoapRequest() throws Exception {
+ // @formatter:off
+ given()
+ .contentType(APPLICATION_SOAP_XML)
+ .body(readFile("invalid-city-soap.xml"))
+ .when()
+ .post("http://localhost:2000/")
+ .then()
+ .log().ifValidationFails()
+ .body(containsString("faultcode"))
+ .statusCode(200); // SOAP: even errors return 200 :-)
+ // @formatter:on
}
}
diff --git a/distribution/src/test/java/com/predic8/membrane/tutorials/AbstractMembraneTutorialTest.java b/distribution/src/test/java/com/predic8/membrane/tutorials/AbstractMembraneTutorialTest.java
index 5e9c53c125..ec5dd8bc42 100644
--- a/distribution/src/test/java/com/predic8/membrane/tutorials/AbstractMembraneTutorialTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/tutorials/AbstractMembraneTutorialTest.java
@@ -31,10 +31,7 @@ protected String getExampleDirName() {
}
@Override
- protected Process2 startServiceProxyScript(ConsoleWatcher watch, String script) throws IOException, InterruptedException {
- Process2.Builder builder = new Process2.Builder().in(baseDir);
- if (watch != null)
- builder = builder.withWatcher(watch);
- return builder.script(script).waitForMembrane().parameters("-c %s".formatted(getTutorialYaml())).start();
+ protected String getParameters() {
+ return "-c %s".formatted(getTutorialYaml());
}
}
\ No newline at end of file
diff --git a/distribution/src/test/java/com/predic8/membrane/tutorials/advanced/EnvironmentVariablesTutorialTest.java b/distribution/src/test/java/com/predic8/membrane/tutorials/advanced/EnvironmentVariablesTutorialTest.java
index f8cfc6c172..1759ca2514 100644
--- a/distribution/src/test/java/com/predic8/membrane/tutorials/advanced/EnvironmentVariablesTutorialTest.java
+++ b/distribution/src/test/java/com/predic8/membrane/tutorials/advanced/EnvironmentVariablesTutorialTest.java
@@ -49,7 +49,7 @@ protected Process2 startServiceProxyScript(ConsoleWatcher watch, String script)
if (watch != null)
builder = builder.withWatcher(watch);
- return builder.script(script).waitForMembrane().parameters("-c %s".formatted(getTutorialYaml())).start();
+ return builder.script(script).waitForMembrane().withParameters("-c %s".formatted(getTutorialYaml())).start();
}
}