[03/23] camel git commit: CAMEL-8239 Split jetty8 and jetty9 support into separate modules
http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/javabody/HttpJavaBodyTest.java -- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/javabody/HttpJavaBodyTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/javabody/HttpJavaBodyTest.java new file mode 100644 index 000..b55d938 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/javabody/HttpJavaBodyTest.java @@ -0,0 +1,126 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jetty.javabody; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.http.HttpConstants; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.junit.Test; + +/** + * @version + */ +public class HttpJavaBodyTest extends BaseJettyTest { + +@Override +public boolean isUseRouteBuilder() { +return false; +} + +@Test +public void testHttpSendJavaBodyAndReceiveString() throws Exception { +context.addRoutes(new RouteBuilder() { +@Override +public void configure() throws Exception { +from(jetty:http://localhost:{{port}}/myapp/myservice;) +.process(new Processor() { +public void process(Exchange exchange) throws Exception { +MyCoolBean cool = exchange.getIn().getBody(MyCoolBean.class); +assertNotNull(cool); + +assertEquals(123, cool.getId()); +assertEquals(Camel, cool.getName()); + +// we send back plain test +exchange.getOut().setHeader(Exchange.CONTENT_TYPE, text/plain); +exchange.getOut().setBody(OK); +} +}); +} +}); +context.start(); + +MyCoolBean cool = new MyCoolBean(123, Camel); + +String reply = template.requestBodyAndHeader(http://localhost:{{port}}/myapp/myservice;, cool, +Exchange.CONTENT_TYPE, HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, String.class); + +assertEquals(OK, reply); +} + +@Test +public void testHttpSendJavaBodyAndReceiveJavaBody() throws Exception { +context.addRoutes(new RouteBuilder() { +@Override +public void configure() throws Exception { +from(jetty:http://localhost:{{port}}/myapp/myservice;) +.process(new Processor() { +public void process(Exchange exchange) throws Exception { +MyCoolBean cool = exchange.getIn().getBody(MyCoolBean.class); +assertNotNull(cool); + +assertEquals(123, cool.getId()); +assertEquals(Camel, cool.getName()); + +MyCoolBean reply = new MyCoolBean(456, Camel rocks); +exchange.getOut().setBody(reply); +exchange.getOut().setHeader(Exchange.CONTENT_TYPE, HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT); +} +}); +} +}); +context.start(); + +MyCoolBean cool = new MyCoolBean(123, Camel); + +MyCoolBean reply = template.requestBodyAndHeader(http://localhost:{{port}}/myapp/myservice;, cool, +Exchange.CONTENT_TYPE, HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, MyCoolBean.class); + +assertEquals(456, reply.getId()); +assertEquals(Camel rocks, reply.getName()); +} + +@Test +public void testHttpSendStringAndReceiveJavaBody() throws Exception { +context.addRoutes(new RouteBuilder() { +@Override +public void configure() throws Exception { +
[03/23] camel git commit: CAMEL-8239 Split jetty8 and jetty9 support into separate modules
http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerTwoEndpointTest.java -- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerTwoEndpointTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerTwoEndpointTest.java new file mode 100644 index 000..bae3655 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerTwoEndpointTest.java @@ -0,0 +1,76 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jetty.jettyproducer; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.junit.Test; + +/** + * @version + */ +public class HttpJettyProducerTwoEndpointTest extends BaseJettyTest { + +@Test +public void testTwoEndpoints() throws Exception { +// these tests does not run well on Windows +if (isPlatform(windows)) { +return; +} + +// give Jetty time to startup properly +Thread.sleep(1000); + +Exchange a = template.request(direct:a, null); +assertNotNull(a); + +Exchange b = template.request(direct:b, null); +assertNotNull(b); + +assertEquals(Bye cheese, a.getOut().getBody(String.class)); +assertEquals(246, a.getOut().getHeader(foo, Integer.class).intValue()); + +assertEquals(Bye cake, b.getOut().getBody(String.class)); +assertEquals(912, b.getOut().getHeader(foo, Integer.class).intValue()); + +assertEquals(5, context.getEndpoints().size()); +} + +@Override +protected RouteBuilder createRouteBuilder() throws Exception { +return new RouteBuilder() { +@Override +public void configure() throws Exception { + from(direct:a).to(jetty://http://localhost:{{port}}/myapp?foo=123bar=cheese;); + + from(direct:b).to(jetty://http://localhost:{{port}}/myapp?foo=456bar=cake;); + +from(jetty://http://localhost:{{port}}/myapp;).process(new Processor() { +public void process(Exchange exchange) throws Exception { +int foo = exchange.getIn().getHeader(foo, Integer.class); +String bar = exchange.getIn().getHeader(bar, String.class); + +exchange.getOut().setHeader(foo, foo * 2); +exchange.getOut().setBody(Bye + bar); +} +}); +} +}; +} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerTwoParametersWithSameKeyTest.java -- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerTwoParametersWithSameKeyTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerTwoParametersWithSameKeyTest.java new file mode 100644 index 000..0b9ea95 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerTwoParametersWithSameKeyTest.java @@ -0,0 +1,119 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in