This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-13799 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 2192eb63c4513064ff22c90bd003188879bc5ad8 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Jul 30 09:57:08 2019 +0200 CAMEL-13799: camel-cdi - Remove support for multiple camel context (not fully implemented and not recommended - 1 context per app/deployment is only supported). Removed @ContentName --- .../org/apache/camel/cdi/CamelContextProducer.java | 4 +- .../camel/cdi/CdiCamelBeanPostProcessor.java | 18 -- .../org/apache/camel/cdi/CdiCamelExtension.java | 18 -- .../java/org/apache/camel/cdi/ContextName.java | 71 ----- .../java/org/apache/camel/cdi/ContextNames.java | 28 -- .../org/apache/camel/cdi/XmlCdiBeanFactory.java | 3 +- .../camel/cdi/bean/FirstCamelContextBean.java | 3 +- .../cdi/bean/FirstCamelContextConvertingRoute.java | 5 +- .../bean/FirstCamelContextEndpointInjectRoute.java | 5 +- .../bean/FirstCamelContextEventConsumingRoute.java | 3 - .../bean/FirstCamelContextEventProducingRoute.java | 3 - .../camel/cdi/bean/FirstCamelContextRoute.java | 5 +- .../camel/cdi/bean/FirstNamedCamelContextBean.java | 2 - .../cdi/bean/FirstNamedCamelContextRoute.java | 5 +- .../camel/cdi/bean/SecondCamelContextBean.java | 4 +- .../bean/SecondCamelContextConvertingRoute.java | 7 +- .../SecondCamelContextEventConsumingRoute.java | 6 +- .../SecondCamelContextEventProducingRoute.java | 6 +- .../cdi/bean/SecondNamedCamelContextBean.java | 2 - .../cdi/bean/SecondNamedCamelContextRoute.java | 7 +- .../InjectedTypeConverterMultipleContextsTest.java | 121 --------- .../cdi/test/MultiCamelContextProducerTest.java | 169 ------------ .../MultiCamelContextReusedRouteCdi20Test.java | 119 -------- .../camel/cdi/test/MultiCamelContextTest.java | 160 ----------- .../cdi/test/MultiContextConsumerTemplateTest.java | 124 --------- .../cdi/test/MultiContextEventEndpointTest.java | 191 ------------- .../cdi/test/MultiContextEventNotifierTest.java | 301 --------------------- .../cdi/test/QualifiedMultiCamelContextTest.java | 174 ------------ .../cdi/test/RouteBuilderWithContextNameTest.java | 93 ------- .../test/RouteBuildersWithSameContextNameTest.java | 91 ------- .../cdi/test/UriQualifierWithContextTest.java | 12 +- .../camel/cdi/test/UriWithWrongContextTest.java | 6 +- .../camel/cdi/test/XmlMultiContextsTest.java | 143 ---------- 33 files changed, 41 insertions(+), 1868 deletions(-) diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java index b7ac57c..fa4ff51 100644 --- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java +++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java @@ -115,9 +115,7 @@ final class CamelContextProducer<T extends CamelContext> extends DelegateProduce } private static CamelContextNameStrategy nameStrategy(Annotated annotated) { - if (annotated.isAnnotationPresent(ContextName.class)) { - return new ExplicitCamelContextNameStrategy(annotated.getAnnotation(ContextName.class).value()); - } else if (annotated.isAnnotationPresent(Named.class)) { + if (annotated.isAnnotationPresent(Named.class)) { // TODO: support stereotype with empty @Named annotation String name = annotated.getAnnotation(Named.class).value(); if (name.isEmpty()) { diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java index a959049..3e45bdf 100644 --- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java +++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java @@ -16,40 +16,22 @@ */ package org.apache.camel.cdi; -import java.util.HashMap; -import java.util.Map; -import javax.enterprise.inject.UnsatisfiedResolutionException; import javax.enterprise.inject.spi.BeanManager; import org.apache.camel.CamelContext; -import org.apache.camel.impl.engine.CamelPostProcessorHelper; import org.apache.camel.impl.engine.DefaultCamelBeanPostProcessor; import static org.apache.camel.cdi.BeanManagerHelper.getReferenceByType; -import static org.apache.camel.cdi.DefaultLiteral.DEFAULT; @Vetoed final class CdiCamelBeanPostProcessor extends DefaultCamelBeanPostProcessor { private final BeanManager manager; - private final Map<String, CamelPostProcessorHelper> postProcessorHelpers = new HashMap<>(); - CdiCamelBeanPostProcessor(BeanManager manager) { this.manager = manager; } - private CamelPostProcessorHelper getPostProcessorHelper(String contextName) { - return postProcessorHelpers.computeIfAbsent(contextName, k -> new CamelPostProcessorHelper(getOrLookupCamelContext(k))); - } - - private CamelContext getOrLookupCamelContext(String contextName) { - // TODO: proper support for custom context qualifiers - return getReferenceByType(manager, CamelContext.class, - contextName.isEmpty() ? DEFAULT : ContextName.Literal.of(contextName)) - .orElseThrow(() -> new UnsatisfiedResolutionException("No Camel context with name [" + contextName + "] is deployed!")); - } - @Override public CamelContext getOrLookupCamelContext() { return getReferenceByType(manager, CamelContext.class).orElse(null); diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java index af7b4a2..d18ef64 100644 --- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java +++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java @@ -273,24 +273,6 @@ public class CdiCamelExtension implements Extension { .map(Bean::getQualifiers) .forEach(contextQualifiers::addAll); - // From the @ContextName qualifiers on RoutesBuilder and RouteContainer beans - List<Bean<?>> routeBeans = cdiBeans.stream() - .filter(hasType(RoutesBuilder.class).or(hasType(RouteContainer.class))) - .filter(bean -> bean.getQualifiers() - .stream() - .filter(isAnnotationType(ContextName.class).and(name -> !contextQualifiers.contains(name))) - .peek(contextQualifiers::add) - .count() > 0 - ) - .collect(Collectors.toList()); - - for (Bean<?> bean : routeBeans) { - Optional<Annotation> annotation = bean.getQualifiers() - .stream() - .filter(isAnnotationType(ContextName.class)).findFirst(); - extraBeans.add(camelContextBean(manager, bean.getBeanClass(), ANY, annotation.get(), APPLICATION_SCOPED)); - } - Set<Bean<?>> allBeans = concat(cdiBeans.stream(), extraBeans.stream()) .collect(toSet()); Set<Bean<?>> contexts = allBeans.stream() 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 deleted file mode 100644 index 2b2fd27..0000000 --- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/ContextName.java +++ /dev/null @@ -1,71 +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.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; -import javax.enterprise.util.AnnotationLiteral; -import javax.inject.Qualifier; - -/** - * CDI qualifier to be used for multi Camel contexts CDI deployment. - * {@code CamelContext} beans can be annotated with the {@code @ContextName} qualifier - * so that the Camel context is named accordingly, e.g.: - * - * <pre><code> - * {@literal @}ApplicationScoped - * {@literal @}ContextName("foo") - * public class FooCamelContext extends DefaultCamelContext { - * } - * </code></pre> - * - * @see org.apache.camel.CamelContext - */ -@Qualifier -@Repeatable(ContextNames.class) -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) -public @interface ContextName { - - /** - * Returns the name of the Camel context. - */ - String value(); - - final class Literal extends AnnotationLiteral<ContextName> implements ContextName { - - private static final long serialVersionUID = 1L; - - private final String name; - - private Literal(String name) { - this.name = name; - } - - public static Literal of(String name) { - return new Literal(name); - } - - @Override - public String value() { - return name; - } - } -} 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 deleted file mode 100644 index 1345217..0000000 --- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/ContextNames.java +++ /dev/null @@ -1,28 +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.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 diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlCdiBeanFactory.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlCdiBeanFactory.java index 1d4bf08..a91938a 100644 --- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlCdiBeanFactory.java +++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlCdiBeanFactory.java @@ -157,8 +157,7 @@ final class XmlCdiBeanFactory { Set<Annotation> annotations = new HashSet<>(); annotations.add(ANY); if (hasId(factory)) { - addAll(annotations, - ContextName.Literal.of(factory.getId()), NamedLiteral.of(factory.getId())); + addAll(annotations, NamedLiteral.of(factory.getId())); } else { annotations.add(DEFAULT); factory.setImplicitId(true); diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextBean.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextBean.java index 808a631..1bf34ca 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextBean.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextBean.java @@ -17,12 +17,11 @@ package org.apache.camel.cdi.bean; import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; -import org.apache.camel.cdi.ContextName; import org.apache.camel.impl.DefaultCamelContext; @ApplicationScoped -@ContextName("first") public class FirstCamelContextBean extends DefaultCamelContext { } diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextConvertingRoute.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextConvertingRoute.java index c7119a0..be2e72f 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextConvertingRoute.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextConvertingRoute.java @@ -16,11 +16,12 @@ */ package org.apache.camel.cdi.bean; +import javax.enterprise.context.ApplicationScoped; + import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.cdi.ContextName; import org.apache.camel.cdi.pojo.TypeConverterOutput; -@ContextName("first") +@ApplicationScoped public class FirstCamelContextConvertingRoute extends RouteBuilder { @Override diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextEndpointInjectRoute.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextEndpointInjectRoute.java index de8434b..f792ea5 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextEndpointInjectRoute.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextEndpointInjectRoute.java @@ -16,18 +16,17 @@ */ package org.apache.camel.cdi.bean; +import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import org.apache.camel.Endpoint; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.cdi.ContextName; import org.apache.camel.cdi.Uri; -@ContextName("first") +@ApplicationScoped public class FirstCamelContextEndpointInjectRoute extends RouteBuilder { @Inject - @ContextName("first") @Uri("direct:inbound") private Endpoint inbound; diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextEventConsumingRoute.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextEventConsumingRoute.java index 7bfa350..abafe7a 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextEventConsumingRoute.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextEventConsumingRoute.java @@ -21,14 +21,11 @@ import javax.inject.Inject; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.cdi.CdiEventEndpoint; -import org.apache.camel.cdi.ContextName; @ApplicationScoped -@ContextName("first") public class FirstCamelContextEventConsumingRoute extends RouteBuilder { @Inject - @ContextName("first") private CdiEventEndpoint<String> stringCdiEventEndpoint; @Override diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextEventProducingRoute.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextEventProducingRoute.java index 114fd0f..15a4a09 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextEventProducingRoute.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextEventProducingRoute.java @@ -21,14 +21,11 @@ import javax.inject.Inject; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.cdi.CdiEventEndpoint; -import org.apache.camel.cdi.ContextName; @ApplicationScoped -@ContextName("first") public class FirstCamelContextEventProducingRoute extends RouteBuilder { @Inject - @ContextName("first") private CdiEventEndpoint<String> stringCdiEventEndpoint; @Override diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextRoute.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextRoute.java index edad80f..d23b147 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextRoute.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstCamelContextRoute.java @@ -16,10 +16,11 @@ */ package org.apache.camel.cdi.bean; +import javax.enterprise.context.ApplicationScoped; + import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.cdi.ContextName; -@ContextName("first") +@ApplicationScoped public class FirstCamelContextRoute extends RouteBuilder { @Override diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstNamedCamelContextBean.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstNamedCamelContextBean.java index c07d6d2..9f1e9a9 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstNamedCamelContextBean.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstNamedCamelContextBean.java @@ -19,11 +19,9 @@ package org.apache.camel.cdi.bean; import javax.enterprise.context.ApplicationScoped; import javax.inject.Named; -import org.apache.camel.cdi.ContextName; import org.apache.camel.impl.DefaultCamelContext; @ApplicationScoped @Named("first") -@ContextName("first") public class FirstNamedCamelContextBean extends DefaultCamelContext { } diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstNamedCamelContextRoute.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstNamedCamelContextRoute.java index 7e94182..9f105bb 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstNamedCamelContextRoute.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/FirstNamedCamelContextRoute.java @@ -16,10 +16,11 @@ */ package org.apache.camel.cdi.bean; +import javax.enterprise.context.ApplicationScoped; + import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.cdi.ContextName; -@ContextName("first") +@ApplicationScoped public class FirstNamedCamelContextRoute extends RouteBuilder { @Override diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextBean.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextBean.java index 6295f07..46ed50f 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextBean.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextBean.java @@ -18,12 +18,12 @@ package org.apache.camel.cdi.bean; import javax.annotation.PostConstruct; import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; -import org.apache.camel.cdi.ContextName; import org.apache.camel.impl.DefaultCamelContext; @ApplicationScoped -@ContextName("second") +@Named("second") public class SecondCamelContextBean extends DefaultCamelContext { @PostConstruct diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextConvertingRoute.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextConvertingRoute.java index be3fef6..ec6b8ee 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextConvertingRoute.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextConvertingRoute.java @@ -16,11 +16,14 @@ */ package org.apache.camel.cdi.bean; +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; + import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.cdi.ContextName; import org.apache.camel.cdi.pojo.TypeConverterOutput; -@ContextName("second") +@ApplicationScoped +@Named("second") public class SecondCamelContextConvertingRoute extends RouteBuilder { @Override diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextEventConsumingRoute.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextEventConsumingRoute.java index 8db76f9..6875e97 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextEventConsumingRoute.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextEventConsumingRoute.java @@ -18,17 +18,17 @@ package org.apache.camel.cdi.bean; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; +import javax.inject.Named; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.cdi.CdiEventEndpoint; -import org.apache.camel.cdi.ContextName; @ApplicationScoped -@ContextName("second") +@Named("second") public class SecondCamelContextEventConsumingRoute extends RouteBuilder { @Inject - @ContextName("second") + @Named("second") private CdiEventEndpoint<String> stringCdiEventEndpoint; @Override diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextEventProducingRoute.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextEventProducingRoute.java index 4325d49..cb62b02 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextEventProducingRoute.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondCamelContextEventProducingRoute.java @@ -18,17 +18,17 @@ package org.apache.camel.cdi.bean; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; +import javax.inject.Named; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.cdi.CdiEventEndpoint; -import org.apache.camel.cdi.ContextName; @ApplicationScoped -@ContextName("second") +@Named("second") public class SecondCamelContextEventProducingRoute extends RouteBuilder { @Inject - @ContextName("second") + @Named("second") private CdiEventEndpoint<String> stringCdiEventEndpoint; @Override diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondNamedCamelContextBean.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondNamedCamelContextBean.java index 3701240..960853a 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondNamedCamelContextBean.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondNamedCamelContextBean.java @@ -19,11 +19,9 @@ package org.apache.camel.cdi.bean; import javax.enterprise.context.ApplicationScoped; import javax.inject.Named; -import org.apache.camel.cdi.ContextName; import org.apache.camel.impl.DefaultCamelContext; @ApplicationScoped @Named("second") -@ContextName("second") public class SecondNamedCamelContextBean extends DefaultCamelContext { } diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondNamedCamelContextRoute.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondNamedCamelContextRoute.java index a2153b1..6bb9642 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondNamedCamelContextRoute.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/bean/SecondNamedCamelContextRoute.java @@ -16,10 +16,13 @@ */ package org.apache.camel.cdi.bean; +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; + import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.cdi.ContextName; -@ContextName("second") +@ApplicationScoped +@Named("second") public class SecondNamedCamelContextRoute extends RouteBuilder { @Override diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/InjectedTypeConverterMultipleContextsTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/InjectedTypeConverterMultipleContextsTest.java deleted file mode 100644 index 03a9e29..0000000 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/InjectedTypeConverterMultipleContextsTest.java +++ /dev/null @@ -1,121 +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.cdi.test; - -import java.util.concurrent.TimeUnit; -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.inject.Produces; - -import org.apache.camel.CamelContext; -import org.apache.camel.Converter; -import org.apache.camel.ProducerTemplate; -import org.apache.camel.cdi.CdiCamelExtension; -import org.apache.camel.cdi.ContextName; -import org.apache.camel.cdi.Uri; -import org.apache.camel.cdi.bean.FirstCamelContextConvertingRoute; -import org.apache.camel.cdi.bean.SecondCamelContextConvertingRoute; -import org.apache.camel.cdi.pojo.TypeConverterInput; -import org.apache.camel.cdi.pojo.TypeConverterOutput; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.impl.DefaultCamelContext; -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; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(Arquillian.class) -@Deprecated -public class InjectedTypeConverterMultipleContextsTest { - - @Deployment - public static Archive<?> deployment() { - return ShrinkWrap.create(JavaArchive.class) - // Camel CDI - .addPackage(CdiCamelExtension.class.getPackage()) - // Test class - .addClass(FirstCamelContextConvertingRoute.class) - .addClass(SecondCamelContextConvertingRoute.class) - // Type converter - .addClass(InjectedTestTypeConverter.class) - // No need as Camel CDI automatically registers the type converter bean - //.addAsManifestResource(new StringAsset("org.apache.camel.cdi.se.converter"), ArchivePaths.create("services/org/apache/camel/TypeConverter")) - // Bean archive deployment descriptor - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Produces - @ContextName("first") - @ApplicationScoped - public CamelContext camelContextFoo() { - return new DefaultCamelContext(); - } - - @Produces - @ContextName("second") - @ApplicationScoped - public CamelContext camelContextBar() { - return new DefaultCamelContext(); - } - - @Test - public void sendMessageToInboundFirst(@ContextName("first") @Uri("direct:inbound") ProducerTemplate inbound, - @ContextName("first") @Uri("mock:outbound") MockEndpoint outbound) throws InterruptedException { - sendMessageToInbound(inbound, outbound, "first"); - } - - @Test - public void sendMessageToInboundSecond(@ContextName("second") @Uri("direct:inbound") ProducerTemplate inbound, - @ContextName("second") @Uri("mock:outbound") MockEndpoint outbound) throws InterruptedException { - sendMessageToInbound(inbound, outbound, "second"); - } - - - private void sendMessageToInbound(ProducerTemplate inbound, MockEndpoint outbound, String contextName) throws InterruptedException { - outbound.expectedMessageCount(1); - outbound.message(0).exchange().matches(fromCamelContext(contextName)); - - TypeConverterInput input = new TypeConverterInput(); - input.setProperty("test"); - - inbound.sendBody(input); - - assertIsSatisfied(2L, TimeUnit.SECONDS, outbound); - assertThat(outbound.getExchanges().get(0).getIn().getBody(TypeConverterOutput.class).getProperty(), is(equalTo("test"))); - } - - @Converter - public static final class InjectedTestTypeConverter { - @Converter - public TypeConverterOutput convert(TypeConverterInput input) throws Exception { - TypeConverterOutput output = new TypeConverterOutput(); - output.setProperty(input.getProperty()); - return output; - } - } - -} - diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiCamelContextProducerTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiCamelContextProducerTest.java deleted file mode 100644 index f22f11f..0000000 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiCamelContextProducerTest.java +++ /dev/null @@ -1,169 +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.cdi.test; - -import java.util.concurrent.TimeUnit; -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.inject.Produces; -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.DefaultCamelContextBean; -import org.apache.camel.cdi.bean.FirstCamelContextRoute; -import org.apache.camel.cdi.bean.UriEndpointRoute; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.impl.DefaultCamelContext; -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.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; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(Arquillian.class) -@Deprecated -public class MultiCamelContextProducerTest { - - @Produces - @ApplicationScoped - @ContextName("first") - private static CamelContext firstContext = new DefaultCamelContext(); - - @Inject - // Support bean class injection for custom beans - private DefaultCamelContextBean defaultCamelContext; - - @Inject @Uri("direct:inbound") - private ProducerTemplate defaultInbound; - - @Inject @Uri("mock:outbound") - private MockEndpoint defaultOutbound; - - @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; - - @Produces - @ApplicationScoped - @ContextName("second") - private static CamelContext secondContext() { - return new DefaultCamelContext(); - } - - @Deployment - public static Archive<?> deployment() { - return ShrinkWrap.create(JavaArchive.class) - // Camel CDI - .addPackage(CdiCamelExtension.class.getPackage()) - // Test classes - .addClasses( - DefaultCamelContextBean.class, - UriEndpointRoute.class, - FirstCamelContextRoute.class) - // Bean archive deployment descriptor - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Test - @InSequence(1) - public void verifyCamelContexts() { - assertThat(defaultCamelContext.getName(), is(equalTo("camel-cdi"))); - assertThat(firstCamelContext.getName(), is(equalTo("first"))); - assertThat(secondCamelContext.getName(), is(equalTo("second"))); - - assertThat(defaultOutbound.getCamelContext().getName(), is(equalTo(defaultCamelContext.getName()))); - assertThat(firstOutbound.getCamelContext().getName(), is(equalTo(firstCamelContext.getName()))); - assertThat(secondOutbound.getCamelContext().getName(), is(equalTo(secondCamelContext.getName()))); - } - - @Test - @InSequence(2) - public void configureCamelContexts() throws Exception { - secondCamelContext.addRoutes(new RouteBuilder() { - @Override - public void configure() { - from("direct:inbound").setHeader("context").constant("second").to("mock:outbound"); - } - }); - } - - @Test - @InSequence(3) - public void sendMessageToDefaultCamelContextInbound() throws InterruptedException { - defaultOutbound.expectedMessageCount(1); - defaultOutbound.expectedBodiesReceived("test-default"); - defaultOutbound.message(0).exchange().matches(fromCamelContext("camel-cdi")); - - defaultInbound.sendBody("test-default"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, defaultOutbound); - } - - @Test - @InSequence(4) - public void sendMessageToFirstCamelContextInbound() throws InterruptedException { - firstOutbound.expectedMessageCount(1); - firstOutbound.expectedBodiesReceived("test-first"); - firstOutbound.expectedHeaderReceived("context", "first"); - firstOutbound.message(0).exchange().matches(fromCamelContext("first")); - - firstInbound.sendBody("test-first"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, firstOutbound); - } - - @Test - @InSequence(5) - public void sendMessageToSecondCamelContextInbound() throws InterruptedException { - secondOutbound.expectedMessageCount(1); - secondOutbound.expectedBodiesReceived("test-second"); - secondOutbound.expectedHeaderReceived("context", "second"); - secondOutbound.message(0).exchange().matches(fromCamelContext("second")); - - secondInbound.sendBody("test-second"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, secondOutbound); - } -} 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 deleted file mode 100644 index 356fe72..0000000 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiCamelContextReusedRouteCdi20Test.java +++ /dev/null @@ -1,119 +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.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) -@Deprecated -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 diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiCamelContextTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiCamelContextTest.java deleted file mode 100644 index 020f888..0000000 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiCamelContextTest.java +++ /dev/null @@ -1,160 +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.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.DefaultCamelContextBean; -import org.apache.camel.cdi.bean.FirstCamelContextBean; -import org.apache.camel.cdi.bean.FirstCamelContextRoute; -import org.apache.camel.cdi.bean.SecondCamelContextBean; -import org.apache.camel.cdi.bean.UriEndpointRoute; -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.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; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(Arquillian.class) -@Deprecated -public class MultiCamelContextTest { - - @Inject - // Support bean class injection for custom beans - private DefaultCamelContextBean defaultCamelContext; - - @Inject @Uri("direct:inbound") - private ProducerTemplate defaultInbound; - - @Inject @Uri("mock:outbound") - private MockEndpoint defaultOutbound; - - @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( - DefaultCamelContextBean.class, - UriEndpointRoute.class, - FirstCamelContextBean.class, - FirstCamelContextRoute.class, - SecondCamelContextBean.class) - // Bean archive deployment descriptor - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Test - @InSequence(1) - public void verifyCamelContexts() { - assertThat(defaultCamelContext.getName(), is(equalTo("camel-cdi"))); - assertThat(firstCamelContext.getName(), is(equalTo("first"))); - assertThat(secondCamelContext.getName(), is(equalTo("second"))); - - assertThat(defaultOutbound.getCamelContext().getName(), is(equalTo(defaultCamelContext.getName()))); - assertThat(firstOutbound.getCamelContext().getName(), is(equalTo(firstCamelContext.getName()))); - assertThat(secondOutbound.getCamelContext().getName(), is(equalTo(secondCamelContext.getName()))); - } - - @Test - @InSequence(2) - public void configureCamelContexts() throws Exception { - secondCamelContext.addRoutes(new RouteBuilder() { - @Override - public void configure() { - from("direct:inbound").setHeader("context").constant("second").to("mock:outbound"); - } - }); - - secondCamelContext.getRouteController().startAllRoutes(); - } - - @Test - @InSequence(3) - public void sendMessageToDefaultCamelContextInbound() throws InterruptedException { - defaultOutbound.expectedMessageCount(1); - defaultOutbound.expectedBodiesReceived("test-default"); - defaultOutbound.message(0).exchange().matches(fromCamelContext("camel-cdi")); - - defaultInbound.sendBody("test-default"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, defaultOutbound); - } - - @Test - @InSequence(4) - public void sendMessageToFirstCamelContextInbound() throws InterruptedException { - firstOutbound.expectedMessageCount(1); - firstOutbound.expectedBodiesReceived("test-first"); - firstOutbound.expectedHeaderReceived("context", "first"); - firstOutbound.message(0).exchange().matches(fromCamelContext("first")); - - firstInbound.sendBody("test-first"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, firstOutbound); - } - - @Test - @InSequence(5) - public void sendMessageToSecondCamelContextInbound() throws InterruptedException { - secondOutbound.expectedMessageCount(1); - secondOutbound.expectedBodiesReceived("test-second"); - secondOutbound.expectedHeaderReceived("context", "second"); - secondOutbound.message(0).exchange().matches(fromCamelContext("second")); - - secondInbound.sendBody("test-second"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, secondOutbound); - } -} diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiContextConsumerTemplateTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiContextConsumerTemplateTest.java deleted file mode 100644 index 2c21c62..0000000 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiContextConsumerTemplateTest.java +++ /dev/null @@ -1,124 +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.cdi.test; - -import java.util.concurrent.TimeUnit; -import javax.inject.Inject; - -import org.apache.camel.CamelContext; -import org.apache.camel.ConsumerTemplate; -import org.apache.camel.ProducerTemplate; -import org.apache.camel.cdi.CdiCamelExtension; -import org.apache.camel.cdi.ContextName; -import org.apache.camel.cdi.bean.DefaultCamelContextBean; -import org.apache.camel.cdi.bean.FirstCamelContextBean; -import org.apache.camel.cdi.bean.SecondCamelContextBean; -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.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.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(Arquillian.class) -@Deprecated -public class MultiContextConsumerTemplateTest { - - @Inject - private CamelContext defaultCamelContext; - - @Inject - private ConsumerTemplate defaultConsumer; - - @Inject - private ProducerTemplate defaultProducer; - - @Inject @ContextName("first") - private CamelContext firstCamelContext; - - @Inject @ContextName("first") - private ConsumerTemplate firstConsumer; - - @Inject @ContextName("first") - private ProducerTemplate firstProducer; - - @Inject @ContextName("second") - private CamelContext secondCamelContext; - - @Inject @ContextName("second") - private ConsumerTemplate secondConsumer; - - @Inject @ContextName("second") - private ProducerTemplate secondProducer; - - @Deployment - public static Archive<?> deployment() { - return ShrinkWrap.create(JavaArchive.class) - // Camel CDI - .addPackage(CdiCamelExtension.class.getPackage()) - // Test classes - .addClasses( - DefaultCamelContextBean.class, - FirstCamelContextBean.class, - SecondCamelContextBean.class) - // Bean archive deployment descriptor - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Test - @InSequence(1) - public void configureCamelContexts() throws Exception { - secondCamelContext.getRouteController().startAllRoutes(); - } - - @Test - @InSequence(2) - public void receiveBodyFromDefaultCamelContext() { - defaultProducer.sendBody("seda:foo", "foo"); - - String body = defaultConsumer.receiveBody("seda:foo", TimeUnit.SECONDS.toMillis(1L), String.class); - - assertThat("Body is incorrect!", body, is(equalTo("foo"))); - } - - @Test - @InSequence(3) - public void receiveBodyFromFirstCamelContext() { - firstProducer.sendBody("seda:bar", "bar"); - - String body = firstConsumer.receiveBody("seda:bar", TimeUnit.SECONDS.toMillis(1L), String.class); - - assertThat("Body is incorrect!", body, is(equalTo("bar"))); - } - - @Test - @InSequence(4) - public void receiveBodyFromSecondCamelContext() { - secondProducer.sendBody("seda:baz", "baz"); - - String body = secondConsumer.receiveBody("seda:baz", TimeUnit.SECONDS.toMillis(1L), String.class); - - assertThat("Body is incorrect!", body, is(equalTo("baz"))); - } -} diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiContextEventEndpointTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiContextEventEndpointTest.java deleted file mode 100644 index b7c0e55..0000000 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiContextEventEndpointTest.java +++ /dev/null @@ -1,191 +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.cdi.test; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.event.Event; -import javax.enterprise.event.Observes; -import javax.inject.Inject; - -import org.apache.camel.CamelContext; -import org.apache.camel.ProducerTemplate; -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.FirstCamelContextEventConsumingRoute; -import org.apache.camel.cdi.bean.FirstCamelContextEventProducingRoute; -import org.apache.camel.cdi.bean.SecondCamelContextBean; -import org.apache.camel.cdi.bean.SecondCamelContextEventConsumingRoute; -import org.apache.camel.cdi.bean.SecondCamelContextEventProducingRoute; -import org.apache.camel.component.mock.MockEndpoint; -import org.hamcrest.Matchers; -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.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied; -import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; - -@RunWith(Arquillian.class) -@Deprecated -public class MultiContextEventEndpointTest { - - @Inject - @ContextName("first") - @Uri("mock:consumeString") - private MockEndpoint firstConsumeString; - - @Inject - @ContextName("second") - @Uri("mock:consumeString") - private MockEndpoint secondConsumeString; - - @Inject - @ContextName("first") - @Uri("direct:produceString") - private ProducerTemplate firstProduceString; - - @Inject - @ContextName("second") - @Uri("direct:produceString") - private ProducerTemplate secondProduceString; - - @Inject - private Event<Object> objectEvent; - - @Inject - private EventObserver observer; - - @Deployment - public static Archive<?> deployment() { - return ShrinkWrap.create(JavaArchive.class) - // Camel CDI - .addPackage(CdiCamelExtension.class.getPackage()) - // Test classes - .addClasses( - FirstCamelContextBean.class, - FirstCamelContextEventConsumingRoute.class, - FirstCamelContextEventProducingRoute.class, - SecondCamelContextBean.class, - SecondCamelContextEventConsumingRoute.class, - SecondCamelContextEventProducingRoute.class) - // Bean archive deployment descriptor - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Test - @InSequence(1) - public void configureCamelContexts(@ContextName("second") CamelContext secondContext) throws Exception { - secondContext.getRouteController().startAllRoutes(); - } - - @Test - @InSequence(2) - public void sendEventsToConsumers() throws InterruptedException { - firstConsumeString.expectedMessageCount(1); - firstConsumeString.expectedBodiesReceived("testFirst"); - - secondConsumeString.expectedMessageCount(2); - secondConsumeString.expectedBodiesReceived("testSecond1", "testSecond2"); - - objectEvent.select(String.class, ContextName.Literal.of("first")).fire("testFirst"); - objectEvent.select(String.class, ContextName.Literal.of("second")).fire("testSecond1"); - objectEvent.select(String.class, ContextName.Literal.of("second")).fire("testSecond2"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, firstConsumeString, secondConsumeString); - } - - @Test - @InSequence(3) - public void sendMessagesToProducers() { - firstProduceString.sendBody("testFirst"); - secondProduceString.sendBody("testSecond"); - - assertThat(observer.getObjectEvents(), Matchers.<Object>contains("testFirst", "testSecond")); - assertThat(observer.getStringEvents(), contains("testFirst", "testSecond")); - assertThat(observer.getFirstStringEvents(), contains("testFirst")); - assertThat(observer.secondStringEvents(), contains("testSecond")); - } - - @Before - public void resetCollectedEvents() { - observer.reset(); - } - - @ApplicationScoped - static class EventObserver { - - private final List<Object> objectEvents = new ArrayList<>(); - - private final List<String> stringEvents = new ArrayList<>(); - - private final List<String> firstStringEvents = new ArrayList<>(); - - private final List<String> secondStringEvents = new ArrayList<>(); - - void collectObjectEvents(@Observes Object event) { - objectEvents.add(event); - } - - void collectStringEvents(@Observes String event) { - stringEvents.add(event); - } - - void collectFirstStringEvents(@Observes @ContextName("first") String event) { - firstStringEvents.add(event); - } - - void collectSecondStringEvents(@Observes @ContextName("second") String event) { - secondStringEvents.add(event); - } - - List<Object> getObjectEvents() { - return objectEvents; - } - - List<String> getStringEvents() { - return stringEvents; - } - - List<String> getFirstStringEvents() { - return firstStringEvents; - } - - List<String> secondStringEvents() { - return secondStringEvents; - } - - void reset() { - objectEvents.clear(); - stringEvents.clear(); - firstStringEvents.clear(); - secondStringEvents.clear(); - } - } -} diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiContextEventNotifierTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiContextEventNotifierTest.java deleted file mode 100644 index 37167fd..0000000 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/MultiContextEventNotifierTest.java +++ /dev/null @@ -1,301 +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.cdi.test; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.event.Observes; -import javax.enterprise.inject.Default; -import javax.enterprise.inject.Produces; -import javax.inject.Inject; -import javax.inject.Named; - -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.DefaultCamelContextBean; -import org.apache.camel.cdi.bean.FirstCamelContextBean; -import org.apache.camel.cdi.bean.FirstCamelContextRoute; -import org.apache.camel.cdi.bean.SecondCamelContextBean; -import org.apache.camel.cdi.bean.UriEndpointRoute; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.spi.CamelEvent.CamelContextStartedEvent; -import org.apache.camel.spi.CamelEvent.CamelContextStartingEvent; -import org.apache.camel.spi.CamelEvent.ExchangeCompletedEvent; -import org.apache.camel.spi.CamelEvent.ExchangeCreatedEvent; -import org.apache.camel.spi.CamelEvent.ExchangeEvent; -import org.apache.camel.spi.CamelEvent.ExchangeSendingEvent; -import org.apache.camel.spi.CamelEvent.ExchangeSentEvent; -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.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; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.everyItem; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.isOneOf; -import static org.junit.Assert.assertThat; - -@RunWith(Arquillian.class) -@Deprecated -public class MultiContextEventNotifierTest { - - @Inject - // Support bean class injection for custom beans - private DefaultCamelContextBean defaultCamelContext; - - @Inject @Uri("direct:inbound") - private ProducerTemplate defaultInbound; - - @Inject @Uri("mock:outbound") - private MockEndpoint defaultOutbound; - - @Produces @ApplicationScoped @Named("defaultContext") - private List<Class> defaultFiredEvents = new ArrayList<>(); - - - @Inject @ContextName("first") - private CamelContext firstCamelContext; - - @Inject @ContextName("first") @Uri("direct:inbound") - private ProducerTemplate firstInbound; - - @Inject @ContextName("first") @Uri("mock:outbound") - private MockEndpoint firstOutbound; - - @Produces @ApplicationScoped @ContextName("first") - private List<Class> firstFiredEvents = new ArrayList<>(); - - - @Inject @ContextName("second") - private CamelContext secondCamelContext; - - @Inject @ContextName("second") @Uri("direct:inbound") - private ProducerTemplate secondInbound; - - @Inject @ContextName("second") @Uri("mock:outbound") - private MockEndpoint secondOutbound; - - @Produces @ApplicationScoped @ContextName("second") - private List<Class> secondFiredEvents = new ArrayList<>(); - - - @Produces @ApplicationScoped @Named("anyContext") - private List<Class> anyFiredEvents = new ArrayList<>(); - - - private void onAnyContextStartingEvent(@Observes CamelContextStartingEvent event, @Named("anyContext") List<Class> events) { - events.add(CamelContextStartingEvent.class); - } - - private void onAnyContextStartedEvent(@Observes CamelContextStartedEvent event, @Named("anyContext") List<Class> events) { - events.add(CamelContextStartedEvent.class); - } - - private void onAnyExchangeEvent(@Observes ExchangeEvent event, @Named("anyContext") List<Class> events) { - events.add(event.getClass().getInterfaces()[0]); - } - - - private void onDefaultContextStartingEvent(@Observes @Default CamelContextStartingEvent event, @Named("defaultContext") List<Class> events) { - events.add(CamelContextStartingEvent.class); - } - - private void onDefaultContextStartedEvent(@Observes @Default CamelContextStartedEvent event, @Named("defaultContext") List<Class> events) { - events.add(CamelContextStartedEvent.class); - } - - private void onDefaultExchangeEvent(@Observes @Default ExchangeEvent event, @Named("defaultContext") List<Class> events) { - events.add(event.getClass().getInterfaces()[0]); - } - - - private void onFirstContextStartingEvent(@Observes @ContextName("first") CamelContextStartingEvent event, @ContextName("first") List<Class> events) { - events.add(CamelContextStartingEvent.class); - } - - private void onFirstContextStartedEvent(@Observes @ContextName("first") CamelContextStartedEvent event, @ContextName("first") List<Class> events) { - events.add(CamelContextStartedEvent.class); - } - - private void onFirstExchangeEvent(@Observes @ContextName("first") ExchangeEvent event, @ContextName("first") List<Class> events) { - events.add(event.getClass().getInterfaces()[0]); - } - - - private void onSecondContextStartingEvent(@Observes @ContextName("second") CamelContextStartingEvent event, @ContextName("second") List<Class> events) { - events.add(CamelContextStartingEvent.class); - } - - private void onSecondContextStartedEvent(@Observes @ContextName("second") CamelContextStartedEvent event, @ContextName("second") List<Class> events) { - events.add(CamelContextStartedEvent.class); - } - - private void onSecondExchangeEvent(@Observes @ContextName("second") ExchangeEvent event, @ContextName("second") List<Class> events) { - events.add(event.getClass().getInterfaces()[0]); - } - - @Deployment - public static Archive<?> deployment() { - return ShrinkWrap.create(JavaArchive.class) - // Camel CDI - .addPackage(CdiCamelExtension.class.getPackage()) - // Test classes - .addClasses( - DefaultCamelContextBean.class, - UriEndpointRoute.class, - FirstCamelContextBean.class, - FirstCamelContextRoute.class, - SecondCamelContextBean.class) - // Bean archive deployment descriptor - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Test - @InSequence(1) - public void configureCamelContexts(@Named("defaultContext") List<Class> defaultEvents, - @ContextName("first") List<Class> firstEvents, - @ContextName("second") List<Class> secondEvents, - @Named("anyContext") List<Class> anyEvents) throws Exception { - secondCamelContext.addRoutes(new RouteBuilder() { - @Override - public void configure() { - from("direct:inbound").setHeader("context").constant("second").to("mock:outbound"); - } - }); - - secondCamelContext.getRouteController().startAllRoutes(); - - assertThat("Events fired for any contexts are incorrect", anyEvents, - everyItem( - isOneOf( - CamelContextStartingEvent.class, - CamelContextStartedEvent.class))); - assertThat("Events fired for default context are incorrect", defaultEvents, - contains( - CamelContextStartingEvent.class, - CamelContextStartedEvent.class)); - assertThat("Events fired for first context are incorrect", firstEvents, - contains( - CamelContextStartingEvent.class, - CamelContextStartedEvent.class)); - assertThat("Events fired for second context are incorrect", secondEvents, - contains( - CamelContextStartingEvent.class, - CamelContextStartedEvent.class)); - } - - @Test - @InSequence(2) - public void sendMessageToDefaultCamelContextInbound(@Named("defaultContext") List<Class> events) throws InterruptedException { - defaultOutbound.expectedMessageCount(1); - defaultOutbound.expectedBodiesReceived("test-default"); - defaultOutbound.message(0).exchange().matches(fromCamelContext("camel-cdi")); - - defaultInbound.sendBody("test-default"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, defaultOutbound); - - assertThat("Events fired are incorrect", events, - contains( - CamelContextStartingEvent.class, - CamelContextStartedEvent.class, - ExchangeSendingEvent.class, - ExchangeCreatedEvent.class, - ExchangeSendingEvent.class, - ExchangeSentEvent.class, - ExchangeCompletedEvent.class, - ExchangeSentEvent.class)); - } - - @Test - @InSequence(3) - public void sendMessageToFirstCamelContextInbound(@ContextName("first") List<Class> events) throws InterruptedException { - firstOutbound.expectedMessageCount(1); - firstOutbound.expectedBodiesReceived("test-first"); - firstOutbound.expectedHeaderReceived("context", "first"); - firstOutbound.message(0).exchange().matches(fromCamelContext("first")); - - firstInbound.sendBody("test-first"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, firstOutbound); - - assertThat("Events fired are incorrect", events, - contains( - CamelContextStartingEvent.class, - CamelContextStartedEvent.class, - ExchangeSendingEvent.class, - ExchangeCreatedEvent.class, - ExchangeSendingEvent.class, - ExchangeSentEvent.class, - ExchangeCompletedEvent.class, - ExchangeSentEvent.class)); - } - - @Test - @InSequence(4) - public void sendMessageToSecondCamelContextInbound(@ContextName("second") List<Class> events) throws InterruptedException { - secondOutbound.expectedMessageCount(1); - secondOutbound.expectedBodiesReceived("test-second"); - secondOutbound.expectedHeaderReceived("context", "second"); - secondOutbound.message(0).exchange().matches(fromCamelContext("second")); - - secondInbound.sendBody("test-second"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, secondOutbound); - - assertThat("Events fired are incorrect", events, - contains( - CamelContextStartingEvent.class, - CamelContextStartedEvent.class, - ExchangeSendingEvent.class, - ExchangeCreatedEvent.class, - ExchangeSendingEvent.class, - ExchangeSentEvent.class, - ExchangeCompletedEvent.class, - ExchangeSentEvent.class)); - } - - @Test - @InSequence(5) - public void stopCamelContexts(@Named("defaultContext") List<Class> defaultEvents, - @ContextName("first") List<Class> firstEvents, - @ContextName("second") List<Class> secondEvents, - @Named("anyContext") List<Class> anyEvents) throws Exception { - defaultCamelContext.stop(); - firstCamelContext.stop(); - secondCamelContext.stop(); - - assertThat("Events count fired for default context are incorrect", defaultEvents, hasSize(8)); - assertThat("Events count fired for first context are incorrect", firstEvents, hasSize(8)); - assertThat("Events count fired for second context are incorrect", secondEvents, hasSize(8)); - assertThat("Events count fired for any contexts are incorrect", anyEvents, hasSize(24)); - } -} diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/QualifiedMultiCamelContextTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/QualifiedMultiCamelContextTest.java deleted file mode 100644 index 490f1d6..0000000 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/QualifiedMultiCamelContextTest.java +++ /dev/null @@ -1,174 +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.cdi.test; - -import java.util.concurrent.TimeUnit; -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import javax.inject.Named; - -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.DefaultCamelContextBean; -import org.apache.camel.cdi.bean.FirstCamelContextRoute; -import org.apache.camel.cdi.bean.UriEndpointRoute; -import org.apache.camel.cdi.qualifier.BarQualifier; -import org.apache.camel.cdi.qualifier.FooQualifier; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.impl.DefaultCamelContext; -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.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; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(Arquillian.class) -@Deprecated -public class QualifiedMultiCamelContextTest { - - @Inject - private CamelContext defaultCamelContext; - - @Inject @Uri("direct:inbound") - private ProducerTemplate defaultInbound; - - @Inject @Uri("mock:outbound") - private MockEndpoint defaultOutbound; - - @Inject @FooQualifier - private CamelContext firstCamelContext; - - @Inject @FooQualifier @Uri("direct:inbound") - private ProducerTemplate firstInbound; - - @Inject @FooQualifier @Uri("mock:outbound") - private MockEndpoint firstOutbound; - - @Inject @BarQualifier - private CamelContext secondCamelContext; - - @Inject @BarQualifier @Uri("direct:inbound") - private ProducerTemplate secondInbound; - - @Inject @BarQualifier @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( - DefaultCamelContextBean.class, - UriEndpointRoute.class, - FooCamelContext.class, - FirstCamelContextRoute.class, - BarCamelContext.class) - // Bean archive deployment descriptor - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Test - @InSequence(1) - public void verifyCamelContexts() { - assertThat(defaultCamelContext.getName(), is(equalTo("camel-cdi"))); - assertThat(firstCamelContext.getName(), is(equalTo("first"))); - assertThat(secondCamelContext.getName(), is(equalTo("second"))); - - assertThat(defaultOutbound.getCamelContext().getName(), is(equalTo(defaultCamelContext.getName()))); - assertThat(firstOutbound.getCamelContext().getName(), is(equalTo(firstCamelContext.getName()))); - assertThat(secondOutbound.getCamelContext().getName(), is(equalTo(secondCamelContext.getName()))); - } - - @Test - @InSequence(2) - public void configureCamelContexts() throws Exception { - secondCamelContext.addRoutes(new RouteBuilder() { - @Override - public void configure() { - from("direct:inbound").setHeader("context").constant("second").to("mock:outbound"); - } - }); - } - - @Test - @InSequence(3) - public void sendMessageToDefaultCamelContextInbound() throws InterruptedException { - defaultOutbound.expectedMessageCount(1); - defaultOutbound.expectedBodiesReceived("test-default"); - defaultOutbound.message(0).exchange().matches(fromCamelContext("camel-cdi")); - - defaultInbound.sendBody("test-default"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, defaultOutbound); - } - - @Test - @InSequence(4) - public void sendMessageToFirstCamelContextInbound() throws InterruptedException { - firstOutbound.expectedMessageCount(1); - firstOutbound.expectedBodiesReceived("test-first"); - firstOutbound.expectedHeaderReceived("context", "first"); - firstOutbound.message(0).exchange().matches(fromCamelContext("first")); - - firstInbound.sendBody("test-first"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, firstOutbound); - } - - @Test - @InSequence(5) - public void sendMessageToSecondCamelContextInbound() throws InterruptedException { - secondOutbound.expectedMessageCount(1); - secondOutbound.expectedBodiesReceived("test-second"); - secondOutbound.expectedHeaderReceived("context", "second"); - secondOutbound.message(0).exchange().matches(fromCamelContext("second")); - - secondInbound.sendBody("test-second"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, secondOutbound); - } -} - -@FooQualifier -@ContextName("first") -@ApplicationScoped -class FooCamelContext extends DefaultCamelContext { - -} - -@BarQualifier -@Named("second") -@ApplicationScoped -class BarCamelContext extends DefaultCamelContext { - -} diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/RouteBuilderWithContextNameTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/RouteBuilderWithContextNameTest.java deleted file mode 100644 index 7372643..0000000 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/RouteBuilderWithContextNameTest.java +++ /dev/null @@ -1,93 +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.cdi.test; - -import java.util.concurrent.TimeUnit; -import javax.enterprise.inject.Any; -import javax.enterprise.inject.Instance; - -import org.apache.camel.CamelContext; -import org.apache.camel.ProducerTemplate; -import org.apache.camel.ServiceStatus; -import org.apache.camel.cdi.CdiCamelExtension; -import org.apache.camel.cdi.ContextName; -import org.apache.camel.cdi.Uri; -import org.apache.camel.cdi.bean.FirstCamelContextEndpointInjectRoute; -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.component.mock.MockEndpoint.assertIsSatisfied; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(Arquillian.class) -public class RouteBuilderWithContextNameTest { - - @Deployment - public static Archive<?> deployment() { - return ShrinkWrap.create(JavaArchive.class) - // Camel CDI - .addPackage(CdiCamelExtension.class.getPackage()) - // Test class - .addClass(FirstCamelContextEndpointInjectRoute.class) - // Bean archive deployment descriptor - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Test - public void verifyCamelContexts(@Any Instance<CamelContext> contexts) { - assertThat("Context instances are incorrect!", contexts, - contains( - hasProperty("name", is(equalTo("first"))))); - } - - @Test - public void verifyNamedCamelContext(@ContextName("first") CamelContext first) { - assertThat("Context name is incorrect!", first.getName(), is(equalTo("first"))); - assertThat("Number of routes is incorrect!", first.getRoutes().size(), is(equalTo(1))); - assertThat("Context status is incorrect!", first.getStatus(), is(equalTo(ServiceStatus.Started))); - } - - @Test - public void verifyDefaultCamelContext(CamelContext context) { - assertThat("Context name is incorrect!", context.getName(), is(equalTo("first"))); - assertThat("Number of routes is incorrect!", context.getRoutes().size(), is(equalTo(1))); - assertThat("Context status is incorrect!", context.getStatus(), is(equalTo(ServiceStatus.Started))); - } - - @Test - public void sendMessageToInbound(@Uri("direct:inbound") ProducerTemplate inbound, - @Uri("mock:outbound") MockEndpoint outbound) throws InterruptedException { - outbound.expectedMessageCount(1); - outbound.expectedBodiesReceived("test"); - outbound.expectedHeaderReceived("context", "first"); - - inbound.sendBody("test"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, outbound); - } -} diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/RouteBuildersWithSameContextNameTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/RouteBuildersWithSameContextNameTest.java deleted file mode 100644 index 4419c15..0000000 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/RouteBuildersWithSameContextNameTest.java +++ /dev/null @@ -1,91 +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.cdi.test; - -import java.util.concurrent.TimeUnit; -import javax.enterprise.inject.Any; -import javax.enterprise.inject.Instance; - -import org.apache.camel.CamelContext; -import org.apache.camel.ProducerTemplate; -import org.apache.camel.ServiceStatus; -import org.apache.camel.cdi.CdiCamelExtension; -import org.apache.camel.cdi.ContextName; -import org.apache.camel.cdi.Uri; -import org.apache.camel.cdi.bean.FirstCamelContextEndpointInjectRoute; -import org.apache.camel.cdi.bean.FirstCamelContextEventConsumingRoute; -import org.apache.camel.cdi.bean.FirstCamelContextEventProducingRoute; -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.component.mock.MockEndpoint.assertIsSatisfied; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(Arquillian.class) -public class RouteBuildersWithSameContextNameTest { - - @Deployment - public static Archive<?> deployment() { - return ShrinkWrap.create(JavaArchive.class) - // Camel CDI - .addPackage(CdiCamelExtension.class.getPackage()) - // Test classes - .addClasses( - FirstCamelContextEndpointInjectRoute.class, - FirstCamelContextEventConsumingRoute.class, - FirstCamelContextEventProducingRoute.class) - // Bean archive deployment descriptor - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Test - public void verifyCamelContexts(@Any Instance<CamelContext> contexts) { - assertThat("Context instances are incorrect!", contexts, - contains( - hasProperty("name", is(equalTo("first"))))); - } - - @Test - public void verifyCamelContext(@ContextName("first") CamelContext first) { - assertThat("Context name is incorrect!", first.getName(), is(equalTo("first"))); - assertThat("Number of routes is incorrect!", first.getRoutes().size(), is(equalTo(3))); - assertThat("Context status is incorrect!", first.getStatus(), is(equalTo(ServiceStatus.Started))); - } - - @Test - public void sendMessageToInbound(@Uri("direct:inbound") ProducerTemplate inbound, - @Uri("mock:outbound") MockEndpoint outbound) throws InterruptedException { - outbound.expectedMessageCount(1); - outbound.expectedBodiesReceived("test"); - outbound.expectedHeaderReceived("context", "first"); - - inbound.sendBody("test"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, outbound); - } -} diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/UriQualifierWithContextTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/UriQualifierWithContextTest.java index 3e4eb79..772e9c8 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/UriQualifierWithContextTest.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/UriQualifierWithContextTest.java @@ -18,12 +18,12 @@ package org.apache.camel.cdi.test; import java.util.concurrent.TimeUnit; import javax.inject.Inject; +import javax.inject.Named; import org.apache.camel.Endpoint; 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.component.mock.MockEndpoint; @@ -42,11 +42,11 @@ import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied; public class UriQualifierWithContextTest { @Inject - @Uri(value = "mock:outbound") @ContextName("first") + @Uri(value = "mock:outbound") private MockEndpoint outbound; @Inject - @Uri(value = "direct:inbound") @ContextName("first") + @Uri(value = "direct:inbound") private ProducerTemplate inbound; @Deployment @@ -71,15 +71,15 @@ public class UriQualifierWithContextTest { } } -@ContextName("first") +@Named("first") class UriWithContextRoute extends RouteBuilder { @Inject - @Uri(value = "direct:inbound") @ContextName("first") + @Uri(value = "direct:inbound") Endpoint inbound; @Inject - @Uri(value = "mock:outbound") @ContextName("first") + @Uri(value = "mock:outbound") MockEndpoint outbound; @Override diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/UriWithWrongContextTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/UriWithWrongContextTest.java index cddb8b1..334f57d 100644 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/UriWithWrongContextTest.java +++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/UriWithWrongContextTest.java @@ -17,11 +17,11 @@ package org.apache.camel.cdi.test; import javax.inject.Inject; +import javax.inject.Named; import org.apache.camel.Endpoint; 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.rule.ExpectedDeploymentException; @@ -68,12 +68,12 @@ public class UriWithWrongContextTest { } } -@ContextName("first") +@Named("first") class UriWithWrongContextRoute extends RouteBuilder { @Inject @Uri(value = "direct:inbound") - @ContextName("second") + @Named("second") Endpoint inbound; @Override diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/XmlMultiContextsTest.java b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/XmlMultiContextsTest.java deleted file mode 100644 index 9a787eb..0000000 --- a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/XmlMultiContextsTest.java +++ /dev/null @@ -1,143 +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.cdi.test; - -import java.nio.file.Paths; -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.ImportResource; -import org.apache.camel.cdi.Uri; -import org.apache.camel.cdi.bean.SecondNamedCamelContextRoute; -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; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(Arquillian.class) -@ImportResource("imported-context.xml") -@Deprecated -public class XmlMultiContextsTest { - - @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:in") - 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 Camel XML - .addAsResource( - Paths.get("src/test/resources/camel-context-multiples.xml").toFile(), - "imported-context.xml") - // Test class - .addClass(SecondNamedCamelContextRoute.class) - // Bean archive deployment descriptor - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Test - public void verifyCamelContexts() { - assertThat("Camel context name is incorrect!", - firstCamelContext.getName(), is(equalTo("first"))); - assertThat("Camel context name is incorrect!", - secondCamelContext.getName(), is(equalTo("second"))); - - assertThat("Producer template context is incorrect!", - firstOutbound.getCamelContext().getName(), is(equalTo(firstCamelContext.getName()))); - assertThat("Producer template context is incorrect!", - secondOutbound.getCamelContext().getName(), is(equalTo(secondCamelContext.getName()))); - } - - @Test - public void sendMessageToFirstCamelContextInbound() throws InterruptedException { - firstOutbound.expectedMessageCount(1); - firstOutbound.expectedBodiesReceived("first-message"); - firstOutbound.expectedHeaderReceived("context", "first"); - firstOutbound.message(0).exchange().matches(fromCamelContext("first")); - - firstInbound.sendBody("first-message"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, firstOutbound); - } - - @Test - public void sendMessageToSecondCamelContextInbound() throws InterruptedException { - secondOutbound.expectedMessageCount(1); - secondOutbound.expectedBodiesReceived("second-message"); - firstOutbound.expectedHeaderReceived("context", "second"); - secondOutbound.message(0).exchange().matches(fromCamelContext("second")); - - secondInbound.sendBody("message"); - - assertIsSatisfied(2L, TimeUnit.SECONDS, secondOutbound); - } - - @ContextName("second") - private static class TestRoute extends RouteBuilder { - - @Override - public void configure() { - from("direct:out").setHeader("context").constant("second").to("mock:outbound"); - } - } -}