DATACASS-59: Completed unit and integration tests for CREATE TABLE using
all available options.
This commit is contained in:
@@ -23,6 +23,7 @@ public class CqlStringUtils {
|
||||
protected static final String DOUBLE_SINGLE_QUOTE = "\'\'";
|
||||
protected static final String DOUBLE_QUOTE = "\"";
|
||||
protected static final String DOUBLE_DOUBLE_QUOTE = "\"\"";
|
||||
protected static final String EMPTY_STRING = "";
|
||||
|
||||
public static StringBuilder noNull(StringBuilder sb) {
|
||||
return sb == null ? new StringBuilder() : sb;
|
||||
@@ -129,4 +130,11 @@ public class CqlStringUtils {
|
||||
return thing == null ? (String) null : new StringBuilder().append(DOUBLE_QUOTE).append(thing).append(DOUBLE_QUOTE)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed single quotes from quoted String option values
|
||||
*/
|
||||
public static String removeSingleQuotes(Object thing) {
|
||||
return thing == null ? (String) null : ((String) thing).replaceAll(SINGLE_QUOTE, EMPTY_STRING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cassandra.core.cql.CqlStringUtils;
|
||||
import org.springframework.cassandra.core.keyspace.ColumnSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.TableDescriptor;
|
||||
import org.springframework.cassandra.core.keyspace.TableOption;
|
||||
import org.springframework.cassandra.core.keyspace.TableOption.CachingOption;
|
||||
|
||||
import com.datastax.driver.core.ColumnMetadata;
|
||||
import com.datastax.driver.core.Session;
|
||||
@@ -91,7 +91,7 @@ public class CqlTableSpecificationAssertions {
|
||||
return;
|
||||
|
||||
case CACHING:
|
||||
assertEquals(CachingOption.valueOf((String) expected).getValue(), actual);
|
||||
assertEquals(((String) expected).toUpperCase(), ((String) actual).toUpperCase());
|
||||
return;
|
||||
|
||||
case COMPACTION:
|
||||
@@ -103,7 +103,10 @@ public class CqlTableSpecificationAssertions {
|
||||
return;
|
||||
}
|
||||
|
||||
assertEquals(expected, actual);
|
||||
log.info(actual.getClass().getName());
|
||||
|
||||
assertEquals(expected,
|
||||
tableOption.quotesValue() && !(actual instanceof CharSequence) ? CqlStringUtils.singleQuote(actual) : actual);
|
||||
}
|
||||
|
||||
public static void assertCompaction(Map<String, Object> expected, Map<String, String> actual) {
|
||||
@@ -128,9 +131,9 @@ public class CqlTableSpecificationAssertions {
|
||||
case BLOOM_FILTER_FP_CHANCE:
|
||||
return (T) (Double) options.getBloomFilterFalsePositiveChance();
|
||||
case CACHING:
|
||||
return (T) options.getCaching();
|
||||
return (T) CqlStringUtils.singleQuote(options.getCaching());
|
||||
case COMMENT:
|
||||
return (T) options.getComment();
|
||||
return (T) CqlStringUtils.singleQuote(options.getComment());
|
||||
case COMPACTION:
|
||||
return (T) options.getCompaction();
|
||||
case COMPACT_STORAGE:
|
||||
@@ -138,7 +141,7 @@ public class CqlTableSpecificationAssertions {
|
||||
case COMPRESSION:
|
||||
return (T) options.getCompression();
|
||||
case DCLOCAL_READ_REPAIR_CHANCE:
|
||||
return (T) (Double) options.getReadRepairChance();
|
||||
return (T) (Double) options.getLocalReadRepairChance();
|
||||
case GC_GRACE_SECONDS:
|
||||
return (T) new Long(options.getGcGraceInSeconds());
|
||||
case READ_REPAIR_CHANCE:
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.springframework.cassandra.test.integration.core.cql.generator;
|
||||
import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.assertTable;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests.BasicTest;
|
||||
@@ -16,6 +18,8 @@ import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCql
|
||||
*/
|
||||
public class CreateTableCqlGeneratorIntegrationTests {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(CreateTableCqlGeneratorIntegrationTests.class);
|
||||
|
||||
/**
|
||||
* Integration test base class that knows how to do everything except instantiate the concrete unit test type T.
|
||||
*
|
||||
@@ -64,9 +68,11 @@ public class CreateTableCqlGeneratorIntegrationTests {
|
||||
|
||||
optionsTest.prepare();
|
||||
|
||||
log.info(optionsTest.cql);
|
||||
|
||||
session.execute(optionsTest.cql);
|
||||
|
||||
// assertTable(optionsTest.specification, keyspace, session);
|
||||
assertTable(optionsTest.specification, keyspace, session);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user