This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6fbbefe6b2f57dc7daab1037c3dc02b08c33bce6 Author: Luca Burgazzoli <[email protected]> AuthorDate: Tue Mar 9 18:50:06 2021 +0100 dsl: refactor camel-xml-jaxb-dsl tests (swagger) --- dsl/camel-xml-jaxb-dsl-test/pom.xml | 1 + dsl/camel-xml-jaxb-dsl-test/swagger/pom.xml | 157 +++++++++++++++++++++ .../xml/jaxb/swagger/DummyRestConsumerFactory.java | 51 +++++++ .../xml/jaxb/swagger/DummyRestProducerFactory.java | 59 ++++++++ .../RestSwaggerReaderPropertyPlaceholderTest.java | 9 +- .../src/test/resources/log4j2-test.properties | 31 ++++ 6 files changed, 305 insertions(+), 3 deletions(-) diff --git a/dsl/camel-xml-jaxb-dsl-test/pom.xml b/dsl/camel-xml-jaxb-dsl-test/pom.xml index 1211a15..b987886 100644 --- a/dsl/camel-xml-jaxb-dsl-test/pom.xml +++ b/dsl/camel-xml-jaxb-dsl-test/pom.xml @@ -39,5 +39,6 @@ <module>cdi</module> <module>jbpm</module> <module>spring</module> + <module>swagger</module> </modules> </project> diff --git a/dsl/camel-xml-jaxb-dsl-test/swagger/pom.xml b/dsl/camel-xml-jaxb-dsl-test/swagger/pom.xml new file mode 100644 index 0000000..97fce75 --- /dev/null +++ b/dsl/camel-xml-jaxb-dsl-test/swagger/pom.xml @@ -0,0 +1,157 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>camel-xml-jaxb-dsl-test</artifactId> + <version>3.9.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-xml-jaxb-dsl-test-swagger</artifactId> + <packaging>jar</packaging> + <name>Camel :: XML DSL Jaxb :: Test :: Swagger</name> + <description>Camel XML DSL Tests with Jaxb and Swagger</description> + + <properties> + <firstVersion>3.9.0</firstVersion> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-xml-jaxb-dsl</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-support</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-swagger-java</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-main</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-management</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-direct</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-rest</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-mock</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core-languages</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bean</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-log</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-telegram</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-seda</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-jcl</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <!-- skip testing on java 8 --> + <profiles> + <profile> + <id>jdk8</id> + <activation> + <jdk>[,8)</jdk> + </activation> + <properties> + <maven.test.skip.exec>true</maven.test.skip.exec> + </properties> + </profile> + </profiles> + +</project> \ No newline at end of file diff --git a/dsl/camel-xml-jaxb-dsl-test/swagger/src/test/java/org/apache/camel/dsl/xml/jaxb/swagger/DummyRestConsumerFactory.java b/dsl/camel-xml-jaxb-dsl-test/swagger/src/test/java/org/apache/camel/dsl/xml/jaxb/swagger/DummyRestConsumerFactory.java new file mode 100644 index 0000000..7dea70b --- /dev/null +++ b/dsl/camel-xml-jaxb-dsl-test/swagger/src/test/java/org/apache/camel/dsl/xml/jaxb/swagger/DummyRestConsumerFactory.java @@ -0,0 +1,51 @@ +/* + * 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.dsl.xml.jaxb.swagger; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.component.seda.SedaEndpoint; +import org.apache.camel.spi.RestConfiguration; +import org.apache.camel.spi.RestConsumerFactory; +import org.apache.camel.support.ClassicUuidGenerator; + +public class DummyRestConsumerFactory implements RestConsumerFactory { + + @Override + public Consumer createConsumer( + CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate, + String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters) + throws Exception { + // just use a seda endpoint for testing purpose + String id; + if (uriTemplate != null) { + id = ClassicUuidGenerator.generateSanitizedId(basePath + uriTemplate); + } else { + id = ClassicUuidGenerator.generateSanitizedId(basePath); + } + // remove leading dash as we add that ourselves + if (id.startsWith("-")) { + id = id.substring(1); + } + SedaEndpoint seda = camelContext.getEndpoint("seda:" + verb + "-" + id, SedaEndpoint.class); + return seda.createConsumer(processor); + } + +} diff --git a/dsl/camel-xml-jaxb-dsl-test/swagger/src/test/java/org/apache/camel/dsl/xml/jaxb/swagger/DummyRestProducerFactory.java b/dsl/camel-xml-jaxb-dsl-test/swagger/src/test/java/org/apache/camel/dsl/xml/jaxb/swagger/DummyRestProducerFactory.java new file mode 100644 index 0000000..2203621 --- /dev/null +++ b/dsl/camel-xml-jaxb-dsl-test/swagger/src/test/java/org/apache/camel/dsl/xml/jaxb/swagger/DummyRestProducerFactory.java @@ -0,0 +1,59 @@ +/* + * 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.dsl.xml.jaxb.swagger; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Producer; +import org.apache.camel.spi.RestConfiguration; +import org.apache.camel.spi.RestProducerFactory; +import org.apache.camel.support.DefaultProducer; +import org.apache.camel.util.StringHelper; + +public class DummyRestProducerFactory implements RestProducerFactory { + + @Override + public Producer createProducer( + CamelContext camelContext, String host, + String verb, String basePath, final String uriTemplate, String queryParameters, + String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters) + throws Exception { + + // use a dummy endpoint + Endpoint endpoint = camelContext.getEndpoint("stub:dummy"); + + return new DefaultProducer(endpoint) { + @Override + public void process(Exchange exchange) throws Exception { + String query = exchange.getIn().getHeader(Exchange.REST_HTTP_QUERY, String.class); + if (query != null) { + String name = StringHelper.after(query, "name="); + exchange.getIn().setBody("Bye " + name); + } + String uri = exchange.getIn().getHeader(Exchange.REST_HTTP_URI, String.class); + if (uri != null) { + int pos = uri.lastIndexOf('/'); + String name = uri.substring(pos + 1); + exchange.getIn().setBody("Hello " + name); + } + } + }; + } +} diff --git a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderPropertyPlaceholderTest.java b/dsl/camel-xml-jaxb-dsl-test/swagger/src/test/java/org/apache/camel/dsl/xml/jaxb/swagger/RestSwaggerReaderPropertyPlaceholderTest.java similarity index 93% rename from components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderPropertyPlaceholderTest.java rename to dsl/camel-xml-jaxb-dsl-test/swagger/src/test/java/org/apache/camel/dsl/xml/jaxb/swagger/RestSwaggerReaderPropertyPlaceholderTest.java index b840ab1..6e4d0ed 100644 --- a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderPropertyPlaceholderTest.java +++ b/dsl/camel-xml-jaxb-dsl-test/swagger/src/test/java/org/apache/camel/dsl/xml/jaxb/swagger/RestSwaggerReaderPropertyPlaceholderTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.swagger; +package org.apache.camel.dsl.xml.jaxb.swagger; import java.util.List; import java.util.Properties; @@ -29,13 +29,16 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.engine.DefaultClassResolver; import org.apache.camel.model.rest.RestDefinition; import org.apache.camel.model.rest.RestParamType; -import org.apache.camel.swagger.producer.DummyRestProducerFactory; +import org.apache.camel.swagger.RestSwaggerReader; +import org.apache.camel.swagger.RestSwaggerSupport; import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class RestSwaggerReaderPropertyPlaceholderTest extends CamelTestSupport { diff --git a/dsl/camel-xml-jaxb-dsl-test/swagger/src/test/resources/log4j2-test.properties b/dsl/camel-xml-jaxb-dsl-test/swagger/src/test/resources/log4j2-test.properties new file mode 100644 index 0000000..56bef5c --- /dev/null +++ b/dsl/camel-xml-jaxb-dsl-test/swagger/src/test/resources/log4j2-test.properties @@ -0,0 +1,31 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +appender.file.type = File +appender.file.name = file +appender.file.fileName = target/camel-xml-jaxb-dsl-test-swagger.log +appender.file.layout.type = PatternLayout +appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n + +appender.out.type = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = [%30.30t] %-30.30c{1} %-5p %m%n + +rootLogger.level = INFO +rootLogger.appenderRef.file.ref = file +#rootLogger.appenderRef.out.ref = out
