camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [1/7] camel git commit: CAMEL-10375: Move camel-couchbase from extra to ASF
Date Thu, 12 Jan 2017 12:16:11 GMT
Repository: camel
Updated Branches:
  refs/heads/master ab530bfe7 -> 9d4a1ec96


http://git-wip-us.apache.org/repos/asf/camel/blob/0f1f14fa/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseComponentTest.java
b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseComponentTest.java
new file mode 100644
index 0000000..cd3850a
--- /dev/null
+++ b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseComponentTest.java
@@ -0,0 +1,179 @@
+/**
+ * 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.couchbase;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class CouchbaseComponentTest {
+
+    @Mock
+    private CamelContext context;
+
+    @Test
+    public void testEndpointCreated() throws Exception {
+        Map<String, Object> params = new HashMap<String, Object>();
+
+        String uri = "couchbase:http://localhost:9191/bucket";
+        String remaining = "http://localhost:9191/bucket";
+
+        Endpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri, remaining,
params);
+        assertNotNull(endpoint);
+    }
+
+    @Test
+    public void testPropertiesSet() throws Exception {
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("username", "ugol");
+        params.put("password", "pwd");
+        params.put("additionalHosts", "127.0.0.1,example.com,another-host");
+        params.put("persistTo", 2);
+        params.put("replicateTo", 3);
+
+        String uri = "couchdb:http://localhost:91234/bucket";
+        String remaining = "http://localhost:91234/bucket";
+
+        CouchbaseEndpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri,
remaining, params);
+
+        assertEquals("http", endpoint.getProtocol());
+        assertEquals("localhost", endpoint.getHostname());
+        assertEquals("bucket", endpoint.getBucket());
+        assertEquals(91234, endpoint.getPort());
+        assertEquals("ugol", endpoint.getUsername());
+        assertEquals("pwd", endpoint.getPassword());
+        assertEquals("127.0.0.1,example.com,another-host", endpoint.getAdditionalHosts());
+        assertEquals(2, endpoint.getPersistTo());
+        assertEquals(3, endpoint.getReplicateTo());
+    }
+
+    @Test
+    public void testCouchbaseURI() throws Exception {
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        String uri = "couchbase:http://localhost/bucket?param=true";
+        String remaining = "http://localhost/bucket?param=true";
+
+        CouchbaseEndpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri,
remaining, params);
+        assertEquals(new URI("http://localhost:8091/pools"), endpoint.makeBootstrapURI()[0]);
+
+    }
+
+    @Test
+    public void testCouchbaseAdditionalHosts() throws Exception {
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("additionalHosts", "127.0.0.1,example.com,another-host");
+        String uri = "couchbase:http://localhost/bucket?param=true";
+        String remaining = "http://localhost/bucket?param=true";
+
+        CouchbaseEndpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri,
remaining, params);
+
+        // System.out.print(endpoint.makeBootstrapURI()[0].toString() + " " +
+        // endpoint.makeBootstrapURI().length + " ");
+        URI[] endpointArray = endpoint.makeBootstrapURI();
+        assertEquals(new URI("http://localhost:8091/pools"), endpointArray[0]);
+        assertEquals(new URI("http://127.0.0.1:8091/pools"), endpointArray[1]);
+        assertEquals(new URI("http://example.com:8091/pools"), endpointArray[2]);
+        assertEquals(new URI("http://another-host:8091/pools"), endpointArray[3]);
+        assertEquals(4, endpointArray.length);
+
+    }
+
+    @Test
+    public void testCouchbaseAdditionalHostsWithSpaces() throws Exception {
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("additionalHosts", " 127.0.0.1, example.com, another-host ");
+        String uri = "couchbase:http://localhost/bucket?param=true";
+        String remaining = "http://localhost/bucket?param=true";
+
+        CouchbaseEndpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri,
remaining, params);
+
+        // System.out.print(endpoint.makeBootstrapURI()[0].toString() + " " +
+        // endpoint.makeBootstrapURI().length + " ");
+        URI[] endpointArray = endpoint.makeBootstrapURI();
+        assertEquals(new URI("http://localhost:8091/pools"), endpointArray[0]);
+        assertEquals(new URI("http://127.0.0.1:8091/pools"), endpointArray[1]);
+        assertEquals(new URI("http://example.com:8091/pools"), endpointArray[2]);
+        assertEquals(new URI("http://another-host:8091/pools"), endpointArray[3]);
+        assertEquals(4, endpointArray.length);
+
+    }
+
+    @Test
+    public void testCouchbaseDuplicateAdditionalHosts() throws Exception {
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("additionalHosts", "127.0.0.1,localhost, localhost");
+        String uri = "couchbase:http://localhost/bucket?param=true";
+        String remaining = "http://localhost/bucket?param=true";
+
+        CouchbaseEndpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri,
remaining, params);
+        URI[] endpointArray = endpoint.makeBootstrapURI();
+        assertEquals(2, endpointArray.length);
+        assertEquals(new URI("http://localhost:8091/pools"), endpointArray[0]);
+        assertEquals(new URI("http://127.0.0.1:8091/pools"), endpointArray[1]);
+
+    }
+
+    @Test
+    public void testCouchbaseNullAdditionalHosts() throws Exception {
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("additionalHosts", null);
+        String uri = "couchbase:http://localhost/bucket?param=true";
+        String remaining = "http://localhost/bucket?param=true";
+
+        CouchbaseEndpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri,
remaining, params);
+
+        // System.out.print(endpoint.makeBootstrapURI()[0].toString() + " " +
+        // endpoint.makeBootstrapURI().length + " ");
+        URI[] endpointArray = endpoint.makeBootstrapURI();
+
+        assertEquals(1, endpointArray.length);
+
+    }
+
+    @Test
+    public void testCouchbasePersistToAndReplicateToParameters() throws Exception {
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("persistTo", "1");
+        params.put("replicateTo", "2");
+        String uri = "couchbase:http://localhost/bucket?param=true";
+        String remaining = "http://localhost/bucket?param=true";
+
+        CouchbaseEndpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri,
remaining, params);
+
+        assertEquals(1, endpoint.getPersistTo());
+        assertEquals(2, endpoint.getReplicateTo());
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/0f1f14fa/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseConsumerTest.java
b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseConsumerTest.java
new file mode 100644
index 0000000..3a52077
--- /dev/null
+++ b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseConsumerTest.java
@@ -0,0 +1,41 @@
+/**
+ * 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.couchbase;
+
+
+import java.net.URI;
+import java.util.ArrayList;
+
+import com.couchbase.client.CouchbaseClient;
+import com.couchbase.client.vbucket.ConfigurationException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.junit.Test;
+
+public class CouchbaseConsumerTest {
+
+    @Test(expected = ConfigurationException.class)
+    public void testNewCouchbaseConsumer() throws Exception {
+        CouchbaseConsumer couchbaseConsumer = new CouchbaseConsumer(new CouchbaseEndpoint(),
new CouchbaseClient(new ArrayList<URI>(), "bucketName", "pwd"), new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                // Nothing to do
+            }
+        });
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/0f1f14fa/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseEndpointTest.java
b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseEndpointTest.java
new file mode 100644
index 0000000..722b797
--- /dev/null
+++ b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseEndpointTest.java
@@ -0,0 +1,162 @@
+/**
+ * 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.couchbase;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.junit.Test;
+
+import static org.apache.camel.component.couchbase.CouchbaseConstants.DEFAULT_COUCHBASE_PORT;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+
+public class CouchbaseEndpointTest {
+
+    @Test
+    public void assertSingleton() throws Exception {
+        CouchbaseEndpoint endpoint = new CouchbaseEndpoint("couchbase:http://localhost/bucket",
"http://localhost/bucket", new CouchbaseComponent());
+        assertTrue(endpoint.isSingleton());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testBucketRequired() throws Exception {
+        new CouchbaseEndpoint("couchbase:http://localhost:80", "http://localhost:80", new
CouchbaseComponent());
+    }
+
+    @Test
+    public void testDefaultPortIsSet() throws Exception {
+        CouchbaseEndpoint endpoint = new CouchbaseEndpoint("couchbase:http://localhost/bucket",
"http://localhost/bucket", new CouchbaseComponent());
+        assertEquals(DEFAULT_COUCHBASE_PORT, endpoint.getPort());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testHostnameRequired() throws Exception {
+        new CouchbaseEndpoint("couchbase:http://:80/bucket", "couchbase://:80/bucket", new
CouchbaseComponent());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testSchemeRequired() throws Exception {
+        new CouchbaseEndpoint("couchbase:localhost:80/bucket", "localhost:80/bucket", new
CouchbaseComponent());
+    }
+
+    @Test
+    public void testCouchbaseEndpoint() {
+        new CouchbaseEndpoint();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCouchbaseEndpointWithoutProtocol() throws Exception {
+        new CouchbaseEndpoint("localhost:80/bucket", "localhost:80/bucket", new CouchbaseComponent());
+    }
+
+    @Test
+    public void testCouchbaseEndpointUri() {
+        new CouchbaseEndpoint("couchbase:localhost:80/bucket", new CouchbaseComponent());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCouchbaseEndpointCreateProducer() throws Exception {
+        new CouchbaseEndpoint("couchbase:localhost:80/bucket", new CouchbaseComponent()).createProducer();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCouchbaseEndpointCreateConsumer() throws Exception {
+        new CouchbaseEndpoint("couchbase:localhost:80/bucket", new CouchbaseComponent()).createConsumer(new
Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                // Nothing to do
+            }
+        });
+    }
+
+    @Test
+    public void testCouchbaseEndpontSettersAndGetters() {
+        CouchbaseEndpoint endpoint = new CouchbaseEndpoint();
+
+        endpoint.setProtocol("couchbase");
+        assertTrue(endpoint.getProtocol().equals("couchbase"));
+
+        endpoint.setBucket("bucket");
+        assertTrue(endpoint.getBucket().equals("bucket"));
+
+        endpoint.setHostname("localhost");
+        assertTrue(endpoint.getHostname().equals("localhost"));
+
+        endpoint.setPort(80);
+        assertTrue(endpoint.getPort() == 80);
+
+        endpoint.setOperation("PUT");
+        assertTrue(endpoint.getOperation().equals("PUT"));
+
+        endpoint.setStartingIdForInsertsFrom(1L);
+        assertTrue(endpoint.getStartingIdForInsertsFrom() == 1L);
+
+        endpoint.setProducerRetryAttempts(5);
+        assertTrue(endpoint.getProducerRetryAttempts() == 5);
+
+        endpoint.setProducerRetryPause(1);
+        assertTrue(endpoint.getProducerRetryPause() == 1);
+
+        endpoint.setDesignDocumentName("beer");
+        assertTrue(endpoint.getDesignDocumentName().equals("beer"));
+
+        endpoint.setViewName("brewery_beers");
+        assertTrue(endpoint.getViewName().equals("brewery_beers"));
+
+        endpoint.setLimit(1);
+        assertTrue(endpoint.getLimit() == 1);
+
+        endpoint.setSkip(1);
+        assertTrue(endpoint.getSkip() == 1);
+
+        endpoint.setRangeStartKey("");
+        assertTrue(endpoint.getRangeStartKey().equals(""));
+
+        endpoint.setRangeEndKey("");
+        assertTrue(endpoint.getRangeEndKey().equals(""));
+
+        endpoint.setConsumerProcessedStrategy("delete");
+        assertTrue(endpoint.getConsumerProcessedStrategy().equals("delete"));
+
+        endpoint.setOpTimeOut(1L);
+        assertTrue(endpoint.getOpTimeOut() == 1L);
+
+        endpoint.setTimeoutExceptionThreshold(1);
+        assertTrue(endpoint.getTimeoutExceptionThreshold() == 1);
+
+        endpoint.setReadBufferSize(1);
+        assertTrue(endpoint.getReadBufferSize() == 1);
+
+        endpoint.setShouldOptimize(true);
+        assertTrue(endpoint.isShouldOptimize());
+
+        endpoint.setMaxReconnectDelay(1L);
+        assertTrue(endpoint.getMaxReconnectDelay() == 1L);
+
+        endpoint.setOpQueueMaxBlockTime(1L);
+        assertTrue(endpoint.getOpQueueMaxBlockTime() == 1L);
+
+        endpoint.setObsPollInterval(1L);
+        assertTrue(endpoint.getObsPollInterval() == 1L);
+
+        endpoint.setObsTimeout(1L);
+        assertTrue(endpoint.getObsTimeout() == 1L);
+
+        endpoint.setDescending(false);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/0f1f14fa/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseProducerTest.java
b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseProducerTest.java
new file mode 100644
index 0000000..a2230fb
--- /dev/null
+++ b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseProducerTest.java
@@ -0,0 +1,231 @@
+/**
+ * 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.couchbase;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.couchbase.client.CouchbaseClient;
+
+import net.spy.memcached.PersistTo;
+import net.spy.memcached.ReplicateTo;
+import net.spy.memcached.internal.OperationFuture;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import static org.apache.camel.component.couchbase.CouchbaseConstants.HEADER_TTL;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+public class CouchbaseProducerTest {
+
+    @Mock
+    private CouchbaseClient client;
+
+    @Mock
+    private CouchbaseEndpoint endpoint;
+
+    @Mock
+    private Exchange exchange;
+
+    @Mock
+    private Message msg;
+
+    @Mock
+    private OperationFuture response;
+
+    private CouchbaseProducer producer;
+
+    @Before
+    public void before() throws Exception {
+        initMocks(this);
+        when(endpoint.getProducerRetryAttempts()).thenReturn(CouchbaseConstants.DEFAULT_PRODUCER_RETRIES);
+        producer = new CouchbaseProducer(endpoint, client, 0, 0);
+        when(exchange.getIn()).thenReturn(msg);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test(expected = CouchbaseException.class)
+    public void testBodyMandatory() throws Exception {
+        when(msg.getMandatoryBody()).thenThrow(InvalidPayloadException.class);
+        producer.process(exchange);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testPersistToLowerThanSupported() throws Exception {
+        producer = new CouchbaseProducer(endpoint, client, -1, 0);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testPersistToHigherThanSupported() throws Exception {
+        producer = new CouchbaseProducer(endpoint, client, 5, 0);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testReplicateToLowerThanSupported() throws Exception {
+        producer = new CouchbaseProducer(endpoint, client, 0, -1);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testReplicateToHigherThanSupported() throws Exception {
+        producer = new CouchbaseProducer(endpoint, client, 0, 4);
+    }
+
+    @Test
+    public void testMaximumValuesForPersistToAndRepicateTo() throws Exception {
+        try {
+            producer = new CouchbaseProducer(endpoint, client, 4, 3);
+        } catch (IllegalArgumentException e) {
+            Assert.fail("Exception was thrown while testing maximum values for persistTo
and replicateTo parameters " + e.getMessage());
+        }
+    }
+
+    @Test
+    public void testExpiryTimeIsSet() throws Exception {
+        OperationFuture of = mock(OperationFuture.class);
+        when(of.get()).thenAnswer(new Answer<Object>() {
+            @Override
+            public Object answer(InvocationOnMock invocation) throws Exception {
+                return true;
+
+            }
+        });
+
+        when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(),
org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class),
+                        org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
+        // Mock out some headers so we can set an expiry
+        int expiry = 5000;
+        Map<String, Object> testHeaders = new HashMap<String, Object>();
+        testHeaders.put("CCB_TTL", Integer.toString(expiry));
+        when(msg.getHeaders()).thenReturn(testHeaders);
+        when(msg.getHeader(HEADER_TTL, String.class)).thenReturn(Integer.toString(expiry));
+
+        when(endpoint.getId()).thenReturn("123");
+        when(endpoint.getOperation()).thenReturn("CCB_PUT");
+        Message outmsg = mock(Message.class);
+        when(exchange.getOut()).thenReturn(msg);
+
+        producer.process(exchange);
+
+        verify(client).set(org.mockito.Matchers.anyString(), Mockito.eq(expiry), org.mockito.Matchers.anyObject(),
org.mockito.Matchers.any(PersistTo.class),
+                           org.mockito.Matchers.any(ReplicateTo.class));
+
+    }
+
+    @Test
+    public void testTimeOutRetryToException() throws Exception {
+
+        OperationFuture of = mock(OperationFuture.class);
+        when(of.get()).thenAnswer(new Answer<Object>() {
+            @Override
+            public Object answer(InvocationOnMock invocation) throws Exception {
+                throw new RuntimeException("Timed out waiting for operation");
+
+            }
+        });
+
+        when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(),
org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class),
+                        org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
+        when(endpoint.getId()).thenReturn("123");
+        when(endpoint.getOperation()).thenReturn("CCB_PUT");
+        try {
+            producer.process(exchange);
+        } catch (Exception e) {
+            // do nothing
+            verify(of, times(3)).get();
+        }
+
+    }
+
+    @Test
+    public void testTimeOutRetryThenSuccess() throws Exception {
+
+        OperationFuture of = mock(OperationFuture.class);
+        when(of.get()).thenAnswer(new Answer<Object>() {
+            @Override
+            public Object answer(InvocationOnMock invocation) throws Exception {
+                throw new RuntimeException("Timed out waiting for operation");
+
+            }
+        }).thenAnswer(new Answer<Object>() {
+            @Override
+            public Object answer(InvocationOnMock invocation) throws Exception {
+                return true;
+
+            }
+        });
+
+        when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(),
org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class),
+                        org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
+        when(endpoint.getId()).thenReturn("123");
+        when(endpoint.getOperation()).thenReturn("CCB_PUT");
+        when(exchange.getOut()).thenReturn(msg);
+
+        producer.process(exchange);
+
+        verify(of, times(2)).get();
+        verify(msg).setBody(true);
+    }
+
+    @Test
+    public void testTimeOutRetryTwiceThenSuccess() throws Exception {
+
+        OperationFuture of = mock(OperationFuture.class);
+        when(of.get()).thenAnswer(new Answer<Object>() {
+            @Override
+            public Object answer(InvocationOnMock invocation) throws Exception {
+                throw new RuntimeException("Timed out waiting for operation");
+
+            }
+        }).thenAnswer(new Answer<Object>() {
+            @Override
+            public Object answer(InvocationOnMock invocation) throws Exception {
+                throw new RuntimeException("Timed out waiting for operation");
+
+            }
+        }).thenAnswer(new Answer<Object>() {
+            @Override
+            public Object answer(InvocationOnMock invocation) throws Exception {
+                return true;
+
+            }
+        });
+
+        when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(),
org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class),
+                        org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
+        when(endpoint.getId()).thenReturn("123");
+        when(endpoint.getOperation()).thenReturn("CCB_PUT");
+        when(exchange.getOut()).thenReturn(msg);
+
+        producer.process(exchange);
+
+        verify(of, times(3)).get();
+        verify(msg).setBody(true);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/0f1f14fa/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/ProduceMessagesSimpleTest.java
----------------------------------------------------------------------
diff --git a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/ProduceMessagesSimpleTest.java
b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/ProduceMessagesSimpleTest.java
new file mode 100644
index 0000000..cc2d5a9
--- /dev/null
+++ b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/ProduceMessagesSimpleTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.couchbase;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class ProduceMessagesSimpleTest extends CamelTestSupport {
+
+    // Ignore test since build environment does not have any couchbase instance
+    @Ignore
+    @Test
+    public void testInsert() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        template.sendBody("direct:start", "ugol");
+        assertMockEndpointsSatisfied();
+
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+
+                // need couchbase installed on localhost
+                from("direct:start").setHeader(CouchbaseConstants.HEADER_ID, constant("120770")).to("couchbase:http://localhost/default").to("mock:result");
+
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/0f1f14fa/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/ProduceMessagesWithAutoIDIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/ProduceMessagesWithAutoIDIntegrationTest.java
b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/ProduceMessagesWithAutoIDIntegrationTest.java
new file mode 100644
index 0000000..1da92f7
--- /dev/null
+++ b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/ProduceMessagesWithAutoIDIntegrationTest.java
@@ -0,0 +1,49 @@
+/**
+ * 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.couchbase;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ProduceMessagesWithAutoIDIntegrationTest extends CamelTestSupport {
+
+    @Test
+    public void testInsert() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(2);
+
+        template.sendBody("direct:start", "ugol1");
+        template.sendBody("direct:start", "ugol2");
+
+        assertMockEndpointsSatisfied();
+
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+
+                // need couchbase installed on localhost
+                from("direct:start").to("couchbase:http://localhost/default?autoStartIdForInserts=true&startingIdForInsertsFrom=1000").to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/0f1f14fa/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/RemoveMessagesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/RemoveMessagesIntegrationTest.java
b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/RemoveMessagesIntegrationTest.java
new file mode 100644
index 0000000..0ac050d
--- /dev/null
+++ b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/RemoveMessagesIntegrationTest.java
@@ -0,0 +1,49 @@
+/**
+ * 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.couchbase;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class RemoveMessagesIntegrationTest extends CamelTestSupport {
+
+    @Test
+    public void testInsert() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(2);
+
+        template.sendBody("direct:start", "ugol1");
+        template.sendBody("direct:start", "ugol2");
+
+        assertMockEndpointsSatisfied();
+
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+
+                // need couchbase installed on localhost
+                from("direct:start").setHeader(CouchbaseConstants.HEADER_ID, constant("120770")).to("couchbase:http://localhost/default?operation='DELETE'").to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/0f1f14fa/components/camel-couchbase/src/test/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/components/camel-couchbase/src/test/resources/log4j2.properties b/components/camel-couchbase/src/test/resources/log4j2.properties
new file mode 100644
index 0000000..1388037
--- /dev/null
+++ b/components/camel-couchbase/src/test/resources/log4j2.properties
@@ -0,0 +1,30 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.file.type = File
+appender.file.name = file
+appender.file.fileName = target/camel-couchbase-test.log
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+appender.out.type = Console
+appender.out.name = out
+appender.out.layout.type = PatternLayout
+appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+logger.kubernetes.name = org.apache.camel.component.couchbase
+logger.kubernetes.level = DEBUG
+rootLogger.level = INFO
+rootLogger.appenderRef.file.ref = file

http://git-wip-us.apache.org/repos/asf/camel/blob/0f1f14fa/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index 9852969..def06f5 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -94,6 +94,7 @@
     <module>camel-cometd</module>
     <module>camel-consul</module>
     <module>camel-context</module>
+    <module>camel-couchbase</module>
     <module>camel-couchdb</module>
     <module>camel-crypto</module>
     <module>camel-csv</module>

http://git-wip-us.apache.org/repos/asf/camel/blob/0f1f14fa/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index f3e813f..d92df30 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -914,6 +914,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.camel</groupId>
+        <artifactId>camel-couchbase</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.camel</groupId>
         <artifactId>camel-couchdb</artifactId>
         <version>${project.version}</version>
       </dependency>
@@ -2217,6 +2222,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.camel</groupId>
+        <artifactId>camel-couchbase-starter</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.camel</groupId>
         <artifactId>camel-couchdb-starter</artifactId>
         <version>${project.version}</version>
       </dependency>


Mime
View raw message