From 548eb299fb5a8445994fb8a747c4793c5c0035af Mon Sep 17 00:00:00 2001 From: john-mcpeek Date: Tue, 24 Dec 2013 00:17:58 -0500 Subject: [PATCH] Added a more complete test. --- .../CqlKeyspaceSpecificationAssertions.java | 136 +++--------------- ...eKeyspaceCqlGeneratorIntegrationTests.java | 2 +- 2 files changed, 17 insertions(+), 121 deletions(-) diff --git a/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlKeyspaceSpecificationAssertions.java b/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlKeyspaceSpecificationAssertions.java index 681226008..0831c4e37 100644 --- a/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlKeyspaceSpecificationAssertions.java +++ b/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlKeyspaceSpecificationAssertions.java @@ -15,8 +15,11 @@ */ package org.springframework.cassandra.test.integration.core.cql.generator; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; +import java.util.Map; + +import org.springframework.cassandra.core.keyspace.Option; import org.springframework.cassandra.core.keyspace.KeyspaceDescriptor; import com.datastax.driver.core.KeyspaceMetadata; @@ -26,128 +29,21 @@ public class CqlKeyspaceSpecificationAssertions { public static double DELTA = 1e-6; // delta for comparisons of doubles + @SuppressWarnings( "unchecked" ) public static void assertKeyspace(KeyspaceDescriptor expected, String keyspace, Session session) { KeyspaceMetadata kmd = session.getCluster().getMetadata().getKeyspace(keyspace.toLowerCase()); - String cql = kmd.asCQLQuery(); - System.out.println( "%%% " + cql ); assertEquals( expected.getName(), kmd.getName() ); -// assertEquals(expected.getName().toLowerCase(), tmd.getName().toLowerCase()); -// assertPartitionKeyColumns(expected, tmd); -// assertPrimaryKeyColumns(expected, tmd); -// assertColumns(expected.getColumns(), tmd.getColumns()); -// assertOptions(expected.getOptions(), tmd.getOptions()); - } + + Map options = kmd.getReplication(); + Map expectedOptions = expected.getOptions(); + Map replicationMap = (Map) expectedOptions.get( "replication" ); + assertEquals(replicationMap.size(), options.size()); -// public static void assertPartitionKeyColumns(TableDescriptor expected, TableMetadata actual) { -// assertColumns(expected.getPartitionKeyColumns(), actual.getPartitionKey()); -// } -// -// public static void assertPrimaryKeyColumns(TableDescriptor expected, TableMetadata actual) { -// assertColumns(expected.getPrimaryKeyColumns(), actual.getPrimaryKey()); -// } -// -// public static void assertOptions(Map expected, Options actual) { -// -// for (String key : expected.keySet()) { -// -// Object value = expected.get(key); -// TableOption tableOption = getTableOptionFor(key); -// -// if (tableOption == null && key.equalsIgnoreCase(TableOption.COMPACT_STORAGE.getName())) { -// // TODO: figure out how to tell if COMPACT STORAGE was used -// continue; -// } -// -// assertOption(tableOption, key, value, getOptionFor(tableOption, tableOption.getType(), actual)); -// } -// } -// -// @SuppressWarnings({ "unchecked", "incomplete-switch" }) -// public static void assertOption(TableOption tableOption, String key, Object expected, Object actual) { -// -// if (tableOption == null) { // then this is a string-only or unknown value -// key.equalsIgnoreCase(actual.toString()); // TODO: determine if this is the right test -// } -// -// switch (tableOption) { -// -// case BLOOM_FILTER_FP_CHANCE: -// case READ_REPAIR_CHANCE: -// case DCLOCAL_READ_REPAIR_CHANCE: -// assertEquals((Double) expected, (Double) actual, DELTA); -// return; -// -// case CACHING: -// assertEquals(CachingOption.valueOf((String) expected).getValue(), actual); -// return; -// -// case COMPACTION: -// assertCompaction((Map) expected, (Map) actual); -// return; -// -// case COMPRESSION: -// assertCompression((Map) expected, (Map) actual); -// return; -// } -// -// assertEquals(expected, actual); -// } -// -// public static void assertCompaction(Map expected, Map actual) { -// // TODO -// } -// -// public static void assertCompression(Map expected, Map actual) { -// // TODO -// } -// -// public static TableOption getTableOptionFor(String key) { -// try { -// return TableOption.valueOf(key); -// } catch (IllegalArgumentException x) { -// return null; -// } -// } -// -// @SuppressWarnings("unchecked") -// public static T getOptionFor(TableOption option, Class type, Options options) { -// switch (option) { -// case BLOOM_FILTER_FP_CHANCE: -// return (T) (Double) options.getBloomFilterFalsePositiveChance(); -// case CACHING: -// return (T) options.getCaching(); -// case COMMENT: -// return (T) options.getComment(); -// case COMPACTION: -// return (T) options.getCompaction(); -// case COMPACT_STORAGE: -// throw new Error(); // TODO: figure out -// case COMPRESSION: -// return (T) options.getCompression(); -// case DCLOCAL_READ_REPAIR_CHANCE: -// return (T) (Double) options.getReadRepairChance(); -// case GC_GRACE_SECONDS: -// return (T) new Long(options.getGcGraceInSeconds()); -// case READ_REPAIR_CHANCE: -// return (T) (Double) options.getReadRepairChance(); -// case REPLICATE_ON_WRITE: -// return (T) (Boolean) options.getReplicateOnWrite(); -// } -// return null; -// } -// -// public static void assertColumns(List expected, List actual) { -// for (int i = 0; i < expected.size(); i++) { -// ColumnSpecification expectedColumn = expected.get(i); -// ColumnMetadata actualColumn = actual.get(i); -// -// assertColumn(expectedColumn, actualColumn); -// } -// } -// -// public static void assertColumn(ColumnSpecification expected, ColumnMetadata actual) { -// assertEquals(expected.getName().toLowerCase(), actual.getName().toLowerCase()); -// assertEquals(expected.getType(), actual.getType()); -// } + for ( Map.Entry optionEntry : replicationMap.entrySet()) { + String optionValue = options.get(optionEntry.getKey().getName()); + String repMapValue = "" + optionEntry.getValue(); + assertTrue(optionValue.endsWith(repMapValue)); + } + } } \ No newline at end of file diff --git a/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateKeyspaceCqlGeneratorIntegrationTests.java b/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateKeyspaceCqlGeneratorIntegrationTests.java index dcf9e8902..0217ed0b6 100644 --- a/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateKeyspaceCqlGeneratorIntegrationTests.java +++ b/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateKeyspaceCqlGeneratorIntegrationTests.java @@ -4,8 +4,8 @@ import static org.springframework.cassandra.test.integration.core.cql.generator. import org.junit.Test; import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest; -import org.springframework.cassandra.test.unit.core.cql.generator.CreateKeyspaceCqlGeneratorTests.CreateKeyspaceTest; import org.springframework.cassandra.test.unit.core.cql.generator.CreateKeyspaceCqlGeneratorTests.BasicTest; +import org.springframework.cassandra.test.unit.core.cql.generator.CreateKeyspaceCqlGeneratorTests.CreateKeyspaceTest; /** * Integration tests that reuse unit tests.