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 2014/12/23 12:25:03 UTC
[3/5] camel git commit: CAMEL-2939: Fixed CS
http://git-wip-us.apache.org/repos/asf/camel/blob/e0b14cd4/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java b/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java
index 5cc42e6..1755612 100644
--- a/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java
+++ b/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java
@@ -1,13 +1,28 @@
+/**
+ * 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.cassandra;
+import java.util.Arrays;
+
import com.datastax.driver.core.Cluster;
-import org.apache.camel.component.cassandra.CassandraEndpoint;
-import org.apache.camel.component.cassandra.CassandraConstants;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
-import java.util.Arrays;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
@@ -19,38 +34,46 @@ import org.junit.Rule;
import org.junit.Test;
public class CassandraComponentProducerTest extends CamelTestSupport {
+
+ private static final String CQL = "insert into camel_user(login, first_name, last_name) values (?, ?, ?)";
+ private static final String NOT_CONSISTENT_URI = "cql://localhost/camel_ks?cql=" + CQL + "&consistencyLevel=ANY";
+
@Rule
- public CassandraCQLUnit cassandra=CassandraUnitUtils.cassandraCQLUnit();
+ public CassandraCQLUnit cassandra = CassandraUnitUtils.cassandraCQLUnit();
+
@Produce(uri = "direct:input")
ProducerTemplate producerTemplate;
+
@Produce(uri = "direct:inputNotConsistent")
ProducerTemplate notConsistentProducerTemplate;
+
@BeforeClass
public static void setUpClass() throws Exception {
CassandraUnitUtils.startEmbeddedCassandra();
}
+
@AfterClass
public static void tearDownClass() throws Exception {
CassandraUnitUtils.cleanEmbeddedCassandra();
}
- private static final String CQL = "insert into camel_user(login, first_name, last_name) values (?, ?, ?)";
- private static final String NOT_CONSISTENT_URI="cql://localhost/camel_ks?cql="+CQL+"&consistencyLevel=ANY";
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
-
+
from("direct:input")
- .to("cql://localhost/camel_ks?cql="+CQL);
+ .to("cql://localhost/camel_ks?cql=" + CQL);
from("direct:inputNotConsistent")
- .to(NOT_CONSISTENT_URI);
+ .to(NOT_CONSISTENT_URI);
}
};
}
+
@Test
- public void testRequest_UriCql() throws Exception {
- Object response = producerTemplate.requestBody(Arrays.asList("w_jiang","Willem","Jiang"));
-
+ public void testRequestUriCql() throws Exception {
+ Object response = producerTemplate.requestBody(Arrays.asList("w_jiang", "Willem", "Jiang"));
+
Cluster cluster = CassandraUnitUtils.cassandraCluster();
Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
ResultSet resultSet = session.execute("select login, first_name, last_name from camel_user where login = ?", "w_jiang");
@@ -61,10 +84,12 @@ public class CassandraComponentProducerTest extends CamelTestSupport {
session.close();
cluster.close();
}
+
@Test
- public void testRequest_MessageCql() throws Exception {
- Object response = producerTemplate.requestBodyAndHeader(new Object[]{"Claus 2","Ibsen 2", "c_ibsen"}, CassandraConstants.CQL_QUERY, "update camel_user set first_name=?, last_name=? where login=?");
-
+ public void testRequestMessageCql() throws Exception {
+ Object response = producerTemplate.requestBodyAndHeader(new Object[]{"Claus 2", "Ibsen 2", "c_ibsen"},
+ CassandraConstants.CQL_QUERY, "update camel_user set first_name=?, last_name=? where login=?");
+
Cluster cluster = CassandraUnitUtils.cassandraCluster();
Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
ResultSet resultSet = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
@@ -77,11 +102,11 @@ public class CassandraComponentProducerTest extends CamelTestSupport {
}
@Test
- public void testRequest_NotConsistent() throws Exception {
-
+ public void testRequestNotConsistent() throws Exception {
+
CassandraEndpoint endpoint = getMandatoryEndpoint(NOT_CONSISTENT_URI, CassandraEndpoint.class);
assertEquals(ConsistencyLevel.ANY, endpoint.getConsistencyLevel());
-
- Object response = notConsistentProducerTemplate.requestBody(Arrays.asList("j_anstey","Jonathan","Anstey"));
+
+ Object response = notConsistentProducerTemplate.requestBody(Arrays.asList("j_anstey", "Jonathan", "Anstey"));
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/e0b14cd4/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraUnitUtils.java
----------------------------------------------------------------------
diff --git a/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraUnitUtils.java b/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraUnitUtils.java
index 4bbcab0..30d6c43 100644
--- a/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraUnitUtils.java
+++ b/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraUnitUtils.java
@@ -1,9 +1,10 @@
-/*
- * Copyright 2014 The Apache Software Foundation.
- *
- * Licensed 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
+/**
+ * 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
*
@@ -26,11 +27,15 @@ import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
/**
* Util methods to manage Cassandra in Unit tests
*/
-public class CassandraUnitUtils {
+public final class CassandraUnitUtils {
public static final String HOST = "127.0.0.1";
public static final String KEYSPACE = "camel_ks";
private static CassandraCQLUnit cassandraCQLUnit;
+
+ private CassandraUnitUtils() {
+ }
+
/**
* Create Cassandra JUnit Rule.
*/
@@ -40,6 +45,7 @@ public class CassandraUnitUtils {
}
return cassandraCQLUnit;
}
+
public static CassandraCQLUnit cassandraCQLUnit(String dataSetCql) {
return cassandraCQLUnit(cqlDataSet(dataSetCql));
}
@@ -47,6 +53,7 @@ public class CassandraUnitUtils {
public static CQLDataSet cqlDataSet(String dataSetCql) {
return new ClassPathCQLDataSet(dataSetCql, KEYSPACE);
}
+
public static void loadCQLDataSet(Session session, String dataSetCql) {
CQLDataLoader loader = new CQLDataLoader(session);
loader.load(cqlDataSet(dataSetCql));
@@ -55,6 +62,7 @@ public class CassandraUnitUtils {
public static CassandraCQLUnit cassandraCQLUnit(CQLDataSet dataset) {
return new CassandraCQLUnit(dataset, "/camel-cassandra.yaml", HOST, 9042);
}
+
/**
* Start embedded Cassandra.
*/
@@ -68,6 +76,7 @@ public class CassandraUnitUtils {
public static void cleanEmbeddedCassandra() throws Exception {
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
}
+
public static Cluster cassandraCluster() {
return Cluster.builder()
.addContactPoint(HOST)
http://git-wip-us.apache.org/repos/asf/camel/blob/e0b14cd4/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/ResultSetConversionStrategiesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/ResultSetConversionStrategiesTest.java b/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/ResultSetConversionStrategiesTest.java
index fbb5393..f5887f2 100644
--- a/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/ResultSetConversionStrategiesTest.java
+++ b/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/ResultSetConversionStrategiesTest.java
@@ -1,9 +1,10 @@
-/*
- * Copyright 2014 The Apache Software Foundation.
- *
- * Licensed 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
+/**
+ * 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
*
@@ -13,25 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.component.cassandra;
-import org.apache.camel.component.cassandra.ResultSetConversionStrategy;
-import org.apache.camel.component.cassandra.ResultSetConversionStrategies;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
import java.util.Collections;
import java.util.List;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
import org.junit.Test;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-import static org.junit.matchers.JUnitMatchers.*;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
/**
* Unit test for {@link ResultSetConversionStrategy} implementations
*/
public class ResultSetConversionStrategiesTest {
-
+
public ResultSetConversionStrategiesTest() {
}
@@ -41,22 +43,22 @@ public class ResultSetConversionStrategiesTest {
ResultSet resultSet = mock(ResultSet.class);
List<Row> rows = Collections.nCopies(20, mock(Row.class));
when(resultSet.all()).thenReturn(rows);
-
+
Object body = strategy.getBody(resultSet);
assertTrue(body instanceof List);
- assertSame(rows, body);
+ assertSame(rows, body);
}
-
+
@Test
public void testOne() {
ResultSetConversionStrategy strategy = ResultSetConversionStrategies.fromName("ONE");
ResultSet resultSet = mock(ResultSet.class);
Row row = mock(Row.class);
when(resultSet.one()).thenReturn(row);
-
+
Object body = strategy.getBody(resultSet);
assertTrue(body instanceof Row);
- assertSame(row, body);
+ assertSame(row, body);
}
@Test
@@ -65,9 +67,9 @@ public class ResultSetConversionStrategiesTest {
ResultSet resultSet = mock(ResultSet.class);
List<Row> rows = Collections.nCopies(20, mock(Row.class));
when(resultSet.iterator()).thenReturn(rows.iterator());
-
+
Object body = strategy.getBody(resultSet);
assertTrue(body instanceof List);
- assertEquals(10, ((List) body).size());
+ assertEquals(10, ((List) body).size());
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/e0b14cd4/components/camel-cassandraql/src/test/java/org/apache/camel/processor/aggregate/cassandra/CassandraAggregationRepositoryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cassandraql/src/test/java/org/apache/camel/processor/aggregate/cassandra/CassandraAggregationRepositoryTest.java b/components/camel-cassandraql/src/test/java/org/apache/camel/processor/aggregate/cassandra/CassandraAggregationRepositoryTest.java
index 9f906b6..1011212 100644
--- a/components/camel-cassandraql/src/test/java/org/apache/camel/processor/aggregate/cassandra/CassandraAggregationRepositoryTest.java
+++ b/components/camel-cassandraql/src/test/java/org/apache/camel/processor/aggregate/cassandra/CassandraAggregationRepositoryTest.java
@@ -1,9 +1,10 @@
-/*
- * Copyright 2014 The Apache Software Foundation.
- *
- * Licensed 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
+/**
+ * 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
*
@@ -13,11 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.processor.aggregate.cassandra;
-import org.apache.camel.processor.aggregate.cassandra.CassandraAggregationRepository;
-import org.apache.camel.processor.aggregate.cassandra.NamedCassandraAggregationRepository;
+import java.util.Set;
+
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import org.apache.camel.CamelContext;
@@ -28,88 +28,102 @@ import org.apache.camel.impl.DefaultExchange;
import org.cassandraunit.CassandraCQLUnit;
import org.junit.After;
import org.junit.AfterClass;
-import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
-import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
/**
* Unite test for {@link CassandraAggregationRepository}
*/
public class CassandraAggregationRepositoryTest {
+ @Rule
+ public CassandraCQLUnit cassandraRule = CassandraUnitUtils.cassandraCQLUnit("AggregationDataSet.cql");
+
private Cluster cluster;
private Session session;
private CassandraAggregationRepository aggregationRepository;
private CamelContext camelContext;
- @Rule
- public CassandraCQLUnit cassandraRule = CassandraUnitUtils.cassandraCQLUnit("AggregationDataSet.cql");
-
+
@BeforeClass
public static void setUpClass() throws Exception {
CassandraUnitUtils.startEmbeddedCassandra();
}
+
@Before
public void setUp() throws Exception {
- camelContext =new DefaultCamelContext();
+ camelContext = new DefaultCamelContext();
cluster = CassandraUnitUtils.cassandraCluster();
session = cluster.connect(CassandraUnitUtils.KEYSPACE);
aggregationRepository = new NamedCassandraAggregationRepository(session, "ID");
aggregationRepository.start();
}
+
@After
public void tearDown() throws Exception {
aggregationRepository.stop();
session.close();
cluster.close();
}
+
@AfterClass
public static void tearDownClass() throws Exception {
CassandraUnitUtils.cleanEmbeddedCassandra();
}
+
private boolean exists(String key) {
return session.execute(
"select KEY from CAMEL_AGGREGATION where NAME=? and KEY=?", "ID", key)
- .one()!=null;
+ .one() != null;
}
+
@Test
public void testAdd() {
// Given
- String key="Add";
+ String key = "Add";
assertFalse(exists(key));
Exchange exchange = new DefaultExchange(camelContext);
// When
aggregationRepository.add(camelContext, key, exchange);
// Then
- assertTrue(exists(key));
+ assertTrue(exists(key));
}
+
@Test
- public void testGet_Exists() {
+ public void testGetExists() {
// Given
- String key="Get_Exists";
+ String key = "Get_Exists";
Exchange exchange = new DefaultExchange(camelContext);
aggregationRepository.add(camelContext, key, exchange);
assertTrue(exists(key));
// When
- Exchange exchange2=aggregationRepository.get(camelContext, key);
+ Exchange exchange2 = aggregationRepository.get(camelContext, key);
// Then
assertNotNull(exchange2);
- assertEquals(exchange.getExchangeId(), exchange2.getExchangeId());
+ assertEquals(exchange.getExchangeId(), exchange2.getExchangeId());
}
+
@Test
- public void testGet_NotExists() {
+ public void testGetNotExists() {
// Given
- String key="Get_NotExists";
+ String key = "Get_NotExists";
assertFalse(exists(key));
// When
- Exchange exchange2=aggregationRepository.get(camelContext, key);
+ Exchange exchange2 = aggregationRepository.get(camelContext, key);
// Then
assertNull(exchange2);
}
+
@Test
- public void testRemove_Exists() {
+ public void testRemoveExists() {
// Given
- String key="Remove_Exists";
+ String key = "Remove_Exists";
Exchange exchange = new DefaultExchange(camelContext);
aggregationRepository.add(camelContext, key, exchange);
assertTrue(exists(key));
@@ -118,10 +132,11 @@ public class CassandraAggregationRepositoryTest {
// Then
assertFalse(exists(key));
}
+
@Test
- public void testRemove_NotExists() {
+ public void testRemoveNotExists() {
// Given
- String key="Remove_NotExists";
+ String key = "RemoveNotExists";
Exchange exchange = new DefaultExchange(camelContext);
assertFalse(exists(key));
// When
@@ -129,28 +144,30 @@ public class CassandraAggregationRepositoryTest {
// Then
assertFalse(exists(key));
}
+
@Test
public void testGetKeys() {
// Given
- String[] keys={"GetKeys1", "GetKeys2"};
- for(String key: keys) {
+ String[] keys = {"GetKeys1", "GetKeys2"};
+ for (String key : keys) {
Exchange exchange = new DefaultExchange(camelContext);
aggregationRepository.add(camelContext, key, exchange);
}
// When
- Set<String> keySet=aggregationRepository.getKeys();
+ Set<String> keySet = aggregationRepository.getKeys();
// Then
- for(String key: keys) {
+ for (String key : keys) {
assertTrue(keySet.contains(key));
}
}
+
@Test
- public void testConfirm_Exist() {
+ public void testConfirmExist() {
// Given
- for(int i=1;i<4;i++) {
- String key="Confirm_"+i;
+ for (int i = 1; i < 4; i++) {
+ String key = "Confirm_" + i;
Exchange exchange = new DefaultExchange(camelContext);
- exchange.setExchangeId("Exchange_"+i);
+ exchange.setExchangeId("Exchange_" + i);
aggregationRepository.add(camelContext, key, exchange);
assertTrue(exists(key));
}
@@ -161,21 +178,22 @@ public class CassandraAggregationRepositoryTest {
assertFalse(exists("Confirm_2"));
assertTrue(exists("Confirm_3"));
}
+
@Test
- public void testConfirm_NotExist() {
+ public void testConfirmNotExist() {
// Given
- for(int i=1;i<4;i++) {
- String key="Confirm_"+i;
+ for (int i = 1; i < 4; i++) {
+ String key = "Confirm_" + i;
Exchange exchange = new DefaultExchange(camelContext);
- exchange.setExchangeId("Exchange_"+i);
+ exchange.setExchangeId("Exchange_" + i);
aggregationRepository.add(camelContext, key, exchange);
assertTrue(exists(key));
}
// When
aggregationRepository.confirm(camelContext, "Exchange_5");
// Then
- for(int i=1;i<4;i++) {
- assertTrue(exists("Confirm_"+i));
+ for (int i = 1; i < 4; i++) {
+ assertTrue(exists("Confirm_" + i));
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/e0b14cd4/components/camel-cassandraql/src/test/java/org/apache/camel/processor/aggregate/cassandra/CassandraAggregationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cassandraql/src/test/java/org/apache/camel/processor/aggregate/cassandra/CassandraAggregationTest.java b/components/camel-cassandraql/src/test/java/org/apache/camel/processor/aggregate/cassandra/CassandraAggregationTest.java
index 381c53e..0302663 100644
--- a/components/camel-cassandraql/src/test/java/org/apache/camel/processor/aggregate/cassandra/CassandraAggregationTest.java
+++ b/components/camel-cassandraql/src/test/java/org/apache/camel/processor/aggregate/cassandra/CassandraAggregationTest.java
@@ -1,9 +1,10 @@
-/*
- * Copyright 2014 The Apache Software Foundation.
- *
- * Licensed 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
+/**
+ * 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
*
@@ -13,35 +14,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.processor.aggregate.cassandra;
-import org.apache.camel.processor.aggregate.cassandra.CassandraAggregationRepository;
-import org.apache.camel.processor.aggregate.cassandra.NamedCassandraAggregationRepository;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
-import java.lang.reflect.Method;
import org.apache.camel.Exchange;
-import org.apache.camel.component.cassandra.CassandraUnitUtils;
-import org.junit.Test;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.cassandra.CassandraUnitUtils;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.processor.aggregate.AggregationStrategy;
import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.camel.utils.cassandra.CassandraUtils;
-import org.cassandraunit.CassandraCQLUnit;
+import org.junit.Test;
+
/**
* Unite test for {@link CassandraAggregationRepository}
*/
public class CassandraAggregationTest extends CamelTestSupport {
private Cluster cluster;
private CassandraAggregationRepository aggregationRepository;
-
+
@Override
protected void doPreSetup() throws Exception {
CassandraUnitUtils.startEmbeddedCassandra();
- cluster = CassandraUnitUtils.cassandraCluster();
- Session rootSession=cluster.connect();
+ cluster = CassandraUnitUtils.cassandraCluster();
+ Session rootSession = cluster.connect();
CassandraUnitUtils.loadCQLDataSet(rootSession, "AggregationDataSet.cql");
rootSession.close();
aggregationRepository = new NamedCassandraAggregationRepository(cluster, CassandraUnitUtils.KEYSPACE, "ID");
@@ -70,27 +66,29 @@ public class CassandraAggregationTest extends CamelTestSupport {
}
String oldBody = oldExchange.getIn().getBody(String.class);
String newBody = newExchange.getIn().getBody(String.class);
- oldExchange.getIn().setBody(oldBody+","+newBody);
+ oldExchange.getIn().setBody(oldBody + "," + newBody);
return oldExchange;
}
};
from("direct:input")
.aggregate(header("aggregationId"), aggregationStrategy)
- .completionSize(3).completionTimeout(3000L)
- .aggregationRepository(aggregationRepository)
+ .completionSize(3).completionTimeout(3000L)
+ .aggregationRepository(aggregationRepository)
.to("mock:output");
}
};
}
+
private void send(String aggregationId, String body) {
super.template.sendBodyAndHeader("direct:input", body, "aggregationId", aggregationId);
}
+
@Test
public void testAggregationRoute() throws Exception {
// Given
MockEndpoint mockOutput = getMockEndpoint("mock:output");
mockOutput.expectedMessageCount(2);
- mockOutput.expectedBodiesReceivedInAnyOrder("A,C,E","B,D");
+ mockOutput.expectedBodiesReceivedInAnyOrder("A,C,E", "B,D");
// When
send("1", "A");
send("2", "B");
@@ -99,6 +97,6 @@ public class CassandraAggregationTest extends CamelTestSupport {
send("1", "E");
// Then
mockOutput.assertIsSatisfied(4000L);
-
+
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/e0b14cd4/components/camel-cassandraql/src/test/java/org/apache/camel/processor/idempotent/cassandra/CassandraIdempotentRepositoryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cassandraql/src/test/java/org/apache/camel/processor/idempotent/cassandra/CassandraIdempotentRepositoryTest.java b/components/camel-cassandraql/src/test/java/org/apache/camel/processor/idempotent/cassandra/CassandraIdempotentRepositoryTest.java
index 83c2513..89a73b4 100644
--- a/components/camel-cassandraql/src/test/java/org/apache/camel/processor/idempotent/cassandra/CassandraIdempotentRepositoryTest.java
+++ b/components/camel-cassandraql/src/test/java/org/apache/camel/processor/idempotent/cassandra/CassandraIdempotentRepositoryTest.java
@@ -1,9 +1,10 @@
-/*
- * Copyright 2014 The Apache Software Foundation.
- *
- * Licensed 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
+/**
+ * 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
*
@@ -21,26 +22,30 @@ import org.apache.camel.component.cassandra.CassandraUnitUtils;
import org.cassandraunit.CassandraCQLUnit;
import org.junit.After;
import org.junit.AfterClass;
-import org.junit.Test;
-import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
* Unit test for {@link CassandraIdempotentRepository}
*/
public class CassandraIdempotentRepositoryTest {
+ @Rule
+ public CassandraCQLUnit cassandraRule = CassandraUnitUtils.cassandraCQLUnit("IdempotentDataSet.cql");
+
private Cluster cluster;
private Session session;
private CassandraIdempotentRepository<String> idempotentRepository;
- @Rule
- public CassandraCQLUnit cassandraRule = CassandraUnitUtils.cassandraCQLUnit("IdempotentDataSet.cql");
-
+
@BeforeClass
public static void setUpClass() throws Exception {
CassandraUnitUtils.startEmbeddedCassandra();
}
+
@Before
public void setUp() throws Exception {
cluster = CassandraUnitUtils.cassandraCluster();
@@ -48,82 +53,91 @@ public class CassandraIdempotentRepositoryTest {
idempotentRepository = new NamedCassandraIdempotentRepository<String>(session, "ID");
idempotentRepository.start();
}
+
@After
public void tearDown() throws Exception {
idempotentRepository.stop();
session.close();
cluster.close();
}
+
@AfterClass
public static void tearDownClass() throws Exception {
CassandraUnitUtils.cleanEmbeddedCassandra();
}
+
private boolean exists(String key) {
return session.execute(
- "select KEY from CAMEL_IDEMPOTENT where NAME=? and KEY=?","ID", key)
- .one()!=null;
+ "select KEY from CAMEL_IDEMPOTENT where NAME=? and KEY=?", "ID", key)
+ .one() != null;
}
+
@Test
- public void testAdd_NotExists() {
+ public void testAddNotExists() {
// Given
- String key="Add_NotExists";
+ String key = "Add_NotExists";
assertFalse(exists(key));
// When
- boolean result=idempotentRepository.add(key);
+ boolean result = idempotentRepository.add(key);
// Then
assertTrue(result);
- assertTrue(exists(key));
+ assertTrue(exists(key));
}
+
@Test
- public void testAdd_Exists() {
+ public void testAddExists() {
// Given
- String key="Add_Exists";
+ String key = "Add_Exists";
assertTrue(exists(key));
// When
- boolean result=idempotentRepository.add(key);
+ boolean result = idempotentRepository.add(key);
// Then
assertFalse(result);
- assertTrue(exists(key));
+ assertTrue(exists(key));
}
+
@Test
- public void testContains_NotExists() {
+ public void testContainsNotExists() {
// Given
- String key="Contains_NotExists";
+ String key = "Contains_NotExists";
assertFalse(exists(key));
// When
- boolean result=idempotentRepository.contains(key);
+ boolean result = idempotentRepository.contains(key);
// Then
assertFalse(result);
}
+
@Test
- public void testContains_Exists() {
+ public void testContainsExists() {
// Given
- String key="Contains_Exists";
+ String key = "Contains_Exists";
assertTrue(exists(key));
// When
- boolean result=idempotentRepository.contains(key);
+ boolean result = idempotentRepository.contains(key);
// Then
assertTrue(result);
}
+
@Test
- public void testRemove_NotExists() {
+ public void testRemoveNotExists() {
// Given
- String key="Remove_NotExists";
+ String key = "Remove_NotExists";
assertFalse(exists(key));
// When
- boolean result=idempotentRepository.contains(key);
+ boolean result = idempotentRepository.contains(key);
// Then
// assertFalse(result);
}
+
@Test
- public void testRemove_Exists() {
+ public void testRemoveExists() {
// Given
- String key="Remove_Exists";
+ String key = "Remove_Exists";
assertTrue(exists(key));
// When
- boolean result=idempotentRepository.remove(key);
+ boolean result = idempotentRepository.remove(key);
// Then
assertTrue(result);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/e0b14cd4/components/camel-cassandraql/src/test/java/org/apache/camel/processor/idempotent/cassandra/CassandraIdempotentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cassandraql/src/test/java/org/apache/camel/processor/idempotent/cassandra/CassandraIdempotentTest.java b/components/camel-cassandraql/src/test/java/org/apache/camel/processor/idempotent/cassandra/CassandraIdempotentTest.java
index 7ac6386..1380bf9 100644
--- a/components/camel-cassandraql/src/test/java/org/apache/camel/processor/idempotent/cassandra/CassandraIdempotentTest.java
+++ b/components/camel-cassandraql/src/test/java/org/apache/camel/processor/idempotent/cassandra/CassandraIdempotentTest.java
@@ -1,9 +1,10 @@
-/*
- * Copyright 2014 The Apache Software Foundation.
- *
- * Licensed 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
+/**
+ * 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
*
@@ -13,28 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.processor.idempotent.cassandra;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
-import org.apache.camel.component.cassandra.CassandraUnitUtils;
-import org.junit.Test;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.cassandra.CassandraUnitUtils;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
/**
* Unite test for {@link CassandraIdempotentRepository}
*/
public class CassandraIdempotentTest extends CamelTestSupport {
private Cluster cluster;
private CassandraIdempotentRepository idempotentRepository;
-
+
@Override
protected void doPreSetup() throws Exception {
CassandraUnitUtils.startEmbeddedCassandra();
- cluster = CassandraUnitUtils.cassandraCluster();
- Session rootSession=cluster.connect();
+ cluster = CassandraUnitUtils.cassandraCluster();
+ Session rootSession = cluster.connect();
CassandraUnitUtils.loadCQLDataSet(rootSession, "IdempotentDataSet.cql");
rootSession.close();
idempotentRepository = new NamedCassandraIdempotentRepository(cluster, CassandraUnitUtils.KEYSPACE, "ID");
@@ -60,15 +61,17 @@ public class CassandraIdempotentTest extends CamelTestSupport {
}
};
}
+
private void send(String idempotentId, String body) {
super.template.sendBodyAndHeader("direct:input", body, "idempotentId", idempotentId);
}
+
@Test
public void testIdempotentRoute() throws Exception {
// Given
MockEndpoint mockOutput = getMockEndpoint("mock:output");
mockOutput.expectedMessageCount(2);
- mockOutput.expectedBodiesReceivedInAnyOrder("A","B");
+ mockOutput.expectedBodiesReceivedInAnyOrder("A", "B");
// When
send("1", "A");
send("2", "B");
@@ -77,6 +80,6 @@ public class CassandraIdempotentTest extends CamelTestSupport {
send("1", "A");
// Then
mockOutput.assertIsSatisfied();
-
+
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/e0b14cd4/components/camel-cassandraql/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-cassandraql/src/test/resources/log4j.properties b/components/camel-cassandraql/src/test/resources/log4j.properties
index 3476f4b..792dd13 100644
--- a/components/camel-cassandraql/src/test/resources/log4j.properties
+++ b/components/camel-cassandraql/src/test/resources/log4j.properties
@@ -1,17 +1,39 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
#
-# The logging properties used
+# The logging properties used during tests
#
-log4j.rootLogger=INFO, out
+log4j.rootLogger=INFO, file
-# uncomment the following line to turn on Camel debugging
+# uncomment this to turn on debug of camel
#log4j.logger.org.apache.camel=DEBUG
-log4j.logger.org.apache.camel.processor.idempotent.cassandra=INFO
-log4j.logger.org.apache.camel.processor.aggregate.cassandra=INFO
-log4j.logger.org.apache.cassandra=WARN
-log4j.logger.com.datastax=WARN
+#log4j.logger.org.apache.camel.component.cassandra=TRACE
+#log4j.logger.org.apache.cassandra=DEBUG
+
# CONSOLE appender not used by default
-log4j.appender.out=org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout=org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
-#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/camel-cassandraql-test.log
+log4j.appender.file.append=true