This commit is contained in:
David Webb
2013-11-25 12:29:01 -05:00
3 changed files with 70 additions and 11 deletions

View File

@@ -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` ``.

View File

@@ -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 <T> The concrete unit test class to which this integration test corresponds.
*/
public static abstract class Base<T extends CreateTableTest> 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<BasicTest> {
@Override
public BasicTest unit() {
return new BasicTest();
}
}
public static class CompositePartitionKeyIntegrationTest extends Base<CompositePartitionKeyTest> {
@Override
public CompositePartitionKeyTest unit() {
return new CompositePartitionKeyTest();
}
}
}

View File

@@ -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<CreateTableSpecification, CreateTableCqlGenerator> {
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);
}
}
}