You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/09/14 12:29:49 UTC

svn commit: r996817 - in /camel/trunk/tests/camel-itest-osgi: pom.xml src/test/java/org/apache/camel/itest/osgi/hawtdb/ src/test/java/org/apache/camel/itest/osgi/hawtdb/HawtDBAggregateRouteTest.java

Author: davsclaus
Date: Tue Sep 14 10:29:48 2010
New Revision: 996817

URL: http://svn.apache.org/viewvc?rev=996817&view=rev
Log:
CAMEL-3120: Added osgi test for hawtdb

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hawtdb/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hawtdb/HawtDBAggregateRouteTest.java
      - copied, changed from r996754, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/protobuf/ProtobufRouteTest.java
Modified:
    camel/trunk/tests/camel-itest-osgi/pom.xml

Modified: camel/trunk/tests/camel-itest-osgi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/pom.xml?rev=996817&r1=996816&r2=996817&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/pom.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/pom.xml Tue Sep 14 10:29:48 2010
@@ -101,6 +101,11 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-hawtdb</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-shiro</artifactId>
       <scope>test</scope>
     </dependency>

Copied: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hawtdb/HawtDBAggregateRouteTest.java (from r996754, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/protobuf/ProtobufRouteTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hawtdb/HawtDBAggregateRouteTest.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hawtdb/HawtDBAggregateRouteTest.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/protobuf/ProtobufRouteTest.java&r1=996754&r2=996817&rev=996817&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/protobuf/ProtobufRouteTest.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hawtdb/HawtDBAggregateRouteTest.java Tue Sep 14 10:29:48 2010
@@ -14,99 +14,83 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.itest.osgi.protobuf;
+package org.apache.camel.itest.osgi.hawtdb;
 
-import org.apache.camel.CamelException;
-import org.apache.camel.FailedToCreateRouteException;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.hawtdb.HawtDBAggregationRepository;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.dataformat.protobuf.ProtobufDataFormat;
-import org.apache.camel.dataformat.protobuf.generated.AddressBookProtos;
 import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 
-import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
 
 @RunWith(JUnit4TestRunner.class)
-public class ProtobufRouteTest extends OSGiIntegrationTestSupport {
+public class HawtDBAggregateRouteTest extends OSGiIntegrationTestSupport {
 
     @Test
-    public void testMarshalAndUnmarshalWithDataFormat() throws Exception {
-        marshalAndUnmarshal("direct:in", "direct:back");
-    }
-    
-    @Test
-    public void testMarshalAndUnmarshalWithDSL1() throws Exception {
-        marshalAndUnmarshal("direct:marshal", "direct:unmarshalA");
-    }
-    
-    @Test
-    public void testMarshalAndUnmarshalWithDSL2() throws Exception {
-        marshalAndUnmarshal("direct:marshal", "direct:unmarshalB");
-    }
-    
-    @Test
-    public void testMarshalAndUnmashalWithDSL3() throws Exception {
-        try {
-            context.addRoutes(new RouteBuilder() {
-                public void configure() throws Exception {
-                    from("direct:unmarshalC").unmarshal().protobuf(new CamelException("wrong instance"))
-                        .to("mock:reverse");
-                }
-            });
-            fail("Expect the exception here");
-        } catch (Exception ex) {
-            assertTrue("Expect FailedToCreateRouteException", ex instanceof FailedToCreateRouteException);
-            assertTrue("Get a wrong reason", ex.getCause() instanceof IllegalArgumentException);
-        }
-    }
-    
-    private void marshalAndUnmarshal(String inURI, String outURI) throws Exception {
-        AddressBookProtos.Person input = AddressBookProtos.Person
-            .newBuilder().setName("Martin").setId(1234).build();
-
-        MockEndpoint mock = getMockEndpoint("mock:reverse");
-        mock.expectedMessageCount(1);
-        mock.message(0).body().isInstanceOf(org.apache.camel.dataformat.protobuf.generated.AddressBookProtos.Person.class);
-        mock.message(0).body().equals(input);
-
-        Object marshalled = template.requestBody(inURI, input);
+    public void testHawtDBAggregateRoute() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:aggregated");
+        mock.expectedBodiesReceived("ABCDE");
+
+        template.sendBodyAndHeader("direct:start", "A", "id", 123);
+        template.sendBodyAndHeader("direct:start", "B", "id", 123);
+        template.sendBodyAndHeader("direct:start", "C", "id", 123);
+        template.sendBodyAndHeader("direct:start", "D", "id", 123);
+        template.sendBodyAndHeader("direct:start", "E", "id", 123);
 
-        template.sendBody(outURI, marshalled);
+        assertMockEndpointsSatisfied(30, TimeUnit.SECONDS);
 
-        mock.assertIsSatisfied();
-
-        AddressBookProtos.Person output = mock.getReceivedExchanges().get(0).getIn().getBody(AddressBookProtos.Person.class);
-        assertEquals("Martin", output.getName());
+        // from endpoint should be preserved
+        assertEquals("direct://start", mock.getReceivedExchanges().get(0).getFromEndpoint().getEndpointUri());
     }
 
-
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                ProtobufDataFormat format = new ProtobufDataFormat(AddressBookProtos.Person.getDefaultInstance());
+                // delete the data directory
+                deleteDirectory("target/data");
+
+                // create the hawtdb repo
+                HawtDBAggregationRepository repo = new HawtDBAggregationRepository("repo1", "target/data/hawtdb.dat");
 
-                from("direct:in").marshal(format);
-                from("direct:back").unmarshal(format).to("mock:reverse");
-                
-                from("direct:marshal").marshal().protobuf();
-                from("direct:unmarshalA").unmarshal().protobuf("org.apache.camel.dataformat.protobuf.generated.AddressBookProtos$Person").to("mock:reverse");
-                
-                from("direct:unmarshalB").unmarshal().protobuf(AddressBookProtos.Person.getDefaultInstance()).to("mock:reverse");
+                // here is the Camel route where we aggregate
+                from("direct:start")
+                    .aggregate(header("id"), new MyAggregationStrategy())
+                        // use our created hawtdb repo as aggregation repository
+                        .completionSize(5).aggregationRepository(repo)
+                        .to("mock:aggregated");
             }
         };
     }
     
+    public static class MyAggregationStrategy implements AggregationStrategy {
+
+        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+            if (oldExchange == null) {
+                return newExchange;
+            }
+            String body1 = oldExchange.getIn().getBody(String.class);
+            String body2 = newExchange.getIn().getBody(String.class);
+
+            oldExchange.getIn().setBody(body1 + body2);
+            return oldExchange;
+        }
+    }
+
     @Configuration
     public static Option[] configure() {
         Option[] options = options(
@@ -117,11 +101,11 @@ public class ProtobufRouteTest extends O
             
             // using the features to install the camel components             
             scanFeatures(getCamelKarafFeatureUrl(),                         
-                          "camel-core", "camel-spring", "camel-test", "camel-protobuf"),
+                          "camel-core", "camel-spring", "camel-test", "camel-hawtdb"),
             
             workingDirectory("target/paxrunner/"),
 
-            felix());
+            equinox());
         
         return options;
     }