Repository: camel Updated Branches: refs/heads/master 1ce745ba1 -> 2d3446993
CAMEL-10464: @ContextName CDI qualifier should be repeatable Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2d344699 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2d344699 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2d344699 Branch: refs/heads/master Commit: 2d344699357357053a50660e0378d03f4c748ed6 Parents: c1a3820 Author: Antonin Stefanutti <anto...@stefanutti.fr> Authored: Tue Dec 27 22:02:31 2016 +0100 Committer: Antonin Stefanutti <anto...@stefanutti.fr> Committed: Tue Dec 27 22:04:35 2016 +0100 ---------------------------------------------------------------------- components/camel-cdi/pom.xml | 17 +++ .../java/org/apache/camel/cdi/ContextName.java | 2 + .../java/org/apache/camel/cdi/ContextNames.java | 28 +++++ .../MultiCamelContextReusedRouteCdi20Test.java | 118 +++++++++++++++++++ 4 files changed, 165 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/2d344699/components/camel-cdi/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-cdi/pom.xml b/components/camel-cdi/pom.xml index 26b328f..fbec4cc 100644 --- a/components/camel-cdi/pom.xml +++ b/components/camel-cdi/pom.xml @@ -186,6 +186,7 @@ <configuration> <excludes> <exclude>**/*Cdi12Test.java</exclude> + <exclude>**/*Cdi20Test.java</exclude> </excludes> </configuration> </plugin> @@ -232,6 +233,20 @@ <profile> <id>weld-1.2</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <excludes> + <exclude>**/*Cdi20Test.java</exclude> + </excludes> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> <!-- provided dependencies --> @@ -307,6 +322,7 @@ <configuration> <excludes> <exclude>**/*Cdi12Test.java</exclude> + <exclude>**/*Cdi20Test.java</exclude> <!-- OWB does not call the InjectionTarget#preDestroy method --> <exclude>**/UnstoppedCamelContext*Test.java</exclude> <!-- Reactivate when OWB-1155 is fixed --> @@ -373,6 +389,7 @@ <artifactId>maven-surefire-plugin</artifactId> <configuration> <excludes> + <exclude>**/*Cdi20Test.java</exclude> <!-- Reactivate when OWB-1155 is fixed --> <exclude>**/ProgrammaticLookupTest.java</exclude> <!-- Reactivate when OWB-1126 is fixed --> http://git-wip-us.apache.org/repos/asf/camel/blob/2d344699/components/camel-cdi/src/main/java/org/apache/camel/cdi/ContextName.java ---------------------------------------------------------------------- diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/ContextName.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/ContextName.java index 1ca4e1f..99d5743 100644 --- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/ContextName.java +++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/ContextName.java @@ -17,6 +17,7 @@ package org.apache.camel.cdi; import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @@ -64,6 +65,7 @@ import javax.inject.Qualifier; * */ @Qualifier +@Repeatable(ContextNames.class) @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) public @interface ContextName { http://git-wip-us.apache.org/repos/asf/camel/blob/2d344699/components/camel-cdi/src/main/java/org/apache/camel/cdi/ContextNames.java ---------------------------------------------------------------------- diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/ContextNames.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/ContextNames.java new file mode 100644 index 0000000..ddd071c --- /dev/null +++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/ContextNames.java @@ -0,0 +1,28 @@ +/** + * 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.cdi; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) +public @interface ContextNames { + ContextName[] value(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/2d344699/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiCamelContextReusedRouteCdi20Test.java ---------------------------------------------------------------------- diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiCamelContextReusedRouteCdi20Test.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiCamelContextReusedRouteCdi20Test.java new file mode 100644 index 0000000..bea038f --- /dev/null +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiCamelContextReusedRouteCdi20Test.java @@ -0,0 +1,118 @@ +/** + * 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.cdi.test; + +import java.util.concurrent.TimeUnit; +import javax.inject.Inject; + +import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.cdi.CdiCamelExtension; +import org.apache.camel.cdi.ContextName; +import org.apache.camel.cdi.Uri; +import org.apache.camel.cdi.bean.FirstCamelContextBean; +import org.apache.camel.cdi.bean.SecondNamedCamelContextBean; +import org.apache.camel.component.mock.MockEndpoint; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.Archive; +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 static org.apache.camel.cdi.expression.ExchangeExpression.fromCamelContext; +import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied; + +@RunWith(Arquillian.class) +public class MultiCamelContextReusedRouteCdi20Test { + + @Inject + @ContextName("first") + private CamelContext firstCamelContext; + + @Inject + @ContextName("first") + @Uri("direct:inbound") + private ProducerTemplate firstInbound; + + @Inject + @ContextName("first") + @Uri("mock:outbound") + private MockEndpoint firstOutbound; + + @Inject + @ContextName("second") + private CamelContext secondCamelContext; + + @Inject + @ContextName("second") + @Uri("direct:inbound") + private ProducerTemplate secondInbound; + + @Inject + @ContextName("second") + @Uri("mock:outbound") + private MockEndpoint secondOutbound; + + @Deployment + public static Archive<?> deployment() { + return ShrinkWrap.create(JavaArchive.class) + // Camel CDI + .addPackage(CdiCamelExtension.class.getPackage()) + // Test classes + .addClasses(FirstCamelContextBean.class, SecondNamedCamelContextBean.class) + // Bean archive deployment descriptor + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + public void sendMessageToFirstCamelContextInbound() throws InterruptedException { + firstOutbound.expectedMessageCount(1); + firstOutbound.expectedBodiesReceived("test-first"); + firstOutbound.expectedHeaderReceived("context", "test"); + firstOutbound.message(0).exchange().matches(fromCamelContext("first")); + + firstInbound.sendBody("test-first"); + + assertIsSatisfied(2L, TimeUnit.SECONDS, firstOutbound); + } + + @Test + public void sendMessageToSecondCamelContextInbound() throws InterruptedException { + secondOutbound.expectedMessageCount(1); + secondOutbound.expectedBodiesReceived("test-second"); + secondOutbound.expectedHeaderReceived("context", "test"); + secondOutbound.message(0).exchange().matches(fromCamelContext("second")); + + secondInbound.sendBody("test-second"); + + assertIsSatisfied(2L, TimeUnit.SECONDS, secondOutbound); + } + + @ContextName("first") + @ContextName("second") + static class ReusedRouteBuilder extends RouteBuilder { + + @Override + public void configure() { + from("direct:inbound").setHeader("context").constant("test").to("mock:outbound"); + } + } +} \ No newline at end of file