Search in sources :

Example 1 with HttpResponse

use of org.wildfly.camel.test.common.http.HttpRequest.HttpResponse in project wildfly-camel by wildfly-extras.

the class CouchbaseIntegrationTest method initCouchbaseServer.

private void initCouchbaseServer() throws Exception {
    HttpResponse response = HttpRequest.post(getResource("pools/default")).header("ns_server-ui", "yes").content("memoryQuota=256").getResponse();
    Assert.assertEquals(200, response.getStatusCode());
    response = HttpRequest.post(getResource("pools/default/buckets")).header("ns_server-ui", "yes").content("threadsNumber=3&replicaIndex=0&replicaNumber=1&evictionPolicy=valueOnly" + "&ramQuotaMB=100&bucketType=membase&name=default&authType=sasl" + "&saslPassword=&otherBucketsRamQuotaMB=100").getResponse();
    Assert.assertEquals(202, response.getStatusCode());
    response = HttpRequest.post(getResource("settings/stats")).header("ns_server-ui", "yes").content("sendStats=false").getResponse();
    Assert.assertEquals(200, response.getStatusCode());
    response = HttpRequest.post(getResource("settings/web")).header("ns_server-ui", "yes").content("password=p4ssw0rd&port=SAME&username=admin").getResponse();
    Assert.assertEquals(200, response.getStatusCode());
    HttpResponse loginResponse = HttpRequest.post(getResource("uilogin")).header("ns_server-ui", "yes").content("password=p4ssw0rd&user=admin").getResponse();
    String loginCookie = loginResponse.getHeader("Set-Cookie");
    Assert.assertEquals(200, loginResponse.getStatusCode());
    Assert.assertNotNull("Login cookie was null", loginCookie);
    // Guard against admin credentials not immediately taking effect
    Thread.sleep(100);
    response = HttpRequest.post(getResource("sampleBuckets/install")).header("ns_server-ui", "yes").header("Cookie", loginCookie).content("[\"beer-sample\"]").getResponse();
    Assert.assertEquals(202, response.getStatusCode());
    // Wait for sample data to be loaded
    int attempts = 0;
    do {
        response = HttpRequest.get(getResource("logs")).header("Accept", "application/json, text/plain, */*").header("ns_server-ui", "yes").header("Cookie", loginCookie).getResponse();
        Assert.assertEquals(200, response.getStatusCode());
        if (!response.getBody().contains("Completed loading sample bucket beer-sample")) {
            attempts++;
            Thread.sleep(500);
        } else {
            return;
        }
    } while (attempts < 30);
    throw new IllegalStateException("Gave up waiting for Couchbase server to become ready");
}
Also used : HttpResponse(org.wildfly.camel.test.common.http.HttpRequest.HttpResponse) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 2 with HttpResponse

use of org.wildfly.camel.test.common.http.HttpRequest.HttpResponse in project wildfly-camel by wildfly-extras.

the class RestDslRootContextTest method testRestDslRootContext.

