Added Keyspace tests.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package org.springframework.cassandra.test.unit.core.cql.generator;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.core.cql.generator.CreateKeyspaceCqlGenerator;
|
||||
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.DefaultOption;
|
||||
import org.springframework.cassandra.core.keyspace.KeyspaceOption;
|
||||
import org.springframework.cassandra.core.keyspace.Option;
|
||||
|
||||
public class CreateKeyspaceCqlGeneratorTests {
|
||||
|
||||
/**
|
||||
* Asserts that the preamble is first & correctly formatted in the given CQL string.
|
||||
*/
|
||||
public static void assertPreamble(String keyspaceName, String cql) {
|
||||
System.out.println( "'" + cql + "'" );
|
||||
assertTrue(cql.startsWith("CREATE KEYSPACE " + keyspaceName + " "));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 CreateKeyspaceTest extends
|
||||
KeyspaceOperationCqlGeneratorTest<CreateKeyspaceSpecification, CreateKeyspaceCqlGenerator> {
|
||||
|
||||
public CreateKeyspaceCqlGenerator generator() {
|
||||
return new CreateKeyspaceCqlGenerator(specification);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BasicTest extends CreateKeyspaceTest {
|
||||
|
||||
public String name = "mytable";
|
||||
public Boolean durableWrites = true;
|
||||
|
||||
public Map<Option, Object> replicationMap = new HashMap<Option, Object>();
|
||||
|
||||
@Override
|
||||
public CreateKeyspaceSpecification specification() {
|
||||
replicationMap.put( new DefaultOption( "class", String.class, false, false, true ), "SimpleStrategy" );
|
||||
replicationMap.put( new DefaultOption( "replication_factor", Long.class, false, false, true ), 1 );
|
||||
replicationMap.put( new DefaultOption( "dc1", Long.class, false, false, true ), 2 );
|
||||
replicationMap.put( new DefaultOption( "dc2", Long.class, false, false, true ), 3 );
|
||||
|
||||
return (CreateKeyspaceSpecification) CreateKeyspaceSpecification.createKeyspace()
|
||||
.name( name )
|
||||
.with( KeyspaceOption.REPLICATION, replicationMap )
|
||||
.with( KeyspaceOption.DURABLE_WRITES, durableWrites );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
prepare();
|
||||
|
||||
assertPreamble(name, cql);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.springframework.cassandra.test.unit.core.cql.generator;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.core.cql.generator.KeyspaceNameCqlGenerator;
|
||||
import org.springframework.cassandra.core.cql.generator.TableNameCqlGenerator;
|
||||
import org.springframework.cassandra.core.keyspace.KeyspaceNameSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.TableNameSpecification;
|
||||
|
||||
/**
|
||||
* Useful test class that specifies just about as much as you can for a CQL generation test. Intended to be extended by
|
||||
* classes that contain methods annotated with {@link Test}. Everything is public because this is a test class with no
|
||||
* need for encapsulation, and it makes for easier reuse in other tests like integration tests (hint hint).
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*
|
||||
* @param <S> The type of the {@link TableNameSpecification}
|
||||
* @param <G> The type of the {@link TableNameCqlGenerator}
|
||||
*/
|
||||
public abstract class KeyspaceOperationCqlGeneratorTest<S extends KeyspaceNameSpecification<?>, G extends KeyspaceNameCqlGenerator<?>> {
|
||||
|
||||
public abstract S specification();
|
||||
|
||||
public abstract G generator();
|
||||
|
||||
public String tableName;
|
||||
public S specification;
|
||||
public G generator;
|
||||
public String cql;
|
||||
|
||||
public void prepare() {
|
||||
this.specification = specification();
|
||||
this.generator = generator();
|
||||
this.cql = generateCql();
|
||||
}
|
||||
|
||||
public String generateCql() {
|
||||
return generator.toCql();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user