Repository: camel Updated Branches: refs/heads/master a4bf413a0 -> 20401a386
http://git-wip-us.apache.org/repos/asf/camel/blob/20401a38/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java new file mode 100644 index 0000000..0f58d01 --- /dev/null +++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java @@ -0,0 +1,150 @@ +/** + * 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.itest.springboot.util; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Document; + +/** + * Resolves the currently used version of a library. Useful to run unit tests directly from the IDE, without passing additional parameters. + * It resolves surefire properties. + */ +public final class DependencyResolver { + + private static final String DEFAULT_PREFIX = "version_"; + + private static DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + private static XPathFactory xPathfactory = XPathFactory.newInstance(); + + private DependencyResolver() { + } + + /** + * Gets a groupId and artifactId in the form "groupId:artifactId" and returns the current version from the pom. + * Uses {@link DependencyResolver#withVersion(String, String)} using a default prefix. + * + * @param groupArtifact the groupId and artifactId in the form "groupId:artifactId" + * @return the maven canonical form of the artifact "groupId:artifactId:version" + * @throws RuntimeException if the version cannot be resolved + */ + public static String withVersion(String groupArtifact) { + return withVersion(DEFAULT_PREFIX, groupArtifact); + } + + /** + * Gets a groupId and artifactId in the form "groupId:artifactId" and returns the current version from the pom. + * Versions are resolved from system properties when using surefire, and by looking at the poms when running from IDE. + * + * @param prefix the prefix to use to lookup the property from surefire + * @param groupArtifact the groupId and artifactId in the form "groupId:artifactId" + * @return the maven canonical form of the artifact "groupId:artifactId:version" + * @throws RuntimeException if the version cannot be resolved + */ + public static String withVersion(String prefix, String groupArtifact) { + String version = System.getProperty(prefix + groupArtifact); + + try { + if (version == null) { + // Usually, when running from IDE + version = resolveSurefireProperty(prefix + groupArtifact); + } + } catch (Exception e) { + throw new IllegalStateException("Error while retrieving version for artifact: " + groupArtifact, e); + } + + if (version == null) { + throw new IllegalStateException("Cannot determine version for maven artifact: " + groupArtifact); + } else if (!isResolved(version)) { + throw new IllegalStateException("Cannot resolve version for maven artifact: " + groupArtifact + ". Missing property value: " + version); + } + + return groupArtifact + ":" + version; + } + + private static String resolveSurefireProperty(String property) throws Exception { + property = getSurefirePropertyFromPom("pom.xml", property); + if (property != null && !isResolved(property)) { + property = resolveProperty("pom.xml", property, 0); + } + if (property != null && !isResolved(property)) { + property = resolveProperty("../pom.xml", property, 0); + } + if (property != null && !isResolved(property)) { + property = resolveProperty("../../parent/pom.xml", property, 0); + } + + return property; + } + + private static String resolveProperty(String pom, String property, int depth) throws Exception { + property = property.trim(); + if (!property.startsWith("${") || !property.endsWith("}")) { + throw new IllegalArgumentException("Wrong property reference: " + property); + } + + String res; + if (property.equals("${project.version}")) { + res = getParentVersion(pom); + } else { + String p = property.substring(2); + p = p.substring(0, p.length() - 1); + res = getPropertyFromPom(pom, p); + if (res == null) { + return property; + } + } + + if (res != null && !isResolved(res) && depth < 5) { + res = resolveProperty(pom, res, depth + 1); + } + return res; + } + + private static String getSurefirePropertyFromPom(String pom, String property) throws Exception { + return xpath(pom, "//plugin[artifactId='maven-surefire-plugin']//systemProperties/property[name='" + property + "']/value/text()"); + } + + private static String getPropertyFromPom(String pom, String property) throws Exception { + return xpath(pom, "/project/properties/" + property + "/text()"); + } + + private static String getParentVersion(String pom) throws Exception { + return xpath(pom, "/project/parent/version/text()"); + } + + private static String xpath(String pom, String expression) throws Exception { + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.parse(pom); + XPath xpath = xPathfactory.newXPath(); + XPathExpression expr = xpath.compile(expression); + String res = expr.evaluate(doc); + if (res != null && res.trim().length() == 0) { + res = null; + } + return res; + } + + private static boolean isResolved(String value) { + return value != null && !value.startsWith("$"); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/20401a38/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/JarExporter.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/JarExporter.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/JarExporter.java index 6886294..2defa9e 100644 --- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/JarExporter.java +++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/JarExporter.java @@ -32,10 +32,9 @@ public class JarExporter { public void exportJar() throws Exception { Archive<?> archive = ArquillianPackager.springBootPackage(new ITestConfigBuilder() - .module("camel-box") + .module("camel-ahc-ws") .build()); - new ZipExporterImpl(archive).exportTo(new File("target/export.zip"), true); } http://git-wip-us.apache.org/repos/asf/camel/blob/20401a38/tests/camel-itest-spring-boot/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension b/tests/camel-itest-spring-boot/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension new file mode 100644 index 0000000..19248f1 --- /dev/null +++ b/tests/camel-itest-spring-boot/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension @@ -0,0 +1 @@ +org.apache.camel.itest.springboot.arquillian.container.ManagedSEContainerExtension http://git-wip-us.apache.org/repos/asf/camel/blob/20401a38/tests/camel-itest-spring-boot/src/test/resources/arquillian.xml ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/resources/arquillian.xml b/tests/camel-itest-spring-boot/src/test/resources/arquillian.xml new file mode 100644 index 0000000..6965e62 --- /dev/null +++ b/tests/camel-itest-spring-boot/src/test/resources/arquillian.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://jboss.org/schema/arquillian" + xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> + + <container qualifier="springboot_managed" default="true"> + + <configuration> + <property name="debug">false</property> + + <property name="librariesPath">${user.dir}/target</property> + </configuration> + + </container> + +</arquillian> http://git-wip-us.apache.org/repos/asf/camel/blob/20401a38/tests/camel-itest-spring-boot/src/test/resources/components/apns-clientStore.p12 ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/resources/components/apns-clientStore.p12 b/tests/camel-itest-spring-boot/src/test/resources/components/apns-clientStore.p12 new file mode 100644 index 0000000..28ab70a Binary files /dev/null and b/tests/camel-itest-spring-boot/src/test/resources/components/apns-clientStore.p12 differ http://git-wip-us.apache.org/repos/asf/camel/blob/20401a38/tests/camel-itest-spring-boot/src/test/resources/components/apns-serverStore.p12 ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/resources/components/apns-serverStore.p12 b/tests/camel-itest-spring-boot/src/test/resources/components/apns-serverStore.p12 new file mode 100644 index 0000000..b375de7 Binary files /dev/null and b/tests/camel-itest-spring-boot/src/test/resources/components/apns-serverStore.p12 differ http://git-wip-us.apache.org/repos/asf/camel/blob/20401a38/tests/camel-itest-spring-boot/src/test/resources/components/ibatis-SqlMapConfig.xml ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/resources/components/ibatis-SqlMapConfig.xml b/tests/camel-itest-spring-boot/src/test/resources/components/ibatis-SqlMapConfig.xml index 6f2ad4d..a4f205d 100644 --- a/tests/camel-itest-spring-boot/src/test/resources/components/ibatis-SqlMapConfig.xml +++ b/tests/camel-itest-spring-boot/src/test/resources/components/ibatis-SqlMapConfig.xml @@ -17,34 +17,34 @@ --> <!DOCTYPE configuration - PUBLIC "-//mybatis.org//DTD Config 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-config.dtd"> + PUBLIC "-//mybatis.org//DTD Config 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> - <settings> - <setting name="useGeneratedKeys" value="false"/> - </settings> + <settings> + <setting name="useGeneratedKeys" value="false"/> + </settings> - <!-- Use type aliases to avoid typing the full classname every time. --> - <!--<typeAliases>--> + <!-- Use type aliases to avoid typing the full classname every time. --> + <!--<typeAliases>--> <!--<typeAlias alias="Order" type="org.apache.camel.example.mybatis.Order"/>--> - <!--</typeAliases>--> - - <!-- setup environment with JDBC data source --> - <environments default="development"> - <environment id="development"> - <transactionManager type="JDBC"/> - <dataSource type="POOLED"> - <property name="driver" value="org.apache.derby.jdbc.EmbeddedDriver"/> - <property name="url" value="jdbc:derby:memory:mybatis;create=true"/> - </dataSource> - </environment> - </environments> - - <!-- mapping files --> - <!--<mappers>--> + <!--</typeAliases>--> + + <!-- setup environment with JDBC data source --> + <environments default="development"> + <environment id="development"> + <transactionManager type="JDBC"/> + <dataSource type="POOLED"> + <property name="driver" value="org.apache.derby.jdbc.EmbeddedDriver"/> + <property name="url" value="jdbc:derby:memory:mybatis;create=true"/> + </dataSource> + </environment> + </environments> + + <!-- mapping files --> + <!--<mappers>--> <!--<mapper resource="org/apache/camel/example/mybatis/Order.xml"/>--> - <!--</mappers>--> + <!--</mappers>--> </configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/20401a38/tests/camel-itest-spring-boot/src/test/resources/components/mybatis-SqlMapConfig.xml ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/resources/components/mybatis-SqlMapConfig.xml b/tests/camel-itest-spring-boot/src/test/resources/components/mybatis-SqlMapConfig.xml index 6f2ad4d..a4f205d 100644 --- a/tests/camel-itest-spring-boot/src/test/resources/components/mybatis-SqlMapConfig.xml +++ b/tests/camel-itest-spring-boot/src/test/resources/components/mybatis-SqlMapConfig.xml @@ -17,34 +17,34 @@ --> <!DOCTYPE configuration - PUBLIC "-//mybatis.org//DTD Config 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-config.dtd"> + PUBLIC "-//mybatis.org//DTD Config 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> - <settings> - <setting name="useGeneratedKeys" value="false"/> - </settings> + <settings> + <setting name="useGeneratedKeys" value="false"/> + </settings> - <!-- Use type aliases to avoid typing the full classname every time. --> - <!--<typeAliases>--> + <!-- Use type aliases to avoid typing the full classname every time. --> + <!--<typeAliases>--> <!--<typeAlias alias="Order" type="org.apache.camel.example.mybatis.Order"/>--> - <!--</typeAliases>--> - - <!-- setup environment with JDBC data source --> - <environments default="development"> - <environment id="development"> - <transactionManager type="JDBC"/> - <dataSource type="POOLED"> - <property name="driver" value="org.apache.derby.jdbc.EmbeddedDriver"/> - <property name="url" value="jdbc:derby:memory:mybatis;create=true"/> - </dataSource> - </environment> - </environments> - - <!-- mapping files --> - <!--<mappers>--> + <!--</typeAliases>--> + + <!-- setup environment with JDBC data source --> + <environments default="development"> + <environment id="development"> + <transactionManager type="JDBC"/> + <dataSource type="POOLED"> + <property name="driver" value="org.apache.derby.jdbc.EmbeddedDriver"/> + <property name="url" value="jdbc:derby:memory:mybatis;create=true"/> + </dataSource> + </environment> + </environments> + + <!-- mapping files --> + <!--<mappers>--> <!--<mapper resource="org/apache/camel/example/mybatis/Order.xml"/>--> - <!--</mappers>--> + <!--</mappers>--> </configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/20401a38/tests/camel-itest-spring-boot/src/test/resources/spring-boot-itest.properties ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/resources/spring-boot-itest.properties b/tests/camel-itest-spring-boot/src/test/resources/spring-boot-itest.properties index a1e2702..6e4c17a 100644 --- a/tests/camel-itest-spring-boot/src/test/resources/spring-boot-itest.properties +++ b/tests/camel-itest-spring-boot/src/test/resources/spring-boot-itest.properties @@ -1,9 +1,9 @@ # Test configuration can be overriden here. # This file is included in the spring-boot jar built by Arquillian. - # It is better disabling unit testing for all-modules-verification, # as many of them fail for various reasons (unrelated to spring-boot) # when running in the arquillian jar. unitTestEnabled=false - -includeTestDependencies=false +includeTestDependencies=true +# to speed-up packaging +mavenOfflineResolution=false http://git-wip-us.apache.org/repos/asf/camel/blob/20401a38/tests/camel-itest-spring-boot/src/test/resources/spring-logback.xml ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/resources/spring-logback.xml b/tests/camel-itest-spring-boot/src/test/resources/spring-logback.xml new file mode 100644 index 0000000..f67c4c0 --- /dev/null +++ b/tests/camel-itest-spring-boot/src/test/resources/spring-logback.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <layout class="ch.qos.logback.classic.PatternLayout"> + <Pattern> + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n + </Pattern> + </layout> + </appender> + + <logger name="org.apache.camel.component" level="debug" + additivity="false"> + <appender-ref ref="STDOUT"/> + </logger> + + <root level="info"> + <appender-ref ref="STDOUT"/> + </root> + +</configuration>