Author: cmoulliard
Date: Wed Oct  3 11:45:27 2012
New Revision: 1393440

URL: http://svn.apache.org/viewvc?rev=1393440&view=rev
Log:
refactor examples to only use one class definition per test

Added:
    
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/ArchiveUtil.java
    
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/DeploymentFactory.java
    
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/IntegrationTest.java
    
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/DeploymentFactory.java
    
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/SeparateRouteBuilderIntegrationTest.java

Added: 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/ArchiveUtil.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/ArchiveUtil.java?rev=1393440&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/ArchiveUtil.java
 (added)
+++ 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/ArchiveUtil.java
 Wed Oct  3 11:45:27 2012
@@ -0,0 +1,53 @@
+package org.apache.camel.example.cdi;
+
+import org.apache.camel.cdi.CdiCamelContext;
+import org.apache.camel.cdi.internal.CamelExtension;
+import org.jboss.arquillian.container.test.api.TargetsContainer;
+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.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.resolver.api.maven.Maven;
+
+import java.io.File;
+
+/**
+ *  Util class used to create Archive used by Arquillian
+ */
+public class ArchiveUtil {
+
+    @TargetsContainer("weld-ee-embedded-1.1")
+    public static Archive<?> createWeldArchive(String[] packages) {
+
+        JavaArchive jar =  ShrinkWrap.create(JavaArchive.class)
+                .addPackage(CdiCamelContext.class.getPackage())
+                .addPackage(CamelExtension.class.getPackage())
+                .addPackages(false, packages)
+                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+
+        // System.out.println(jar.toString(true));
+
+        return jar;
+    }
+
+    @TargetsContainer("jbossas-managed")
+    public static Archive<?> createJBossASArchive(String[] packages) {
+
+        JavaArchive jarTest = ShrinkWrap.create(JavaArchive.class)
+                .addPackages(false, packages)
+                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+
+        File[] libs = Maven.resolver()
+                .loadPomFromFile("pom.xml")
+                
.resolve("org.apache.camel:camel-core","org.apache.camel:camel-cdi","org.apache.activemq:activemq-camel")
+                .withTransitivity()
+                .as(File.class);
+
+        return ShrinkWrap
+                .create(WebArchive.class, "test.war")
+                .addAsLibrary(jarTest)
+                .addAsLibraries(libs);
+    }
+
+}

Added: 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/DeploymentFactory.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/DeploymentFactory.java?rev=1393440&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/DeploymentFactory.java
 (added)
+++ 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/DeploymentFactory.java
 Wed Oct  3 11:45:27 2012
@@ -0,0 +1,58 @@
+/**
+ * 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.one;
+
+import org.apache.camel.cdi.CdiCamelContext;
+import org.apache.camel.cdi.internal.CamelExtension;
+import org.apache.camel.example.cdi.ArchiveUtil;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.TargetsContainer;
+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.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.resolver.api.maven.Maven;
+
+import java.io.File;
+
+/**
+ *  Factory to create archive according to the container selected
+ */
+public class DeploymentFactory {
+
+    @Deployment
+    public static Archive<?> createArchive() {
+
+        String deploymentType = System.getProperty("arquillian");
+        Archive<?> archive = null;
+
+        // TODO FIND A BETTER WAY TO PASS PACKAGES
+        String[] packages = 
{"org.apache.camel.example.cdi","org.apache.camel.example.cdi.one"};
+
+        System.out.println("Deployment type : " + deploymentType);
+
+        if (deploymentType.equals("weld-ee-embedded-1.1")) {
+            archive = ArchiveUtil.createWeldArchive(packages);
+
+        } else if (deploymentType.equals("jbossas-managed")) {
+            archive =  ArchiveUtil.createJBossASArchive(packages);
+        }
+        return archive;
+    }
+
+}

Added: 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/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?rev=1393440&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/IntegrationTest.java
 (added)
