camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/6] camel git commit: CAMEL-9201: Improved support for programmatic lookup
Date Tue, 23 Feb 2016 12:22:48 GMT
Repository: camel
Updated Branches:
  refs/heads/master 5865d2e4a -> 5fbf7c5d6


CAMEL-9201: Improved support for programmatic lookup


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/93631c85
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/93631c85
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/93631c85

Branch: refs/heads/master
Commit: 93631c85f4250b3843a7ada987c99aeed909a11d
Parents: 5865d2e
Author: Antonin Stefanutti <antonin@stefanutti.fr>
Authored: Tue Feb 23 12:30:05 2016 +0100
Committer: Antonin Stefanutti <antonin@stefanutti.fr>
Committed: Tue Feb 23 12:30:05 2016 +0100

----------------------------------------------------------------------
 components/camel-cdi/pom.xml                    | 17 ++++
 .../org/apache/camel/cdi/CdiCamelExtension.java |  4 +-
 .../java/org/apache/camel/cdi/CdiSpiHelper.java |  4 +
 .../src/main/java/org/apache/camel/cdi/Uri.java | 26 ++++++
 .../camel/cdi/test/ProgrammaticLookupTest.java  | 89 ++++++++++++++++++++
 5 files changed, 138 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/93631c85/components/camel-cdi/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-cdi/pom.xml b/components/camel-cdi/pom.xml
index 6c10e00..fb23bce 100644
--- a/components/camel-cdi/pom.xml
+++ b/components/camel-cdi/pom.xml
@@ -264,6 +264,8 @@
                 <exclude>**/*Cdi12Test.java</exclude>
                 <!-- OWB does not call the InjectionTarget#preDestroy method -->
                 <exclude>**/UnstoppedCamelContext*Test.java</exclude>
+                <!-- Reactivate when OWB-1122 is fixed -->
+                <exclude>**/ProgrammaticLookupTest.java</exclude>
               </excludes>
             </configuration>
           </plugin>
@@ -317,6 +319,21 @@
     <profile>
       <id>owb-1.2</id>
 
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <excludes>
+                <!-- Reactivate when OWB-1122 is fixed -->
+                <exclude>**/ProgrammaticLookupTest.java</exclude>
+              </excludes>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+
       <dependencies>
 
         <!-- provided dependencies -->

http://git-wip-us.apache.org/repos/asf/camel/blob/93631c85/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java
----------------------------------------------------------------------
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 9f80a0f..4cacd4a 100755
--- 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
@@ -172,7 +172,7 @@ public class CdiCamelExtension implements Extension {
             Class<?> type = CdiSpiHelper.getRawType(am.getBaseType());
             if (Endpoint.class.isAssignableFrom(type) || ProducerTemplate.class.equals(type))
{
                 Set<Annotation> qualifiers = CdiSpiHelper.getQualifiers(am, manager);
-                producerQualifiers.put(am.getJavaMember(), qualifiers.isEmpty() ? Collections.<Annotation>singleton(DefaultLiteral.INSTANCE)
: qualifiers);
+                producerQualifiers.put(am.getJavaMember(), qualifiers);
                 Set<Annotation> annotations = new HashSet<>(am.getAnnotations());
                 annotations.removeAll(qualifiers);
                 annotations.add(Excluded.INSTANCE);
@@ -239,7 +239,7 @@ public class CdiCamelExtension implements Extension {
                 }
             } else {
                 if (Endpoint.class.isAssignableFrom(type) || ProducerTemplate.class.isAssignableFrom(type))
{
-                    qualifiers.addAll(CdiSpiHelper.excludeElementOfTypes(contextQualifiers,
Any.class, Default.class, Named.class));
+                    qualifiers.addAll(CdiSpiHelper.excludeElementOfTypes(contextQualifiers,
Default.class, Named.class));
                 }
             }
             // TODO: would be more correct to add a bean for each Camel context bean

http://git-wip-us.apache.org/repos/asf/camel/blob/93631c85/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java
index d2cb4af..8a7c8c5 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java
@@ -138,6 +138,10 @@ final class CdiSpiHelper {
                 qualifiers.add(annotation);
             }
         }
+        if (qualifiers.isEmpty()) {
+            qualifiers.add(DefaultLiteral.INSTANCE);
+        }
+        qualifiers.add(AnyLiteral.INSTANCE);
         return qualifiers;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/93631c85/components/camel-cdi/src/main/java/org/apache/camel/cdi/Uri.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/Uri.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/Uri.java
index 0fff3d1..538f882 100755
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/Uri.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/Uri.java
@@ -20,6 +20,7 @@ import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
+import javax.enterprise.util.AnnotationLiteral;
 import javax.enterprise.util.Nonbinding;
 import javax.inject.Qualifier;
 
@@ -60,4 +61,29 @@ public @interface Uri {
      */
     @Deprecated
     @Nonbinding String context() default "";
+
+    final class Literal extends AnnotationLiteral<Uri> implements Uri {
+
+        private static final long serialVersionUID = 1L;
+
+        private final String uri;
+
+        private Literal(String uri) {
+            this.uri = uri;
+        }
+
+        public static Literal of(String uri) {
+            return new Literal(uri);
+        }
+
+        @Override
+        public String value() {
+            return uri;
+        }
+
+        @Override
+        public String context() {
+            return "";
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/93631c85/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/ProgrammaticLookupTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/ProgrammaticLookupTest.java
b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/ProgrammaticLookupTest.java
new file mode 100644
index 0000000..eb1eb18
--- /dev/null
+++ b/components/camel-cdi/src/test/java/org/apache/camel/cdi/test/ProgrammaticLookupTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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 javax.inject.Inject;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.cdi.CdiCamelExtension;
+import org.apache.camel.cdi.Uri;
+import org.apache.camel.cdi.bean.EndpointInjectRoute;
+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.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+@RunWith(Arquillian.class)
+public class ProgrammaticLookupTest {
+
+    @Any
+    @Inject
+    Instance<CamelContext> contexts;
+
+    @Any
+    @Inject
+    private Instance<ProducerTemplate> producers;
+
+    @Any
+    @Inject
+    private Instance<Endpoint> endpoints;
+
+    @Deployment
+    public static Archive<?> deployment() {
+        return ShrinkWrap.create(JavaArchive.class)
+            // Camel CDI
+            .addPackage(CdiCamelExtension.class.getPackage())
+            // Test class
+            .addClass(EndpointInjectRoute.class)
+            // Bean archive deployment descriptor
+            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+    }
+
+    @Test
+    public void verifyCamelContext() {
+        assertThat("Context instance status is incorrect!", contexts.get().getStatus(), is(equalTo(ServiceStatus.Started)));
+    }
+
+    @Test
+    public void sendMessageToInbound() throws InterruptedException {
+        ProducerTemplate inbound = producers.select(Uri.Literal.of("direct:inbound")).get();
+        MockEndpoint outbound = endpoints.select(MockEndpoint.class, Uri.Literal.of("mock:outbound")).get();
+
+        outbound.expectedMessageCount(1);
+        outbound.expectedBodiesReceived("test");
+
+        inbound.sendBody("test");
+
+        assertIsSatisfied(2L, TimeUnit.SECONDS, outbound);
+    }
+}


Mime
View raw message