Search in sources :

Example 31 with Process2

use of com.predic8.membrane.examples.Process2 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 32 with Process2

use of com.predic8.membrane.examples.Process2 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 33 with Process2

use of com.predic8.membrane.examples.Process2 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)

Example 34 with Process2

use of com.predic8.membrane.examples.Process2 in project service-proxy by membrane.

the class ProxyTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("proxy");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        getAndAssert200("http://localhost:2000/axis2/services/BLZService?wsdl");
        getAndAssert200("http://localhost:2001/axis2/services/BLZService?wsdl");
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 35 with Process2

use of com.predic8.membrane.examples.Process2 in project service-proxy by membrane.

the class QuickstartRESTTest method doit.

@Test
public void doit() throws IOException, InterruptedException {
    File baseDir = getExampleDir("quickstart-rest");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        String result = getAndAssert200("http://localhost:2000/restnames/name.groovy?name=Pia");
        assertContains("Italy", result);
        AssertUtils.closeConnections();
        new ProxiesXmlUtil(new File(baseDir, "proxies.xml")).updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + "	xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + "	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + "	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + "					    http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + "	<router>\r\n" + "\r\n" + "       <serviceProxy name=\"names\" port=\"2000\">\r\n" + "         <path isRegExp=\"true\">/(rest)?names.*</path>\r\n" + "         <rewriter>\r\n" + "           <map from=\"/names/(.*)\" to=\"/restnames/name\\.groovy\\?name=$1\" />\r\n" + "         </rewriter>\r\n" + "         <statisticsCSV file=\"log.csv\" />\r\n" + "         <response>\r\n" + "           <regExReplacer regex=\"\\s*,\\s*&lt;\" replace=\"&lt;\" />\r\n" + "           <transform xslt=\"restnames.xsl\" />\r\n" + "         </response>\r\n" + "         <target host=\"thomas-bayer.com\" port=\"80\" />\r\n" + "       </serviceProxy>\r\n" + "     \r\n" + "       <serviceProxy name=\"Console\" port=\"9000\">\r\n" + "         <basicAuthentication>\r\n" + "           <user name=\"alice\" password=\"membrane\" />\r\n" + "         </basicAuthentication>			\r\n" + "         <adminConsole />\r\n" + "       </serviceProxy>	\r\n" + "     </router>\r\n" + "</spring:beans>", sl);
        result = getAndAssert200("http://localhost:2000/names/Pia");
        assertContains("Italy, Spain", result);
        assertContainsNot(",<", result);
        String csvLog = FileUtils.readFileToString(new File(baseDir, "log.csv"));
        assertContains("Pia", csvLog);
        AssertUtils.setupHTTPAuthentication("localhost", 9000, "alice", "membrane");
        result = getAndAssert200("http://localhost:9000/admin/");
        assertContains("ServiceProxies", result);
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) ProxiesXmlUtil(com.predic8.membrane.examples.ProxiesXmlUtil) File(java.io.File) Test(org.junit.Test)

Aggregations

Process2 (com.predic8.membrane.examples.Process2)37 Test (org.junit.Test)36 File (java.io.File)30 BufferLogger (com.predic8.membrane.examples.util.BufferLogger)4 SubstringWaitableConsoleEvent (com.predic8.membrane.examples.util.SubstringWaitableConsoleEvent)4 ProxiesXmlUtil (com.predic8.membrane.examples.ProxiesXmlUtil)3 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)3 AssertUtils.replaceInFile (com.predic8.membrane.test.AssertUtils.replaceInFile)2 OtpProvider (com.predic8.membrane.core.interceptor.authentication.session.totp.OtpProvider)1 FilenameFilter (java.io.FilenameFilter)1 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)1