Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions distribution/examples/offline/membrane.cmd

This file was deleted.

21 changes: 0 additions & 21 deletions distribution/examples/offline/membrane.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,25 @@ public abstract class DistributionExtractingTestcase {
private static File membraneHome;
protected File baseDir;

/**
* The directory of the example relative to <code>distribution/examples</code>
*/
protected abstract String getExampleDirName();

/**
* The parameters to start the script with
*/
protected String getParameters() {
return "";
}

/**
* The environment variables for the script
*/
protected Map<String, String> getEnvs() {
return Map.of();
}

@BeforeAll
public static void beforeAll() throws Exception {
log.info("unzipping router distribution");
Expand Down Expand Up @@ -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");
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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<String, String> envs) {
env.putAll(envs);
return this;
}

public Builder withParameters(String parameters) {
this.parameters = parameters;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,23 @@
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() {
return "web-services-soap/rest2soap-template";
}

@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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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/"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}
}
Loading
Loading