camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r706679 - in /activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice: ConciseGuiceRouteTest.java GuiceRouteWithNamedKeysTest.java GuiceTest.java TraditionalGuiceRouteTest.java
Date Tue, 21 Oct 2008 16:32:51 GMT
Author: jstrachan
Date: Tue Oct 21 09:32:51 2008
New Revision: 706679

URL: http://svn.apache.org/viewvc?rev=706679&view=rev
Log:
refactored the test cases to reuse code and avoid explicit lifecycle usage (and a double-start
issue)

Modified:
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java

Modified: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java?rev=706679&r1=706678&r2=706679&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
(original)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
Tue Oct 21 09:32:51 2008
@@ -21,7 +21,8 @@
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 
-import org.apache.camel.CamelContext;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
 
 
 /**
@@ -34,10 +35,7 @@
     public void testGuice() throws Exception {
         // lets disable resource injection to avoid JNDI being used
         Injector injector = Guice.createInjector(new CamelModuleWithRouteTypes(MyRouteInstaller.class,
MyHardcodeRoute.class).noResourceInjection());
-        CamelContext camelContext = injector.getInstance(CamelContext.class);
-        camelContext.start();
-        Thread.sleep(1000);
-        camelContext.stop();
+        GuiceTest.assertCamelContextRunningThenCloseInjector(injector);
     }
 
 }
\ No newline at end of file

Modified: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java?rev=706679&r1=706678&r2=706679&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
(original)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
Tue Oct 21 09:32:51 2008
@@ -85,10 +85,7 @@
         assertEquals("route builder list: " + list, 0, list.size());
 */
 
-        CamelContext camelContext = injector.getInstance(CamelContext.class);
-        camelContext.start();
-        Thread.sleep(1000);
-        camelContext.stop();
+        GuiceTest.assertCamelContextRunningThenCloseInjector(injector);
     }
 
 

Modified: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java?rev=706679&r1=706678&r2=706679&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
(original)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
Tue Oct 21 09:32:51 2008
@@ -21,6 +21,7 @@
 import com.google.inject.Guice;
 import com.google.inject.Inject;
 import com.google.inject.Injector;
+import com.google.inject.spi.CloseFailedException;
 
 import org.apache.camel.CamelContext;
 
@@ -29,6 +30,23 @@
  */
 public class GuiceTest extends TestCase {
 
+    /**
+     * Asserts that the CamelContext is available in the given Injector, that its been started,
then close the injector
+     * @param injector
+     * @throws CloseFailedException
+     */
+    public static void assertCamelContextRunningThenCloseInjector(Injector injector) throws
Exception {
+        CamelContext camelContext = injector.getInstance(CamelContext.class);
+
+        org.hamcrest.MatcherAssert.assertThat(camelContext, org.hamcrest.Matchers.is(GuiceCamelContext.class));
+        GuiceCamelContext guiceContext = (GuiceCamelContext) camelContext;
+        assertTrue("is started!", guiceContext.isStarted());
+
+        Thread.sleep(1000);
+
+        injector.close();
+    }
+
     public static class Cheese {
         private final CamelContext camelContext;
 
@@ -50,6 +68,8 @@
         assertNotNull("Should have cheese", cheese);
         assertNotNull("Should have camelContext", cheese.getCamelContext());
         System.out.println("Got " + cheese);
+
+        assertCamelContextRunningThenCloseInjector(injector);
     }
 
 }
\ No newline at end of file

Modified: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java?rev=706679&r1=706678&r2=706679&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
(original)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
Tue Oct 21 09:32:51 2008
@@ -42,10 +42,7 @@
 
     public void testGuice() throws Exception {
         Injector injector = Guice.createInjector(new MyModule());
-        CamelContext camelContext = injector.getInstance(CamelContext.class);
-        camelContext.start();
-        Thread.sleep(1000);
-        camelContext.stop();
+        GuiceTest.assertCamelContextRunningThenCloseInjector(injector);
     }
 
 }



Mime
View raw message