+++ 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/one/IntegrationTest.java
 Wed Oct  3 11:45:27 2012
@@ -0,0 +1,85 @@
+/**
+ * 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.one;
+
+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.apache.camel.example.cdi.one.DeploymentFactory;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(Arquillian.class)
+public class IntegrationTest extends DeploymentFactory {
+
+    private static final transient Logger LOG = 
LoggerFactory.getLogger(IntegrationTest.class);
+
+    static boolean routeConfigured;
+
+    @Inject
+    MyRoutes config;
+
+    @Inject
+    @Mock
+    MockEndpoint result;
+
+    @Produces
+    @ApplicationScoped
+    @ContextName
+    public RouteBuilder createRoute() {
+        return new RouteBuilder()
+        {
+            public void configure()
+            {
+                routeConfigured = true;
+                Endpoint resultEndpoint = config.getResultEndpoint();
+                LOG.info("consuming from output: " + resultEndpoint + " to 
endpoint: " + result);
+
+                from(resultEndpoint).to(result);
+            }
+        };
+    }
+
+    @Test
+    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();
+    }
+
+}

Added: 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/DeploymentFactory.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/DeploymentFactory.java?rev=1393440&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/DeploymentFactory.java
 (added)
+++ 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/DeploymentFactory.java
 Wed Oct  3 11:45:27 2012
@@ -0,0 +1,59 @@
+/**
+ * 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.cdi.CdiCamelContext;
+import org.apache.camel.cdi.internal.CamelExtension;
+import org.apache.camel.example.cdi.ArchiveUtil;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.TargetsContainer;
+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.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.resolver.api.maven.Maven;
+
+import java.io.File;
+
+/**
+ *  Factory to create archive (jar, war)
+ */
+public class DeploymentFactory {
+
+    @Deployment
+    public static Archive<?> createArchive() {
+
+        String deploymentType = System.getProperty("arquillian");
+        Archive<?> archive = null;
+
+        // TODO FIND A BETTER WAY TO PASS PACKAGES
+        String[] packages = 
{"org.apache.camel.example.cdi","org.apache.camel.example.cdi.two"};
+
+        System.out.println("Deployment type : " + deploymentType);
+
+        if (deploymentType.equals("weld-ee-embedded-1.1")) {
+            archive = ArchiveUtil.createWeldArchive(packages);
+
+        } else if (deploymentType.equals("jbossas-managed")) {
+            archive =  ArchiveUtil.createJBossASArchive(packages);
+        }
+        return archive;
+    }
+
+}
+

Added: 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/SeparateRouteBuilderIntegrationTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/SeparateRouteBuilderIntegrationTest.java?rev=1393440&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/SeparateRouteBuilderIntegrationTest.java
 (added)
+++ 
camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/two/SeparateRouteBuilderIntegrationTest.java
 Wed Oct  3 11:45:27 2012
@@ -0,0 +1,53 @@
+/**
+ * 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.cdi.CdiCamelContext;
+import org.apache.camel.cdi.internal.CamelExtension;
+import org.apache.camel.example.cdi.two.DeploymentFactory;
+import org.apache.camel.example.cdi.MyRoutes;
+import org.apache.camel.example.cdi.one.*;
+import org.apache.camel.example.cdi.two.TestRouteBuilder;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.TargetsContainer;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.inject.Inject;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Lets use a separate {@link 
org.apache.camel.example.cdi.two.TestRouteBuilder} to test the routes
+ */
+@RunWith(Arquillian.class)
+public class SeparateRouteBuilderIntegrationTest extends DeploymentFactory {
+
+    @Inject
+    TestRouteBuilder testRouteBuilder;
+
+    @Test
+    public void integrationTest() throws Exception {
+        assertNotNull("testRouteBuilder not injected!", testRouteBuilder);
+
+        testRouteBuilder.assertIsSatisfied();
+    }
+}


Reply via email to