camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [1/2] camel git commit: CAMEL-9036 Camel-Hazelcast: Add support for set Data Structure, added Producer and Consumer Tests
Date Thu, 30 Jul 2015 15:37:20 GMT
Repository: camel
Updated Branches:
  refs/heads/master 600aeba46 -> 57989d7d1


CAMEL-9036 Camel-Hazelcast: Add support for set Data Structure, added Producer and Consumer
Tests


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/57989d7d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/57989d7d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/57989d7d

Branch: refs/heads/master
Commit: 57989d7d1f466199e2f448342995dc32b52ff8a1
Parents: b781dc0
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Thu Jul 30 17:33:33 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Jul 30 17:33:45 2015 +0200

----------------------------------------------------------------------
 .../hazelcast/HazelcastErrorMessagesTest.java   |   2 +-
 .../hazelcast/HazelcastSetConsumerTest.java     | 104 +++++++++++++
 .../hazelcast/HazelcastSetProducerTest.java     | 147 +++++++++++++++++++
 3 files changed, 252 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/57989d7d/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastErrorMessagesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastErrorMessagesTest.java
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastErrorMessagesTest.java
index 31dbc64..63f454c 100644
--- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastErrorMessagesTest.java
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastErrorMessagesTest.java
@@ -36,7 +36,7 @@ public class HazelcastErrorMessagesTest extends HazelcastCamelTestSupport
{
         } catch (Exception e) {
             assertTrue(e.getMessage().contains(
                     "Your URI does not provide a correct 'type' prefix. It should be anything
like "
-                            + "'hazelcast:[map:|multimap:|atomicvalue:|instance:|queue:|seda:|list:|replicatedmap:]name'
but is 'hazelcast://error:foo"));
+                            + "'hazelcast:[map:|multimap:|atomicvalue:|instance:|queue:|seda:|list:|replicatedmap:|set:]name'
but is 'hazelcast://error:foo"));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/57989d7d/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSetConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSetConsumerTest.java
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSetConsumerTest.java
new file mode 100644
index 0000000..3c43d2f
--- /dev/null
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSetConsumerTest.java
@@ -0,0 +1,104 @@
+/**
+ * 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.component.hazelcast;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.IList;
+import com.hazelcast.core.ISet;
+import com.hazelcast.core.ItemEvent;
+import com.hazelcast.core.ItemEventType;
+import com.hazelcast.core.ItemListener;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+
+import static org.mockito.Mockito.*;
+
+public class HazelcastSetConsumerTest extends HazelcastCamelTestSupport {
+
+    @Mock
+    private ISet<String> set;
+
+    private ArgumentCaptor<ItemListener> argument;
+
+    @Override
+    @SuppressWarnings("unchecked")
+    protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) {
+        when(hazelcastInstance.<String>getSet("foo")).thenReturn(set);
+        argument = ArgumentCaptor.forClass(ItemListener.class);
+        when(set.addItemListener(argument.capture(), eq(true))).thenReturn("foo");
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) {
+        verify(hazelcastInstance).getSet("foo");
+        verify(set).addItemListener(any(ItemListener.class), eq(true));
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void add() throws InterruptedException {
+        MockEndpoint out = getMockEndpoint("mock:added");
+        out.expectedMessageCount(1);
+
+        final ItemEvent<String> event = new ItemEvent<String>("mm", ItemEventType.ADDED,
"foo", null);
+        argument.getValue().itemAdded(event);
+
+        assertMockEndpointsSatisfied(2000, TimeUnit.MILLISECONDS);
+
+        this.checkHeaders(out.getExchanges().get(0).getIn().getHeaders(), HazelcastConstants.ADDED);
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void remove() throws InterruptedException {
+        MockEndpoint out = getMockEndpoint("mock:removed");
+        out.expectedMessageCount(1);
+
+        final ItemEvent<String> event = new ItemEvent<String>("mm", ItemEventType.REMOVED,
"foo", null);
+        argument.getValue().itemRemoved(event);
+
+        assertMockEndpointsSatisfied(2000, TimeUnit.MILLISECONDS);
+        this.checkHeaders(out.getExchanges().get(0).getIn().getHeaders(), HazelcastConstants.REMOVED);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from(String.format("hazelcast:%sfoo", HazelcastConstants.SET_PREFIX)).log("object...").choice().when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.ADDED))
+                        .log("...added").to("mock:added").when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.REMOVED)).log("...removed").to("mock:removed").otherwise()
+                        .log("fail!");
+            }
+        };
+    }
+
+    private void checkHeaders(Map<String, Object> headers, String action) {
+        assertEquals(action, headers.get(HazelcastConstants.LISTENER_ACTION));
+        assertEquals(HazelcastConstants.CACHE_LISTENER, headers.get(HazelcastConstants.LISTENER_TYPE));
+        assertEquals(null, headers.get(HazelcastConstants.OBJECT_ID));
+        assertNotNull(headers.get(HazelcastConstants.LISTENER_TIME));
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/57989d7d/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSetProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSetProducerTest.java
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSetProducerTest.java
new file mode 100644
index 0000000..dbf9b58
--- /dev/null
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSetProducerTest.java
@@ -0,0 +1,147 @@
+/**
+ * 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.component.hazelcast;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.IList;
+import com.hazelcast.core.ISet;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.After;
+import org.junit.Test;
+import org.mockito.Mock;
+
+import static org.mockito.Mockito.*;
+
+public class HazelcastSetProducerTest extends HazelcastCamelTestSupport {
+
+    @Mock
+    private ISet<String> set;
+
+    @Override
+    protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) {
+        when(hazelcastInstance.<String>getSet("bar")).thenReturn(set);
+    }
+
+    @Override
+    protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) {
+        verify(hazelcastInstance, atLeastOnce()).getSet("bar");
+    }
+
+    @After
+    public final void verifySetMock() {
+        verifyNoMoreInteractions(set);
+    }
+
+    @Test(expected = CamelExecutionException.class)
+    public void testWithInvalidOperation() {
+        template.sendBody("direct:addInvalid", "bar");
+    }
+
+    @Test
+    public void addValue() throws InterruptedException {
+        template.sendBody("direct:add", "bar");
+        verify(set).add("bar");
+    }
+
+    @Test
+    public void addValueWithOperationNumber() throws InterruptedException {
+        template.sendBody("direct:addWithOperationNumber", "bar");
+        verify(set).add("bar");
+    }
+
+    @Test
+    public void addValueWithOperationName() throws InterruptedException {
+        template.sendBody("direct:addWithOperationName", "bar");
+        verify(set).add("bar");
+    }
+
+    @Test
+    public void removeValue() throws InterruptedException {
+        template.sendBody("direct:removevalue", "foo2");
+        verify(set).remove("foo2");
+    }
+    
+    @Test
+    public void clearList() {
+        template.sendBody("direct:clear", "");
+        verify(set).clear();
+    }
+    
+    @Test
+    public void addAll() throws InterruptedException {
+        Collection t = new ArrayList();
+        t.add("test1");
+        t.add("test2");
+        template.sendBody("direct:addAll", t);
+        verify(set).addAll(t);
+    }
+    
+    @Test
+    public void removeAll() throws InterruptedException {
+        Collection t = new ArrayList();
+        t.add("test1");
+        t.add("test2");
+        template.sendBody("direct:removeAll", t);
+        verify(set).removeAll(t);
+    }
+    
+    @Test
+    public void retainAll() throws InterruptedException {
+        Collection t = new ArrayList();
+        t.add("test1");
+        t.add("test2");
+        template.sendBody("direct:retainAll", t);
+        verify(set).retainAll(t);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+
+                from("direct:addInvalid").setHeader(HazelcastConstants.OPERATION, constant("bogus")).toF("hazelcast:%sbar",
HazelcastConstants.SET_PREFIX);
+
+                from("direct:add").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_OPERATION)).toF("hazelcast:%sbar",
HazelcastConstants.SET_PREFIX);
+
+                from("direct:removevalue").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION)).to(
+                        String.format("hazelcast:%sbar", HazelcastConstants.SET_PREFIX));
+                
+                from("direct:clear").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.CLEAR_OPERATION)).toF("hazelcast:%sbar",
HazelcastConstants.SET_PREFIX);
+
+                from("direct:addAll").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_ALL_OPERATION)).to(
+                        String.format("hazelcast:%sbar", HazelcastConstants.SET_PREFIX));
+                
+                from("direct:removeAll").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVE_ALL_OPERATION)).to(
+                        String.format("hazelcast:%sbar", HazelcastConstants.SET_PREFIX));
+                
+                from("direct:retainAll").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.RETAIN_ALL_OPERATION)).to(
+                        String.format("hazelcast:%sbar", HazelcastConstants.SET_PREFIX));
+                
+                from("direct:addWithOperationNumber").toF("hazelcast:%sbar?operation=%s",
HazelcastConstants.SET_PREFIX, HazelcastConstants.ADD_OPERATION);
+                from("direct:addWithOperationName").toF("hazelcast:%sbar?operation=add",
HazelcastConstants.SET_PREFIX);
+            }
+        };
+    }
+
+}
+


Mime
View raw message