camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1172210 - in /camel/trunk/tests/camel-itest-osgi: ./ src/test/java/org/apache/camel/itest/osgi/hazelcast/
Date Sun, 18 Sep 2011 07:37:52 GMT
Author: davsclaus
Date: Sun Sep 18 07:37:51 2011
New Revision: 1172210

URL: http://svn.apache.org/viewvc?rev=1172210&view=rev
Log:
CAMEL-4461: Added hazelcast osgi test. Thanks to Ioannis for the patch.

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java
  (with props)
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/SimpleObject.java
  (with props)
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=1172210&r1=1172209&r2=1172210&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/pom.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/pom.xml Sun Sep 18 07:37:51 2011
@@ -158,6 +158,11 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-hazelcast</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-hl7</artifactId>
       <scope>test</scope>
     </dependency>

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java?rev=1172210&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java
(added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java
Sun Sep 18 07:37:51 2011
@@ -0,0 +1,114 @@
+package org.apache.camel.itest.osgi.hazelcast;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
+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 org.apache.camel.component.hazelcast.HazelcastConstants;
+
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+
+@RunWith(JUnit4TestRunner.class)
+public class HazelcastTest extends OSGiIntegrationTestSupport {
+
+    @Test
+    public void testAtomicNumber() throws Exception {
+        String reply = template.requestBody("direct:getatomic", null, String.class);
+        assertNotNull(reply);
+        long value = Long.parseLong(reply);
+        assertEquals("Should be 0",0L,value);
+
+
+        template.sendBody("direct:setatomic", 100L);
+        reply = template.requestBody("direct:getatomic", null, String.class);
+        assertNotNull(reply);
+        value = Long.parseLong(reply);
+        assertEquals("Should be 100",100L,value);
+    }
+
+    @Test
+    public void testMap() throws Exception {
+        SimpleObject item1 = new SimpleObject(1L,"Some value");
+        SimpleObject item2 = new SimpleObject(2L,"Some other value");
+
+        template.sendBodyAndHeader("direct:mapput", item1,HazelcastConstants.OBJECT_ID,"1");
+        template.sendBodyAndHeader("direct:mapput", item2,HazelcastConstants.OBJECT_ID,"2");
+
+        Object result2 = template.requestBodyAndHeader("direct:mapget", null,HazelcastConstants.OBJECT_ID,"2");
+        assertNotNull(result2);
+        assertEquals("Should be equal",item2,result2);
+        Object result1 = template.requestBodyAndHeader("direct:mapget", null,HazelcastConstants.OBJECT_ID,"1");
+        assertNotNull(result1);
+        assertEquals("Should be equal",item1,result1);
+        Object resul3 = template.requestBodyAndHeader("direct:mapget", null,HazelcastConstants.OBJECT_ID,"3");
+        assertNull(resul3);
+    }
+
+
+     @Test
+    public void testQueue() throws Exception {
+        SimpleObject item1 = new SimpleObject(1L,"Some value");
+        SimpleObject item2 = new SimpleObject(2L,"Some other value");
+
+        template.sendBodyAndHeader("direct:queueput", item1,HazelcastConstants.OPERATION,HazelcastConstants.ADD_OPERATION);
+        template.sendBodyAndHeader("direct:queueput", item2,HazelcastConstants.OPERATION,HazelcastConstants.ADD_OPERATION);
+
+        Object result1 = template.requestBody("direct:queuepoll",new Object());
+        assertNotNull(result1);
+        assertEquals("Should be equal",item1,result1);
+        Object result2 = template.requestBody("direct:queuepoll",new Object());
+        assertNotNull(result2);
+        assertEquals("Should be equal",item1,result1);
+        Object resul3 = template.requestBody("direct:queuepoll",new Object());
+        assertNull(resul3);
+    }
+
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+
+                //Atomic number
+                from("direct:getatomic")
+                        .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
+                        .toF("hazelcast:atomicvalue:myvalue");
+
+                from("direct:setatomic")
+                        .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.SETVALUE_OPERATION))
+                        .toF("hazelcast:atomicvalue:myvalue");
+
+                //Map
+                from("direct:mapput")
+                        .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))
+                        .toF("hazelcast:map:mymap", HazelcastConstants.MAP_PREFIX);
+
+                from("direct:mapget")
+                        .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.GET_OPERATION))
+                        .toF("hazelcast:map:mymap");
+
+                //Queue
+                from("direct:queueput")
+                        .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION))
+                        .toF("hazelcast:queue:myqueue");
+
+                from("direct:queuepoll")
+                        .setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.POLL_OPERATION))
+                        .toF("hazelcast:queue:myqueue");
+            }
+        };
+    }
+
+    @Configuration
+    public static Option[] configure() {
+        Option[] options = combine(
+            getDefaultCamelKarafOptions(),
+            // using the features to install the other camel components
+            scanFeatures(getCamelKarafFeatureUrl(), "camel-hazelcast"));
+
+        return options;
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/SimpleObject.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/SimpleObject.java?rev=1172210&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/SimpleObject.java
(added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/SimpleObject.java
Sun Sep 18 07:37:51 2011
@@ -0,0 +1,51 @@
+package org.apache.camel.itest.osgi.hazelcast;
+
+import java.io.Serializable;
+
+public class SimpleObject implements Serializable {
+
+    Long id;
+    Object value;
+
+    public SimpleObject(Long id) {
+        this.id = id;
+    }
+
+    public SimpleObject(Long id, Object value) {
+        this.id = id;
+        this.value = value;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Object getValue() {
+        return value;
+    }
+
+    public void setValue(Object value) {
+        this.value = value;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        SimpleObject that = (SimpleObject) o;
+
+        if (!id.equals(that.id)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return id.hashCode();
+    }
+}

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/SimpleObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/SimpleObject.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message