camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r1390918 - in /camel/trunk: components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/ examples/camel-example-cdi/ examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/ examples/camel-example-cdi/src/test/java/org/ap...
Date Thu, 27 Sep 2012 10:04:37 GMT
Author: jstrachan
Date: Thu Sep 27 10:04:36 2012
New Revision: 1390918

URL: http://svn.apache.org/viewvc?rev=1390918&view=rev
Log:
split the example integration test into 2 separate tests; one using an embedded @Produces
@ContextAware RouteBuilder producer method and another using a separate TestRouteBuilder;
also fixed the bug in CamelContextConfig of not correctly using the correct class for producer
methods or beans

Added:
    camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/
    camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/IntegrationTest.java
  (contents, props changed)
      - copied, changed from r1390881, camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java
    camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/
    camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/SeparateRouteBuilderIntegrationTest.java
  (contents, props changed)
      - copied, changed from r1390867, camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java
    camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/TestRouteBuilder.java
  (with props)
Removed:
    camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java
Modified:
    camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelContextConfig.java
    camel/trunk/examples/camel-example-cdi/pom.xml

Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelContextConfig.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelContextConfig.java?rev=1390918&r1=1390917&r2=1390918&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelContextConfig.java
(original)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelContextConfig.java
Thu Sep 27 10:04:36 2012
@@ -28,6 +28,7 @@ import org.apache.camel.RuntimeCamelExce
 import org.apache.camel.cdi.CdiCamelContext;
 import org.apache.camel.model.RouteContainer;
 import org.apache.camel.util.ObjectHelper;
+import org.jboss.weld.bean.ProducerMethod;
 
 /**
  * Configuration options to be applied to a {@link org.apache.camel.CamelContext} by a {@link
CamelContextBean}
@@ -43,6 +44,10 @@ public class CamelContextConfig {
         for (Bean<?> bean : routeBuilderBeans) {
             CreationalContext<?> createContext = beanManager.createCreationalContext(bean);
             Class<?> beanClass = bean.getBeanClass();
+            if (bean instanceof ProducerMethod) {
+                ProducerMethod producerMethod = (ProducerMethod) bean;
+                beanClass = producerMethod.getType();
+            }
             Object reference = beanManager.getReference(bean, beanClass, createContext);
             ObjectHelper.notNull(reference, "Could not instantiate bean of type " + beanClass.getName()
+ " for " + bean);
             try {

Modified: camel/trunk/examples/camel-example-cdi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cdi/pom.xml?rev=1390918&r1=1390917&r2=1390918&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-cdi/pom.xml (original)
+++ camel/trunk/examples/camel-example-cdi/pom.xml Thu Sep 27 10:04:36 2012
@@ -145,6 +145,20 @@
           <failOnMissingWebXml>false</failOnMissingWebXml>
         </configuration>
       </plugin>
+
+      <plugin>
+        <!-- lets re-enable IntegrationTest -->
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/*Test.java</include>
+          </includes>
+          <excludes>
+            <exclude>**/*XXXTest.*</exclude>
+          </excludes>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 
@@ -156,6 +170,13 @@
       </activation>
       <dependencies>
         <dependency>
+            <groupId>org.jboss.spec</groupId>
+            <artifactId>jboss-javaee-6.0</artifactId>
+            <version>${jboss-javaee-6-version}</version>
+            <type>pom</type>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
           <groupId>org.jboss.arquillian.container</groupId>
           <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
           <version>${arquillian-weld-ee-embedded-version}</version>

