From a9463d3d633dac3029896cd7e4001d3d49aa31d0 Mon Sep 17 00:00:00 2001 From: astefanutti Date: Tue, 26 Aug 2014 17:00:49 +0200 Subject: [PATCH] First simple test --- pom.xml | 109 ++++++++++-------- .../camel/cdi/CdiBeanRegistry.java | 15 +-- .../camel/cdi/CdiCamelFactory.java | 1 + .../camel/cdi/CdiPropertiesComponent.java | 4 +- .../cdi/{Configuration.java => Config.java} | 2 +- .../camel/cdi/SimpleRouteTest.java | 85 ++++++++++++++ .../camel/cdi/bean/SimpleRoute.java | 27 +++++ 7 files changed, 182 insertions(+), 61 deletions(-) rename src/main/java/io/astefanutti/camel/cdi/{Configuration.java => Config.java} (97%) mode change 100755 => 100644 create mode 100644 src/test/java/io/astefanutti/camel/cdi/SimpleRouteTest.java create mode 100644 src/test/java/io/astefanutti/camel/cdi/bean/SimpleRoute.java diff --git a/pom.xml b/pom.xml index 6ac969e..97776c5 100755 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,7 @@ UTF-8 2.13.0 1.2 + 1.7.7 2.2.4.Final 2.0.0-SNAPSHOT 1.1.5.Final @@ -215,24 +216,10 @@ - - ch.qos.logback - logback-classic - 1.1.2 - test - - org.slf4j jul-to-slf4j - 1.7.7 - test - - - - junit - junit - 4.11 + ${slf4j.version} test @@ -243,13 +230,6 @@ test - - org.hamcrest - hamcrest-library - 1.3 - test - - org.easytesting fest-reflect @@ -275,17 +255,6 @@ pom - - - org.jboss.shrinkwrap.descriptors - shrinkwrap-descriptors-depchain - ${shrinkwrap.descriptors.version} - test - pom - - @@ -306,20 +275,6 @@ pom - - org.jboss.arquillian.container - arquillian-weld-se-embedded-1.1 - ${arquillian.weld.version} - test - - - - org.jboss.arquillian.container - arquillian-weld-ee-embedded-1.1 - ${arquillian.weld.version} - test - - @@ -358,6 +313,66 @@ provided + + + + log4j + log4j + 1.2.17 + test + + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + provided + + + + junit + junit + 4.11 + test + + + + org.hamcrest + hamcrest-library + 1.3 + test + + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + + + org.jboss.shrinkwrap.descriptors + shrinkwrap-descriptors-depchain + ${shrinkwrap.descriptors.version} + test + pom + + + + org.jboss.arquillian.container + arquillian-weld-se-embedded-1.1 + ${arquillian.weld.version} + test + + + + org.jboss.weld + weld-core-impl + test + + diff --git a/src/main/java/io/astefanutti/camel/cdi/CdiBeanRegistry.java b/src/main/java/io/astefanutti/camel/cdi/CdiBeanRegistry.java index d4b9015..4c98595 100755 --- a/src/main/java/io/astefanutti/camel/cdi/CdiBeanRegistry.java +++ b/src/main/java/io/astefanutti/camel/cdi/CdiBeanRegistry.java @@ -15,20 +15,15 @@ */ package io.astefanutti.camel.cdi; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import org.apache.camel.spi.Registry; +import org.apache.camel.util.ObjectHelper; import javax.enterprise.inject.Vetoed; import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.BeanManager; - -import org.apache.camel.spi.Registry; -import org.apache.camel.util.ObjectHelper; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; @Vetoed class CdiBeanRegistry implements Registry { diff --git a/src/main/java/io/astefanutti/camel/cdi/CdiCamelFactory.java b/src/main/java/io/astefanutti/camel/cdi/CdiCamelFactory.java index c679244..4fc80ef 100755 --- a/src/main/java/io/astefanutti/camel/cdi/CdiCamelFactory.java +++ b/src/main/java/io/astefanutti/camel/cdi/CdiCamelFactory.java @@ -44,6 +44,7 @@ private static MockEndpoint createMockEndpoint(InjectionPoint point, CamelContex MockEndpoint endpoint = camelContext.getEndpoint(uri, MockEndpoint.class); if (endpoint == null) throw new NoSuchEndpointException(uri); + return endpoint; } diff --git a/src/main/java/io/astefanutti/camel/cdi/CdiPropertiesComponent.java b/src/main/java/io/astefanutti/camel/cdi/CdiPropertiesComponent.java index 823481f..61f8da8 100755 --- a/src/main/java/io/astefanutti/camel/cdi/CdiPropertiesComponent.java +++ b/src/main/java/io/astefanutti/camel/cdi/CdiPropertiesComponent.java @@ -18,18 +18,16 @@ import org.apache.camel.component.properties.DefaultPropertiesParser; import org.apache.camel.component.properties.PropertiesComponent; -import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Instance; import javax.inject.Inject; import javax.inject.Named; import java.util.Properties; -@ApplicationScoped @Named("properties") class CdiPropertiesComponent extends PropertiesComponent { @Inject - CdiPropertiesComponent(@Configuration Instance properties) { + CdiPropertiesComponent(@Config Instance properties) { setPropertiesParser(properties.isUnsatisfied() ? new DefaultPropertiesParser() : new CdiPropertiesParser(properties.get())); } diff --git a/src/main/java/io/astefanutti/camel/cdi/Configuration.java b/src/main/java/io/astefanutti/camel/cdi/Config.java old mode 100755 new mode 100644 similarity index 97% rename from src/main/java/io/astefanutti/camel/cdi/Configuration.java rename to src/main/java/io/astefanutti/camel/cdi/Config.java index 8f5c77a..966a0f8 --- a/src/main/java/io/astefanutti/camel/cdi/Configuration.java +++ b/src/main/java/io/astefanutti/camel/cdi/Config.java @@ -30,5 +30,5 @@ @Documented @Retention(RUNTIME) @Target({ METHOD, FIELD, PARAMETER, TYPE }) -public @interface Configuration { +public @interface Config { } diff --git a/src/test/java/io/astefanutti/camel/cdi/SimpleRouteTest.java b/src/test/java/io/astefanutti/camel/cdi/SimpleRouteTest.java new file mode 100644 index 0000000..b58300a --- /dev/null +++ b/src/test/java/io/astefanutti/camel/cdi/SimpleRouteTest.java @@ -0,0 +1,85 @@ +/** + * Copyright (C) 2014 Antonin Stefanutti (antonin.stefanutti@gmail.com) + * + * Licensed 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 io.astefanutti.camel.cdi; + +import io.astefanutti.camel.cdi.bean.SimpleRoute; +import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.mock.MockEndpoint; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.junit.InSequence; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; +import java.util.concurrent.TimeUnit; + +import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied; + +@RunWith(Arquillian.class) +public class SimpleRouteTest { + + @Inject + @Uri("direct:inbound") + private ProducerTemplate inbound; + + @Inject + @Mock("mock:outbound") + private MockEndpoint outbound; + + @Inject + private CamelContext camelContext; + + @Deployment + public static Archive deployment() { + return ShrinkWrap.create(JavaArchive.class) + // Camel CDI + .addPackages(true, Filters.exclude(".*Test.*"), CdiCamelExtension.class.getPackage()) + // Test class + .addClass(SimpleRoute.class) + // Bean archive deployment descriptor + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + @InSequence(1) + public void startCamelContext() throws Exception { + camelContext.start(); + } + + @Test + @InSequence(2) + public void sendInboundMessage() throws InterruptedException { + outbound.expectedMessageCount(1); + outbound.expectedBodiesReceived("test"); + + inbound.sendBody("test"); + + assertIsSatisfied(2L, TimeUnit.SECONDS, outbound); + } + + @Test + @InSequence(3) + public void stopCamelContext() throws Exception { + camelContext.stop(); + } +} diff --git a/src/test/java/io/astefanutti/camel/cdi/bean/SimpleRoute.java b/src/test/java/io/astefanutti/camel/cdi/bean/SimpleRoute.java new file mode 100644 index 0000000..4f18135 --- /dev/null +++ b/src/test/java/io/astefanutti/camel/cdi/bean/SimpleRoute.java @@ -0,0 +1,27 @@ +/** + * Copyright (C) 2014 Antonin Stefanutti (antonin.stefanutti@gmail.com) + * + * Licensed 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 io.astefanutti.camel.cdi.bean; + + +import org.apache.camel.builder.RouteBuilder; + +public class SimpleRoute extends RouteBuilder { + + @Override + public void configure() { + from("direct:inbound").to("mock:outbound"); + } +}