Repository: camel Updated Branches: refs/heads/master d30d78429 -> 4acb8ed7e
CAMEL-10052: Improvement to spring-boot integration tests Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a441b893 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a441b893 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a441b893 Branch: refs/heads/master Commit: a441b8938d036df618990e719d2f4a140840442d Parents: d30d784 Author: Nicola Ferraro <ni.ferr...@gmail.com> Authored: Fri Jun 17 11:03:35 2016 +0200 Committer: Nicola Ferraro <ni.ferr...@gmail.com> Committed: Fri Jun 17 11:03:35 2016 +0200 ---------------------------------------------------------------------- tests/camel-itest-spring-boot/pom.xml | 14 +++ .../camel/itest/springboot/ITestConfig.java | 46 ++++++++ .../itest/springboot/ITestConfigBuilder.java | 79 +++++++++++-- .../command/ComponentTestCommand.java | 3 +- .../springboot/command/UnitTestCommand.java | 9 +- .../camel/itest/springboot/CamelBoxTest.java | 1 + .../camel/itest/springboot/CamelIbatisTest.java | 1 + .../itest/springboot/CamelKubernetesTest.java | 3 + .../camel/itest/springboot/CamelMinaTest.java | 48 -------- .../itest/springboot/CamelMybatisTest.java | 1 + .../itest/springboot/CamelSalesforceTest.java | 1 + .../itest/springboot/CamelSpringRedisTest.java | 3 + .../itest/springboot/CamelSwaggerJavaTest.java | 3 + .../itest/springboot/CamelSwaggerTest.java | 3 + .../springboot/util/ArquillianPackager.java | 118 +++++++++++++------ .../itest/springboot/util/JarExporter.java | 2 +- .../components/ibatis-SqlMapConfig.xml | 50 ++++++++ .../components/mybatis-SqlMapConfig.xml | 50 ++++++++ 18 files changed, 337 insertions(+), 98 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/pom.xml ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/pom.xml b/tests/camel-itest-spring-boot/pom.xml index 3324851..d65ca46 100644 --- a/tests/camel-itest-spring-boot/pom.xml +++ b/tests/camel-itest-spring-boot/pom.xml @@ -121,6 +121,20 @@ <includes> <include>**/*Test.java</include> </includes> + <systemProperties> + <property> + <name>itestComponentVersion</name> + <value>${project.version}</value> + </property> + <property> + <name>springDataRedisVersion</name> + <value>${spring-data-redis-version}</value> + </property> + <property> + <name>hibernateValidatorVersion</name> + <value>${hibernate-validator-version}</value> + </property> + </systemProperties> </configuration> </plugin> </plugins> http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/ITestConfig.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/ITestConfig.java b/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/ITestConfig.java index 200be45..2650b74 100644 --- a/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/ITestConfig.java +++ b/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/ITestConfig.java @@ -17,6 +17,8 @@ package org.apache.camel.itest.springboot; import java.io.Serializable; +import java.util.Map; +import java.util.Set; /** * A configuration bean for a test execution. @@ -35,6 +37,8 @@ public class ITestConfig implements Serializable { private Boolean includeTestDependencies; + private Boolean includeProvidedDependencies; + private Boolean unitTestEnabled; private String unitTestInclusionPattern; @@ -45,6 +49,12 @@ public class ITestConfig implements Serializable { private Integer unitTestsExpectedNumber; + private Map<String, String> resources; + + private Set<String> additionalDependencies; + + private Boolean autoStartComponent; + public ITestConfig() { } @@ -88,6 +98,14 @@ public class ITestConfig implements Serializable { this.includeTestDependencies = includeTestDependencies; } + public Boolean getIncludeProvidedDependencies() { + return includeProvidedDependencies; + } + + public void setIncludeProvidedDependencies(Boolean includeProvidedDependencies) { + this.includeProvidedDependencies = includeProvidedDependencies; + } + public Boolean getUnitTestEnabled() { return unitTestEnabled; } @@ -128,6 +146,30 @@ public class ITestConfig implements Serializable { this.unitTestsExpectedNumber = unitTestsExpectedNumber; } + public Map<String, String> getResources() { + return resources; + } + + public Set<String> getAdditionalDependencies() { + return additionalDependencies; + } + + public void setAdditionalDependencies(Set<String> additionalDependencies) { + this.additionalDependencies = additionalDependencies; + } + + public void setResources(Map<String, String> resources) { + this.resources = resources; + } + + public Boolean getAutoStartComponent() { + return autoStartComponent; + } + + public void setAutoStartComponent(Boolean autoStartComponent) { + this.autoStartComponent = autoStartComponent; + } + @Override public String toString() { final StringBuilder sb = new StringBuilder("ITestConfig{"); @@ -136,11 +178,15 @@ public class ITestConfig implements Serializable { sb.append(", mavenVersion='").append(mavenVersion).append('\''); sb.append(", modulesPath='").append(modulesPath).append('\''); sb.append(", includeTestDependencies=").append(includeTestDependencies); + sb.append(", includeProvidedDependencies=").append(includeProvidedDependencies); sb.append(", unitTestEnabled=").append(unitTestEnabled); sb.append(", unitTestInclusionPattern='").append(unitTestInclusionPattern).append('\''); sb.append(", unitTestExclusionPattern='").append(unitTestExclusionPattern).append('\''); sb.append(", unitTestBasePackage='").append(unitTestBasePackage).append('\''); sb.append(", unitTestsExpectedNumber=").append(unitTestsExpectedNumber); + sb.append(", resources=").append(resources); + sb.append(", additionalDependencies=").append(additionalDependencies); + sb.append(", autoStartComponent=").append(autoStartComponent); sb.append('}'); return sb.toString(); } http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/ITestConfigBuilder.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/ITestConfigBuilder.java b/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/ITestConfigBuilder.java index 092665b..fb20ec1 100644 --- a/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/ITestConfigBuilder.java +++ b/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/ITestConfigBuilder.java @@ -17,7 +17,9 @@ package org.apache.camel.itest.springboot; import java.io.InputStream; -import java.util.Optional; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; import java.util.Properties; /** @@ -79,6 +81,31 @@ public class ITestConfigBuilder { return this; } + public ITestConfigBuilder autostart(Boolean autostart) { + config.setAutoStartComponent(autostart); + return this; + } + + public ITestConfigBuilder resource(String file, String dest) { + if (config.getResources() == null) { + config.setResources(new HashMap<>()); + } + config.getResources().put(file, dest); + return this; + } + + public ITestConfigBuilder dependency(String dependencyCanonicalForm) { + if (config.getAdditionalDependencies() == null) { + config.setAdditionalDependencies(new HashSet<>()); + } + config.getAdditionalDependencies().add(dependencyCanonicalForm); + return this; + } + + public ITestConfigBuilder resource(String file) { + return resource(file, file); + } + public ITestConfig build() { // Checking conditions @@ -88,35 +115,51 @@ public class ITestConfigBuilder { // Set the defaults if (config.getUnitTestEnabled() == null) { - config.setUnitTestEnabled(booleanProperty("unitTestEnabled").orElse(false)); + config.setUnitTestEnabled(booleanPropertyOr("unitTestEnabled", false)); } if (config.getMavenGroup() == null) { - config.setMavenGroup(property("mavenGroup").orElse("org.apache.camel")); + config.setMavenGroup(propertyOr("mavenGroup", "org.apache.camel")); } if (config.getMavenVersion() == null) { - config.setMavenVersion(property("mavenVersion").orElse(null)); + config.setMavenVersion(propertyOr("mavenVersion", null)); } if (config.getUnitTestInclusionPattern() == null) { - config.setUnitTestInclusionPattern(property("unitTestInclusionPattern").orElse("^.*Test$")); // All tests + config.setUnitTestInclusionPattern(propertyOr("unitTestInclusionPattern", "^.*Test$")); // All tests } if (config.getUnitTestExclusionPattern() == null) { - config.setUnitTestExclusionPattern(property("unitTestExclusionPattern").orElse(".*(\\.integration\\..*|XXXTest$)")); // Integration test + config.setUnitTestExclusionPattern(propertyOr("unitTestExclusionPattern", ".*(\\.integration\\..*|XXXTest$)")); // Integration test } if (config.getIncludeTestDependencies() == null) { - config.setIncludeTestDependencies(booleanProperty("includeTestDependencies").orElse(config.getUnitTestEnabled())); + config.setIncludeTestDependencies(booleanPropertyOr("includeTestDependencies", config.getUnitTestEnabled())); + } + + if (config.getIncludeProvidedDependencies() == null) { + config.setIncludeProvidedDependencies(booleanPropertyOr("includeProvidedDependencies", true)); } if (config.getModulesPath() == null) { - config.setModulesPath(property("modulesPath").orElse("../../components/")); + config.setModulesPath(propertyOr("modulesPath", "../../components/")); } if (config.getUnitTestBasePackage() == null) { - config.setUnitTestBasePackage(property("unitTestBasePackage").orElse("org.apache.camel")); + config.setUnitTestBasePackage(propertyOr("unitTestBasePackage", "org.apache.camel")); + } + + if (config.getAutoStartComponent() == null) { + config.setAutoStartComponent(booleanPropertyOr("autostartComponent", true)); + } + + if (config.getResources() == null) { + config.setResources(Collections.emptyMap()); + } + + if (config.getAdditionalDependencies() == null) { + config.setAdditionalDependencies(Collections.emptySet()); } return config; @@ -126,7 +169,7 @@ public class ITestConfigBuilder { throw new IllegalStateException("Configuration is not complete: " + msg); } - private Optional<String> property(String name) { + private String propertyOr(String name, String defaultVal) { if (properties == null) { properties = new Properties(); try { @@ -137,10 +180,20 @@ public class ITestConfigBuilder { } } - return Optional.ofNullable(properties.getProperty(name)); + String res = properties.getProperty(name); + if (res == null) { + res = defaultVal; + } + return res; } - private Optional<Boolean> booleanProperty(String name) { - return property(name).map(Boolean::valueOf); + private Boolean booleanPropertyOr(String name, Boolean defaultVal) { + String prop = propertyOr(name, null); + Boolean res = defaultVal; + if (prop != null) { + res = Boolean.valueOf(prop); + } + + return res; } } http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/command/ComponentTestCommand.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/command/ComponentTestCommand.java b/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/command/ComponentTestCommand.java index 909757f..1eb5998 100644 --- a/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/command/ComponentTestCommand.java +++ b/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/command/ComponentTestCommand.java @@ -42,7 +42,8 @@ public class ComponentTestCommand extends AbstractTestCommand implements Command logger.info("Getting Camel component: {}", component); - org.apache.camel.Component comp = context.getComponent(component, true, false); + org.apache.camel.Component comp = context.getComponent(component, true, config.getAutoStartComponent()); + assertNotNull("Cannot get module with name: " + component, comp); logger.info("Found Camel module: {} instance: {} with className: {}", component, comp, comp.getClass()); http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/command/UnitTestCommand.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/command/UnitTestCommand.java b/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/command/UnitTestCommand.java index c3b99fe..cbc70a4 100644 --- a/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/command/UnitTestCommand.java +++ b/tests/camel-itest-spring-boot/src/main/java/org/apache/camel/itest/springboot/command/UnitTestCommand.java @@ -21,8 +21,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Set; import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.apache.camel.CamelContext; import org.apache.camel.itest.springboot.Command; @@ -34,6 +34,7 @@ import org.junit.runner.notification.Failure; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.core.type.filter.RegexPatternTypeFilter; import org.springframework.stereotype.Component; @@ -61,7 +62,11 @@ public class UnitTestCommand extends AbstractTestCommand implements Command { scanner.addIncludeFilter(new RegexPatternTypeFilter(pattern)); - List<String> testClasses = new LinkedList<>(scanner.findCandidateComponents(config.getUnitTestBasePackage()).stream().map(bd -> bd.getBeanClassName()).collect(Collectors.toList())); + Set<BeanDefinition> defs = scanner.findCandidateComponents(config.getUnitTestBasePackage()); + List<String> testClasses = new LinkedList<>(); + for (BeanDefinition bd : defs) { + testClasses.add(bd.getBeanClassName()); + } if (config.getUnitTestExclusionPattern() != null) { Pattern exclusionPattern = Pattern.compile(config.getUnitTestExclusionPattern()); http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelBoxTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelBoxTest.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelBoxTest.java index 9b7e736..d053fb3 100644 --- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelBoxTest.java +++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelBoxTest.java @@ -35,6 +35,7 @@ public class CamelBoxTest extends AbstractSpringBootTestSupport { public static ITestConfig createTestConfig() { return new ITestConfigBuilder() .module(inferModuleName(CamelBoxTest.class)) + .autostart(false) // needs configuration .build(); } http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelIbatisTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelIbatisTest.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelIbatisTest.java index d490a46..da96353 100644 --- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelIbatisTest.java +++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelIbatisTest.java @@ -35,6 +35,7 @@ public class CamelIbatisTest extends AbstractSpringBootTestSupport { public static ITestConfig createTestConfig() { return new ITestConfigBuilder() .module(inferModuleName(CamelIbatisTest.class)) + .resource("components/ibatis-SqlMapConfig.xml", "SqlMapConfig.xml") .build(); } http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelKubernetesTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelKubernetesTest.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelKubernetesTest.java index 4d728de..b5d86a0 100644 --- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelKubernetesTest.java +++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelKubernetesTest.java @@ -27,6 +27,8 @@ import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class CamelKubernetesTest extends AbstractSpringBootTestSupport { + private static final String HIBERNATE_VALIDATOR_VERSION = System.getProperty("hibernateValidatorVersion", "5.2.4.Final"); + @Deployment public static Archive<?> createSpringBootPackage() throws Exception { return ArquillianPackager.springBootPackage(createTestConfig()); @@ -35,6 +37,7 @@ public class CamelKubernetesTest extends AbstractSpringBootTestSupport { public static ITestConfig createTestConfig() { return new ITestConfigBuilder() .module(inferModuleName(CamelKubernetesTest.class)) + .dependency("org.hibernate:hibernate-validator:" + HIBERNATE_VALIDATOR_VERSION) .build(); } http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelMinaTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelMinaTest.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelMinaTest.java deleted file mode 100644 index ddb798d..0000000 --- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelMinaTest.java +++ /dev/null @@ -1,48 +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.itest.springboot; - -import org.apache.camel.itest.springboot.util.ArquillianPackager; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.Archive; -import org.junit.Test; -import org.junit.runner.RunWith; - - -@RunWith(Arquillian.class) -public class CamelMinaTest extends AbstractSpringBootTestSupport { - - @Deployment - public static Archive<?> createSpringBootPackage() throws Exception { - return ArquillianPackager.springBootPackage(createTestConfig()); - } - - public static ITestConfig createTestConfig() { - return new ITestConfigBuilder() - .module(inferModuleName(CamelMinaTest.class)) - .build(); - } - - @Test - public void componentTests() throws Exception { - this.runComponentTest(config); - this.runModuleUnitTestsIfEnabled(config); - } - - -} http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelMybatisTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelMybatisTest.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelMybatisTest.java index f767f18..f59d7f6 100644 --- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelMybatisTest.java +++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelMybatisTest.java @@ -35,6 +35,7 @@ public class CamelMybatisTest extends AbstractSpringBootTestSupport { public static ITestConfig createTestConfig() { return new ITestConfigBuilder() .module(inferModuleName(CamelMybatisTest.class)) + .resource("components/mybatis-SqlMapConfig.xml", "SqlMapConfig.xml") .build(); } http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSalesforceTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSalesforceTest.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSalesforceTest.java index b53afb8..f83f131 100644 --- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSalesforceTest.java +++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSalesforceTest.java @@ -35,6 +35,7 @@ public class CamelSalesforceTest extends AbstractSpringBootTestSupport { public static ITestConfig createTestConfig() { return new ITestConfigBuilder() .module(inferModuleName(CamelSalesforceTest.class)) + .autostart(false) // needs configuration .build(); } http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSpringRedisTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSpringRedisTest.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSpringRedisTest.java index d7ed65f..6e77d9f 100644 --- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSpringRedisTest.java +++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSpringRedisTest.java @@ -27,6 +27,8 @@ import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class CamelSpringRedisTest extends AbstractSpringBootTestSupport { + private static final String SPRING_DATA_REDIS_VERSION = System.getProperty("springDataRedisVersion", "1.6.4.RELEASE"); + @Deployment public static Archive<?> createSpringBootPackage() throws Exception { return ArquillianPackager.springBootPackage(createTestConfig()); @@ -35,6 +37,7 @@ public class CamelSpringRedisTest extends AbstractSpringBootTestSupport { public static ITestConfig createTestConfig() { return new ITestConfigBuilder() .module(inferModuleName(CamelSpringRedisTest.class)) + .dependency("org.springframework.data:spring-data-redis:" + SPRING_DATA_REDIS_VERSION) .build(); } http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSwaggerJavaTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSwaggerJavaTest.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSwaggerJavaTest.java index 6ab6333..ee4c35a 100644 --- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSwaggerJavaTest.java +++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSwaggerJavaTest.java @@ -27,6 +27,8 @@ import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class CamelSwaggerJavaTest extends AbstractSpringBootTestSupport { + private static final String HIBERNATE_VALIDATOR_VERSION = System.getProperty("hibernateValidatorVersion", "5.2.4.Final"); + @Deployment public static Archive<?> createSpringBootPackage() throws Exception { return ArquillianPackager.springBootPackage(createTestConfig()); @@ -35,6 +37,7 @@ public class CamelSwaggerJavaTest extends AbstractSpringBootTestSupport { public static ITestConfig createTestConfig() { return new ITestConfigBuilder() .module(inferModuleName(CamelSwaggerJavaTest.class)) + .dependency("org.hibernate:hibernate-validator:" + HIBERNATE_VALIDATOR_VERSION) .build(); } http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSwaggerTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSwaggerTest.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSwaggerTest.java index da3c3f0..3aacefc 100644 --- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSwaggerTest.java +++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelSwaggerTest.java @@ -27,6 +27,8 @@ import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class CamelSwaggerTest extends AbstractSpringBootTestSupport { + private static final String HIBERNATE_VALIDATOR_VERSION = System.getProperty("hibernateValidatorVersion", "5.2.4.Final"); + @Deployment public static Archive<?> createSpringBootPackage() throws Exception { return ArquillianPackager.springBootPackage(createTestConfig()); @@ -35,6 +37,7 @@ public class CamelSwaggerTest extends AbstractSpringBootTestSupport { public static ITestConfig createTestConfig() { return new ITestConfigBuilder() .module(inferModuleName(CamelSwaggerTest.class)) + .dependency("org.hibernate:hibernate-validator:" + HIBERNATE_VALIDATOR_VERSION) .build(); } http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java index c9d9e9f..7293812 100644 --- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java +++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java @@ -17,6 +17,7 @@ package org.apache.camel.itest.springboot.util; import java.io.File; +import java.io.FilenameFilter; import java.io.IOException; import java.security.AccessController; import java.security.PrivilegedAction; @@ -27,10 +28,9 @@ import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Optional; +import java.util.Map; import java.util.Set; import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.apache.camel.itest.springboot.ITestConfig; import org.apache.camel.itest.springboot.arquillian.SpringBootZipExporterImpl; @@ -85,48 +85,79 @@ public final class ArquillianPackager { ark = ark.addAsManifestResource("BOOT-MANIFEST.MF", "MANIFEST.MF"); ark = ark.addAsResource("spring-boot-itest.properties"); + for (Map.Entry<String, String> res : config.getResources().entrySet()) { + ark = ark.addAsResource(res.getKey(), res.getValue()); + } + ark = ark.addAsDirectories("/lib"); - String version = config.getMavenVersion(); + String version = System.getProperty("itestComponentVersion"); + if (version == null) { + config.getMavenVersion(); + } if (version == null) { // It is missing when launching from IDE List<MavenResolvedArtifact> resolved = Arrays.asList(Maven.resolver().loadPomFromFile("pom.xml").importRuntimeDependencies().resolve().withTransitivity().asResolvedArtifact()); - Optional<MavenResolvedArtifact> camelDep = resolved.stream().filter(dep -> dep.getCoordinate().getGroupId().equals("org.apache.camel")).findAny(); - version = camelDep.map(art -> art.getCoordinate().getVersion()).orElse(null); - debug("Resolved version: " + version); - if (version == null) { - throw new IllegalStateException("Cannot determine the current version of the camel component"); + for (MavenResolvedArtifact dep : resolved) { + if (dep.getCoordinate().getGroupId().equals("org.apache.camel")) { + version = dep.getCoordinate().getVersion(); + break; + } } } - // Test dependencies - List<MavenDependency> testDependencies = new LinkedList<>(); - if (config.getIncludeTestDependencies() || config.getUnitTestEnabled()) { + debug("Resolved version: " + version); + if (version == null) { + throw new IllegalStateException("Cannot determine the current version of the camel component"); + } + + MavenDependencyExclusion[] loggingHellExclusions = new MavenDependencyExclusion[]{MavenDependencies.createExclusion("org.slf4j", "slf4j-log4j12"), MavenDependencies.createExclusion("log4j", + "log4j"), MavenDependencies.createExclusion("org.slf4j", "slf4j-simple")}; - List<MavenResolvedArtifact> testArtifacts = Arrays.asList(Maven.resolver() - .loadPomFromFile(config.getModulesPath() + config.getModuleName() + "/pom.xml") - .importTestDependencies() - .resolve().withoutTransitivity().asResolvedArtifact()); + // Module dependencies + List<MavenDependency> moduleDependencies = new LinkedList<>(); - MavenDependencyExclusion[] excl = new MavenDependencyExclusion[]{MavenDependencies.createExclusion("org.slf4j", "slf4j-log4j12"), MavenDependencies.createExclusion("log4j", "log4j")}; + MavenCoordinate mainJar = MavenCoordinates.createCoordinate(config.getMavenGroup(), config.getModuleName(), version, PackagingType.JAR, null); + MavenDependency mainDep = MavenDependencies.createDependency(mainJar, ScopeType.COMPILE, false, loggingHellExclusions); + moduleDependencies.add(mainDep); - testDependencies = testArtifacts.stream() - .map(MavenResolvedArtifact::getCoordinate) - .filter(ArquillianPackager::validTestDependency) // remove direct logging dependencies from test libs - .map(c -> MavenDependencies.createDependency(c, ScopeType.RUNTIME, false, excl)) // remove transitive logging dependencies from test libs - .collect(Collectors.toList()); + for (String canonicalForm : config.getAdditionalDependencies()) { + MavenCoordinate coord = MavenCoordinates.createCoordinate(canonicalForm); + MavenDependency dep = MavenDependencies.createDependency(coord, ScopeType.RUNTIME, false); + moduleDependencies.add(dep); } + if (config.getIncludeProvidedDependencies() || config.getIncludeTestDependencies() || config.getUnitTestEnabled()) { + + List<ScopeType> scopes = new LinkedList<>(); + if (config.getIncludeTestDependencies() || config.getUnitTestEnabled()) { + scopes.add(ScopeType.TEST); + } + if (config.getIncludeProvidedDependencies()) { + scopes.add(ScopeType.PROVIDED); + } + + List<MavenResolvedArtifact> moduleArtifacts = Arrays.asList(Maven.resolver() + .loadPomFromFile(config.getModulesPath() + config.getModuleName() + "/pom.xml") + .importDependencies(scopes.toArray(new ScopeType[]{})) + .resolve().withoutTransitivity().asResolvedArtifact()); + - MavenCoordinate jar = MavenCoordinates.createCoordinate(config.getMavenGroup(), config.getModuleName(), version, PackagingType.JAR, null); - MavenDependency dep = MavenDependencies.createDependency(jar, ScopeType.COMPILE, false); + for (MavenResolvedArtifact art : moduleArtifacts) { + MavenCoordinate c = art.getCoordinate(); + if (!validTestDependency(c)) { + continue; + } + MavenDependency dep = MavenDependencies.createDependency(c, ScopeType.RUNTIME, false, loggingHellExclusions); + moduleDependencies.add(dep); + } + } List<File> dependencies = new LinkedList<>(); dependencies.addAll(Arrays.asList(Maven.resolver() .loadPomFromFile("pom.xml") .importRuntimeDependencies() - .addDependencies(dep) - .addDependencies(testDependencies) + .addDependencies(moduleDependencies) .resolve() .withTransitivity() .asFile())); @@ -153,10 +184,15 @@ public final class ArquillianPackager { public static void copyResource(String folder, String fileNameRegex, String targetFolder) throws IOException { - Pattern pattern = Pattern.compile(fileNameRegex); + final Pattern pattern = Pattern.compile(fileNameRegex); File sourceFolder = new File(folder); - File[] candidates = sourceFolder.listFiles((dir, name) -> pattern.matcher(name).matches()); + File[] candidates = sourceFolder.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return pattern.matcher(name).matches(); + } + }); if (candidates.length == 0) { Assert.fail("No file matching regex " + fileNameRegex + " has been found"); } @@ -166,7 +202,12 @@ public final class ArquillianPackager { } private static ClassLoader getExtensionClassloader() { - ClassLoader cl = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> Thread.currentThread().getContextClassLoader()); + ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { + @Override + public ClassLoader run() { + return Thread.currentThread().getContextClassLoader(); + } + }); if (cl == null) { cl = ClassLoader.getSystemClassLoader(); } @@ -176,10 +217,15 @@ public final class ArquillianPackager { private static boolean validTestDependency(MavenCoordinate coordinate) { - Pattern log4j = Pattern.compile("^log4j$"); - Pattern slf4jLog4j = Pattern.compile("^slf4j-log4j12$"); + Pattern[] patterns = new Pattern[]{Pattern.compile("^log4j$"), Pattern.compile("^slf4j-log4j12$"), Pattern.compile("^slf4j-simple")}; - boolean valid = !log4j.matcher(coordinate.getArtifactId()).matches() && !slf4jLog4j.matcher(coordinate.getArtifactId()).matches(); + boolean valid = true; + for (Pattern p : patterns) { + if (p.matcher(coordinate.getArtifactId()).matches()) { + valid = false; + break; + } + } if (!valid) { debug("Discarded test dependency " + coordinate.toCanonicalForm()); @@ -211,7 +257,10 @@ public final class ArquillianPackager { private static JavaArchive addTestResources(JavaArchive ark, ITestConfig config) throws IOException { File test = new File(config.getModulesPath() + config.getModuleName() + "/target/test-classes/"); - File[] fs = Optional.ofNullable(test.listFiles()).orElse(new File[]{}); + File[] fs = test.listFiles(); + if (fs == null) { + fs = new File[]{}; + } LinkedList<File> testFiles = new LinkedList<>(Arrays.asList(fs)); while (!testFiles.isEmpty()) { File f = testFiles.pop(); @@ -220,7 +269,10 @@ public final class ArquillianPackager { ark = ark.addAsResource(f, relative); } else { ark = ark.addAsDirectory(relative); - File[] files = Optional.ofNullable(f.listFiles()).orElse(new File[]{}); + File[] files = f.listFiles(); + if (files == null) { + files = new File[]{}; + } testFiles.addAll(Arrays.asList(files)); } } http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/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 4157559..6886294 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,7 +32,7 @@ public class JarExporter { public void exportJar() throws Exception { Archive<?> archive = ArquillianPackager.springBootPackage(new ITestConfigBuilder() - .module("camel-jetty9") + .module("camel-box") .build()); http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/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 new file mode 100644 index 0000000..6f2ad4d --- /dev/null +++ b/tests/camel-itest-spring-boot/src/test/resources/components/ibatis-SqlMapConfig.xml @@ -0,0 +1,50 @@ +<?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. +--> + +<!DOCTYPE configuration + PUBLIC "-//mybatis.org//DTD Config 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-config.dtd"> + +<configuration> + + <settings> + <setting name="useGeneratedKeys" value="false"/> + </settings> + + <!-- 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>--> + <!--<mapper resource="org/apache/camel/example/mybatis/Order.xml"/>--> + <!--</mappers>--> + +</configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/a441b893/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 new file mode 100644 index 0000000..6f2ad4d --- /dev/null +++ b/tests/camel-itest-spring-boot/src/test/resources/components/mybatis-SqlMapConfig.xml @@ -0,0 +1,50 @@ +<?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. +--> + +<!DOCTYPE configuration + PUBLIC "-//mybatis.org//DTD Config 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-config.dtd"> + +<configuration> + + <settings> + <setting name="useGeneratedKeys" value="false"/> + </settings> + + <!-- 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>--> + <!--<mapper resource="org/apache/camel/example/mybatis/Order.xml"/>--> + <!--</mappers>--> + +</configuration> \ No newline at end of file