CAMEL-8545: camel-swagger-java to run outside servlet - work in progress
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/818557e5 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/818557e5 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/818557e5 Branch: refs/heads/master Commit: 818557e56f9cd1b3f61b6963a2d3721497e19d2f Parents: aa3e117 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Sep 22 17:40:45 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Sep 23 07:51:04 2015 +0200 ---------------------------------------------------------------------- components/camel-netty4-http/pom.xml | 5 ++ .../netty4/http/rest/RestApiNettyTest.java | 80 ++++++++++++++++++++ components/camel-swagger-java/pom.xml | 5 -- .../apache/camel/swagger/RestApiNettyTest.java | 65 ---------------- 4 files changed, 85 insertions(+), 70 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/818557e5/components/camel-netty4-http/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/pom.xml b/components/camel-netty4-http/pom.xml index 8e80b61..f5942eb 100644 --- a/components/camel-netty4-http/pom.xml +++ b/components/camel-netty4-http/pom.xml @@ -80,6 +80,11 @@ <artifactId>camel-jaxb</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-swagger-java</artifactId> + <scope>test</scope> + </dependency> <!-- logging --> <dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/818557e5/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestApiNettyTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestApiNettyTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestApiNettyTest.java new file mode 100644 index 0000000..2abf8f1 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestApiNettyTest.java @@ -0,0 +1,80 @@ +/** + * 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.netty4.http.rest; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.netty4.http.BaseNettyTest; +import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.model.rest.RestParamType; +import org.apache.camel.swagger.SwaggerRestApiProcessorFactory; +import org.junit.Test; + +public class RestApiNettyTest extends BaseNettyTest { + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("SwaggerRestApiProcessorFactory", new SwaggerRestApiProcessorFactory()); + return jndi; + } + + @Override + protected boolean useJmx() { + return true; + } + + @Test + public void testApi() throws Exception { + String out = template.requestBody("netty4-http:http://localhost:{{port}}/api-doc/", null, String.class); + assertNotNull(out); + log.info(out); + + String id = context.getName(); + assertTrue(out.contains("{\"name\": \"" + id + "\"}")); + + out = template.requestBody("netty4-http:http://localhost:{{port}}/api-doc/" + id, null, String.class); + assertNotNull(out); + log.info(out); + + assertTrue(out.contains("\"/hello/bye/{name}\"")); + assertTrue(out.contains("\"/hello/hi/{name}\"")); + assertTrue(out.contains("\"summary\" : \"To update the greeting message\"")); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + restConfiguration().component("netty4-http").host("localhost").port(getPort()).apiContextPath("/api-doc"); + + rest("/hello").consumes("application/json").produces("application/json") + .get("/hi/{name}").description("Saying hi") + .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam() + .to("log:hi") + .get("/bye/{name}").description("Saying bye") + .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam() + .responseMessage().code(200).message("A reply message").endResponseMessage() + .to("log:bye") + .post("/bye").description("To update the greeting message").consumes("application/xml").produces("application/xml") + .param().name("greeting").type(RestParamType.body).dataType("string").description("Message to use as greeting").endParam() + .to("log:bye"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/818557e5/components/camel-swagger-java/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-swagger-java/pom.xml b/components/camel-swagger-java/pom.xml index 33072cf..742a9e5 100644 --- a/components/camel-swagger-java/pom.xml +++ b/components/camel-swagger-java/pom.xml @@ -114,11 +114,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-netty4-http</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/camel/blob/818557e5/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestApiNettyTest.java ---------------------------------------------------------------------- diff --git a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestApiNettyTest.java b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestApiNettyTest.java deleted file mode 100644 index 6379515..0000000 --- a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestApiNettyTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * 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.swagger; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.impl.JndiRegistry; -import org.apache.camel.model.rest.RestParamType; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; - -public class RestApiNettyTest extends CamelTestSupport { - - @Override - protected JndiRegistry createRegistry() throws Exception { - JndiRegistry jndi = super.createRegistry(); - jndi.bind("SwaggerRestApiProcessorFactory", new SwaggerRestApiProcessorFactory()); - return jndi; - } - - @Override - protected boolean useJmx() { - return true; - } - - @Test - public void testApi() throws Exception { - Thread.sleep(999999); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - restConfiguration().component("netty4-http").host("localhost").port(8080).apiContextPath("/api-doc"); - - rest("/hello").consumes("application/json").produces("application/json") - .get("/hi/{name}").description("Saying hi") - .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam() - .to("log:hi") - .get("/bye/{name}").description("Saying bye") - .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam() - .responseMessage().code(200).message("A reply message").endResponseMessage() - .to("log:bye") - .post("/bye").description("To update the greeting message").consumes("application/xml").produces("application/xml") - .param().name("greeting").type(RestParamType.body).dataType("string").description("Message to use as greeting").endParam() - .to("log:bye"); - } - }; - } -}