From c3e889312e5deb97594b8486242867eade135810 Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Mon, 25 Nov 2013 09:27:07 -0600 Subject: [PATCH 1/2] updated readme --- readme.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 62cd2f006..e2cc10081 100644 --- a/readme.md +++ b/readme.md @@ -2,9 +2,6 @@ Spring Data Cassandra ===================== This is a Spring Data subproject for Cassandra that uses the binary CQL3 protocol via -the official DataStax 1.0.X Java driver (https://github.com/datastax/java-driver). +the official DataStax 1.x Java driver (https://github.com/datastax/java-driver). Supports native CQL3 queries in Spring Repositories. - -For now, you can get and start a local Cassandra instance via the \*n\*x script `test-support/get-and-start-cassandra`. -It stores the cassandra process id in the file `.cassandra/dist/dsc-cassandra-x.y.z/cassandra.pid`, where `x.y.z` is the latest version of Cassandra. You can use this process id to stop Cassandra via ``kill `cat .cassandra/dist/dsc-cassandra-x.y.z/cassandra.pid` ``. \ No newline at end of file From a4f0acc902bf7e2a59f03773a1acd5758f4240e2 Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Mon, 25 Nov 2013 10:45:17 -0600 Subject: [PATCH 2/2] added another test & streamlined unit+integration testing --- ...eateTableCqlGeneratorIntegrationTests.java | 37 +++++++++++++++++- .../CreateTableCqlGeneratorTests.java | 39 ++++++++++++++++--- 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateTableCqlGeneratorIntegrationTests.java b/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateTableCqlGeneratorIntegrationTests.java index bd9c91b1e..be7b762d9 100644 --- a/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateTableCqlGeneratorIntegrationTests.java +++ b/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateTableCqlGeneratorIntegrationTests.java @@ -4,14 +4,31 @@ import static org.springframework.cassandra.test.integration.core.cql.generator. import org.junit.Test; import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests.BasicTest; +import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests.CompositePartitionKeyTest; +import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests.CreateTableTest; +/** + * Integration tests that reuse unit tests. + * + * @author Matthew T. Adams + */ public class CreateTableCqlGeneratorIntegrationTests { - public static class BasicIntegrationTest extends AbstractEmbeddedCassandraIntegrationTest { - BasicTest unit = new BasicTest(); + /** + * Integration test base class that knows how to do everything except instantiate the concrete unit test type T. + * + * @author Matthew T. Adams + * + * @param The concrete unit test class to which this integration test corresponds. + */ + public static abstract class Base extends AbstractEmbeddedCassandraIntegrationTest { + T unit; + + public abstract T unit(); @Test public void test() { + unit = unit(); unit.prepare(); session.execute(unit.cql); @@ -19,4 +36,20 @@ public class CreateTableCqlGeneratorIntegrationTests { assertTable(unit.specification, keyspace, session); } } + + public static class BasicIntegrationTest extends Base { + + @Override + public BasicTest unit() { + return new BasicTest(); + } + } + + public static class CompositePartitionKeyIntegrationTest extends Base { + + @Override + public CompositePartitionKeyTest unit() { + return new CompositePartitionKeyTest(); + } + } } \ No newline at end of file diff --git a/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateTableCqlGeneratorTests.java b/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateTableCqlGeneratorTests.java index 6005d22f7..7ebd71580 100644 --- a/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateTableCqlGeneratorTests.java +++ b/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateTableCqlGeneratorTests.java @@ -37,10 +37,15 @@ public class CreateTableCqlGeneratorTests { } /** - * Convenient base class that other test classes can use so as not to repeat the generics declarations. + * Convenient base class that other test classes can use so as not to repeat the generics declarations or + * {@link #generator()} method. */ public static abstract class CreateTableTest extends TableOperationCqlGeneratorTest { + + public CreateTableCqlGenerator generator() { + return new CreateTableCqlGenerator(specification); + } } public static class BasicTest extends CreateTableTest { @@ -55,8 +60,30 @@ public class CreateTableCqlGeneratorTests { return createTable().name(name).partitionKeyColumn(partitionKey0, partitionKeyType0).column(column1, columnType1); } - public CreateTableCqlGenerator generator() { - return new CreateTableCqlGenerator(specification); + @Test + public void test() { + prepare(); + + assertPreamble(name, cql); + assertColumns(String.format("%s %s, %s %s", partitionKey0, partitionKeyType0, column1, columnType1), cql); + assertPrimaryKey(partitionKey0, cql); + } + } + + public static class CompositePartitionKeyTest extends CreateTableTest { + + public String name = "composite_partition_key_table"; + public DataType partKeyType0 = DataType.text(); + public String partKey0 = "partKey0"; + public DataType partKeyType1 = DataType.text(); + public String partKey1 = "partKey1"; + public String column0 = "column0"; + public DataType columnType0 = DataType.text(); + + @Override + public CreateTableSpecification specification() { + return createTable().name(name).partitionKeyColumn(partKey0, partKeyType0) + .partitionKeyColumn(partKey1, partKeyType1).column(column0, columnType0); } @Test @@ -64,8 +91,10 @@ public class CreateTableCqlGeneratorTests { prepare(); assertPreamble(name, cql); - assertColumns(partitionKey0 + " " + partitionKeyType0 + ", " + column1 + " " + columnType1, cql); - assertPrimaryKey(partitionKey0, cql); + assertColumns( + String.format("%s %s, %s %s, %s %s", partKey0, partKeyType0, partKey1, partKeyType1, column0, columnType0), + cql); + assertPrimaryKey(String.format("(%s, %s)", partKey0, partKey1), cql); } } }