Search in sources :

Example 16 with Service

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

the class REST2SOAPJSONTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("rest2soap-json");
    AssertUtils.replaceInFile(new File(baseDir, "proxies.xml"), "2000", "2043");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        assertContains("\"bic\":\"COLSDE33XXX\"", getAndAssert200("http://localhost:2043/bank/37050198", new String[] { "Accept", "application/json" }));
        assertContains("\"bic\":\"GENODE61KIR\"", getAndAssert200("http://localhost:2043/bank/66762332", new String[] { "Accept", "application/json" }));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 17 with Service

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

the class FileExchangeStoreTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("file-exchangestore");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        getAndAssert200("http://localhost:2000/");
        Thread.sleep(1000);
        File exchangesDir = new File(baseDir, "exchanges");
        if (!containsRecursively(exchangesDir, new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".msg");
            }
        }))
            throw new AssertionError("Did not find *.msg in exchanges dir.");
    } finally {
        sl.killScript();
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 18 with Service

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

the class BasicAuthTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("basic-auth");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        disableHTTPAuthentication();
        getAndAssert(401, CUSTOMER_HOST_LOCAL + CUSTOMER_PATH);
        setupHTTPAuthentication("localhost", 2000, "alice", "membrane");
        getAndAssert200(CUSTOMER_HOST_LOCAL + CUSTOMER_PATH);
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 19 with Service

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

the class RoutingTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File base = getExampleDir("versioning/routing");
    String[] header = new String[] { "Content-Type", "text/xml" };
    String request_v11 = FileUtils.readFileToString(new File(base, "request_v11.xml"));
    String request_v20 = FileUtils.readFileToString(new File(base, "request_v20.xml"));
    replaceInFile(new File(base, "proxies.xml"), "8080", "3024");
    replaceInFile(new File(base, "proxies.xml"), "2000", "3025");
    replaceInFile(new File(base, "src/com/predic8/contactservice/Launcher.java"), "8080", "3024");
    Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
    try {
        Process2 antNode1 = new Process2.Builder().in(base).waitAfterStartFor("run:").executable("ant run").start();
        try {
            // wait for Endpoints to start
            Thread.sleep(2000);
            // directly talk to versioned endpoints
            assertContains("1.1", postAndAssert(200, "http://localhost:3024/ContactService/v11", header, request_v11));
            assertContains("2.0", postAndAssert(200, "http://localhost:3024/ContactService/v20", header, request_v20));
            // talk to wrong endpoint
            postAndAssert(500, "http://localhost:3024/ContactService/v20", header, request_v11);
            // talk to proxy
            assertContains("1.1", postAndAssert(200, "http://localhost:3025/ContactService", header, request_v11));
            assertContains("2.0", postAndAssert(200, "http://localhost:3025/ContactService", header, request_v20));
        } finally {
            antNode1.killScript();
        }
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) AssertUtils.replaceInFile(com.predic8.membrane.test.AssertUtils.replaceInFile) File(java.io.File) Test(org.junit.Test)

Example 20 with Service

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

the class SOAPProxyValidationTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("validation" + File.separator + "soap-Proxy");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        String url = "http://localhost:2000/axis2/services/BLZService/getBankResponse";
        String[] headers = new String[] { "Content-Type", "application/soap+xml" };
        postAndAssert(200, url, headers, readFileToString(new File(baseDir, "blz-soap.xml")));
        postAndAssert(400, url, headers, readFileToString(new File(baseDir, "invalid-blz-soap.xml")));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) 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