Copied: camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/IntegrationTest.java
(from r1390881, camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/IntegrationTest.java?p2=camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/IntegrationTest.java&p1=camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java&r1=1390881&r2=1390918&rev=1390918&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java
(original)
+++ camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/IntegrationTest.java
Thu Sep 27 10:04:36 2012
@@ -14,17 +14,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.example.cdi;
+package org.apache.camel.example.cdi.one;
 
+import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.inject.Produces;
 import javax.inject.Inject;
 
+import org.apache.camel.Endpoint;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.cdi.CdiCamelContext;
 import org.apache.camel.cdi.ContextName;
 import org.apache.camel.cdi.Mock;
 import org.apache.camel.cdi.internal.CamelExtension;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.example.cdi.MyRoutes;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
@@ -32,13 +35,18 @@ import org.jboss.shrinkwrap.api.asset.Em
 import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 /**
+ * Lets use an embedded {@link RouteBuilder} to test {@link MyRoutes}
  */
 @RunWith(Arquillian.class)
 public class IntegrationTest {
+    private static final transient Logger LOG = LoggerFactory.getLogger(IntegrationTest.class);
 
     @Inject
     MyRoutes config;
@@ -47,12 +55,19 @@ public class IntegrationTest {
     @Mock
     MockEndpoint result;
 
+    static boolean routeConfigured;
+
     @Produces
+    @ApplicationScoped
     @ContextName
     public RouteBuilder createRoutes() {
         return new RouteBuilder() {
             public void configure() {
-                from(config.getResultEndpoint()).to(result);
+                routeConfigured = true;
+                Endpoint resultEndpoint = config.getResultEndpoint();
+                LOG.info("consuming from output: " + resultEndpoint + " to endpoint: " +
result);
+
+                from(resultEndpoint).to(result);
             }
         };
     }
@@ -61,6 +76,7 @@ public class IntegrationTest {
     public void integrationTest() throws Exception {
         assertNotNull("config not injected!", config);
         assertNotNull("MockEndpoint result not injected!", result);
+        assertTrue("RouteBuilder has not been configured!", routeConfigured);
 
         result.expectedMessageCount(2);
         result.assertIsSatisfied();
@@ -69,9 +85,10 @@ public class IntegrationTest {
     @Deployment
     public static JavaArchive createDeployment() {
         return ShrinkWrap.create(JavaArchive.class)
-                .addPackage(CdiCamelContext.class.getPackage())
+                //.addPackage(CdiCamelContext.class.getPackage())
                 .addPackage(CamelExtension.class.getPackage())
                 .addPackage(MyRoutes.class.getPackage())
+                .addPackage(IntegrationTest.class.getPackage())
                 .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
     }
 }

Propchange: camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/IntegrationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/SeparateRouteBuilderIntegrationTest.java
(from r1390867, camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/SeparateRouteBuilderIntegrationTest.java?p2=camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/SeparateRouteBuilderIntegrationTest.java&p1=camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java&r1=1390867&r2=1390918&rev=1390918&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java
(original)
+++ camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/SeparateRouteBuilderIntegrationTest.java
Thu Sep 27 10:04:36 2012
@@ -14,17 +14,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.example.cdi;
+package org.apache.camel.example.cdi.two;
 
-import javax.enterprise.inject.Produces;
-import javax.inject.Inject;
-
-import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.cdi.CdiCamelContext;
-import org.apache.camel.cdi.ContextName;
-import org.apache.camel.cdi.Mock;
 import org.apache.camel.cdi.internal.CamelExtension;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.example.cdi.MyRoutes;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
@@ -33,37 +28,24 @@ import org.jboss.shrinkwrap.api.spec.Jav
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import javax.inject.Inject;
+
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 /**
+ * Lets use a separate {@link TestRouteBuilder} to test the routes
  */
 @RunWith(Arquillian.class)
-public class IntegrationTest {
-
+public class SeparateRouteBuilderIntegrationTest {
     @Inject
-    MyRoutes config;
-
-    @Inject
-    @Mock
-    MockEndpoint result;
-
-    @Produces
-    @ContextName
-    public RouteBuilder createRoutes() {
-        return new RouteBuilder() {
-            public void configure() {
-                from(config.getResultEndpoint()).to(result);
-            }
-        };
-    }
+    TestRouteBuilder testRouteBuilder;
 
     @Test
     public void integrationTest() throws Exception {
-        assertNotNull("config not injected!", config);
-        assertNotNull("MockEndpoint result not injected!", result);
+        assertNotNull("testRouteBuilder not injected!", testRouteBuilder);
 
-        result.expectedMessageCount(2);
-        result.assertIsSatisfied();
+        testRouteBuilder.assertIsSatisfied();
     }
 
     @Deployment
@@ -72,6 +54,7 @@ public class IntegrationTest {
                 .addPackage(CdiCamelContext.class.getPackage())
                 .addPackage(CamelExtension.class.getPackage())
                 .addPackage(MyRoutes.class.getPackage())
+                .addPackage(SeparateRouteBuilderIntegrationTest.class.getPackage())
                 .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
     }
 }

Propchange: camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/SeparateRouteBuilderIntegrationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/TestRouteBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/TestRouteBuilder.java?rev=1390918&view=auto
==============================================================================
--- camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/TestRouteBuilder.java
(added)
+++ camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/TestRouteBuilder.java
Thu Sep 27 10:04:36 2012
@@ -0,0 +1,64 @@
+/**
+ *
+ * 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.example.cdi.two;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.cdi.ContextName;
+import org.apache.camel.cdi.Mock;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.example.cdi.MyRoutes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+@ApplicationScoped
+@ContextName
+public class TestRouteBuilder extends RouteBuilder {
+    private static final transient Logger LOG = LoggerFactory.getLogger(TestRouteBuilder.class);
+
+    @Inject
+    MyRoutes config;
+
+    @Inject
+    @Mock
+    MockEndpoint result;
+
+    boolean routeConfigured;
+
+    @Override
+    public void configure() throws Exception {
+        routeConfigured = true;
+        Endpoint resultEndpoint = config.getResultEndpoint();
+        LOG.info("consuming from output: " + resultEndpoint + " to : " + result);
+
+        from(resultEndpoint).to(result);
+    }
+
+    public void assertIsSatisfied() {
+        assertTrue("TestRouteBuilder has not been configured!" + routeConfigured, routeConfigured);
+        assertNotNull("MockEndpoint result not injected!", result);
+
+        result.expectedMessageCount(2);
+    }
+}

Propchange: camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/TestRouteBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message