Search in sources :

Example 6 with Service

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

the class LoginTest method test.

@Test
public void test() throws IOException, InterruptedException {
    Process2 sl = new Process2.Builder().in(getExampleDir("login")).script("service-proxy").waitForMembrane().start();
    try {
        String form = AssertUtils.getAndAssert200("http://localhost:2000/");
        AssertUtils.assertContains("Username:", form);
        AssertUtils.assertContains("Password:", form);
        form = AssertUtils.postAndAssert(200, "http://localhost:2000/login/", new String[] { "Content-Type", "application/x-www-form-urlencoded" }, "username=john&password=password");
        AssertUtils.assertContains("token:", form);
        String token = new OtpProvider().getNextCode("abcdefghijklmnop", System.currentTimeMillis());
        form = AssertUtils.postAndAssert(200, "http://localhost:2000/login/", new String[] { "Content-Type", "application/x-www-form-urlencoded" }, "token=" + token);
        // successful login?
        AssertUtils.assertContains("This page has moved to", form);
        // access the "protected" page
        form = AssertUtils.getAndAssert200("http://localhost:2000/");
        AssertUtils.assertContains("predic8.com", form);
        // logout
        form = AssertUtils.getAndAssert200("http://localhost:2000/login/logout");
        AssertUtils.assertContains("Username:", form);
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) OtpProvider(com.predic8.membrane.core.interceptor.authentication.session.totp.OtpProvider) Test(org.junit.Test)

Example 7 with Service

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

the class RateLimiterTest method test.

@Test
public void test() throws IOException, InterruptedException {
    Process2 sl = new Process2.Builder().in(getExampleDir("rateLimiter")).script("service-proxy").waitForMembrane().start();
    try {
        AssertUtils.getAndAssert200("http://localhost:2000/");
        AssertUtils.getAndAssert200("http://localhost:2000/");
        AssertUtils.getAndAssert200("http://localhost:2000/");
        AssertUtils.getAndAssert(429, "http://localhost:2000/");
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) Test(org.junit.Test)

Example 8 with Service

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

the class ThrottleTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("throttle");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        getAndAssert200("http://localhost:2000/");
        long start = System.currentTimeMillis();
        getAndAssert200("http://localhost:2000/");
        long elapsedMillis = System.currentTimeMillis() - start;
        Assert.assertTrue(elapsedMillis >= 1000);
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 9 with Service

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

the class SSLClient method test.

@Test
public void test() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyManagementException {
    File baseDir = getExampleDir("ssl-client");
    AssertUtils.replaceInFile(new File(baseDir, "proxies.xml"), "8080", "3023");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        AssertUtils.assertContains("<title>Google", getAndAssert200("http://localhost:3023/"));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 10 with Service

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

the class JSONSchemaValidationTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("validation" + File.separator + "json-schema");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        for (int port : new int[] { 2000, 2001 }) {
            postAndAssert(200, "http://localhost:" + port + "/", readFileToString(new File(baseDir, "good" + port + ".json")));
            postAndAssert(400, "http://localhost:" + port + "/", readFileToString(new File(baseDir, "bad" + port + ".json")));
        }
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) 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