@Test
public void testRestDslRootContext() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            restConfiguration().component("undertow").contextPath("/").host("localhost").port(8080);
            rest().get().route().setBody(constant("GET: /")).endRest();
        }
    });
    camelctx.start();
    try {
        deployer.deploy(SIMPLE_WAR);
        // Verify root context path
        HttpResponse response = HttpRequest.get("http://localhost:8080/").getResponse();
        Assert.assertEquals(200, response.getStatusCode());
        Assert.assertTrue(response.getBody().contains("GET: /"));
        // Verify other deployed context paths
        response = HttpRequest.get("http://localhost:8080/simple").getResponse();
        Assert.assertEquals(200, response.getStatusCode());
        Assert.assertTrue(response.getBody().contains("GET: /simple"));
    } finally {
        deployer.undeploy(SIMPLE_WAR);
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpResponse(org.wildfly.camel.test.common.http.HttpRequest.HttpResponse) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 3 with HttpResponse

use of org.wildfly.camel.test.common.http.HttpRequest.HttpResponse in project wildfly-camel by wildfly-extras.

the class CXFWSSecureConsumerIntegrationTest method testCXFSecureConsumer.

@Test
public void testCXFSecureConsumer() throws Exception {
    CamelContext camelContext = new DefaultCamelContext();
    CxfComponent cxfComponent = camelContext.getComponent("cxf", CxfComponent.class);
    CxfEndpoint cxfProducer = createCxfEndpoint(SECURE_WS_ENDPOINT_URL, cxfComponent);
    cxfProducer.setSslContextParameters(createSSLContextParameters());
    CxfEndpoint cxfConsumer = createCxfEndpoint(SECURE_WS_ENDPOINT_URL, cxfComponent);
    camelContext.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to(cxfProducer);
            from(cxfConsumer).transform(simple("Hello ${body}"));
        }
    });
    try {
        // Force WildFly to generate a self-signed SSL cert & keystore
        HttpRequest.get("https://localhost:8443").throwExceptionOnFailure(false).getResponse();
        camelContext.start();
        ProducerTemplate template = camelContext.createProducerTemplate();
        String result = template.requestBody("direct:start", "Kermit", String.class);
        Assert.assertEquals("Hello Kermit", result);
        // Verify that if we attempt to use HTTP, we get a 302 redirect to the HTTPS endpoint URL
        HttpResponse response = HttpRequest.get(INSECURE_WS_ENDPOINT_URL + "?wsdl").throwExceptionOnFailure(false).getResponse();
        Assert.assertEquals(302, response.getStatusCode());
        Assert.assertEquals(response.getHeader("Location"), SECURE_WS_ENDPOINT_URL + "?wsdl");
    } finally {
        camelContext.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpResponse(org.wildfly.camel.test.common.http.HttpRequest.HttpResponse) CxfComponent(org.apache.camel.component.cxf.CxfComponent) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 4 with HttpResponse

use of org.wildfly.camel.test.common.http.HttpRequest.HttpResponse in project wildfly-camel by wildfly-extras.

the class SpringContextBindingWarTest method deployResourceInjectionTest.

private void deployResourceInjectionTest(String depName, String expectedResult) throws Exception {
    try {
        deployer.deploy(depName);
        CamelContext camelctx = contextRegistry.getCamelContext("jndi-delayed-binding-spring-context");
        Assert.assertNotNull("Expected jndi-delayed-binding-spring-context to not be null", camelctx);
        Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
        String contextPath = depName.replace(".war", "");
        HttpResponse response = HttpRequest.get("http://localhost:8080/" + contextPath).getResponse();
        Assert.assertEquals(expectedResult, response.getBody());
    } finally {
        deployer.undeploy(depName);
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) HttpResponse(org.wildfly.camel.test.common.http.HttpRequest.HttpResponse)

Example 5 with HttpResponse

use of org.wildfly.camel.test.common.http.HttpRequest.HttpResponse in project wildfly-camel by wildfly-extras.

the class RestDslMultipleVerbsIntegrationTest method testRestDslMultipleVerbs.

@Test
public void testRestDslMultipleVerbs() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            restConfiguration().component("undertow").contextPath("camel/rest").host("localhost").port(8080);
            rest("/hello").get("/{name}").to("direct:get").post("/{name}").to("direct:post").put("/{name}").to("direct:put");
            from("direct:get").setBody(simple("GET ${header.name}"));
            from("direct:post").setBody(simple("POST ${header.name}"));
            from("direct:put").setBody(simple("PUT ${header.name}"));
        }
    });
    camelctx.start();
    try {
        HttpResponse result = HttpRequest.get("http://localhost:8080/camel/rest/hello/Kermit").getResponse();
        Assert.assertEquals("GET Kermit", result.getBody());
        result = HttpRequest.post("http://localhost:8080/camel/rest/hello/Kermit").getResponse();
        Assert.assertEquals("POST Kermit", result.getBody());
        result = HttpRequest.put("http://localhost:8080/camel/rest/hello/Kermit").getResponse();
        Assert.assertEquals("PUT Kermit", result.getBody());
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpResponse(org.wildfly.camel.test.common.http.HttpRequest.HttpResponse) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

HttpResponse (org.wildfly.camel.test.common.http.HttpRequest.HttpResponse)10 CamelContext (org.apache.camel.CamelContext)8 Test (org.junit.Test)8 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)5 HttpHandler (io.undertow.server.HttpHandler)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 Client (javax.ws.rs.client.Client)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 CxfComponent (org.apache.camel.component.cxf.CxfComponent)1 CxfEndpoint (org.apache.camel.component.cxf.CxfEndpoint)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 ServiceContainer (org.jboss.msc.service.ServiceContainer)1 ServiceName (org.jboss.msc.service.ServiceName)1 ExpectedException (org.junit.rules.ExpectedException)1 Host (org.wildfly.extension.undertow.Host)1