Search in sources :

Example 46 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class LoadBalancerStaticTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File base = getExampleDir("loadbalancer-static");
    AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023");
    Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
    try {
        for (int i = 0; i < 7; i++) Assert.assertEquals(i % 3 + 1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 47 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class LoggingCSVTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("logging-csv");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        getAndAssert200("http://localhost:2000/");
    } finally {
        sl.killScript();
    }
    assertContains("text/html", readFileToString(new File(baseDir, "log.csv")));
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 48 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class LoggingJDBCTest method test.

@Test
public void test() throws IOException, InterruptedException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
    copyDerbyJarToMembraneLib();
    File baseDir = getExampleDir("logging-jdbc");
    File beansConfig = new File(baseDir, "proxies.xml");
    FileUtils.writeStringToFile(beansConfig, FileUtils.readFileToString(beansConfig).replace("org.apache.derby.jdbc.ClientDriver", "org.apache.derby.jdbc.EmbeddedDriver").replace("jdbc:derby://localhost:1527/membranedb;create=true", "jdbc:derby:derbyDB;create=true"));
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        getAndAssert200("http://localhost:2000/");
    } finally {
        sl.killScript();
    }
    assertLogToDerbySucceeded(baseDir);
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 49 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class OAuth2MembraneTest method test.

@Test
public void test() throws Exception {
    Process2 sl = new Process2.Builder().in(getExampleDir("oauth2/membrane/authorization_server")).script("service-proxy").waitForMembrane().start();
    Process2 sl2 = new Process2.Builder().in(getExampleDir("oauth2/membrane/client")).script("service-proxy").waitForMembrane().start();
    try {
        AssertUtils.getAndAssert200("http://localhost:2001");
        String[] headers = new String[2];
        headers[0] = "Content-Type";
        headers[1] = "application/x-www-form-urlencoded";
        AssertUtils.postAndAssert(200, "http://localhost:2000/login/", headers, "target=&username=john&password=password");
        AssertUtils.postAndAssert(200, "http://localhost:2000/login/consent", headers, "target=&consent=Accept");
        Assert.assertEquals(AssertUtils.getAndAssert200("http://thomas-bayer.com"), AssertUtils.getAndAssert200("http://localhost:2000/"));
    } finally {
        sl.killScript();
        sl2.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) Test(org.junit.Test)

Example 50 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class OAuth2ApiTest method test.

@Test
public void test() throws Exception {
    Process2 sl = new Process2.Builder().in(getExampleDir("oauth2/api/authorization_server")).script("service-proxy").waitForMembrane().start();
    Process2 sl2 = new Process2.Builder().in(getExampleDir("oauth2/api/token_validator")).script("service-proxy").waitForMembrane().start();
    BufferLogger b = new BufferLogger();
    Process2 sl3 = new Process2.Builder().in(getExampleDir("oauth2/api")).withWatcher(b).script("start").waitAfterStartFor("OK").start();
    // sl3 can fail because at least the start.sh is very fragile in parsing the response for the access token. If the number or order of the params changes then start.sh will fail.
    try {
        // This is kind of redundant as sl3 already waits until "OK" is written or timeouts when its not
        assertTrue(b.toString().contains("OK"));
    } finally {
        sl.killScript();
        sl2.killScript();
        sl3.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) BufferLogger(com.predic8.membrane.examples.util.BufferLogger) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)39 Process2 (com.predic8.membrane.examples.Process2)35 File (java.io.File)29 StringWriter (java.io.StringWriter)5 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)4 Rule (com.predic8.membrane.core.rules.Rule)4 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 HttpRouter (com.predic8.membrane.core.HttpRouter)3 ProxiesXmlUtil (com.predic8.membrane.examples.ProxiesXmlUtil)3 BufferLogger (com.predic8.membrane.examples.util.BufferLogger)3 SubstringWaitableConsoleEvent (com.predic8.membrane.examples.util.SubstringWaitableConsoleEvent)3 Definitions (com.predic8.wsdl.Definitions)3 Port (com.predic8.wsdl.Port)3 Service (com.predic8.wsdl.Service)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Exchange (com.predic8.membrane.core.exchange.Exchange)2 Request (com.predic8.membrane.core.http.Request)2 Response (com.predic8.membrane.core.http.Response)2