diff --git a/pom.xml b/pom.xml index 3125c1474..772d19143 100644 --- a/pom.xml +++ b/pom.xml @@ -32,9 +32,15 @@ 2.1.9.2 1.0 2.16 - 0.3.1 2.1.11 2.1.7.1 + + embedded + localhost + 19042 + 19160 + 17000 + 17001 @@ -99,12 +105,6 @@ - - com.github.jbellis - jamm - ${jamm.version} - test - @@ -144,27 +144,6 @@ test - - org.cassandraunit - cassandra-unit-spring - ${cassandra-unit.version} - - - cassandra-all - org.apache.cassandra - - - com.datastax.cassandra - cassandra-driver-core - - - slf4j-log4j12 - org.slf4j - - - test - - javax.el el-api @@ -192,14 +171,6 @@ 3.1 test - - - org.hectorclient - hector-core - 1.1-4 - test - - @@ -222,14 +193,6 @@ com.datastax.cassandra cassandra-driver-dse - - com.github.jbellis - jamm - - - org.cassandraunit - cassandra-unit-spring - @@ -247,28 +210,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - reserve-network-port - - reserve-network-port - - process-resources - - - build.cassandra.native_transport_port - build.cassandra.rpc_port - build.cassandra.storage_port - build.cassandra.ssl_storage_port - - - - - org.apache.maven.plugins maven-dependency-plugin @@ -282,9 +223,11 @@ false **/test/unit/**/*.java + **/*UnitTests.java **/test/integration/**/*.java + **/**IntegrationTests.java **/test/performance/**/*.java @@ -298,14 +241,16 @@ ${failsafe.version} 1 - -Xms1g -Xmx1g -Xss256k -javaagent:${com.github.jbellis:jamm:jar} + -Xms1g -Xmx1g -Xss256k true false **/test/integration/**/*.java + **/*IntegrationTests.java **/test/unit/**/*.java + **/*UnitTests.java **/test/performance/**/*.java @@ -356,6 +301,57 @@ + + + embedded-cassandra + + true + + + + embedded + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + reserve-network-port + + reserve-network-port + + generate-test-resources + + + build.cassandra.native_transport_port + build.cassandra.rpc_port + build.cassandra.storage_port + build.cassandra.ssl_storage_port + + + + + + + + + + external-cassandra + + + external + 9042 + 9160 + 7000 + 7001 + + diff --git a/spring-cql/pom.xml b/spring-cql/pom.xml index a50919052..d16ad210d 100644 --- a/spring-cql/pom.xml +++ b/spring-cql/pom.xml @@ -71,10 +71,6 @@ el-api test - - org.cassandraunit - cassandra-unit-spring - org.apache.cassandra cassandra-all @@ -82,8 +78,8 @@ test - slf4j-log4j12 - org.slf4j + ch.qos.logback + logback-core guava diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/config/PoolingOptionsFactoryBeanTest.java b/spring-cql/src/test/java/org/springframework/cassandra/config/PoolingOptionsFactoryBeanUnitTest.java similarity index 88% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/config/PoolingOptionsFactoryBeanTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/config/PoolingOptionsFactoryBeanUnitTest.java index 6216b0eea..57818a123 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/config/PoolingOptionsFactoryBeanTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/config/PoolingOptionsFactoryBeanUnitTest.java @@ -1,31 +1,30 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.config; +package org.springframework.cassandra.config; import org.junit.Assert; import org.junit.Test; -import org.springframework.cassandra.config.PoolingOptionsFactoryBean; /** - * Pooling Options Factory Bean Test. https://jira.spring.io/browse/DATACASS-176 - * + * Unit tests for {@link PoolingOptionsFactoryBean} + * * @author Sumit Kumar * @author David Webb */ -public class PoolingOptionsFactoryBeanTest { +public class PoolingOptionsFactoryBeanUnitTest { private static final int REMOTE_MIN_SIMULTANEOUS_REQUESTS = 111; private static final int REMOTE_MAX_SIMULTANEOUS_REQUESTS = 127; @@ -39,8 +38,9 @@ public class PoolingOptionsFactoryBeanTest { /** * The max values should be set before setting core values. Otherwise the core values will be compared with the * default max values which is 8. Same for other min-max properties pairs. This test checks the same. - * + * * @throws Exception Any unhandled scenarios will result in a test failure. + * @see DATACASS-176 */ @Test public void testAfterPropertiesSet() throws Exception { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/CqlIdentifierTest.java b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/CqlIdentifierUnitTests.java similarity index 85% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/CqlIdentifierTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/cql/CqlIdentifierUnitTests.java index c90d6d47e..0209e72ca 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/CqlIdentifierTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/CqlIdentifierUnitTests.java @@ -1,29 +1,33 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql; +package org.springframework.cassandra.core.cql; import static org.junit.Assert.*; -import static org.springframework.cassandra.core.cql.CqlIdentifier.cqlId; -import static org.springframework.cassandra.core.cql.CqlIdentifier.quotedCqlId; +import static org.springframework.cassandra.core.cql.CqlIdentifier.*; import org.junit.Test; import org.springframework.cassandra.core.ReservedKeyword; -import org.springframework.cassandra.core.cql.CqlIdentifier; -public class CqlIdentifierTest { +/** + * Unit tests for {@link CqlIdentifier}. + * + * @author John McPeek + * @author Matthew T. Adams + */ +public class CqlIdentifierUnitTests { @Test public void testUnquotedIdentifiers() { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/IndexOperationCqlGeneratorTest.java b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractIndexOperationCqlGeneratorTest.java similarity index 79% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/IndexOperationCqlGeneratorTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractIndexOperationCqlGeneratorTest.java index 0eb3692c5..b31499892 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/IndexOperationCqlGeneratorTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractIndexOperationCqlGeneratorTest.java @@ -1,35 +1,34 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql.generator; +package org.springframework.cassandra.core.cql.generator; import org.junit.Test; -import org.springframework.cassandra.core.cql.generator.IndexNameCqlGenerator; import org.springframework.cassandra.core.keyspace.IndexNameSpecification; /** * 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 * @author David Webb * @param The type of the {@link IndexNameSpecification} * @param The type of the {@link IndexNameCqlGenerator} */ -public abstract class IndexOperationCqlGeneratorTest, G extends IndexNameCqlGenerator> { +public abstract class AbstractIndexOperationCqlGeneratorTest, G extends IndexNameCqlGenerator> { public abstract S specification(); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/KeyspaceOperationCqlGeneratorTest.java b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractKeyspaceOperationCqlGeneratorTest.java similarity index 78% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/KeyspaceOperationCqlGeneratorTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractKeyspaceOperationCqlGeneratorTest.java index 895174242..9ed3e84a0 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/KeyspaceOperationCqlGeneratorTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractKeyspaceOperationCqlGeneratorTest.java @@ -1,26 +1,24 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql.generator; +package org.springframework.cassandra.core.cql.generator; import java.util.UUID; import org.apache.commons.lang3.StringUtils; 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.KeyspaceActionSpecification; import org.springframework.cassandra.core.keyspace.TableNameSpecification; @@ -28,12 +26,12 @@ 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 The type of the {@link TableNameSpecification} * @param The type of the {@link TableNameCqlGenerator} */ -public abstract class KeyspaceOperationCqlGeneratorTest, G extends KeyspaceNameCqlGenerator> { +public abstract class AbstractKeyspaceOperationCqlGeneratorTest, G extends KeyspaceNameCqlGenerator> { public abstract S specification(); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/TableOperationCqlGeneratorTest.java b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractTableOperationCqlGeneratorTest.java similarity index 78% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/TableOperationCqlGeneratorTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractTableOperationCqlGeneratorTest.java index bbba8e433..d10b5438e 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/TableOperationCqlGeneratorTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractTableOperationCqlGeneratorTest.java @@ -1,33 +1,32 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql.generator; +package org.springframework.cassandra.core.cql.generator; -import org.springframework.cassandra.core.cql.generator.TableNameCqlGenerator; 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 The type of the {@link TableNameSpecification} * @param The type of the {@link TableNameCqlGenerator} */ -public abstract class TableOperationCqlGeneratorTest, G extends TableNameCqlGenerator> { +public abstract class AbstractTableOperationCqlGeneratorTest, G extends TableNameCqlGenerator> { public abstract S specification(); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterKeyspaceCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AlterKeyspaceCqlGeneratorUnitTests.java similarity index 85% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterKeyspaceCqlGeneratorTests.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AlterKeyspaceCqlGeneratorUnitTests.java index b40aa1d60..4c302d5d3 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterKeyspaceCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AlterKeyspaceCqlGeneratorUnitTests.java @@ -1,34 +1,39 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql.generator; +package org.springframework.cassandra.core.cql.generator; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.HashMap; import java.util.Map; import org.junit.Test; -import org.springframework.cassandra.core.cql.generator.AlterKeyspaceCqlGenerator; import org.springframework.cassandra.core.keyspace.AlterKeyspaceSpecification; import org.springframework.cassandra.core.keyspace.DefaultOption; import org.springframework.cassandra.core.keyspace.KeyspaceOption; import org.springframework.cassandra.core.keyspace.Option; -import org.springframework.cassandra.test.unit.support.Utils; +import org.springframework.cassandra.support.RandomKeySpaceName; -public class AlterKeyspaceCqlGeneratorTests { +/** + * Unit tests for {@link AlterKeyspaceCqlGenerator}. + * + * @author John McPeek + * @author Matthew T. Adams + */ +public class AlterKeyspaceCqlGeneratorUnitTests { /** * Asserts that the preamble is first & correctly formatted in the given CQL string. @@ -53,12 +58,12 @@ public class AlterKeyspaceCqlGeneratorTests { /** * Convenient base class that other test classes can use so as not to repeat the generics declarations. */ - public static abstract class AlterKeyspaceTest extends - KeyspaceOperationCqlGeneratorTest {} + public static abstract class AlterKeyspaceTest + extends AbstractKeyspaceOperationCqlGeneratorTest {} public static class CompleteTest extends AlterKeyspaceTest { - public String name = Utils.randomKeyspaceName(); + public String name = RandomKeySpaceName.create(); public Boolean durableWrites = true; public Map replicationMap = new HashMap(); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterTableCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AlterTableCqlGeneratorUnitTests.java similarity index 90% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterTableCqlGeneratorTests.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AlterTableCqlGeneratorUnitTests.java index 227a30c04..e4be74c06 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterTableCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AlterTableCqlGeneratorUnitTests.java @@ -1,21 +1,21 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql.generator; +package org.springframework.cassandra.core.cql.generator; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.LinkedHashMap; import java.util.Map; @@ -23,7 +23,6 @@ import java.util.Map; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.cassandra.core.cql.generator.AlterTableCqlGenerator; import org.springframework.cassandra.core.keyspace.AlterTableSpecification; import org.springframework.cassandra.core.keyspace.Option; import org.springframework.cassandra.core.keyspace.TableOption; @@ -34,9 +33,15 @@ import org.springframework.cassandra.core.keyspace.TableOption.KeyCachingOption; import com.datastax.driver.core.DataType; -public class AlterTableCqlGeneratorTests { +/** + * Unit tests for {@link AlterTableCqlGenerator}. + * + * @author Matthew T. Adams + * @author David Webb + */ +public class AlterTableCqlGeneratorUnitTests { - private final static Logger log = LoggerFactory.getLogger(AlterTableCqlGeneratorTests.class); + private final static Logger log = LoggerFactory.getLogger(AlterTableCqlGeneratorUnitTests.class); /** * Asserts that the preamble is first & correctly formatted in the given CQL string. @@ -47,7 +52,7 @@ public class AlterTableCqlGeneratorTests { /** * Asserts that the given list of columns definitions are contained in the given CQL string properly. - * + * * @param columnSpec IE, "foo text, bar blob" */ public static void assertColumnChanges(String columnSpec, String cql) { @@ -57,9 +62,8 @@ public class AlterTableCqlGeneratorTests { /** * Convenient base class that other test classes can use so as not to repeat the generics declarations. */ - public static abstract class AlterTableTest extends - TableOperationCqlGeneratorTest { - } + public static abstract class AlterTableTest + extends AbstractTableOperationCqlGeneratorTest {} public static class BasicTest extends AlterTableTest { @@ -94,7 +98,7 @@ public class AlterTableCqlGeneratorTests { /** * Fully test all available create table options - * + * * @author David Webb */ public static class MultipleOptionsTest extends AlterTableTest { @@ -130,9 +134,7 @@ public class AlterTableCqlGeneratorTests { cachingMap.put(CachingOption.KEYS, KeyCachingOption.ALL); cachingMap.put(CachingOption.ROWS_PER_PARTITION, "10"); - return AlterTableSpecification - .alterTable() - .name(name) + return AlterTableSpecification.alterTable().name(name) // .with(TableOption.COMPACT_STORAGE) .with(TableOption.READ_REPAIR_CHANCE, readRepairChance).with(TableOption.COMPACTION, compactionMap) .with(TableOption.COMPRESSION, compressionMap).with(TableOption.BLOOM_FILTER_FP_CHANCE, bloomFilterFpChance) diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateIndexCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateIndexCqlGeneratorUnitTests.java similarity index 76% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateIndexCqlGeneratorTests.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateIndexCqlGeneratorUnitTests.java index ed9e817d8..b513a30b7 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateIndexCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateIndexCqlGeneratorUnitTests.java @@ -1,27 +1,32 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql.generator; +package org.springframework.cassandra.core.cql.generator; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import org.junit.Test; -import org.springframework.cassandra.core.cql.generator.CreateIndexCqlGenerator; import org.springframework.cassandra.core.keyspace.CreateIndexSpecification; -public class CreateIndexCqlGeneratorTests { +/** + * Unit tests for {@link CreateIndexCqlGenerator}. + * + * @author Matthew T. Adams + * @author David Webb + */ +public class CreateIndexCqlGeneratorUnitTests { /** * Asserts that the preamble is first & correctly formatted in the given CQL string. @@ -32,8 +37,8 @@ public class CreateIndexCqlGeneratorTests { /** * Asserts that the given list of columns definitions are contained in the given CQL string properly. - * - * @param columnSpec IE, "(foo)" + * + * @param columnName IE, "(foo)" */ public static void assertColumn(String columnName, String cql) { assertTrue(cql.contains("(" + columnName + ")")); @@ -43,8 +48,8 @@ public class CreateIndexCqlGeneratorTests { * 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 CreateIndexTest extends - IndexOperationCqlGeneratorTest { + public static abstract class CreateIndexTest + extends AbstractIndexOperationCqlGeneratorTest { public CreateIndexCqlGenerator generator() { return new CreateIndexCqlGenerator(specification); @@ -67,7 +72,6 @@ public class CreateIndexCqlGeneratorTests { assertPreamble(name, tableName, cql); assertColumn(column1, cql); - } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateKeyspaceCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateKeyspaceCqlGeneratorUnitTests.java similarity index 84% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateKeyspaceCqlGeneratorTests.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateKeyspaceCqlGeneratorUnitTests.java index 18d3a7964..67545fe77 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateKeyspaceCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateKeyspaceCqlGeneratorUnitTests.java @@ -1,35 +1,40 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql.generator; +package org.springframework.cassandra.core.cql.generator; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.HashMap; import java.util.Map; import org.junit.Test; import org.springframework.cassandra.config.KeyspaceAttributes; -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; -import org.springframework.cassandra.test.unit.support.Utils; +import org.springframework.cassandra.support.RandomKeySpaceName; -public class CreateKeyspaceCqlGeneratorTests { +/** + * Unit tests for {@link CreateKeyspaceCqlGenerator}. + * + * @author John McPeek + * @author Matthew T. Adams + */ +public class CreateKeyspaceCqlGeneratorUnitTests { /** * Asserts that the preamble is first & correctly formatted in the given CQL string. @@ -56,8 +61,8 @@ public class CreateKeyspaceCqlGeneratorTests { * 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 { + public static abstract class CreateKeyspaceTest + extends AbstractKeyspaceOperationCqlGeneratorTest { @Override public CreateKeyspaceCqlGenerator generator() { @@ -67,7 +72,7 @@ public class CreateKeyspaceCqlGeneratorTests { public static class BasicTest extends CreateKeyspaceTest { - public String name = Utils.randomKeyspaceName(); + public String name = RandomKeySpaceName.create(); public Boolean durableWrites = true; public Map replicationMap = KeyspaceAttributes.newSimpleReplication(); @@ -92,7 +97,7 @@ public class CreateKeyspaceCqlGeneratorTests { public static class NoOptionsBasicTest extends CreateKeyspaceTest { - public String name = Utils.randomKeyspaceName(); + public String name = RandomKeySpaceName.create(); public Boolean durableWrites = true; public Map replicationMap = KeyspaceAttributes.newSimpleReplication(); @@ -116,7 +121,7 @@ public class CreateKeyspaceCqlGeneratorTests { public static class NetworkTopologyTest extends CreateKeyspaceTest { - public String name = Utils.randomKeyspaceName(); + public String name = RandomKeySpaceName.create(); public Boolean durableWrites = false; public Map replicationMap = new HashMap(); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateTableCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateTableCqlGeneratorUnitTests.java similarity index 94% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateTableCqlGeneratorTests.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateTableCqlGeneratorUnitTests.java index 64f09b694..bef0347a0 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateTableCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateTableCqlGeneratorUnitTests.java @@ -1,22 +1,22 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql.generator; +package org.springframework.cassandra.core.cql.generator; -import static org.junit.Assert.assertTrue; -import static org.springframework.cassandra.core.cql.CqlIdentifier.cqlId; +import static org.junit.Assert.*; +import static org.springframework.cassandra.core.cql.CqlIdentifier.*; import java.util.ArrayList; import java.util.Arrays; @@ -30,7 +30,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cassandra.core.ReservedKeyword; import org.springframework.cassandra.core.cql.CqlIdentifier; -import org.springframework.cassandra.core.cql.generator.CreateTableCqlGenerator; import org.springframework.cassandra.core.keyspace.CreateTableSpecification; import org.springframework.cassandra.core.keyspace.Option; import org.springframework.cassandra.core.keyspace.TableOption; @@ -41,9 +40,15 @@ import org.springframework.cassandra.core.keyspace.TableOption.KeyCachingOption; import com.datastax.driver.core.DataType; -public class CreateTableCqlGeneratorTests { +/** + * Unit tests for {@link CreateTableCqlGenerator}. + * + * @author Matthew T. Adams + * @author David Webb + */ +public class CreateTableCqlGeneratorUnitTests { - private static final Logger log = LoggerFactory.getLogger(CreateTableCqlGeneratorTests.class); + private static final Logger log = LoggerFactory.getLogger(CreateTableCqlGeneratorUnitTests.class); /** * Asserts that the preamble is first & correctly formatted in the given CQL string. @@ -54,7 +59,7 @@ public class CreateTableCqlGeneratorTests { /** * Asserts that the given primary key definition is contained in the given CQL string properly. - * + * * @param primaryKeyString IE, "foo", "foo, bar, baz", "(foo, bar), baz", etc */ public static void assertPrimaryKey(String primaryKeyString, String cql) { @@ -63,7 +68,7 @@ public class CreateTableCqlGeneratorTests { /** * Asserts that the given list of columns definitions are contained in the given CQL string properly. - * + * * @param columnSpec IE, "foo text, bar blob" */ public static void assertColumns(String columnSpec, String cql) { @@ -103,8 +108,8 @@ public class CreateTableCqlGeneratorTests { * 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 static abstract class CreateTableTest + extends AbstractTableOperationCqlGeneratorTest { @Override public CreateTableCqlGenerator generator() { @@ -166,7 +171,7 @@ public class CreateTableCqlGeneratorTests { /** * Test just the Read Repair Chance - * + * * @author David Webb */ public static class ReadRepairChanceTest extends CreateTableTest { @@ -201,7 +206,7 @@ public class CreateTableCqlGeneratorTests { /** * Fully test all available create table options - * + * * @author David Webb */ public static class MultipleOptionsTest extends CreateTableTest { @@ -272,7 +277,7 @@ public class CreateTableCqlGeneratorTests { public static final List FUNKY_LEGAL_NAMES; static { - List funkies = new ArrayList(Arrays.asList(new String[] { /* TODO */})); + List funkies = new ArrayList(Arrays.asList(new String[] { /* TODO */ })); // TODO: should these work? "a \"\" x", "a\"\"\"\"x", "a b" for (ReservedKeyword funky : ReservedKeyword.values()) { funkies.add(funky.name()); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropIndexCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropIndexCqlGeneratorUnitTests.java similarity index 78% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropIndexCqlGeneratorTests.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropIndexCqlGeneratorUnitTests.java index 363ee4eef..f047ff16d 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropIndexCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropIndexCqlGeneratorUnitTests.java @@ -1,27 +1,32 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql.generator; +package org.springframework.cassandra.core.cql.generator; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import org.junit.Test; -import org.springframework.cassandra.core.cql.generator.DropIndexCqlGenerator; import org.springframework.cassandra.core.keyspace.DropIndexSpecification; -public class DropIndexCqlGeneratorTests { +/** + * Unit tests for {@link DropIndexCqlGenerator}. + * + * @author Matthew T. Adams + * @author David Webb + */ +public class DropIndexCqlGeneratorUnitTests { /** * Asserts that the preamble is first & correctly formatted in the given CQL string. @@ -33,8 +38,8 @@ public class DropIndexCqlGeneratorTests { /** * Convenient base class that other test classes can use so as not to repeat the generics declarations. */ - public static abstract class DropIndexTest extends - IndexOperationCqlGeneratorTest {} + public static abstract class DropIndexTest + extends AbstractIndexOperationCqlGeneratorTest {} public static class BasicTest extends DropIndexTest { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropKeyspaceCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropKeyspaceCqlGeneratorUnitTests.java similarity index 67% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropKeyspaceCqlGeneratorTests.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropKeyspaceCqlGeneratorUnitTests.java index 3875ccb22..dab693a78 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropKeyspaceCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropKeyspaceCqlGeneratorUnitTests.java @@ -1,28 +1,34 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql.generator; +package org.springframework.cassandra.core.cql.generator; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import org.junit.Test; -import org.springframework.cassandra.core.cql.generator.DropKeyspaceCqlGenerator; import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification; -import org.springframework.cassandra.test.unit.support.Utils; +import org.springframework.cassandra.support.RandomKeySpaceName; -public class DropKeyspaceCqlGeneratorTests { +/** + * Unit tests for {@link DropKeyspaceCqlGenerator}. + * + * @author John McPeek + * @author Matthew T. Adams + * @author David Webb + */ +public class DropKeyspaceCqlGeneratorUnitTests { /** * Asserts that the preamble is first & correctly formatted in the given CQL string. @@ -34,13 +40,12 @@ public class DropKeyspaceCqlGeneratorTests { /** * Convenient base class that other test classes can use so as not to repeat the generics declarations. */ - public static abstract class DropTableTest extends - KeyspaceOperationCqlGeneratorTest { - } + public static abstract class DropTableTest + extends AbstractKeyspaceOperationCqlGeneratorTest {} public static class BasicTest extends DropTableTest { - public String name = Utils.randomKeyspaceName(); + public String name = RandomKeySpaceName.create(); @Override public DropKeyspaceSpecification specification() { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropTableCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropTableCqlGeneratorUnitTests.java similarity index 53% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropTableCqlGeneratorTests.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropTableCqlGeneratorUnitTests.java index cb4098954..7a72bede4 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropTableCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropTableCqlGeneratorUnitTests.java @@ -1,27 +1,32 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql.generator; +package org.springframework.cassandra.core.cql.generator; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import org.junit.Test; -import org.springframework.cassandra.core.cql.generator.DropTableCqlGenerator; import org.springframework.cassandra.core.keyspace.DropTableSpecification; -public class DropTableCqlGeneratorTests { +/** + * Unit tests for {@link DropTableCqlGenerator}. + * + * @author Matthew T. Adams + * @author David Webb + */ +public class DropTableCqlGeneratorUnitTests { /** * Asserts that the preamble is first & correctly formatted in the given CQL string. @@ -30,20 +35,11 @@ public class DropTableCqlGeneratorTests { assertTrue(cql.equals("DROP TABLE " + (ifExists ? "IF EXISTS " : "") + tableName + ";")); } - /** - * Asserts that the given list of columns definitions are contained in the given CQL string properly. - * - * @param columnSpec IE, "foo text, bar blob" - */ - public static void assertColumnChanges(String columnSpec, String cql) { - assertTrue(cql.contains("")); - } - /** * Convenient base class that other test classes can use so as not to repeat the generics declarations. */ - public static abstract class DropTableTest extends - TableOperationCqlGeneratorTest {} + public static abstract class DropTableTest + extends AbstractTableOperationCqlGeneratorTest {} public static class BasicTest extends DropTableTest { @@ -64,24 +60,4 @@ public class DropTableCqlGeneratorTests { assertStatement(name, false, cql); } } - - // public static class IfExistsTest extends DropTableTest { - // - // public String name = "mytable"; - // - // public DropTableSpecification specification() { - // return DropTableSpecification.dropTable().ifExists().name(name); - // } - // - // public DropTableCqlGenerator generator() { - // return new DropTableCqlGenerator(specification); - // } - // - // @Test - // public void test() { - // prepare(); - // - // assertStatement(name, true, cql); - // } - // } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/keyspace/OptionTest.java b/spring-cql/src/test/java/org/springframework/cassandra/core/keyspace/OptionUnitTests.java similarity index 87% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/keyspace/OptionTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/core/keyspace/OptionUnitTests.java index 5535f9cf0..2ed24cadd 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/keyspace/OptionTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/keyspace/OptionUnitTests.java @@ -1,31 +1,33 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.keyspace; +package org.springframework.cassandra.core.keyspace; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.lang.annotation.RetentionPolicy; import org.junit.Test; -import org.springframework.cassandra.core.keyspace.DefaultOption; -import org.springframework.cassandra.core.keyspace.Option; -public class OptionTest { +/** + * Unit tests for {@link Option}. + * + * @author Matthew T. Adams + * @author JohnMcPeek + */ +public class OptionUnitTests { @Test(expected = IllegalArgumentException.class) public void testOptionWithNullName() { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/support/CassandraExceptionTranslatorTest.java b/spring-cql/src/test/java/org/springframework/cassandra/support/CassandraExceptionTranslatorTest.java similarity index 89% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/support/CassandraExceptionTranslatorTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/support/CassandraExceptionTranslatorTest.java index 5b1009c0e..b846cb993 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/support/CassandraExceptionTranslatorTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/support/CassandraExceptionTranslatorTest.java @@ -1,26 +1,23 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.support; +package org.springframework.cassandra.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import org.junit.Test; -import org.springframework.cassandra.support.CassandraExceptionTranslator; import org.springframework.cassandra.support.exception.CassandraInvalidConfigurationInQueryException; import org.springframework.cassandra.support.exception.CassandraInvalidQueryException; import org.springframework.cassandra.support.exception.CassandraKeyspaceExistsException; @@ -32,6 +29,11 @@ import com.datastax.driver.core.exceptions.AlreadyExistsException; import com.datastax.driver.core.exceptions.InvalidConfigurationInQueryException; import com.datastax.driver.core.exceptions.InvalidQueryException; +/** + * Unit tests for {@link CassandraExceptionTranslator} + * + * @author Matthew T. Adams + */ public class CassandraExceptionTranslatorTest { CassandraExceptionTranslator tx = new CassandraExceptionTranslator(); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractCqlTemplateIntegrationTest.java b/spring-cql/src/test/java/org/springframework/cassandra/support/RandomKeySpaceName.java similarity index 50% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractCqlTemplateIntegrationTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/support/RandomKeySpaceName.java index 2d9bd4091..382dbae35 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractCqlTemplateIntegrationTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/support/RandomKeySpaceName.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,28 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.integration; +package org.springframework.cassandra.support; -import org.junit.Before; -import org.springframework.cassandra.core.CqlOperations; -import org.springframework.cassandra.core.CqlTemplate; +import java.util.UUID; /** + * Generates a random key space name starting with {@code ks}. + * * @author Matthew T. Adams - * @author Oliver Gierke */ -public class AbstractCqlTemplateIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest { +public class RandomKeySpaceName { - protected CqlOperations t; + private RandomKeySpaceName() { - public AbstractCqlTemplateIntegrationTest() {} - - public AbstractCqlTemplateIntegrationTest(String keyspace) { - super(keyspace); } - - @Before - public void createTemplate() { - this.t = new CqlTemplate(session); + + /** + * Creates a random key space name starting with {@code ks} based on a random {@link UUID}. + * + * @return + */ + public static String create() { + return "ks" + UUID.randomUUID().toString().replace("-", ""); } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/support/TestListener.java b/spring-cql/src/test/java/org/springframework/cassandra/support/TestListener.java new file mode 100644 index 000000000..361c5ffa8 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/support/TestListener.java @@ -0,0 +1,49 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cassandra.support; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * Convenient listener base class that includes a {@link CountDownLatch} in order to test asynchronous behavior. + * + * @author Matthew T. Adams + */ +public class TestListener { + + protected CountDownLatch latch; + + public TestListener() { + this(1); + } + + public TestListener(int latchCount) { + latch = new CountDownLatch(latchCount); + } + + public void await() throws InterruptedException { + latch.await(); + } + + public void await(long ms) throws InterruptedException { + latch.await(ms, TimeUnit.MILLISECONDS); + } + + public void countDown() { + latch.countDown(); + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractEmbeddedCassandraIntegrationTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractEmbeddedCassandraIntegrationTest.java index 0a082bee8..67dda41fd 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractEmbeddedCassandraIntegrationTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractEmbeddedCassandraIntegrationTest.java @@ -1,12 +1,12 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2013-2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,81 +15,77 @@ */ package org.springframework.cassandra.test.integration; -import java.io.IOException; import java.util.UUID; -import org.apache.cassandra.exceptions.ConfigurationException; -import org.apache.thrift.transport.TTransportException; -import org.cassandraunit.utils.EmbeddedCassandraServerHelper; -import org.junit.BeforeClass; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cassandra.test.integration.support.SpringCqlBuildProperties; -import org.springframework.cassandra.test.unit.support.Utils; +import org.junit.ClassRule; +import org.junit.Rule; +import org.springframework.cassandra.core.SessionCallback; +import org.springframework.cassandra.test.integration.support.CqlDataSet; +import org.springframework.dao.DataAccessException; import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Session; /** - * Abstract base integration test class that starts an embedded Cassandra instance. - * + * Abstract base integration test class that starts an embedded Cassandra instance. Test clients can use the + * {@link #cluster} instance to create sessions and get access. Expect the {@link #cluster} instance to be closed once + * the test has been run. + *

+ * This class is intended to be subclassed by integration test classes. + * * @author Matthew T. Adams + * @author Mark Paluch */ -public class AbstractEmbeddedCassandraIntegrationTest { - - public static String uuid() { - return UUID.randomUUID().toString(); - } - - static Logger log = LoggerFactory.getLogger(AbstractEmbeddedCassandraIntegrationTest.class); - - protected static String CASSANDRA_CONFIG = "spring-cassandra.yaml"; - protected static String CASSANDRA_HOST = "localhost"; - - protected static SpringCqlBuildProperties PROPS = new SpringCqlBuildProperties(); - protected static int CASSANDRA_NATIVE_PORT = PROPS.getCassandraPort(); +public abstract class AbstractEmbeddedCassandraIntegrationTest { /** - * The session connected to the system keyspace. + * Initiate a Cassandra environment in test class scope. */ - protected static Session system; + @ClassRule public final static CassandraRule cassandraEnvironment = new CassandraRule("embedded-cassandra.yaml"); + + /** + * Initiate a Cassandra environment in test scope. + */ + @Rule public final CassandraRule cassandraRule = cassandraEnvironment.testInstance() + .before(new SessionCallback() { + @Override + public Object doInSession(Session s) throws DataAccessException { + AbstractEmbeddedCassandraIntegrationTest.this.cluster = s.getCluster(); + return null; + } + }); /** * The {@link Cluster} that's connected to Cassandra. */ - protected static Cluster cluster; + protected Cluster cluster; - public static String randomKeyspaceName() { - return Utils.randomKeyspaceName(); - } - - @BeforeClass - public static void startCassandra() throws TTransportException, IOException, InterruptedException, - ConfigurationException { - - EmbeddedCassandraServerHelper.startEmbeddedCassandra(CASSANDRA_CONFIG); - } - - public static Cluster cluster() { - return Cluster.builder().addContactPoint(CASSANDRA_HOST).withPort(CASSANDRA_NATIVE_PORT).build(); + /** + * Creates a random UUID. + * + * @return + */ + public static String uuid() { + return UUID.randomUUID().toString(); } /** - * Ensures that the cluster is created and that the session {@link #SYSTEM} is connected to it. + * Returns the {@link Cluster}. + * + * @return */ - public static void ensureClusterConnection() { - - // check cluster - if (cluster == null) { - cluster = cluster(); - } - - if (system == null) { - system = cluster.connect(); - } + public Cluster getCluster() { + return cluster; } - public AbstractEmbeddedCassandraIntegrationTest() { - ensureClusterConnection(); + /** + * Executes a CQL script from a classpath resource in given {@code keyspace}. + * + * @param cqlResourceName + * @param keyspace + */ + public void execute(String cqlResourceName, String keyspace) { + cassandraRule.execute(CqlDataSet.fromClassPath(cqlResourceName).executeIn(keyspace)); } + } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractKeyspaceCreatingIntegrationTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractKeyspaceCreatingIntegrationTest.java index e93fd4a44..9579b99df 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractKeyspaceCreatingIntegrationTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractKeyspaceCreatingIntegrationTest.java @@ -1,12 +1,12 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2013-2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,142 +15,96 @@ */ package org.springframework.cassandra.test.integration; -import org.junit.After; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cassandra.core.CqlOperations; -import org.springframework.cassandra.core.CqlTemplate; -import org.springframework.util.StringUtils; +import org.junit.ClassRule; +import org.springframework.cassandra.core.SessionCallback; +import org.springframework.dao.DataAccessException; +import org.springframework.util.Assert; -import com.datastax.driver.core.Host; -import com.datastax.driver.core.KeyspaceMetadata; import com.datastax.driver.core.Session; -import com.datastax.driver.core.Session.State; /** - * Abstract base integration test class that creates a keyspace - * + * Abstract base integration test class that provides a keyspace during the test runtime. + *

+ * Keyspaces are created and removed by this base class. The {@link #getKeyspace() keyspace} and {@link #getSession() + * session} are provided by this class during the test lifecycle (before test/test/after test). The keyspace is retained + * until the whole test class is completed. Any tables created in a test will be visible in subsequent tests of the same + * class. + *

+ * This class is intended to be subclassed by integration test classes. + * * @author Matthew T. Adams * @author David Webb + * @author Mark Paluch */ public abstract class AbstractKeyspaceCreatingIntegrationTest extends AbstractEmbeddedCassandraIntegrationTest { - static Logger log = LoggerFactory.getLogger(AbstractKeyspaceCreatingIntegrationTest.class); + /** + * Class rule to prepare a keyspace to give tests a keyspace context. The keyspace name is random and changes per + * test. + */ + @ClassRule public final static KeyspaceRule keyspaceRule = new KeyspaceRule(cassandraEnvironment); /** * The session that's connected to the keyspace used in the current instance's test. */ - protected static Session session; + protected Session session; /** * The name of the keyspace to use for this test instance. */ - protected String keyspace; + protected final String keyspace; + /** + * Creates a new {@link AbstractKeyspaceCreatingIntegrationTest}. + */ public AbstractKeyspaceCreatingIntegrationTest() { - this(randomKeyspaceName()); + this(keyspaceRule.getKeyspaceName()); } - public AbstractKeyspaceCreatingIntegrationTest(String keyspace) { + private AbstractKeyspaceCreatingIntegrationTest(final String keyspace) { + + Assert.hasText(keyspace, "Keyspace must not be empty"); this.keyspace = keyspace; - ensureKeyspaceAndSession(); - } + this.session = keyspaceRule.getSession(); - /** - * Returns whether we're currently connected to the keyspace. - */ - public static boolean connected() { - return session != null; - } + cassandraRule.before(new SessionCallback() { - /** - * Whether to drop the keyspace that was created after the test has completed. Subclasses should override and return - * true, since this default implementation returns false. - */ - public boolean dropKeyspaceAfterTest() { - return false; - } + @Override + public Object doInSession(Session s) throws DataAccessException { - public void ensureKeyspaceAndSession() { - - // ensure that test keyspace exists - - if (!StringUtils.hasText(keyspace)) { - keyspace = null; - } - - if (keyspace != null) { - // see if we need to create the keyspace - KeyspaceMetadata kmd = cluster.getMetadata().getKeyspace(keyspace); - if (kmd == null) { // then create keyspace - - String cql = "CREATE KEYSPACE " + keyspace - + " WITH durable_writes = false AND replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};"; - log.info("creating keyspace {} via CQL [{}]", keyspace, cql); - - system.execute(cql); + if (!keyspace.equals(s.getLoggedKeyspace())) { + s.execute(String.format("USE %s;", keyspace)); + } + return null; } - } - - // keyspace now exists; ensure the session is using it - if (session == null) { - - log.info("connecting to keyspace {}", keyspace == null ? "system" : keyspace + "..."); - - session = keyspace == null ? cluster.connect() : cluster.connect(keyspace); - - log.info("connected to keyspace {}", keyspace == null ? "system" : keyspace); - - } else { - - debugSession(); - - log.info("session already connected to a keyspace; attempting to change to use {}", keyspace); - - String cql = "USE " + (keyspace == null ? "system" : keyspace) + ";"; - - log.debug(cql); - - getTemplate().execute(cql); - - log.info("now using keyspace " + keyspace); - - } + }); } - protected static CqlOperations getTemplate() { - - return new CqlTemplate(session); + /** + * Returns the {@link Session}. The session is logged into the {@link #getKeyspace()}. + * + * @return + */ + public Session getSession() { + return session; } - protected static void debugSession() { - if (session == null) { - log.warn("Session is null...cannot debug that"); - return; - } - - State state = session.getState(); - - for (Host h : state.getConnectedHosts()) { - - log.debug(String.format("Session Host dc [%s], rack [%s], ver [%s], state [%s]", h.getDatacenter(), h.getRack(), - h.getCassandraVersion(), h.getState())); - } - + /** + * Returns the keyspace name. + * + * @return + */ + public String getKeyspace() { + return keyspace; } - @After - public void after() { - if (dropKeyspaceAfterTest() && keyspace != null) { - - session.execute("USE system"); - - log.info("dropping keyspace {} ...", keyspace); - - system.execute("DROP KEYSPACE " + keyspace); - - log.info("dropped keyspace {}", keyspace); - } + /** + * Drop a Keyspace if it exists. + * + * @param keyspace + */ + public void dropKeyspace(String keyspace) { + session.execute("DROP KEYSPACE IF EXISTS " + keyspace); } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/CassandraRule.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/CassandraRule.java new file mode 100644 index 000000000..dec262852 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/CassandraRule.java @@ -0,0 +1,386 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cassandra.test.integration; + +import static org.springframework.cassandra.test.integration.CassandraRule.InvocationMode.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.rules.ExternalResource; +import org.springframework.cassandra.core.SessionCallback; +import org.springframework.cassandra.test.integration.support.CassandraConnectionProperties; +import org.springframework.cassandra.test.integration.support.CqlDataSet; +import org.springframework.dao.DataAccessException; +import org.springframework.util.Assert; +import org.springframework.util.SocketUtils; + +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Session; + +/** + * Rule to provide a Cassandra context for integration tests. This rule can use/spin up either an embedded Cassandra + * instance or use an external instance. Typical usage: + * + *
+ * {
+ * 	public class MyIntegrationTest {
+ * 		@Rule public CassandraRule rule = new CassandraRule(CONFIG). //
+ * 				before(new ClassPathCQLDataSet("CreateIndexCqlGeneratorIntegrationTests-BasicTest.cql", "keyspace"));
+ * 	}
+ * }
+ * 
+ * + * @author Mark Paluch + */ +public class CassandraRule extends ExternalResource { + + private final CassandraConnectionProperties properties = new CassandraConnectionProperties(); + private final String configurationFileName; + private final long startUpTimeout; + + private List> before = new ArrayList>(); + private Map, InvocationMode> invocationModeMap = new HashMap, InvocationMode>(); + private List> after = new ArrayList>(); + + private Session session; + private Cluster cluster; + private CassandraRule parent; + private Integer cassandraPort; + + /** + * Creates a new {@link CassandraRule} and allows the use of a config file. + * + * @param yamlConfigurationResource name of the configuration resource, must not be {@literal null} and not empty + */ + public CassandraRule(String yamlConfigurationResource) { + this(yamlConfigurationResource, EmbeddedCassandraServerHelper.DEFAULT_STARTUP_TIMEOUT); + } + + /** + * Creates a new {@link CassandraRule}, allows the use of a config file and to provide a startup timeout. + * + * @param yamlConfigurationResource name of the configuration resource, must not be {@literal null} and not empty + * @param startUpTimeout the startup timeout + */ + public CassandraRule(String yamlConfigurationResource, long startUpTimeout) { + + Assert.hasText(yamlConfigurationResource, "Configuration file name must not be empty!"); + + this.configurationFileName = yamlConfigurationResource; + this.startUpTimeout = startUpTimeout; + } + + /** + * Creates a new {@link CassandraRule} using a parent {@link CassandraRule} to preserve cluster/connection facilities. + * + * @param parent the parent instance + */ + private CassandraRule(CassandraRule parent) { + + this.configurationFileName = null; + this.startUpTimeout = -1; + this.parent = parent; + } + + /** + * Add a {@link CqlDataSet} to execute before each test run. + * + * @param cqlDataSet must not be {@literal null} + * @return the rule + */ + public CassandraRule before(CqlDataSet cqlDataSet) { + return before(each(), cqlDataSet); + } + + /** + * Add a {@link CqlDataSet} to execute before the test run. + * + * @param invocationMode must not be {@literal null} + * @param cqlDataSet must not be {@literal null} + * @return the rule + */ + public CassandraRule before(InvocationMode invocationMode, final CqlDataSet cqlDataSet) { + + Assert.notNull(cqlDataSet, "CQLDataSet must not be null"); + + SessionCallback sessionCallback = new SessionCallback() { + @Override + public Void doInSession(Session s) throws DataAccessException { + load(s, cqlDataSet); + return null; + } + }; + + before(invocationMode, sessionCallback); + return this; + } + + /** + * Add a {@link SessionCallback} to execute before each test run. + * + * @param sessionCallback must not be {@literal null} + * @return the rule + */ + public CassandraRule before(final SessionCallback sessionCallback) { + + Assert.notNull(sessionCallback, "SessionCallback must not be null"); + return before(each(), sessionCallback); + } + + /** + * Add a {@link SessionCallback} to execute before the test run. + * + * @param invocationMode must not be {@literal null} + * @param sessionCallback must not be {@literal null} + * @return the rule + */ + @SuppressWarnings("unchecked") + public CassandraRule before(InvocationMode invocationMode, final SessionCallback sessionCallback) { + + Assert.notNull(sessionCallback, "SessionCallback must not be null"); + + before.add((SessionCallback) sessionCallback); + invocationModeMap.put(sessionCallback, invocationMode); + return this; + } + + /** + * Add a {@link CqlDataSet} to execute before the test run. + * + * @param cqlDataSet must not be {@literal null} + * @return the rule + */ + public CassandraRule after(final CqlDataSet cqlDataSet) { + + Assert.notNull(cqlDataSet, "CQLDataSet must not be null"); + + after.add(new SessionCallback() { + @Override + public Void doInSession(Session s) throws DataAccessException { + load(session, cqlDataSet); + return null; + } + }); + + return this; + } + + /** + * Execute a {@link CqlDataSet}. + * + * @param cqlDataSet the CQL data set, must not be {@literal null}. + */ + public void execute(CqlDataSet cqlDataSet) { + + Assert.notNull(cqlDataSet, "CQLDataSet must not be null"); + load(session, cqlDataSet); + } + + /** + * Execute the {@code before} sequence. + * + * @throws Exception + */ + @Override + public void before() throws Exception { + + startCassandraIfNeeded(); + setupConnection(); + executeBeforeHooks(); + } + + /** + * Execute the {@code after} sequence. + */ + @Override + protected void after() { + + super.after(); + executeAfterHooks(); + cleanupConnection(); + } + + /** + * Returns the {@link Cluster}. + * + * @return the Cluster + */ + public Cluster getCluster() { + return cluster; + } + + /** + * Returns the {@link Session}. The session state can be initialized and pointing to a keyspace other than + * {@code system}. + * + * @return the Session + */ + public Session getSession() { + return session; + } + + /** + * Returns the Cassandra port. + * + * @return the Cassandra port + */ + public int getPort() { + + Assert.state(cassandraPort != null, "Cassandra port is not initialized"); + return cassandraPort; + } + + /** + * Creates a {@link CassandraRule} to be used in a own scope. The derived {@link CassandraRule} shares the connection + * of this instance and starts with a fresh before/after configuration. + * + * @return a derived {@link CassandraRule} sharing the connection of this instance + */ + public CassandraRule testInstance() { + return new CassandraRule(this); + } + + private void startCassandraIfNeeded() throws Exception { + + if (parent == null && properties.getCassandraType() == CassandraConnectionProperties.CassandraType.EMBEDDED) { + + /* start an embedded Cassandra instance*/ + if (!System.getProperties().containsKey("com.sun.management.jmxremote.port")) { + System.setProperty("com.sun.management.jmxremote.port", "" + SocketUtils.findAvailableTcpPort(1024)); + } + + if (configurationFileName != null) { + EmbeddedCassandraServerHelper.startEmbeddedCassandra(configurationFileName, startUpTimeout); + } + } + } + + private void executeBeforeHooks() { + + for (SessionCallback sessionCallback : before) { + + InvocationMode invocationMode = invocationModeMap.get(sessionCallback); + if (invocationMode == never()) { + continue; + } + + if (invocationMode == firstTest()) { + invocationModeMap.put(sessionCallback, never()); + } + + sessionCallback.doInSession(session); + } + } + + private void executeAfterHooks() { + + for (SessionCallback sessionCallback : after) { + sessionCallback.doInSession(session); + } + } + + private void setupConnection() { + + if (parent == null) { + String hostIp; + int port; + + if (properties.getCassandraType() == CassandraConnectionProperties.CassandraType.EMBEDDED) { + hostIp = EmbeddedCassandraServerHelper.getHost(); + port = EmbeddedCassandraServerHelper.getNativeTransportPort(); + } else { + hostIp = properties.getCassandraHost(); + port = properties.getCassandraPort(); + } + cassandraPort = port; + cluster = new Cluster.Builder().addContactPoints(hostIp).withPort(port).build(); + } else { + cluster = parent.cluster; + cassandraPort = parent.cassandraPort; + } + + session = cluster.connect(); + } + + private void cleanupConnection() { + + if (parent == null) { + session.close(); + cluster.closeAsync(); + cluster = null; + } else { + session.closeAsync(); + } + + session = null; + } + + private void load(Session session, final CqlDataSet cqlDataSet) { + + if (cqlDataSet.getKeyspaceName() != null && !cqlDataSet.getKeyspaceName().equals(session.getLoggedKeyspace())) { + session.execute(String.format("USE %s;", cqlDataSet.getKeyspaceName())); + } + + for (String statement : cqlDataSet.getCqlStatements()) { + session.execute(statement); + } + } + + /** + * Invocation mode for before calls. + */ + public static class InvocationMode { + + private final static InvocationMode once = new InvocationMode(); + private final static InvocationMode each = new InvocationMode(); + private final static InvocationMode never = new InvocationMode(); + + /** + * Invocation mode to invoke an action once at before the first test. + * + * @return the {@code on first test} invocation mode + */ + public static InvocationMode firstTest() { + return once; + } + + /** + * Invocation mode to invoke an action on each run. + * + * @return the {@code on each test} invocation mode + */ + public static InvocationMode each() { + return each; + } + + /** + * Invocation mode to never invoke an action. + * + * @return the {@code never} invocation mode + */ + static InvocationMode never() { + return never; + } + + private InvocationMode() { + + } + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/EmbeddedCassandraServerHelper.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/EmbeddedCassandraServerHelper.java new file mode 100644 index 000000000..6faebe819 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/EmbeddedCassandraServerHelper.java @@ -0,0 +1,258 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cassandra.test.integration; + +import static java.util.concurrent.TimeUnit.*; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.db.commitlog.CommitLog; +import org.apache.cassandra.io.util.FileUtils; +import org.apache.cassandra.service.CassandraDaemon; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.FileCopyUtils; + +/** + * Imported Embedded Cassandra server startup helper. + * + * @author Mark Paluch + */ +class EmbeddedCassandraServerHelper { + + private static Logger log = LoggerFactory.getLogger(EmbeddedCassandraServerHelper.class); + + public static final long DEFAULT_STARTUP_TIMEOUT = 10000; + public static final String DEFAULT_TMP_DIR = "target/embeddedCassandra"; + + private final static AtomicReference sync = new AtomicReference(); + private final static AtomicReference cassandraRef = new AtomicReference(); + + private static String launchedYamlFile; + + /** + * Get the embedded cassandra cluster name + * + * @return the cluster name + */ + public static String getClusterName() { + return DatabaseDescriptor.getClusterName(); + } + + /** + * Get embedded cassandra host. + * + * @return the cassandra host + */ + public static String getHost() { + return DatabaseDescriptor.getRpcAddress().getHostName(); + } + + /** + * Get embedded cassandra RPC port. + * + * @return the cassandra RPC port + */ + public static int getRpcPort() { + return DatabaseDescriptor.getRpcPort(); + } + + /** + * Get embedded cassandra native transport port. + * + * @return the cassandra native transport port. + */ + public static int getNativeTransportPort() { + return DatabaseDescriptor.getNativeTransportPort(); + } + + /** + * Start an embedded Cassandra instance. + * + * @param yamlResource + * @param timeout + * @throws Exception + */ + public static void startEmbeddedCassandra(String yamlResource, long timeout) throws Exception { + startEmbeddedCassandra(yamlResource, DEFAULT_TMP_DIR, timeout); + } + + /** + * Start an embedded Cassandra instance. + * + * @param yamlResource + * @param tmpDir + * @param timeout + * @throws Exception + */ + public static void startEmbeddedCassandra(String yamlResource, String tmpDir, long timeout) throws Exception { + + if (cassandraRef.get() != null) { + /* nothing to do Cassandra is already started */ + return; + } + + if (!sync.compareAndSet(null, new Object())) { + /* A different Thread was faster, so nothing to do for us here */ + return; + } + + File yamlFile = new File(tmpDir, new File(yamlResource).getName()); + prepareCassandraDirectory(yamlResource, tmpDir, yamlFile); + startEmbeddedCassandra(yamlFile, timeout); + } + + /** + * Cleanup directory, copy YAML file to configuration directory and + * + * @param yamlFileName + * @param cassandraDirectoryName + * @param yamlFile + * @throws IOException + */ + private static void prepareCassandraDirectory(String yamlFileName, String cassandraDirectoryName, File yamlFile) + throws IOException { + + File cassandraDirectory = new File(cassandraDirectoryName); + + rmdirs(cassandraDirectory); + copy(yamlFileName, cassandraDirectory); + } + + /** + * Set embedded cassandra up and spawn it in a new thread. + */ + private static void startEmbeddedCassandra(File file, long timeout) throws Exception { + + checkConfigNameForRestart(file.getAbsolutePath()); + + log.debug("Starting cassandra..."); + log.debug("Initialization needed"); + + System.setProperty("cassandra.config", "file:" + file.getAbsolutePath()); + System.setProperty("cassandra-foreground", "true"); + System.setProperty("cassandra.native.epoll.enabled", "false"); // JNA doesn't cope with relocated netty + + cleanupAndRecreateDirectories(); + + final CassandraDaemon cassandraDaemon = new CassandraDaemon(); + ExecutorService executor = Executors.newSingleThreadExecutor(); + Future future = executor.submit(new Runnable() { + @Override + public void run() { + cassandraDaemon.activate(); + cassandraRef.compareAndSet(null, cassandraDaemon); + } + }); + + try { + future.get(timeout, MILLISECONDS); + } catch (ExecutionException e) { + + log.error("Cassandra daemon did not start after " + timeout + " ms. Consider increasing the timeout"); + throw new IllegalStateException("Cassandra daemon did not start within timeout", e); + } catch (InterruptedException e) { + + log.error("Interrupted waiting for Cassandra daemon to start:", e); + Thread.currentThread().interrupt(); + + throw new IllegalStateException(e); + } finally { + executor.shutdown(); + } + } + + private static void cleanupAndRecreateDirectories() throws IOException { + + createCassandraDirectories(); + cleanup(); + createCassandraDirectories(); + + CommitLog commitLog = CommitLog.instance; + commitLog.getContext(); // wait for commit log allocator instantiation to avoid hanging on a race condition + commitLog.resetUnsafe(); // cleanup screws w/ CommitLog, this brings it back to safe state + } + + private static void cleanup() throws IOException { + + // clean up commitlog and data locations + rmdirs(DatabaseDescriptor.getCommitLogLocation()); + rmdirs(DatabaseDescriptor.getAllDataFileLocations()); + } + + private static void checkConfigNameForRestart(String yamlFile) { + + boolean wasPreviouslyLaunched = cassandraRef.get() != null; + + if (wasPreviouslyLaunched && !launchedYamlFile.equals(yamlFile)) { + throw new UnsupportedOperationException("We can't launch two Cassandra configurations in the same JVM instance"); + } + + launchedYamlFile = yamlFile; + } + + /** + * Copies a resource from within the jar to a directory. + * + * @param resource name of the resource + * @param targetDirectory name of the target directory + * @throws IOException + */ + private static void copy(String resource, File targetDirectory) throws IOException { + + FileUtils.createDirectory(targetDirectory); + + File file = new File(targetDirectory, new File(resource).getName()); + InputStream is = EmbeddedCassandraServerHelper.class.getClassLoader().getResourceAsStream(resource); + OutputStream out = new FileOutputStream(file); + + FileCopyUtils.copy(is, out); + + out.close(); + is.close(); + } + + private static void createCassandraDirectories() { + DatabaseDescriptor.createAllDirectories(); + } + + private static void rmdirs(String... fileOrDirectories) throws IOException { + + for (String fileOrDirectory : fileOrDirectories) { + rmdirs(new File(fileOrDirectory)); + } + } + + private static void rmdirs(File... fileOrDirectories) throws IOException { + + for (File fileOrDirectory : fileOrDirectories) { + if (!fileOrDirectory.exists()) { + continue; + } + FileUtils.deleteRecursive(fileOrDirectory); + } + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/KeyspaceRule.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/KeyspaceRule.java new file mode 100644 index 000000000..5cc80a2f6 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/KeyspaceRule.java @@ -0,0 +1,137 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cassandra.test.integration; + +import org.junit.rules.ExternalResource; +import org.springframework.cassandra.core.SessionCallback; +import org.springframework.cassandra.support.RandomKeySpaceName; +import org.springframework.dao.DataAccessException; +import org.springframework.util.Assert; + +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Session; + +/** + * Class rule to prepare a keyspace to give tests a keyspace context. This rule uses {@link CassandraRule} to obtain a + * Cassandra connection context. It can be used as {@link org.junit.ClassRule} and {@link org.junit.rules.TestRule}. + *

+ * This rule maintains the keyspace throughout the test lifecycle. The keyspace is created when running the preparing + * {@link #before()} methods. At the same time, the {@link #getSession() session} is logged into the created keyspace + * and can be used for further interaction during the test. {@link #after()} the test is finished this rule drops the + * keyspace. + *

+ * Neither {@link Cluster} nor {@link Session} should be closed outside by any caller otherwise the rule cannot perform + * its cleanup after the test run. + * + * @author Mark Paluch + */ +public class KeyspaceRule extends ExternalResource { + + private Cluster cluster; + private Session session; + private final String keyspaceName; + + /** + * Create a {@link KeyspaceRule} initialized with a {@link CassandraRule} for creating a keyspace using a random name. + * + * @param cassandraRule + */ + public KeyspaceRule(CassandraRule cassandraRule) { + this(cassandraRule, RandomKeySpaceName.create()); + } + + /** + * Create a {@link KeyspaceRule} initialized with a {@link CassandraRule} for creating a keyspace using the given + * {@code keyspaceName}. + * + * @param cassandraRule + * @param keyspaceName + */ + public KeyspaceRule(CassandraRule cassandraRule, String keyspaceName) { + + Assert.notNull(cassandraRule, "CassandraRule must not be null!"); + Assert.hasText(keyspaceName, "KeyspaceName must not be empty!"); + + // Support initialized and initializing CassandraRule. + if (cassandraRule.getCluster() != null) { + this.cluster = cassandraRule.getCluster(); + this.session = cluster.connect(); + } else { + cassandraRule.before(new SessionCallback() { + @Override + public Object doInSession(Session s) throws DataAccessException { + KeyspaceRule.this.cluster = s.getCluster(); + KeyspaceRule.this.session = cluster.connect(); + return null; + } + }); + } + this.keyspaceName = keyspaceName; + } + + /** + * Create a {@link KeyspaceRule} initialized with a {@link Cluster} for creating a keyspace using the given + * {@code keyspaceName}. + * + * @param cluster + * @param keyspaceName + */ + public KeyspaceRule(Cluster cluster, String keyspaceName) { + + Assert.notNull(cluster, "Cluster must not be null!"); + Assert.hasText(keyspaceName, "KeyspaceName must not be empty!"); + + this.cluster = cluster; + this.session = cluster.connect(); + this.keyspaceName = keyspaceName; + } + + @Override + protected void before() throws Throwable { + + Assert.state(session != null, "Session was not initialized"); + + session.execute(String.format("CREATE KEYSPACE %s WITH durable_writes = false AND " + + "replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};", keyspaceName)); + session.execute(String.format("USE %s;", keyspaceName)); + } + + @Override + protected void after() { + + session.execute("USE system;"); + session.execute(String.format("DROP KEYSPACE %s;", keyspaceName)); + } + + /** + * Returns the {@link Session}. The session state can be initialized and pointing to a keyspace other than + * {@code system}. + * + * @return + */ + public Session getSession() { + return session; + } + + /** + * Returns the keyspace name. + * + * @return + */ + public String getKeyspaceName() { + return keyspaceName; + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/config/CassandraCqlClusterFactoryBeanTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/CassandraCqlClusterFactoryBeanIntegrationTests.java similarity index 83% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/config/CassandraCqlClusterFactoryBeanTests.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/CassandraCqlClusterFactoryBeanIntegrationTests.java index e4ac97a7e..776c50636 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/config/CassandraCqlClusterFactoryBeanTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/CassandraCqlClusterFactoryBeanIntegrationTests.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.config; +package org.springframework.cassandra.test.integration.config; import static org.junit.Assert.*; @@ -26,11 +26,11 @@ import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraI import com.datastax.driver.core.ProtocolVersion; /** - * Integration tests for {@link CassandraCqlClusterFactoryBean}. + * Unit tests for {@link CassandraCqlClusterFactoryBean}. * * @author Kirk Clemens */ -public class CassandraCqlClusterFactoryBeanTests extends AbstractEmbeddedCassandraIntegrationTest { +public class CassandraCqlClusterFactoryBeanIntegrationTests extends AbstractEmbeddedCassandraIntegrationTest { private CassandraCqlClusterFactoryBean cassandraCqlClusterFactoryBean; @@ -48,7 +48,7 @@ public class CassandraCqlClusterFactoryBeanTests extends AbstractEmbeddedCassand public void configuredProtocolVersionShouldBeSet() throws Exception { cassandraCqlClusterFactoryBean.setProtocolVersion(ProtocolVersion.V2); - cassandraCqlClusterFactoryBean.setPort(CASSANDRA_NATIVE_PORT); + cassandraCqlClusterFactoryBean.setPort(cassandraEnvironment.getPort()); cassandraCqlClusterFactoryBean.afterPropertiesSet(); assertEquals(ProtocolVersion.V2, getProtocolVersionEnum(cassandraCqlClusterFactoryBean)); @@ -57,7 +57,7 @@ public class CassandraCqlClusterFactoryBeanTests extends AbstractEmbeddedCassand @Test public void defaultProtocolVersionShouldBeSet() throws Exception { - cassandraCqlClusterFactoryBean.setPort(CASSANDRA_NATIVE_PORT); + cassandraCqlClusterFactoryBean.setPort(cassandraEnvironment.getPort()); cassandraCqlClusterFactoryBean.afterPropertiesSet(); assertEquals(ProtocolVersion.NEWEST_SUPPORTED, getProtocolVersionEnum(cassandraCqlClusterFactoryBean)); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/IntegrationTestUtils.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/IntegrationTestUtils.java index 60c6fab80..486740ef6 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/IntegrationTestUtils.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/IntegrationTestUtils.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,12 +15,15 @@ */ package org.springframework.cassandra.test.integration.config; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; import org.springframework.cassandra.core.CqlTemplate; import com.datastax.driver.core.Session; +/** + * @author Matthew T. Adams + */ public class IntegrationTestUtils { public static void assertCqlTemplate(CqlTemplate cqlTemplate) { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/AbstractIntegrationTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/AbstractIntegrationTest.java index 6c8315232..f7b066d11 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/AbstractIntegrationTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/AbstractIntegrationTest.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,11 +25,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.datastax.driver.core.Session; +/** + * @author Matthew T. Adams + */ @RunWith(SpringJUnit4ClassRunner.class) public abstract class AbstractIntegrationTest extends AbstractEmbeddedCassandraIntegrationTest { - @Inject - protected Session session; + @Inject protected Session session; @Before public void assertSession() { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/AbstractKeyspaceCreatingConfiguration.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/AbstractKeyspaceCreatingConfiguration.java deleted file mode 100644 index d404fc766..000000000 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/AbstractKeyspaceCreatingConfiguration.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2013-2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.cassandra.test.integration.config.java; - -import org.springframework.cassandra.config.CassandraCqlSessionFactoryBean; -import org.springframework.cassandra.config.java.AbstractSessionConfiguration; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.StringUtils; - -import com.datastax.driver.core.KeyspaceMetadata; -import com.datastax.driver.core.Session; - -import static org.springframework.cassandra.core.cql.generator.CreateKeyspaceCqlGenerator.toCql; -import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.createKeyspace; - -@Configuration -public abstract class AbstractKeyspaceCreatingConfiguration extends AbstractSessionConfiguration { - - @Override - public CassandraCqlSessionFactoryBean session() throws Exception { - - createKeyspaceIfNecessary(); - - return super.session(); - } - - protected void createKeyspaceIfNecessary() throws Exception { - String keyspace = getKeyspaceName(); - if (!StringUtils.hasText(keyspace)) { - return; - } - - Session system = cluster().getObject().connect(); - KeyspaceMetadata kmd = system.getCluster().getMetadata().getKeyspace(keyspace); - if (kmd != null) { - return; - } - - system.execute(toCql(createKeyspace().name(keyspace).withSimpleReplication())); - system.close(); - } -} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/Config.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/Config.java index ba269edcc..7d8844301 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/Config.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/Config.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,8 +15,8 @@ */ package org.springframework.cassandra.test.integration.config.java; -import org.springframework.context.annotation.Configuration; import org.springframework.cassandra.test.integration.support.AbstractTestJavaConfig; +import org.springframework.context.annotation.Configuration; @Configuration public class Config extends AbstractTestJavaConfig { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/ConfigTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/ConfigIntegrationTests.java similarity index 73% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/ConfigTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/ConfigIntegrationTests.java index a5c98a9e4..7a5c150ae 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/ConfigTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/ConfigIntegrationTests.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,13 +18,20 @@ package org.springframework.cassandra.test.integration.config.java; import org.junit.Test; import org.springframework.test.context.ContextConfiguration; +/** + * @author Matthew T. Adams + */ @ContextConfiguration(classes = Config.class) -public class ConfigTest extends AbstractIntegrationTest { +public class ConfigIntegrationTests extends AbstractIntegrationTest { @Test public void test() { - session - .execute("CREATE KEYSPACE ConfigTest WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"); + + session.execute("DROP KEYSPACE IF EXISTS ConfigTest"); + + session.execute("CREATE KEYSPACE ConfigTest " + "WITH " + + "REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"); + session.execute("USE ConfigTest"); } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/CqlTemplateConfigIntegrationTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/CqlTemplateConfigIntegrationTests.java similarity index 70% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/CqlTemplateConfigIntegrationTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/CqlTemplateConfigIntegrationTests.java index 31ef8f889..9cc0bda2d 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/CqlTemplateConfigIntegrationTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/CqlTemplateConfigIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2013-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,16 @@ */ package org.springframework.cassandra.test.integration.config.java; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + import org.junit.After; import org.junit.Before; import org.junit.Test; import org.springframework.cassandra.config.java.AbstractCqlTemplateConfiguration; import org.springframework.cassandra.core.CqlTemplate; -import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest; -import org.springframework.cassandra.test.integration.config.IntegrationTestUtils; -import org.springframework.cassandra.test.unit.support.Utils; +import org.springframework.cassandra.support.RandomKeySpaceName; +import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Configuration; @@ -32,46 +34,44 @@ import com.datastax.driver.core.Session; /** * @author Matthews T. Adams * @author Oliver Gierke + * @author Mark Paluch */ -public class CqlTemplateConfigIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest { +public class CqlTemplateConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrationTest { - public static final String KEYSPACE_NAME = Utils.randomKeyspaceName(); + public static final String KEYSPACE_NAME = RandomKeySpaceName.create(); @Configuration public static class Config extends AbstractCqlTemplateConfiguration { @Override protected String getKeyspaceName() { - return KEYSPACE_NAME; + return "system"; } @Override protected int getPort() { - return CASSANDRA_NATIVE_PORT; + return cassandraEnvironment.getPort(); } } - + Session session; ConfigurableApplicationContext context; - + @Before public void setUp() { - this.context = new AnnotationConfigApplicationContext(Config.class); this.session = context.getBean(Session.class); } - + @After public void tearDown() { context.close(); } - public CqlTemplateConfigIntegrationTest() { - super(KEYSPACE_NAME); - } - @Test public void test() { - IntegrationTestUtils.assertCqlTemplate(context.getBean(CqlTemplate.class)); + + CqlTemplate cqlTemplate = context.getBean(CqlTemplate.class); + assertThat(cqlTemplate.describeRing().size(), is(greaterThan(0))); } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/KeyspaceCreatingJavaConfigTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/KeyspaceCreatingJavaConfigIntegrationTests.java similarity index 83% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/KeyspaceCreatingJavaConfigTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/KeyspaceCreatingJavaConfigIntegrationTests.java index 6b2f75549..04c64246d 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/KeyspaceCreatingJavaConfigTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/KeyspaceCreatingJavaConfigIntegrationTests.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,12 +20,17 @@ import org.junit.Test; import org.springframework.cassandra.test.integration.config.IntegrationTestUtils; import org.springframework.test.context.ContextConfiguration; +/** + * @author Matthew T. Adams + */ @ContextConfiguration(classes = KeyspaceCreatingJavaConfig.class) -public class KeyspaceCreatingJavaConfigTest extends AbstractIntegrationTest { +public class KeyspaceCreatingJavaConfigIntegrationTests extends AbstractIntegrationTest { @Test public void test() { Assert.assertNotNull(session); IntegrationTestUtils.assertKeyspaceExists(KeyspaceCreatingJavaConfig.KEYSPACE_NAME, session); + + session.execute("DROP KEYSPACE " + KeyspaceCreatingJavaConfig.KEYSPACE_NAME + ";"); } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests.java similarity index 69% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests.java index 7e3f3fb95..37bb11b67 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,10 +15,9 @@ */ package org.springframework.cassandra.test.integration.config.xml; -import javax.inject.Inject; - import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest; import org.springframework.cassandra.test.integration.config.IntegrationTestUtils; import org.springframework.test.context.ContextConfiguration; @@ -26,18 +25,20 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.datastax.driver.core.Session; +/** + * @author Matthew T. Adams + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class FullySpecifiedKeyspaceCreatingXmlConfigTest extends AbstractEmbeddedCassandraIntegrationTest { +public class FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrationTest { - @Inject - Session s; + @Autowired Session session; @Test public void test() { - IntegrationTestUtils.assertKeyspaceExists("full1", s); - IntegrationTestUtils.assertKeyspaceExists("full2", s); - IntegrationTestUtils.assertKeyspaceExists("script1", s); - IntegrationTestUtils.assertKeyspaceExists("script2", s); + IntegrationTestUtils.assertKeyspaceExists("full1", session); + IntegrationTestUtils.assertKeyspaceExists("full2", session); + IntegrationTestUtils.assertKeyspaceExists("script1", session); + IntegrationTestUtils.assertKeyspaceExists("script2", session); } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalKeyspaceCreatingXmlConfigTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalKeyspaceCreatingXmlConfigIntegrationTests.java similarity index 79% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalKeyspaceCreatingXmlConfigTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalKeyspaceCreatingXmlConfigIntegrationTests.java index 1842b760a..7fe7ac4ca 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalKeyspaceCreatingXmlConfigTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalKeyspaceCreatingXmlConfigIntegrationTests.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,10 +15,9 @@ */ package org.springframework.cassandra.test.integration.config.xml; -import javax.inject.Inject; - import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest; import org.springframework.cassandra.test.integration.config.IntegrationTestUtils; import org.springframework.test.context.ContextConfiguration; @@ -26,15 +25,17 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.datastax.driver.core.Session; +/** + * @author Matthew T. Adams + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class MinimalKeyspaceCreatingXmlConfigTest extends AbstractEmbeddedCassandraIntegrationTest { +public class MinimalKeyspaceCreatingXmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrationTest { - @Inject - Session s; + @Autowired Session session; @Test public void test() { - IntegrationTestUtils.assertKeyspaceExists("minimal", s); + IntegrationTestUtils.assertKeyspaceExists("minimal", session); } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigIntegrationTests.java similarity index 63% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigIntegrationTests.java index b0fd4f351..3f1594ca3 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigIntegrationTests.java @@ -1,12 +1,12 @@ /* - * Copyright 2013-2015 the original author or authors. - * + * Copyright 2013-2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,13 +15,16 @@ */ package org.springframework.cassandra.test.integration.config.xml; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.springframework.cassandra.core.CqlOperations; -import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest; +import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest; +import org.springframework.cassandra.test.integration.KeyspaceRule; import org.springframework.cassandra.test.integration.config.IntegrationTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -31,25 +34,24 @@ import com.datastax.driver.core.Session; /** * @author Matthews T. Adams * @author Oliver Gierke + * @author Mark Paluch */ -public class MinimalXmlConfigTest extends AbstractKeyspaceCreatingIntegrationTest { +public class MinimalXmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrationTest { public static final String KEYSPACE = "minimalxmlconfigtest"; - public MinimalXmlConfigTest() { - super(KEYSPACE); - } + private Session session; + private ConfigurableApplicationContext context; + + @Rule public final KeyspaceRule keyspaceRule = new KeyspaceRule(cassandraEnvironment, KEYSPACE); - Session session; - ConfigurableApplicationContext context; - @Before public void setUp() { - - this.context = new ClassPathXmlApplicationContext("MinimalXmlConfigTest-context.xml", getClass()); + + this.context = new ClassPathXmlApplicationContext("MinimalXmlConfigIntegrationTests-context.xml", getClass()); this.session = context.getBean(Session.class); } - + @After public void tearDown() { context.close(); @@ -57,10 +59,10 @@ public class MinimalXmlConfigTest extends AbstractKeyspaceCreatingIntegrationTes @Test public void test() { - - IntegrationTestUtils.assertSession(session); + IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, session); - assertNotNull(context.getBean(CqlOperations.class)); + CqlOperations cqlOperations = context.getBean(CqlOperations.class); + assertThat(cqlOperations.describeRing().size(), is(greaterThan(0))); } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests.java similarity index 63% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests.java index f30996c16..c13e273f0 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,37 +15,46 @@ */ package org.springframework.cassandra.test.integration.config.xml; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; +import static org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification.*; import javax.inject.Inject; +import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.cassandra.core.CqlOperations; -import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest; +import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest; import org.springframework.cassandra.test.integration.config.IntegrationTestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.datastax.driver.core.Session; +/** + * @author Mark Paluch + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class PropertyPlaceholderNamespaceCreatingXmlConfigTest extends AbstractKeyspaceCreatingIntegrationTest { +public class PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests + extends AbstractEmbeddedCassandraIntegrationTest { - @Inject - Session s; + @Inject private Session session; - @Inject - CqlOperations ops; + @Inject private CqlOperations ops; @Test public void test() { - IntegrationTestUtils.assertSession(s); - IntegrationTestUtils.assertKeyspaceExists("ppncxct", s); + IntegrationTestUtils.assertSession(session); + IntegrationTestUtils.assertKeyspaceExists("ppncxct", session); assertNotNull(ops); } + @After + public void tearDown() throws Exception { + dropKeyspace("ppncxct"); + dropKeyspace("foo123"); + } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigIntegrationTests.java similarity index 67% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigIntegrationTests.java index 2c8737016..3fec09d12 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigIntegrationTests.java @@ -1,12 +1,12 @@ /* - * Copyright 2013-2015 the original author or authors. - * + * Copyright 2013-2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,8 +17,10 @@ package org.springframework.cassandra.test.integration.config.xml; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; -import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest; +import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest; +import org.springframework.cassandra.test.integration.KeyspaceRule; import org.springframework.cassandra.test.integration.config.IntegrationTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -28,25 +30,24 @@ import com.datastax.driver.core.Session; /** * @author Matthews T. Adams * @author Oliver Gierke + * @author Mark Paluch */ -public class XmlConfigTest extends AbstractKeyspaceCreatingIntegrationTest { +public class XmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrationTest { public static final String KEYSPACE = "xmlconfigtest"; - Session session; - ConfigurableApplicationContext context; - - public XmlConfigTest() { - super(KEYSPACE); - } - + @Rule public KeyspaceRule keyspaceRule = new KeyspaceRule(cassandraEnvironment, KEYSPACE); + + private Session session; + private ConfigurableApplicationContext context; + @Before public void setUp() { - - this.context = new ClassPathXmlApplicationContext("XmlConfigTest-context.xml", getClass()); + + this.context = new ClassPathXmlApplicationContext("XmlConfigIntegrationTests-context.xml", getClass()); this.session = context.getBean(Session.class); } - + @After public void tearDown() { context.close(); @@ -54,7 +55,6 @@ public class XmlConfigTest extends AbstractKeyspaceCreatingIntegrationTest { @Test public void test() { - IntegrationTestUtils.assertSession(session); IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, session); } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/Book.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/Book.java similarity index 90% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/Book.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/Book.java index 1a7d52f00..403e32e27 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/Book.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/Book.java @@ -1,23 +1,23 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.integration.core.template; +package org.springframework.cassandra.test.integration.core; /** * Test POJO - * + * * @author David Webb */ public class Book { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/BookListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/BookListener.java similarity index 85% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/BookListener.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/BookListener.java index bac13b20d..dfb270457 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/BookListener.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/BookListener.java @@ -1,29 +1,29 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.integration.core.template; +package org.springframework.cassandra.test.integration.core; import org.springframework.cassandra.core.AsynchronousQueryListener; -import org.springframework.cassandra.test.unit.support.TestListener; +import org.springframework.cassandra.support.TestListener; import com.datastax.driver.core.ResultSetFuture; import com.datastax.driver.core.Row; /** * Test Implementation of the {@link AsynchronousQueryListener} - * + * * @author David Webb * @author Matthew T. Adams */ diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/CQLOperationsTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/CqlOperationsIntegrationTests.java similarity index 94% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/CQLOperationsTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/CqlOperationsIntegrationTests.java index e62f28f0f..14d3b8f65 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/CQLOperationsTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/CqlOperationsIntegrationTests.java @@ -1,23 +1,21 @@ /* - * Copyright 2013-2015 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.integration.core.template; +package org.springframework.cassandra.test.integration.core; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.Collection; import java.util.LinkedList; @@ -28,10 +26,7 @@ import java.util.UUID; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; -import org.cassandraunit.CassandraCQLUnit; -import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,18 +65,20 @@ import com.datastax.driver.core.querybuilder.QueryBuilder; import com.datastax.driver.core.querybuilder.Truncate; /** - * Unit Tests for CqlTemplate - * + * Integration tests for {@link CqlOperations}. + * * @author David Webb * @author Oliver Gierke + * @author Mark Paluch */ -public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { +public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingIntegrationTest { private static final String BOOK_INSERT = "insert into book (isbn, title, author, pages) values (?, ?, ?, ?)"; - private static Logger log = LoggerFactory.getLogger(CQLOperationsTest.class); + private static Logger log = LoggerFactory.getLogger(CqlOperationsIntegrationTests.class); private CqlOperations cqlTemplate; + /* * Objects used for test data */ @@ -91,15 +88,10 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { final Object[] o2 = new Object[] { "2345", "War and Peace", "Russian Dude", new Integer(456) }; final Object[] o3 = new Object[] { "3456", "Jane Ayre", "Charlotte", new Integer(456) }; - /** - * This loads any test specific Cassandra objects - */ - @Rule - public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet( - "cassandraOperationsTest-cql-dataload.cql", this.keyspace), CASSANDRA_CONFIG); - @Before public void setupTemplate() { + + execute("cassandraOperationsTest-cql-dataload.cql", this.keyspace); this.cqlTemplate = new CqlTemplate(session); } @@ -123,7 +115,7 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { @Override public Collection mapHosts(Set host) throws DriverException { - List list = new LinkedList(); + List list = new LinkedList(); for (Host h : host) { MyHost mh = new MyHost(); @@ -226,7 +218,7 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { /** * This is an implementation of RowIterator for the purposes of testing passing your own Impl to CqlTemplate - * + * * @author David Webb */ final class MyRowIterator implements RowIterator { @@ -383,18 +375,18 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { Book b1 = cqlTemplate.queryAsynchronously("select * from book where isbn='" + isbn + "'", - new ResultSetExtractor() { + new ResultSetExtractor() { - @Override - public Book extractData(ResultSet rs) throws DriverException, DataAccessException { - Row r = rs.one(); - assertNotNull(r); + @Override + public Book extractData(ResultSet rs) throws DriverException, DataAccessException { + Row r = rs.one(); + assertNotNull(r); - Book b = rowToBook(r); + Book b = rowToBook(r); - return b; - } - }, 60l, TimeUnit.SECONDS); + return b; + } + }, 60l, TimeUnit.SECONDS); Book b2 = getBook(isbn); @@ -413,18 +405,18 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { Book b1 = cqlTemplate.queryAsynchronously("select * from book where isbn='" + isbn + "'", - new ResultSetExtractor() { + new ResultSetExtractor() { - @Override - public Book extractData(ResultSet rs) throws DriverException, DataAccessException { - Row r = rs.one(); - assertNotNull(r); + @Override + public Book extractData(ResultSet rs) throws DriverException, DataAccessException { + Row r = rs.one(); + assertNotNull(r); - Book b = rowToBook(r); + Book b = rowToBook(r); - return b; - } - }, 60l, TimeUnit.SECONDS, options); + return b; + } + }, 60l, TimeUnit.SECONDS, options); Book b2 = getBook(isbn); @@ -510,9 +502,7 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { public void processRow(Row row) throws DriverException { assertNotNull(row); - Book b = rowToBook(row); - assertBook(b1, b); } @@ -532,7 +522,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { final Book b1 = getBook(isbn); ResultSetFuture rsf = cqlTemplate.queryAsynchronously("select * from book where isbn='" + isbn + "'", options); - ResultSet rs = rsf.getUninterruptibly(); assertNotNull(rs); @@ -543,15 +532,11 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { public void processRow(Row row) throws DriverException { assertNotNull(row); - Book b = rowToBook(row); - assertBook(b1, b); - } }); - } @Test @@ -583,7 +568,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { insertTestObjectArray(); ResultSetFuture rsf = cqlTemplate.queryAsynchronously("select * from book where isbn in ('1234','2345','3456')"); - ResultSet rs = rsf.getUninterruptibly(); assertNotNull(rs); @@ -649,7 +633,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { ResultSetFuture rsf = cqlTemplate.queryAsynchronously("select * from book where isbn in ('" + ISBN_NINES + "')"); ResultSet rs = rsf.getUninterruptibly(); - assertNotNull(rs); Book book = cqlTemplate.processOne(rs, new RowMapper() { @@ -678,8 +661,8 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { public void queryForObjectTestCqlStringRequiredTypeInvalid() { @SuppressWarnings("unused") - Float title = cqlTemplate - .queryForObject("select title from book where isbn in ('" + ISBN_NINES + "')", Float.class); + Float title = cqlTemplate.queryForObject("select title from book where isbn in ('" + ISBN_NINES + "')", + Float.class); } @@ -690,7 +673,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { .queryAsynchronously("select title from book where isbn in ('" + ISBN_NINES + "')"); ResultSet rs = rsf.getUninterruptibly(); - assertNotNull(rs); String title = cqlTemplate.processOne(rs, String.class); @@ -705,11 +687,9 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { Map rsMap = cqlTemplate.queryForMap("select * from book where isbn in ('" + ISBN_NINES + "')"); Book b1 = objectToBook(rsMap.get("isbn"), rsMap.get("title"), rsMap.get("author"), rsMap.get("pages")); - Book b2 = getBook(ISBN_NINES); assertBook(b1, b2); - } @Test @@ -718,17 +698,14 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { ResultSetFuture rsf = cqlTemplate.queryAsynchronously("select * from book where isbn in ('" + ISBN_NINES + "')"); ResultSet rs = rsf.getUninterruptibly(); - assertNotNull(rs); Map rsMap = cqlTemplate.processMap(rs); Book b1 = objectToBook(rsMap.get("isbn"), rsMap.get("title"), rsMap.get("author"), rsMap.get("pages")); - Book b2 = getBook(ISBN_NINES); assertBook(b1, b2); - } @Test @@ -742,7 +719,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { assertNotNull(titles); assertEquals(titles.size(), 3); - } @Test @@ -752,13 +728,11 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { insertTestObjectArray(); ResultSetFuture rsf = cqlTemplate.queryAsynchronously("select * from book where isbn in ('1234','2345','3456')"); - ResultSet rs = rsf.getUninterruptibly(); assertNotNull(rs); List titles = cqlTemplate.processList(rs, String.class); - assertNotNull(titles); assertEquals(titles.size(), 3); } @@ -1105,24 +1079,20 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { String tableName = "truncate_test"; CreateTableSpecification createTableSpec = new CreateTableSpecification(); - createTableSpec.name(tableName).partitionKeyColumn("id", DataType.text()).column("foo", DataType.text()); - cqlTemplate.execute(createTableSpec); Insert insert = QueryBuilder.insertInto(tableName).value("id", uuid()).value("foo", "bar"); - cqlTemplate.execute(insert); Truncate truncate = QueryBuilder.truncate(tableName); - cqlTemplate.execute(truncate); } /** * Assert that a Book matches the arguments expected - * + * * @param b * @param orderedElements */ @@ -1146,7 +1116,7 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { /** * Convert Object[] to a Book - * + * * @param bookElements * @return */ @@ -1161,9 +1131,9 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { /** * Assert that 2 Book objects are the same - * - * @param b - * @param orderedElements + * + * @param b1 + * @param b2 */ public static void assertBook(Book b1, Book b2) { @@ -1176,7 +1146,7 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { /** * Get a Book from Cassandra for assertions. - * + * * @param isbn * @return */ @@ -1212,7 +1182,7 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { /** * Get a Book from Cassandra for assertions, if the Book is not retruned then retry as needed. This is used for * assertions after asynchronous insert/ingest to give the datastore time to catch up with the tests. - * + * * @param isbn * @param retryMillis * @param numRetries @@ -1237,10 +1207,9 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { /** * Get a Book from Cassandra for assertions, if the Book is not retruned then retry as needed. This is used for - * assertions after asynchronous insert/ingest to give the datastore time to catch up with the tests. - * - * Defaults to 5 retries @ 200ms intervals - * + * assertions after asynchronous insert/ingest to give the datastore time to catch up with the tests. Defaults to 5 + * retries @ 200ms intervals + * * @param isbn * @return */ diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/AsynchronousTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/AsynchronousCqlOperationsIntegrationTests.java similarity index 75% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/AsynchronousTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/AsynchronousCqlOperationsIntegrationTests.java index 9a10a0e28..e2f110d0b 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/AsynchronousTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/AsynchronousCqlOperationsIntegrationTests.java @@ -1,11 +1,26 @@ -package org.springframework.cassandra.test.integration.core.template.async; +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cassandra.test.integration.core.async; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.springframework.cassandra.core.keyspace.CreateTableSpecification.createTable; +import static org.junit.Assert.*; +import static org.springframework.cassandra.core.keyspace.CreateTableSpecification.*; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -17,12 +32,16 @@ import org.junit.Test; import org.springframework.cassandra.core.AsynchronousQueryListener; import org.springframework.cassandra.core.Cancellable; import org.springframework.cassandra.core.ConsistencyLevel; +import org.springframework.cassandra.core.CqlOperations; +import org.springframework.cassandra.core.CqlTemplate; import org.springframework.cassandra.core.QueryForListOfMapListener; import org.springframework.cassandra.core.QueryForMapListener; import org.springframework.cassandra.core.QueryForObjectListener; import org.springframework.cassandra.core.QueryOptions; import org.springframework.cassandra.core.RetryPolicy; import org.springframework.cassandra.support.exception.CassandraConnectionFailureException; +import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest; +import org.springframework.util.Assert; import org.springframework.util.StringUtils; import com.datastax.driver.core.DataType; @@ -30,9 +49,20 @@ import com.datastax.driver.core.Row; import com.datastax.driver.core.querybuilder.QueryBuilder; import com.datastax.driver.core.querybuilder.Select; -public class AsynchronousTest extends AbstractAsynchronousTest { +/** + * @author Mark Paluch + */ +public class AsynchronousCqlOperationsIntegrationTests extends AbstractKeyspaceCreatingIntegrationTest { public static final String TABLE = "book"; + CqlOperations cqlOperations; + + @Before + public void setUp() { + cqlOperations = new CqlTemplate(session); + ensureTableExists(); + cqlOperations.truncate(TABLE); + } public static String cql(Book book, String... columns) { if (columns == null || columns.length == 0) { @@ -49,8 +79,8 @@ public class AsynchronousTest extends AbstractAsynchronousTest { quoted[i] = "'" + quoted[i] + "'"; } - return String - .format("select * from %s where title in (%s)", TABLE, StringUtils.arrayToCommaDelimitedString(quoted)); + return String.format("select * from %s where title in (%s)", TABLE, + StringUtils.arrayToCommaDelimitedString(quoted)); } public static Select select(String isbn) { @@ -66,6 +96,17 @@ public class AsynchronousTest extends AbstractAsynchronousTest { } }; + public static final Comparator> MAP_WITH_ISBN_COMPARATOR = new Comparator>() { + @Override + public int compare(Map o1, Map o2) { + Assert.isInstanceOf(Comparable.class, o1.get("isbn"), + "Map o1 must contain a key 'isbn' and a Comparable value to compare the maps"); + Assert.isInstanceOf(Comparable.class, o2.get("isbn"), + "Map o2 must contain a key 'isbn' and a Comparable value to compare the maps"); + return ((Comparable) o1.get("isbn")).compareTo(o2.get("isbn")); + } + }; + public static void assertMapEquals(Map expected, Map actual) { for (Object key : expected.keySet()) { assertTrue(actual.containsKey(key)); @@ -74,7 +115,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest { } void ensureTableExists() { - t.execute(createTable(TABLE).ifNotExists().partitionKeyColumn("title", DataType.ascii()) + cqlOperations.execute(createTable(TABLE).ifNotExists().partitionKeyColumn("title", DataType.ascii()) .clusteredKeyColumn("isbn", DataType.ascii())); } @@ -82,17 +123,11 @@ public class AsynchronousTest extends AbstractAsynchronousTest { Book[] books = new Book[n]; for (int i = 0; i < n; i++) { Book b = books[i] = Book.random(); - t.execute(String.format("insert into %s (isbn, title) values ('%s', '%s')", TABLE, b.isbn, b.title)); + cqlOperations.execute(String.format("insert into %s (isbn, title) values ('%s', '%s')", TABLE, b.isbn, b.title)); } return books; } - @Before - public void beforeEach() { - ensureTableExists(); - t.truncate(TABLE); - } - void assertBook(Book expected, Book actual) { assertEquals(expected.isbn, actual.isbn); assertEquals(expected.title, actual.title); @@ -115,7 +150,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest { BasicListener listener = new BasicListener(); doAsyncQuery(expected, listener); listener.await(); - Row r = t.getResultSetUninterruptibly(listener.rsf).one(); + Row r = cqlOperations.getResultSetUninterruptibly(listener.rsf).one(); Book actual = new Book(r.getString(0), r.getString(1)); assertBook(expected, actual); } @@ -185,7 +220,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest { */ abstract void doAsyncQuery(Book[] books, QueryForListOfMapListener listener); - List> expected; // subclass should set this value in doAsyncQuery + List> expected; // subclass should set this value in doAsyncQuery void test(int n) throws Exception { Book[] books = insert(n); @@ -197,6 +232,9 @@ public class AsynchronousTest extends AbstractAsynchronousTest { throw listener.exception; } + // sort results the same way as the books array above + Collections.sort(listener.result, MAP_WITH_ISBN_COMPARATOR); + for (int i = 0; i < expected.size(); i++) { assertMapEquals(expected.get(i), listener.result.get(i)); } @@ -208,7 +246,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest { new AsynchronousQueryListenerTestTemplate() { @Override void doAsyncQuery(Book b, BasicListener listener) { - Cancellable qc = t.queryAsynchronously(cql(b), listener); + Cancellable qc = cqlOperations.queryAsynchronously(cql(b), listener); qc.cancel(); } }.test(); @@ -219,7 +257,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest { new AsynchronousQueryListenerTestTemplate() { @Override void doAsyncQuery(Book b, BasicListener listener) { - t.queryAsynchronously(cql(b), listener); + cqlOperations.queryAsynchronously(cql(b), listener); } }.test(); } @@ -228,7 +266,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest { new AsynchronousQueryListenerTestTemplate() { @Override void doAsyncQuery(Book b, BasicListener listener) { - t.queryAsynchronously(cql(b), listener, new QueryOptions(cl, RetryPolicy.LOGGING)); + cqlOperations.queryAsynchronously(cql(b), listener, new QueryOptions(cl, RetryPolicy.LOGGING)); } }.test(); } @@ -248,7 +286,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest { new AsynchronousQueryListenerTestTemplate() { @Override void doAsyncQuery(Book b, BasicListener listener) { - t.queryAsynchronously(cql(b), listener); + cqlOperations.queryAsynchronously(cql(b), listener); } }.test(); } @@ -259,7 +297,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest { @Override void doAsyncQuery(Book b, QueryForObjectListener listener) { - t.queryForObjectAsynchronously(cql(b, "title"), String.class, listener); + cqlOperations.queryForObjectAsynchronously(cql(b, "title"), String.class, listener); expected = b.title; } @@ -272,7 +310,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest { @Override void doAsyncQuery(Book b, QueryForObjectListener listener) { QueryOptions opts = new QueryOptions(cl, RetryPolicy.LOGGING); - t.queryForObjectAsynchronously(cql(b, "title"), String.class, listener, opts); + cqlOperations.queryForObjectAsynchronously(cql(b, "title"), String.class, listener, opts); expected = b.title; } @@ -295,7 +333,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest { @Override void doAsyncQuery(Book b, QueryForMapListener listener) { - t.queryForMapAsynchronously(cql(b), listener); + cqlOperations.queryForMapAsynchronously(cql(b), listener); expected = new HashMap(); expected.put("isbn", b.isbn); expected.put("title", b.title); @@ -310,7 +348,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest { @Override void doAsyncQuery(Book b, QueryForMapListener listener) { QueryOptions opts = new QueryOptions(cl, RetryPolicy.LOGGING); - t.queryForMapAsynchronously(cql(b), listener, opts); + cqlOperations.queryForMapAsynchronously(cql(b), listener, opts); expected = new HashMap(); expected.put("isbn", b.isbn); expected.put("title", b.title); @@ -337,17 +375,17 @@ public class AsynchronousTest extends AbstractAsynchronousTest { void doAsyncQuery(Book[] books, QueryForListOfMapListener listener) { String[] titles = new String[books.length]; - expected = new ArrayList>(books.length); + expected = new ArrayList>(books.length); for (int i = 0; i < books.length; i++) { Book b = books[i]; titles[i] = b.title; - HashMap row = new HashMap(2); + Map row = new HashMap(2); row.put("title", b.title); row.put("isbn", b.isbn); expected.add(row); } - t.queryForListOfMapAsynchronously(cql(titles), listener); + cqlOperations.queryForListOfMapAsynchronously(cql(titles), listener); } }.test(2); @@ -360,17 +398,18 @@ public class AsynchronousTest extends AbstractAsynchronousTest { void doAsyncQuery(Book[] books, QueryForListOfMapListener listener) { String[] titles = new String[books.length]; - expected = new ArrayList>(books.length); + expected = new ArrayList>(books.length); for (int i = 0; i < books.length; i++) { Book b = books[i]; titles[i] = b.title; - HashMap row = new HashMap(2); + Map row = new HashMap(2); row.put("title", b.title); row.put("isbn", b.isbn); expected.add(row); } - t.queryForListOfMapAsynchronously(cql(titles), listener, new QueryOptions(cl, RetryPolicy.LOGGING)); + cqlOperations.queryForListOfMapAsynchronously(cql(titles), listener, new QueryOptions(cl, RetryPolicy.LOGGING)); + } }.test(2); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/BasicListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/BasicListener.java new file mode 100644 index 000000000..03e448a2a --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/BasicListener.java @@ -0,0 +1,36 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cassandra.test.integration.core.async; + +import org.springframework.cassandra.core.AsynchronousQueryListener; +import org.springframework.cassandra.support.TestListener; + +import com.datastax.driver.core.ResultSetFuture; + +/** + * @author Matthew T. Adams + * @author David Webb + */ +class BasicListener extends TestListener implements AsynchronousQueryListener { + + ResultSetFuture rsf; + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + this.rsf = rsf; + countDown(); + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/Book.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/Book.java new file mode 100644 index 000000000..36652226a --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/Book.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cassandra.test.integration.core.async; + +import java.util.UUID; + +/** + * @author Matthew T. Adams + */ +public class Book { + + public static final String uuid() { + return UUID.randomUUID().toString(); + } + + public static Book random() { + return new Book("title-" + uuid(), "isbn-" + uuid()); + } + + public Book() {} + + public Book(String title, String isbn) { + this.isbn = isbn; + this.title = title; + } + + public String isbn; + public String title; +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/ListListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/ListListener.java new file mode 100644 index 000000000..4645261cf --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/ListListener.java @@ -0,0 +1,43 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cassandra.test.integration.core.async; + +import java.util.List; + +import org.springframework.cassandra.core.QueryForListListener; +import org.springframework.cassandra.support.TestListener; + +/** + * @author Matthew T. Adams + * @author David Webb + */ +public class ListListener extends TestListener implements QueryForListListener { + + Exception exception; + List result; + + @Override + public void onQueryComplete(List results) { + this.result = results; + countDown(); + } + + @Override + public void onException(Exception x) { + this.exception = x; + countDown(); + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/SpringCassandraBuildProperties.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/ListOfMapListener.java similarity index 50% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/SpringCassandraBuildProperties.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/ListOfMapListener.java index d6eeb1789..d7be6032f 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/SpringCassandraBuildProperties.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/ListOfMapListener.java @@ -1,26 +1,25 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.support; +package org.springframework.cassandra.test.integration.core.async; -import org.springframework.cassandra.test.integration.support.SpringCqlBuildProperties; +import java.util.Map; -@SuppressWarnings("serial") -public class SpringCassandraBuildProperties extends SpringCqlBuildProperties { +import org.springframework.cassandra.core.QueryForListOfMapListener; - public SpringCassandraBuildProperties() { - super("/" + SpringCassandraBuildProperties.class.getName() + ".properties"); - } -} +/** + * @author Matthew T. Adams + */ +public class ListOfMapListener extends ListListener> implements QueryForListOfMapListener {} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/MapListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/MapListener.java new file mode 100644 index 000000000..7a4f3f7a0 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/MapListener.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cassandra.test.integration.core.async; + +import java.util.Map; + +import org.springframework.cassandra.core.QueryForMapListener; +import org.springframework.cassandra.support.TestListener; + +/** + * @author Matthew T. Adams + */ +public class MapListener extends TestListener implements QueryForMapListener { + + Map result; + Exception exception; + + @Override + public void onQueryComplete(Map results) { + this.result = results; + countDown(); + } + + @Override + public void onException(Exception x) { + this.exception = x; + countDown(); + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/ObjectListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/ObjectListener.java new file mode 100644 index 000000000..cf02c30af --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/ObjectListener.java @@ -0,0 +1,41 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cassandra.test.integration.core.async; + +import org.springframework.cassandra.core.QueryForObjectListener; +import org.springframework.cassandra.support.TestListener; + +/** + * @author Matthew T. Adams + * @author David Webb + */ +class ObjectListener extends TestListener implements QueryForObjectListener { + + T result; + Exception exception; + + @Override + public void onQueryComplete(T result) { + this.result = result; + countDown(); + } + + @Override + public void onException(Exception x) { + this.exception = x; + countDown(); + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlIndexSpecificationAssertions.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlIndexSpecificationAssertions.java index 86f784edb..92e591d5d 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlIndexSpecificationAssertions.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlIndexSpecificationAssertions.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,18 +15,19 @@ */ package org.springframework.cassandra.test.integration.core.cql.generator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; import org.springframework.cassandra.core.keyspace.IndexDescriptor; import com.datastax.driver.core.ColumnMetadata.IndexMetadata; import com.datastax.driver.core.Session; +/** + * @author David Webb + * @author Matthew T. Adams + */ public class CqlIndexSpecificationAssertions { - public static double DELTA = 1e-6; // delta for comparisons of doubles - public static void assertIndex(IndexDescriptor expected, String keyspace, Session session) { IndexMetadata imd = session.getCluster().getMetadata().getKeyspace(keyspace.toLowerCase()) .getTable(expected.getTableName().toCql()).getColumn(expected.getColumnName().toCql()).getIndex(); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlKeyspaceSpecificationAssertions.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlKeyspaceSpecificationAssertions.java index f6a363a1f..dfc312e62 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlKeyspaceSpecificationAssertions.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlKeyspaceSpecificationAssertions.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,8 +15,7 @@ */ package org.springframework.cassandra.test.integration.core.cql.generator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.Map; @@ -26,10 +25,11 @@ import org.springframework.cassandra.core.keyspace.Option; import com.datastax.driver.core.KeyspaceMetadata; import com.datastax.driver.core.Session; +/** + * @author John McPeek + */ 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()); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlTableSpecificationAssertions.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlTableSpecificationAssertions.java index f544fde52..2f53228f0 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlTableSpecificationAssertions.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlTableSpecificationAssertions.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,8 +15,7 @@ */ package org.springframework.cassandra.test.integration.core.cql.generator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; import java.util.List; import java.util.Map; @@ -34,6 +33,11 @@ import com.datastax.driver.core.Session; import com.datastax.driver.core.TableMetadata; import com.datastax.driver.core.TableMetadata.Options; +/** + * @author Matthew T. Adams + * @author Matthew T. Adams + * @author Alex Shvid + */ public class CqlTableSpecificationAssertions { private final static Logger log = LoggerFactory.getLogger(CqlTableSpecificationAssertions.class); @@ -93,23 +97,23 @@ public class CqlTableSpecificationAssertions { switch (tableOption) { - case BLOOM_FILTER_FP_CHANCE: - case READ_REPAIR_CHANCE: - case DCLOCAL_READ_REPAIR_CHANCE: - assertEquals((Double) expected, (Double) actual, DELTA); - return; + case BLOOM_FILTER_FP_CHANCE: + case READ_REPAIR_CHANCE: + case DCLOCAL_READ_REPAIR_CHANCE: + assertEquals((Double) expected, (Double) actual, DELTA); + return; - case CACHING: - assertCaching((Map) expected, (Map) actual); - return; + case CACHING: + assertCaching((Map) expected, (Map) actual); + return; - case COMPACTION: - assertCompaction((Map) expected, (Map) actual); - return; + case COMPACTION: + assertCompaction((Map) expected, (Map) actual); + return; - case COMPRESSION: - assertCompression((Map) expected, (Map) actual); - return; + case COMPRESSION: + assertCompression((Map) expected, (Map) actual); + return; } log.info(actual.getClass().getName()); @@ -141,24 +145,24 @@ public class CqlTableSpecificationAssertions { @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) CqlStringUtils.singleQuote(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.getLocalReadRepairChance(); - case GC_GRACE_SECONDS: - return (T) new Long(options.getGcGraceInSeconds()); - case READ_REPAIR_CHANCE: - return (T) (Double) options.getReadRepairChance(); + case BLOOM_FILTER_FP_CHANCE: + return (T) (Double) options.getBloomFilterFalsePositiveChance(); + case CACHING: + return (T) options.getCaching(); + case COMMENT: + return (T) CqlStringUtils.singleQuote(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.getLocalReadRepairChance(); + case GC_GRACE_SECONDS: + return (T) new Long(options.getGcGraceInSeconds()); + case READ_REPAIR_CHANCE: + return (T) (Double) options.getReadRepairChance(); } return null; } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateIndexCqlGeneratorIntegrationTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateIndexCqlGeneratorIntegrationTests.java index 31d4373a5..2309d05a9 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateIndexCqlGeneratorIntegrationTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateIndexCqlGeneratorIntegrationTests.java @@ -1,12 +1,12 @@ /* - * Copyright 2013-2015 the original author or authors. - * + * Copyright 2013-2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,27 +15,26 @@ */ package org.springframework.cassandra.test.integration.core.cql.generator; -import static org.springframework.cassandra.test.integration.core.cql.generator.CqlIndexSpecificationAssertions.assertIndex; +import static org.springframework.cassandra.test.integration.core.cql.generator.CqlIndexSpecificationAssertions.*; -import org.cassandraunit.CassandraCQLUnit; -import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; -import org.junit.Rule; import org.junit.Test; +import org.springframework.cassandra.core.cql.generator.CreateIndexCqlGeneratorUnitTests.BasicTest; +import org.springframework.cassandra.core.cql.generator.CreateIndexCqlGeneratorUnitTests.CreateIndexTest; import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest; -import org.springframework.cassandra.test.unit.core.cql.generator.CreateIndexCqlGeneratorTests.BasicTest; -import org.springframework.cassandra.test.unit.core.cql.generator.CreateIndexCqlGeneratorTests.CreateIndexTest; +import org.springframework.cassandra.test.integration.support.CqlDataSet; /** * Integration tests that reuse unit tests. - * + * * @author Matthew T. Adams * @author Oliver Gierke + * @author Mark Paluch */ public class CreateIndexCqlGeneratorIntegrationTests { /** * 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. */ @@ -57,13 +56,12 @@ public class CreateIndexCqlGeneratorIntegrationTests { public static class BasicIntegrationTest extends Base { - /** - * This loads any test specific Cassandra objects - */ - @Rule - public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet( - "integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest.cql", this.keyspace), - CASSANDRA_CONFIG); + public BasicIntegrationTest() { + + cassandraRule.before( + CqlDataSet.fromClassPath("integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest.cql") + .executeIn(this.keyspace)); + } @Override public BasicTest unit() { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateKeyspaceCqlGeneratorIntegrationTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateKeyspaceCqlGeneratorIntegrationTests.java index b9b7e27c8..3020c4e7f 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateKeyspaceCqlGeneratorIntegrationTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateKeyspaceCqlGeneratorIntegrationTests.java @@ -1,12 +1,12 @@ /* - * Copyright 2013-2015 the original author or authors. - * + * Copyright 2013-2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,28 +15,29 @@ */ package org.springframework.cassandra.test.integration.core.cql.generator; -import static org.springframework.cassandra.test.integration.core.cql.generator.CqlKeyspaceSpecificationAssertions.assertKeyspace; +import static org.springframework.cassandra.test.integration.core.cql.generator.CqlKeyspaceSpecificationAssertions.*; import org.junit.Test; -import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest; -import org.springframework.cassandra.test.unit.core.cql.generator.CreateKeyspaceCqlGeneratorTests.BasicTest; -import org.springframework.cassandra.test.unit.core.cql.generator.CreateKeyspaceCqlGeneratorTests.CreateKeyspaceTest; -import org.springframework.cassandra.test.unit.core.cql.generator.CreateKeyspaceCqlGeneratorTests.NetworkTopologyTest; +import org.springframework.cassandra.core.cql.generator.CreateKeyspaceCqlGeneratorUnitTests.BasicTest; +import org.springframework.cassandra.core.cql.generator.CreateKeyspaceCqlGeneratorUnitTests.CreateKeyspaceTest; +import org.springframework.cassandra.core.cql.generator.CreateKeyspaceCqlGeneratorUnitTests.NetworkTopologyTest; +import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest; /** * Integration tests that reuse unit tests. - * + * * @author John McPeek * @author Oliver Gierke + * @author Mark Paluch */ public class CreateKeyspaceCqlGeneratorIntegrationTests { /** * Integration test base class that knows how to do everything except instantiate the concrete unit test type T. - * + * * @param The concrete unit test class to which this integration test corresponds. */ - public static abstract class Base extends AbstractEmbeddedCassandraIntegrationTest { + public static abstract class Base extends AbstractKeyspaceCreatingIntegrationTest { T unit; public abstract T unit(); @@ -46,9 +47,11 @@ public class CreateKeyspaceCqlGeneratorIntegrationTests { unit = unit(); unit.prepare(); - system.execute(unit.cql); + session.execute(unit.cql); - assertKeyspace(unit.specification, unit.keyspace, system); + assertKeyspace(unit.specification, unit.keyspace, session); + + dropKeyspace(unit.keyspace); } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateTableCqlGeneratorIntegrationTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateTableCqlGeneratorIntegrationTests.java index 278838ae7..5952e8947 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateTableCqlGeneratorIntegrationTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateTableCqlGeneratorIntegrationTests.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2015 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,17 +15,17 @@ */ package org.springframework.cassandra.test.integration.core.cql.generator; -import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.assertTable; +import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.*; import org.junit.Test; +import org.springframework.cassandra.core.cql.generator.CreateTableCqlGeneratorUnitTests.BasicTest; +import org.springframework.cassandra.core.cql.generator.CreateTableCqlGeneratorUnitTests.CompositePartitionKeyTest; +import org.springframework.cassandra.core.cql.generator.CreateTableCqlGeneratorUnitTests.CreateTableTest; import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest; -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 * @author Oliver Gierke */ @@ -33,19 +33,19 @@ public class CreateTableCqlGeneratorIntegrationTests { /** * 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 AbstractKeyspaceCreatingIntegrationTest { - + T unit; public abstract T unit(); @Test public void test() { - + unit = unit(); unit.prepare(); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/FunkyIdentifierIntegrationTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/FunkyIdentifierIntegrationTest.java deleted file mode 100644 index 2b15c3e50..000000000 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/FunkyIdentifierIntegrationTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2013-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.cassandra.test.integration.core.cql.generator; - -import org.junit.Test; -import org.springframework.cassandra.core.cql.generator.CreateTableCqlGenerator; -import org.springframework.cassandra.core.keyspace.CreateTableSpecification; -import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest; -import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests.FunkyTableNameTest; - -import com.datastax.driver.core.DataType; - -/** - * @author Matthew T. Adams - * @author Oliver Gierke - */ -public class FunkyIdentifierIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest { - - public FunkyIdentifierIntegrationTest() { - super(randomKeyspaceName()); - } - - @Test - public void testFunkyTableName() { - for (String name : FunkyTableNameTest.FUNKY_LEGAL_NAMES) { - session.execute(new CreateTableCqlGenerator(CreateTableSpecification.createTable().name(name) - .partitionKeyColumn("key", DataType.text())).toCql()); - } - } - - @Test - public void testFunkyColumnName() { - String table = "funky"; - int i = 0; - for (String name : FunkyTableNameTest.FUNKY_LEGAL_NAMES) { - session.execute(new CreateTableCqlGenerator(CreateTableSpecification.createTable().name(table + i++) - .partitionKeyColumn(name, DataType.text())).toCql()); - } - } - - @Test - public void testFunkyTableAndColumnName() { - for (String name : FunkyTableNameTest.FUNKY_LEGAL_NAMES) { - session.execute(new CreateTableCqlGenerator(CreateTableSpecification.createTable().name(name) - .partitionKeyColumn(name, DataType.text())).toCql()); - } - } -} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/IndexLifecycleCqlGeneratorIntegrationTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/IndexLifecycleCqlGeneratorIntegrationTests.java index bd20a0db8..e9f579804 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/IndexLifecycleCqlGeneratorIntegrationTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/IndexLifecycleCqlGeneratorIntegrationTests.java @@ -1,12 +1,12 @@ /* - * Copyright 2013-2015 the original author or authors. - * + * Copyright 2013-2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,43 +15,38 @@ */ package org.springframework.cassandra.test.integration.core.cql.generator; -import static org.springframework.cassandra.test.integration.core.cql.generator.CqlIndexSpecificationAssertions.assertIndex; -import static org.springframework.cassandra.test.integration.core.cql.generator.CqlIndexSpecificationAssertions.assertNoIndex; +import static org.springframework.cassandra.test.integration.core.cql.generator.CqlIndexSpecificationAssertions.*; -import org.cassandraunit.CassandraCQLUnit; -import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; -import org.junit.Rule; +import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.cassandra.core.cql.generator.CreateIndexCqlGeneratorUnitTests; +import org.springframework.cassandra.core.cql.generator.DropIndexCqlGeneratorUnitTests; import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest; -import org.springframework.cassandra.test.unit.core.cql.generator.CreateIndexCqlGeneratorTests; -import org.springframework.cassandra.test.unit.core.cql.generator.DropIndexCqlGeneratorTests; /** * Integration tests that reuse unit tests. - * + * * @author Matthew T. Adams * @author Oliver Gierke + * @author Mark Paluch */ public class IndexLifecycleCqlGeneratorIntegrationTests extends AbstractKeyspaceCreatingIntegrationTest { - Logger log = LoggerFactory.getLogger(IndexLifecycleCqlGeneratorIntegrationTests.class); + private final static Logger log = LoggerFactory.getLogger(IndexLifecycleCqlGeneratorIntegrationTests.class); - /** - * This loads any test specific Cassandra objects - */ - @Rule - public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet( - "integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest.cql", this.keyspace), - CASSANDRA_CONFIG); + @Before + public void setUp() throws Exception { + execute("integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest.cql", this.keyspace); + } @Test public void lifecycleTest() { - CreateIndexCqlGeneratorTests.BasicTest createTest = new CreateIndexCqlGeneratorTests.BasicTest(); - DropIndexCqlGeneratorTests.BasicTest dropTest = new DropIndexCqlGeneratorTests.BasicTest(); - DropIndexCqlGeneratorTests.IfExistsTest dropIfExists = new DropIndexCqlGeneratorTests.IfExistsTest(); + CreateIndexCqlGeneratorUnitTests.BasicTest createTest = new CreateIndexCqlGeneratorUnitTests.BasicTest(); + DropIndexCqlGeneratorUnitTests.BasicTest dropTest = new DropIndexCqlGeneratorUnitTests.BasicTest(); + DropIndexCqlGeneratorUnitTests.IfExistsTest dropIfExists = new DropIndexCqlGeneratorUnitTests.IfExistsTest(); createTest.prepare(); dropTest.prepare(); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableLifecycleIntegrationTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableLifecycleIntegrationTests.java similarity index 63% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableLifecycleIntegrationTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableLifecycleIntegrationTests.java index aad2cf2d9..4ea472c1d 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableLifecycleIntegrationTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableLifecycleIntegrationTests.java @@ -1,12 +1,12 @@ /* - * Copyright 2013-2015 the original author or authors. - * + * Copyright 2013-2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,47 +15,37 @@ */ package org.springframework.cassandra.test.integration.core.cql.generator; -import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.assertNoTable; -import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.assertTable; +import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.*; -import org.cassandraunit.CassandraCQLUnit; -import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; -import org.junit.Rule; +import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.cassandra.core.cql.generator.AlterTableCqlGeneratorUnitTests; +import org.springframework.cassandra.core.cql.generator.CreateTableCqlGeneratorUnitTests; import org.springframework.cassandra.core.cql.generator.DropTableCqlGenerator; +import org.springframework.cassandra.core.cql.generator.DropTableCqlGeneratorUnitTests; import org.springframework.cassandra.core.keyspace.DropTableSpecification; import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest; -import org.springframework.cassandra.test.unit.core.cql.generator.AlterTableCqlGeneratorTests; -import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests; -import org.springframework.cassandra.test.unit.core.cql.generator.DropTableCqlGeneratorTests; /** * Test CREATE TABLE / ALTER TABLE / DROP TABLE - * + * * @author David Webb * @author Oliver Gierke + * @author Mark Paluch */ -public class TableLifecycleIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest { +public class TableLifecycleIntegrationTests extends AbstractKeyspaceCreatingIntegrationTest { - private final static Logger log = LoggerFactory.getLogger(TableLifecycleIntegrationTest.class); + private final static Logger log = LoggerFactory.getLogger(TableLifecycleIntegrationTests.class); - CreateTableCqlGeneratorTests.MultipleOptionsTest createTableTest = new CreateTableCqlGeneratorTests.MultipleOptionsTest(); + CreateTableCqlGeneratorUnitTests.MultipleOptionsTest createTableTest = new CreateTableCqlGeneratorUnitTests.MultipleOptionsTest(); - public TableLifecycleIntegrationTest() { - super("tlit"); + @Before + public void setUp() throws Exception { + execute("cassandraOperationsTest-cql-dataload.cql", this.keyspace); } - @Override - public boolean dropKeyspaceAfterTest() { - return true; - } - - @Rule - public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet( - "cassandraOperationsTest-cql-dataload.cql", this.keyspace), CASSANDRA_CONFIG); - @Test public void testDrop() { @@ -88,7 +78,7 @@ public class TableLifecycleIntegrationTest extends AbstractKeyspaceCreatingInteg assertTable(createTableTest.specification, keyspace, session); - AlterTableCqlGeneratorTests.MultipleOptionsTest alterTest = new AlterTableCqlGeneratorTests.MultipleOptionsTest(); + AlterTableCqlGeneratorUnitTests.MultipleOptionsTest alterTest = new AlterTableCqlGeneratorUnitTests.MultipleOptionsTest(); alterTest.prepare(); log.info(alterTest.cql); @@ -108,7 +98,7 @@ public class TableLifecycleIntegrationTest extends AbstractKeyspaceCreatingInteg } - public class DropTableTest extends DropTableCqlGeneratorTests.DropTableTest { + public class DropTableTest extends DropTableCqlGeneratorUnitTests.DropTableTest { @Override public DropTableSpecification specification() { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableOptionsIntegrationTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableOptionsIntegrationTests.java similarity index 75% rename from spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableOptionsIntegrationTest.java rename to spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableOptionsIntegrationTests.java index 9bd027aea..174d75390 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableOptionsIntegrationTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableOptionsIntegrationTests.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2015 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,28 +15,28 @@ */ package org.springframework.cassandra.test.integration.core.cql.generator; -import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.assertTable; +import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.*; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.cassandra.core.cql.generator.CreateTableCqlGeneratorUnitTests; import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest; -import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests; /** * Test CREATE TABLE for all Options and assert against C* TableMetaData - * + * * @author David Webb * @author Oliver Gierke */ -public class TableOptionsIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest { +public class TableOptionsIntegrationTests extends AbstractKeyspaceCreatingIntegrationTest { - private final static Logger log = LoggerFactory.getLogger(TableOptionsIntegrationTest.class); + private final static Logger log = LoggerFactory.getLogger(TableOptionsIntegrationTests.class); @Test public void test() { - CreateTableCqlGeneratorTests.MultipleOptionsTest optionsTest = new CreateTableCqlGeneratorTests.MultipleOptionsTest(); + CreateTableCqlGeneratorUnitTests.MultipleOptionsTest optionsTest = new CreateTableCqlGeneratorUnitTests.MultipleOptionsTest(); optionsTest.prepare(); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/AbstractAsynchronousTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/AbstractAsynchronousTest.java deleted file mode 100644 index 703f21c86..000000000 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/AbstractAsynchronousTest.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.springframework.cassandra.test.integration.core.template.async; - -import org.springframework.cassandra.test.integration.AbstractCqlTemplateIntegrationTest; - -public abstract class AbstractAsynchronousTest extends AbstractCqlTemplateIntegrationTest {} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/BasicListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/BasicListener.java deleted file mode 100644 index bac24d6e5..000000000 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/BasicListener.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.springframework.cassandra.test.integration.core.template.async; - -import org.springframework.cassandra.core.AsynchronousQueryListener; -import org.springframework.cassandra.test.unit.support.TestListener; - -import com.datastax.driver.core.ResultSetFuture; - -class BasicListener extends TestListener implements AsynchronousQueryListener { - - ResultSetFuture rsf; - - @Override - public void onQueryComplete(ResultSetFuture rsf) { - this.rsf = rsf; - countDown(); - } -} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/Book.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/Book.java deleted file mode 100644 index afab94959..000000000 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/Book.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.springframework.cassandra.test.integration.core.template.async; - -import java.util.UUID; - -public class Book { - - public static final String uuid() { - return UUID.randomUUID().toString(); - } - - public static Book random() { - return new Book(uuid(), uuid()); - } - - public Book() {} - - public Book(String title, String isbn) { - this.isbn = isbn; - this.title = title; - } - - public String isbn; - public String title; -} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ListListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ListListener.java deleted file mode 100644 index 1b1060da8..000000000 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ListListener.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.springframework.cassandra.test.integration.core.template.async; - -import java.util.List; - -import org.springframework.cassandra.core.QueryForListListener; -import org.springframework.cassandra.test.unit.support.TestListener; - -public class ListListener extends TestListener implements QueryForListListener { - - Exception exception; - List result; - - @Override - public void onQueryComplete(List results) { - this.result = results; - countDown(); - } - - @Override - public void onException(Exception x) { - this.exception = x; - countDown(); - } -} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ListOfMapListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ListOfMapListener.java deleted file mode 100644 index 6bd66a564..000000000 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ListOfMapListener.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.springframework.cassandra.test.integration.core.template.async; - -import java.util.Map; - -import org.springframework.cassandra.core.QueryForListOfMapListener; - -public class ListOfMapListener extends ListListener> implements QueryForListOfMapListener {} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/MapListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/MapListener.java deleted file mode 100644 index 22f170316..000000000 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/MapListener.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.springframework.cassandra.test.integration.core.template.async; - -import java.util.Map; - -import org.springframework.cassandra.core.QueryForMapListener; -import org.springframework.cassandra.test.unit.support.TestListener; - -public class MapListener extends TestListener implements QueryForMapListener { - - Map result; - Exception exception; - - @Override - public void onQueryComplete(Map results) { - this.result = results; - countDown(); - } - - @Override - public void onException(Exception x) { - this.exception = x; - countDown(); - } -} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ObjectListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ObjectListener.java deleted file mode 100644 index 2d17645d0..000000000 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ObjectListener.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.springframework.cassandra.test.integration.core.template.async; - -import org.springframework.cassandra.core.QueryForObjectListener; -import org.springframework.cassandra.test.unit.support.TestListener; - -class ObjectListener extends TestListener implements QueryForObjectListener { - - T result; - Exception exception; - - @Override - public void onQueryComplete(T result) { - this.result = result; - countDown(); - } - - @Override - public void onException(Exception x) { - this.exception = x; - countDown(); - } -} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/AbstractTestJavaConfig.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/AbstractTestJavaConfig.java index 9b9bdf419..c30fc9852 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/AbstractTestJavaConfig.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/AbstractTestJavaConfig.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,14 +18,16 @@ package org.springframework.cassandra.test.integration.support; import org.springframework.cassandra.config.java.AbstractSessionConfiguration; import org.springframework.context.annotation.Configuration; +/** + * @author Matthew T. Adams + */ @Configuration public abstract class AbstractTestJavaConfig extends AbstractSessionConfiguration { - public static SpringCqlBuildProperties PROPS = new SpringCqlBuildProperties(); - public static final int PORT = PROPS.getCassandraPort(); + private final static CassandraConnectionProperties PROPERTIES = new CassandraConnectionProperties(); @Override protected int getPort() { - return PORT; + return PROPERTIES.getCassandraPort(); } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/CassandraConnectionProperties.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/CassandraConnectionProperties.java new file mode 100644 index 000000000..70455ce96 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/CassandraConnectionProperties.java @@ -0,0 +1,180 @@ +/* + * Copyright 2013-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cassandra.test.integration.support; + +import java.io.InputStream; +import java.util.Properties; + +import org.springframework.core.convert.converter.Converter; +import org.springframework.util.Assert; + +/** + * Cassandra connection properties using {@code config/cassandra-connection.properties}. Properties are generated during + * the build and can be override using system properties. + * + * @author Mark Paluch + */ +@SuppressWarnings("serial") +public class CassandraConnectionProperties extends Properties { + + protected String resourceName = null; + + /** + * Creates a new {@link CassandraConnectionProperties} using properties from + * {@code config/cassandra-connection.properties}. + */ + public CassandraConnectionProperties() { + this("/config/cassandra-connection.properties"); + } + + protected CassandraConnectionProperties(String resourceName) { + this.resourceName = resourceName; + loadProperties(); + } + + private void loadProperties() { + loadProperties(resourceName); + putAll(System.getProperties()); + } + + private void loadProperties(String resourceName) { + InputStream in = null; + try { + in = getClass().getResourceAsStream(resourceName); + if (in == null) { + return; + } + load(in); + } catch (Exception x) { + throw new RuntimeException(x); + } finally { + if (in != null) { + try { + in.close(); + } catch (Exception e) { + // gulp + } + } + } + } + + /** + * @return the Cassandra port (native). + */ + public int getCassandraPort() { + return getInt("build.cassandra.native_transport_port"); + } + + /** + * @return the Cassandra RPC port + */ + public int getCassandraRpcPort() { + return getInt("build.cassandra.rpc_port"); + } + + /** + * @return the Cassandra Storage port + */ + public int getCassandraStoragePort() { + return getInt("build.cassandra.storage_port"); + } + + /** + * @return the Cassandra SSL Storage port + */ + public int getCassandraSslStoragePort() { + return getInt("build.cassandra.ssl_storage_port"); + } + + /** + * @return the Cassandra hostname + */ + public String getCassandraHost() { + return getProperty("build.cassandra.host"); + } + + /** + * @return the Cassandra type (Embedded or External) + */ + public CassandraType getCassandraType() { + + String property = getProperty("build.cassandra.mode"); + if (property != null && property.equalsIgnoreCase(CassandraType.EXTERNAL.name())) { + return CassandraType.EXTERNAL; + } + return CassandraType.EMBEDDED; + } + + /** + * Retrieve a property and return its value as {@code int}. + * + * @param propertyName name of the property, must not be empty and not {@literal null}. + * @return the property value + */ + public int getInt(String propertyName) { + return convert(propertyName, Integer.class, new Converter() { + public Integer convert(String value) { + return Integer.parseInt(value); + } + }); + } + + /** + * Retrieve a property and return its value as {@code long}. + * + * @param propertyName name of the property, must not be empty and not {@literal null}. + * @return the property value + */ + public long getLong(String propertyName) { + return convert(propertyName, Long.class, new Converter() { + public Long convert(String value) { + return Long.parseLong(value); + } + }); + } + + /** + * Retrieve a property and return its value as {@code boolean}. + * + * @param propertyName name of the property, must not be empty and not {@literal null}. + * @return the property value + */ + public boolean getBoolean(String propertyName) { + return convert(propertyName, Boolean.class, new Converter() { + public Boolean convert(String value) { + return Boolean.parseBoolean(value); + } + }); + } + + private T convert(String propertyName, Class type, Converter converter) { + + Assert.hasText(propertyName, "PropertyName must not be empty!"); + + String propertyValue = getProperty(propertyName); + try { + return converter.convert(propertyValue); + } catch (Exception e) { + throw new IllegalArgumentException(String.format("%1$s: cannot parse value [%2$s] of property [%3$s] as a [%4$s]", + resourceName, propertyValue, propertyName, type.getSimpleName()), e); + } + } + + public enum CassandraType { + EMBEDDED, EXTERNAL + + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/CqlDataSet.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/CqlDataSet.java new file mode 100644 index 000000000..1b6a1b67a --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/CqlDataSet.java @@ -0,0 +1,91 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cassandra.test.integration.support; + +import java.net.URL; +import java.nio.charset.Charset; +import java.util.List; + +import org.springframework.util.Assert; + +import com.google.common.io.Resources; + +import lombok.SneakyThrows; + +/** + * An executable CQL data set. The data set can be created from class path resources and execution can be bound to a + * particular keyspace. + * + * @author Mark Paluch + */ +public class CqlDataSet { + + private URL location = null; + private String keyspaceName = null; + + private CqlDataSet(URL location, String keyspaceName) { + this.location = location; + this.keyspaceName = keyspaceName; + } + + /** + * Obtain the {@link List} of statements to execute. + * + * @return + */ + public List getCqlStatements() { + return getLines(); + } + + @SneakyThrows + private List getLines() { + return Resources.readLines(location, Charset.defaultCharset()); + } + + /** + * Returns the optional keyspace name. + * + * @return + */ + public String getKeyspaceName() { + return keyspaceName; + } + + /** + * Bind the {@link CqlDataSet} to a particular keyspace. Creates a new instance of the {@link CqlDataSet} with the + * keyspace name set. + * + * @param keyspaceName + * @return + */ + public CqlDataSet executeIn(String keyspaceName) { + + Assert.hasText(keyspaceName, "KeyspaceName must not be empty!"); + return new CqlDataSet(location, keyspaceName); + } + + /** + * Create a {@link CqlDataSet} from a class-path resource. + * + * @param resource + * @return + */ + public static CqlDataSet fromClassPath(String resource) { + + URL url = Resources.getResource(resource); + return new CqlDataSet(url, null); + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/SpringCqlBuildProperties.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/SpringCqlBuildProperties.java deleted file mode 100644 index 384124736..000000000 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/support/SpringCqlBuildProperties.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2013-2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.cassandra.test.integration.support; - -import java.io.InputStream; -import java.util.Properties; - -@SuppressWarnings("serial") -public class SpringCqlBuildProperties extends Properties { - - protected String resourceName = null; - - public SpringCqlBuildProperties() { - this("/" + SpringCqlBuildProperties.class.getName() + ".properties"); - } - - protected SpringCqlBuildProperties(String resourceName) { - this.resourceName = resourceName; - - loadProperties(); - } - - public void loadProperties() { - loadProperties(resourceName); - } - - protected void loadProperties(String resourceName) { - InputStream in = null; - try { - in = getClass().getResourceAsStream(resourceName); - if (in == null) { - return; - } - load(in); - - } catch (Exception x) { - throw new RuntimeException(x); - - } finally { - if (in != null) { - try { - in.close(); - } catch (Exception e) { - // gulp - } - } - } - } - - public int getCassandraPort() { - return getInt("build.cassandra.native_transport_port"); - } - - public int getCassandraRpcPort() { - return getInt("build.cassandra.rpc_port"); - } - - public int getCassandraStoragePort() { - return getInt("build.cassandra.storage_port"); - } - - public int getCassandraSslStoragePort() { - return getInt("build.cassandra.ssl_storage_port"); - } - - public long getCqlInitializationTimeout() { - return getLong("build.cql.init.timeout"); - } - - public int getInt(String key) { - String property = getProperty(key); - return Integer.parseInt(property); - } - - public long getLong(String key) { - String property = getProperty(key); - return Long.parseLong(property); - } - - public boolean getBoolean(String key) { - return Boolean.parseBoolean(getProperty(key)); - } -} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/support/TestListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/support/TestListener.java deleted file mode 100644 index 2afd35d9f..000000000 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/support/TestListener.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.springframework.cassandra.test.unit.support; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -/** - * Convenient listener base class that includes a {@link CountDownLatch} in order to test asynchronous behavior. - * - * @author Matthew T. Adams - */ -public class TestListener { - - protected CountDownLatch latch; - - public TestListener() { - this(1); - } - - public TestListener(int latchCount) { - latch = new CountDownLatch(latchCount); - } - - public void await() throws InterruptedException { - latch.await(); - } - - public void await(long ms) throws InterruptedException { - latch.await(ms, TimeUnit.MILLISECONDS); - } - - public void countDown() { - latch.countDown(); - } -} diff --git a/spring-cql/src/test/resources/cassandraOperationsTest-cql-cleanup.cql b/spring-cql/src/test/resources/cassandraOperationsTest-cql-cleanup.cql new file mode 100644 index 000000000..20ec4e1d6 --- /dev/null +++ b/spring-cql/src/test/resources/cassandraOperationsTest-cql-cleanup.cql @@ -0,0 +1 @@ +DROP KEYSPACE CqlOperationsIntegrationTests; diff --git a/spring-cql/src/test/resources/cassandraOperationsTest-cql-dataload.cql b/spring-cql/src/test/resources/cassandraOperationsTest-cql-dataload.cql index 6bf20234b..e5c5195cb 100644 --- a/spring-cql/src/test/resources/cassandraOperationsTest-cql-dataload.cql +++ b/spring-cql/src/test/resources/cassandraOperationsTest-cql-dataload.cql @@ -1,3 +1,5 @@ create table if not exists book (isbn text, title text, author text, pages int, PRIMARY KEY (isbn)); create table if not exists book_alt (isbn text, title text, author text, pages int, PRIMARY KEY (isbn)); -insert into book (isbn, title, author, pages) values ('999999999', 'Book of Nines', 'Nine Nine', 999); \ No newline at end of file +truncate table book; +truncate table book_alt; +insert into book (isbn, title, author, pages) values ('999999999', 'Book of Nines', 'Nine Nine', 999); diff --git a/spring-cql/src/test/resources/org.springframework.cassandra.test.integration.support.SpringCqlBuildProperties.properties b/spring-cql/src/test/resources/config/cassandra-connection.properties similarity index 53% rename from spring-cql/src/test/resources/org.springframework.cassandra.test.integration.support.SpringCqlBuildProperties.properties rename to spring-cql/src/test/resources/config/cassandra-connection.properties index 67a67b8e5..be62cb0ef 100644 --- a/spring-cql/src/test/resources/org.springframework.cassandra.test.integration.support.SpringCqlBuildProperties.properties +++ b/spring-cql/src/test/resources/config/cassandra-connection.properties @@ -1,5 +1,8 @@ +# cassandra-connection.properties is needed twice because of enabled random port generation +# Generated ports are only valid for one module build.cassandra.native_transport_port=@build.cassandra.native_transport_port@ build.cassandra.rpc_port=@build.cassandra.rpc_port@ build.cassandra.storage_port=@build.cassandra.storage_port@ build.cassandra.ssl_storage_port=@build.cassandra.ssl_storage_port@ -build.cql.init.timeout=60000 +build.cassandra.mode=@build.cassandra.mode@ +build.cassandra.host=@build.cassandra.host@ diff --git a/spring-cql/src/test/resources/spring-cassandra.yaml b/spring-cql/src/test/resources/embedded-cassandra.yaml similarity index 100% rename from spring-cql/src/test/resources/spring-cassandra.yaml rename to spring-cql/src/test/resources/embedded-cassandra.yaml diff --git a/spring-cql/src/test/resources/integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest-After.cql b/spring-cql/src/test/resources/integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest-After.cql new file mode 100644 index 000000000..16e15d491 --- /dev/null +++ b/spring-cql/src/test/resources/integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest-After.cql @@ -0,0 +1 @@ +drop table if exists mytable; \ No newline at end of file diff --git a/spring-cql/src/test/resources/integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest.cql b/spring-cql/src/test/resources/integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest.cql index 5201c753c..0a3d8873e 100644 --- a/spring-cql/src/test/resources/integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest.cql +++ b/spring-cql/src/test/resources/integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest.cql @@ -1 +1 @@ -create table mytable (id uuid primary key, column1 text); \ No newline at end of file +create table if not exists mytable (id uuid primary key, column1 text); \ No newline at end of file diff --git a/spring-cql/src/test/resources/logback-test.xml b/spring-cql/src/test/resources/logback-test.xml deleted file mode 100644 index 2fdffd95c..000000000 --- a/spring-cql/src/test/resources/logback-test.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - %d %5p | %t | %-55logger{55} | %m | %n - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-cql/src/test/resources/logback.xml b/spring-cql/src/test/resources/logback.xml new file mode 100644 index 000000000..bcd2ae87e --- /dev/null +++ b/spring-cql/src/test/resources/logback.xml @@ -0,0 +1,29 @@ + + + + + + %d %5p | %t | %-55logger{55} | %m | %n + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest-context.xml b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests-context.xml similarity index 79% rename from spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest-context.xml rename to spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests-context.xml index ce94f1a7c..047b3587f 100644 --- a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest-context.xml +++ b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests-context.xml @@ -8,7 +8,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + location="classpath:/config/cassandra-connection.properties,classpath:/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests.properties" /> diff --git a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests.properties b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests.properties new file mode 100644 index 000000000..905a30b2c --- /dev/null +++ b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests.properties @@ -0,0 +1 @@ +script2=CREATE KEYSPACE IF NOT EXISTS script2 WITH durable_writes = true AND replication = { 'replication_factor' : 1, 'class' : 'SimpleStrategy' }; diff --git a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest.properties b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest.properties deleted file mode 100644 index a5049296f..000000000 --- a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest.properties +++ /dev/null @@ -1 +0,0 @@ -script2=CREATE KEYSPACE script2 WITH durable_writes = true AND replication = { 'replication_factor' : 1, 'class' : 'SimpleStrategy' }; diff --git a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/MinimalKeyspaceCreatingXmlConfigTest-context.xml b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/MinimalKeyspaceCreatingXmlConfigIntegrationTests-context.xml similarity index 87% rename from spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/MinimalKeyspaceCreatingXmlConfigTest-context.xml rename to spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/MinimalKeyspaceCreatingXmlConfigIntegrationTests-context.xml index 2ab887bbc..974d17a69 100644 --- a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/MinimalKeyspaceCreatingXmlConfigTest-context.xml +++ b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/MinimalKeyspaceCreatingXmlConfigIntegrationTests-context.xml @@ -8,7 +8,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + location="classpath:/config/cassandra-connection.properties" /> diff --git a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigTest-context.xml b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigIntegrationTests-context.xml similarity index 87% rename from spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigTest-context.xml rename to spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigIntegrationTests-context.xml index 44196aef5..5878c2bfc 100644 --- a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigTest-context.xml +++ b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigIntegrationTests-context.xml @@ -7,7 +7,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + location="classpath:/config/cassandra-connection.properties" /> diff --git a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigTest-context.xml b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests-context.xml similarity index 100% rename from spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigTest-context.xml rename to spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests-context.xml diff --git a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest-context.xml b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/XmlConfigIntegrationTests-context.xml similarity index 93% rename from spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest-context.xml rename to spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/XmlConfigIntegrationTests-context.xml index 7893eb4db..58b3b398a 100644 --- a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest-context.xml +++ b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/XmlConfigIntegrationTests-context.xml @@ -7,7 +7,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + location="classpath:/config/cassandra-connection.properties" /> diff --git a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/ppncxct.properties b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/ppncxct.properties index acde6caf6..ee21af18d 100644 --- a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/ppncxct.properties +++ b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/ppncxct.properties @@ -6,7 +6,7 @@ cluster.jmxReportingEnabled=false cluster.reconnection.delayMillis=5000 cluster.sslEnabled= true keyspace.name=ppncxct -keyspace.action=CREATE +keyspace.action=CREATE_DROP dc1.name=DCJAX dc1.rf=2 dc2.name=DCCTL diff --git a/spring-data-cassandra/pom.xml b/spring-data-cassandra/pom.xml index c109fb265..9a6dce992 100644 --- a/spring-data-cassandra/pom.xml +++ b/spring-data-cassandra/pom.xml @@ -71,18 +71,6 @@ test - - org.cassandraunit - cassandra-unit-spring - test - - - slf4j-log4j12 - org.slf4j - - - - org.apache.cassandra cassandra-all @@ -90,8 +78,8 @@ test - slf4j-log4j12 - org.slf4j + ch.qos.logback + logback-core guava @@ -118,12 +106,6 @@ test - - org.hectorclient - hector-core - test - - javax.validation @@ -164,5 +146,4 @@ test - diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/convert/ColumnReaderTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/ColumnReaderUnitTests.java similarity index 69% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/convert/ColumnReaderTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/ColumnReaderUnitTests.java index 4b55f7bad..4099d0fdd 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/convert/ColumnReaderTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/ColumnReaderUnitTests.java @@ -1,29 +1,47 @@ -package org.springframework.data.cassandra.test.unit.convert; +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.cassandra.convert; + +import static org.junit.Assert.*; +import static org.mockito.BDDMockito.*; -import com.datastax.driver.core.ColumnDefinitions; -import com.datastax.driver.core.Row; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.cassandra.core.cql.CqlIdentifier; -import org.springframework.data.cassandra.convert.ColumnReader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.BDDMockito.given; +import com.datastax.driver.core.ColumnDefinitions; +import com.datastax.driver.core.Row; +/** + * Unit tests for {@link ColumnReader}. + * + * @author Christopher Batey + */ @RunWith(MockitoJUnitRunner.class) -public class ColumnReaderTest { +public class ColumnReaderUnitTests { public static final String NON_EXISTENT_COLUMN = "column_name"; - @Mock - private Row row; + @Mock private Row row; - @Mock - private ColumnDefinitions columnDefinitions; + @Mock private ColumnDefinitions columnDefinitions; private ColumnReader underTest; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/convert/MappingCassandraConverterTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/MappingCassandraConverterUnitTests.java similarity index 90% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/convert/MappingCassandraConverterTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/MappingCassandraConverterUnitTests.java index d567d0ce7..2d9ae4464 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/convert/MappingCassandraConverterTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/MappingCassandraConverterUnitTests.java @@ -14,10 +14,11 @@ * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.convert; +package org.springframework.data.cassandra.convert; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; +import static org.junit.Assume.*; import java.io.Serializable; import java.util.ArrayList; @@ -27,8 +28,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.cassandra.core.PrimaryKeyType; +import org.springframework.core.SpringVersion; import org.springframework.core.convert.ConverterNotFoundException; -import org.springframework.data.cassandra.convert.MappingCassandraConverter; import org.springframework.data.cassandra.mapping.CassandraType; import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.PrimaryKeyClass; @@ -47,12 +48,12 @@ import com.datastax.driver.core.querybuilder.Update; import com.datastax.driver.core.querybuilder.Update.Assignments; /** - * Tests for {@link MappingCassandraConverter}. - * + * Unit tests for {@link MappingCassandraConverter}. + * * @author Mark Paluch * @soundtrack Outlandich - Dont Leave Me Feat Cyt (Sun Kidz Electrocore Mix) */ -public class MappingCassandraConverterTests { +public class MappingCassandraConverterUnitTests { @Rule public final ExpectedException expectedException = ExpectedException.none(); @@ -78,7 +79,9 @@ public class MappingCassandraConverterTests { * @see DATACASS-260 */ @Test - public void insertEnumDoesNotMapToOrdinal() { + public void insertEnumDoesNotMapToOrdinalBeforeSpring43() { + + assumeThat(SpringVersion.getVersion(), not(startsWith("4.3"))); expectedException.expect(ConverterNotFoundException.class); expectedException.expectMessage(allOf(containsString("No converter found"), containsString("java.lang.Integer"))); @@ -91,6 +94,24 @@ public class MappingCassandraConverterTests { mappingCassandraConverter.write(unsupportedEnumToOrdinalMapping, insert); } + /** + * @see DATACASS-255 + */ + @Test + public void insertEnumMapsToOrdinalWithSpring43() { + + assumeThat(SpringVersion.getVersion(), startsWith("4.3")); + + UnsupportedEnumToOrdinalMapping unsupportedEnumToOrdinalMapping = new UnsupportedEnumToOrdinalMapping(); + unsupportedEnumToOrdinalMapping.setAsOrdinal(Condition.USED); + + Insert insert = QueryBuilder.insertInto("table"); + + mappingCassandraConverter.write(unsupportedEnumToOrdinalMapping, insert); + + assertThat(getValues(insert), contains((Object) Integer.valueOf(Condition.USED.ordinal()))); + } + /** * @see DATACASS-260 */ diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityVerifierIntegrationTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntityMetadataVerifierUnitTests.java similarity index 71% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityVerifierIntegrationTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntityMetadataVerifierUnitTests.java index 6fdaebf0a..a1034c20c 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityVerifierIntegrationTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntityMetadataVerifierUnitTests.java @@ -1,19 +1,19 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.mapping; +package org.springframework.data.cassandra.mapping; import static org.junit.Assert.*; @@ -21,81 +21,69 @@ import java.io.Serializable; import org.junit.Before; import org.junit.Test; +import org.slf4j.LoggerFactory; import org.springframework.cassandra.core.Ordering; import org.springframework.cassandra.core.PrimaryKeyType; import org.springframework.data.annotation.Id; -import org.springframework.data.cassandra.mapping.CassandraMappingContext; -import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; -import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext; -import org.springframework.data.cassandra.mapping.PrimaryKey; -import org.springframework.data.cassandra.mapping.PrimaryKeyClass; -import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.mapping.model.MappingException; -/** - * @author dwebb - */ -public class BasicCassandraPersistentEntityVerifierIntegrationTest { +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.LoggerContext; - CassandraMappingContext mappingContext; +/** + * Unit tests for {@link org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntityMetadataVerifier} + * through {@link CassandraMappingContext} + * + * @author David Webb + * @author Mark Paluch + */ +public class BasicCassandraPersistentEntityMetadataVerifierUnitTests { + + private static LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); + private Logger logger = loggerContext.getLogger(BasicCassandraPersistentEntityMetadataVerifier.class); + private CassandraMappingContext mappingContext; @Before - public void init() { - + public void setUp() { mappingContext = new BasicCassandraMappingContext(); - } @Test(expected = MappingException.class) public void testNonPersistentType() { - mappingContext.getPersistentEntity(NonPersistentClass.class); - } @Test(expected = MappingException.class) public void testTooManyAnnotations() { - mappingContext.getPersistentEntity(TooManyAnnotations.class); - } @Test public void testNonPrimaryKeyClass() { - mappingContext.getPersistentEntity(Person.class); } @Test(expected = MappingException.class) public void testPrimaryKeyClassNotFullyImplemented() { - mappingContext.getPersistentEntity(AnimalPkNoOverrides.class); - } @Test public void testPrimaryKeyClass() { mappingContext.getPersistentEntity(AnimalPK.class); - mappingContext.getPersistentEntity(Animal.class); - } @Test(expected = MappingException.class) public void testNoPartitionKey() { - mappingContext.getPersistentEntity(NoPartitionKey.class); - } @Test(expected = MappingException.class) public void testPkAndPkc() { - mappingContext.getPersistentEntity(PkAndPkc.class); - } @Test @@ -116,8 +104,7 @@ public class BasicCassandraPersistentEntityVerifierIntegrationTest { static class NonPersistentClass { - @Id - private String id; + @Id private String id; private String foo; private String bar; @@ -127,8 +114,7 @@ public class BasicCassandraPersistentEntityVerifierIntegrationTest { @Table static class Person { - @Id - private String id; + @Id private String id; private String firstName; private String lastName; @@ -138,9 +124,7 @@ public class BasicCassandraPersistentEntityVerifierIntegrationTest { @Table static class Animal { - @PrimaryKey - private AnimalPK key; - + @PrimaryKey AnimalPK key; private String name; } @@ -157,28 +141,18 @@ public class BasicCassandraPersistentEntityVerifierIntegrationTest { return super.equals(obj); } - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private String species; - - @PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.PARTITIONED) - private String breed; - - @PrimaryKeyColumn(ordinal = 2, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.DESCENDING) - private String color; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) String species; + @PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.PARTITIONED) String breed; + @PrimaryKeyColumn(ordinal = 2, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.DESCENDING) String color; } @PrimaryKeyClass static class AnimalPkNoOverrides { - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private String species; - - @PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.PARTITIONED) - private String breed; - - @PrimaryKeyColumn(ordinal = 2, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.DESCENDING) - private String color; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) String species; + @PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.PARTITIONED) String breed; + @PrimaryKeyColumn(ordinal = 2, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.DESCENDING) String color; } @Table @@ -188,34 +162,26 @@ public class BasicCassandraPersistentEntityVerifierIntegrationTest { @Table public static class NoPartitionKey { - @PrimaryKeyColumn(ordinal = 0) - String key; + @PrimaryKeyColumn(ordinal = 0) String key; } @Table public static class PkAndPkc { - @PrimaryKey - String primaryKey; - - @PrimaryKeyColumn(ordinal = 0) - String primaryKeyColumn; + @PrimaryKey String primaryKey; + @PrimaryKeyColumn(ordinal = 0) String primaryKeyColumn; } @Table public static class OnePkc { - @PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED, ordinal = 0) - String pk; + @PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED, ordinal = 0) String pk; } @Table public static class MultiPkc { - @PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED, ordinal = 0) - String pk0; - - @PrimaryKeyColumn(ordinal = 1) - String pk1; + @PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED, ordinal = 0) String pk0; + @PrimaryKeyColumn(ordinal = 1) String pk1; } } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/BasicCassandraPersistentEntityOrderPropertiesTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntityOrderPropertiesUnitTests.java similarity index 79% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/BasicCassandraPersistentEntityOrderPropertiesTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntityOrderPropertiesUnitTests.java index 782d308bc..d3f25395a 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/BasicCassandraPersistentEntityOrderPropertiesTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntityOrderPropertiesUnitTests.java @@ -1,21 +1,21 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.unit; +package org.springframework.data.cassandra.mapping; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import java.io.Serializable; import java.util.LinkedList; @@ -25,19 +25,14 @@ import org.junit.Before; import org.junit.Test; import org.springframework.cassandra.core.PrimaryKeyType; import org.springframework.data.annotation.Id; -import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; -import org.springframework.data.cassandra.mapping.CassandraPersistentProperty; -import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext; -import org.springframework.data.cassandra.mapping.PrimaryKey; -import org.springframework.data.cassandra.mapping.PrimaryKeyClass; -import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.mapping.PropertyHandler; /** + * Unit tests for {@link BasicCassandraMappingContext}. + * * @author David Webb */ -public class BasicCassandraPersistentEntityOrderPropertiesTest { +public class BasicCassandraPersistentEntityOrderPropertiesUnitTests { private List expected; private BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext(); @@ -96,8 +91,7 @@ public class BasicCassandraPersistentEntityOrderPropertiesTest { @Table static class CompositeKeyEntity { - @PrimaryKey - private CompositePK key; + @PrimaryKey private CompositePK key; private String attribute; @@ -111,14 +105,11 @@ public class BasicCassandraPersistentEntityOrderPropertiesTest { @PrimaryKeyClass static class CompositePK implements Serializable { - @PrimaryKeyColumn(ordinal = 2, type = PrimaryKeyType.PARTITIONED) - private String key0; + @PrimaryKeyColumn(ordinal = 2, type = PrimaryKeyType.PARTITIONED) private String key0; - @PrimaryKeyColumn(ordinal = 0) - private String key1; + @PrimaryKeyColumn(ordinal = 0) private String key1; - @PrimaryKeyColumn(ordinal = 1) - private String key2; + @PrimaryKeyColumn(ordinal = 1) private String key2; @Override public int hashCode() { @@ -162,8 +153,7 @@ public class BasicCassandraPersistentEntityOrderPropertiesTest { @Table static class SimpleKeyEntity { - @Id - private String id; + @Id private String id; } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntityUnitTests.java similarity index 78% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntityUnitTests.java index 28df7b5dc..83306656b 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntityUnitTests.java @@ -1,44 +1,41 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.mapping; +package org.springframework.data.cassandra.mapping; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.when; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.context.ApplicationContext; -import org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntity; -import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.util.ClassTypeInformation; /** - * Integration tests for {@link BasicCassandraPersistentEntity}. - * + * Unit tests for {@link BasicCassandraPersistentEntity}. + * * @author Alex Shvid * @author Matthew T. Adams */ @RunWith(MockitoJUnitRunner.class) -public class BasicCassandraPersistentEntityIntegrationTests { +public class BasicCassandraPersistentEntityUnitTests { - @Mock - ApplicationContext context; + @Mock ApplicationContext context; @Test public void subclassInheritsAtDocumentAnnotation() { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentPropertyIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentPropertyUnitTests.java similarity index 63% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentPropertyIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentPropertyUnitTests.java index 18fb9df40..8be596e08 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentPropertyIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentPropertyUnitTests.java @@ -1,55 +1,45 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.mapping; +package org.springframework.data.cassandra.mapping; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; import java.lang.reflect.Field; import java.util.Date; import org.junit.Before; import org.junit.Test; -import org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntity; -import org.springframework.data.cassandra.mapping.BasicCassandraPersistentProperty; -import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; -import org.springframework.data.cassandra.mapping.CassandraPersistentProperty; -import org.springframework.data.cassandra.mapping.CassandraSimpleTypeHolder; -import org.springframework.data.cassandra.mapping.Column; -import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.util.ClassTypeInformation; import org.springframework.util.ReflectionUtils; /** - * Integration test for {@link BasicCassandraPersistentProperty}. - * + * Unit tests for {@link BasicCassandraPersistentProperty}. + * * @author Alex Shvid */ -public class BasicCassandraPersistentPropertyIntegrationTests { +public class BasicCassandraPersistentPropertyUnitTests { static class Timeline { - @PrimaryKey - String id; + @PrimaryKey String id; Date time; - @Column("message") - String text; + @Column("message") String text; } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CassandraCompositePrimaryKeyIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CassandraCompositePrimaryKeyUnitTests.java similarity index 76% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CassandraCompositePrimaryKeyIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CassandraCompositePrimaryKeyUnitTests.java index 23892b034..1a3107852 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CassandraCompositePrimaryKeyIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CassandraCompositePrimaryKeyUnitTests.java @@ -1,23 +1,22 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.mapping; +package org.springframework.data.cassandra.mapping; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.springframework.cassandra.core.cql.CqlIdentifier.cqlId; +import static org.junit.Assert.*; +import static org.springframework.cassandra.core.cql.CqlIdentifier.*; import java.io.Serializable; import java.lang.reflect.Field; @@ -32,28 +31,17 @@ import org.springframework.cassandra.core.PrimaryKeyType; import org.springframework.cassandra.core.cql.CqlIdentifier; import org.springframework.cassandra.core.keyspace.ColumnSpecification; import org.springframework.cassandra.core.keyspace.CreateTableSpecification; -import org.springframework.data.cassandra.mapping.BasicCassandraPersistentProperty; -import org.springframework.data.cassandra.mapping.CassandraMappingContext; -import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; -import org.springframework.data.cassandra.mapping.CassandraPersistentProperty; -import org.springframework.data.cassandra.mapping.CassandraSimpleTypeHolder; -import org.springframework.data.cassandra.mapping.Column; -import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext; -import org.springframework.data.cassandra.mapping.PrimaryKey; -import org.springframework.data.cassandra.mapping.PrimaryKeyClass; -import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.util.ClassTypeInformation; import org.springframework.util.ReflectionUtils; import com.datastax.driver.core.DataType; /** - * Integration test for {@link BasicCassandraPersistentProperty} with a composite primary key class. - * + * Unit tests for {@link BasicCassandraPersistentProperty} with a composite primary key class. + * * @author Matthew T. Adams */ -public class CassandraCompositePrimaryKeyIntegrationTests { +public class CassandraCompositePrimaryKeyUnitTests { private static final CassandraSimpleTypeHolder SIMPLE_TYPE_HOLDER = new CassandraSimpleTypeHolder(); @@ -62,11 +50,9 @@ public class CassandraCompositePrimaryKeyIntegrationTests { private static final long serialVersionUID = 1L; - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - String z; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) String z; - @PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.CLUSTERED) - String a; + @PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.CLUSTERED) String a; @Override public int hashCode() { @@ -104,13 +90,11 @@ public class CassandraCompositePrimaryKeyIntegrationTests { @Table static class Thing { - @PrimaryKey - Key id; + @PrimaryKey Key id; Date time; - @Column("message") - String text; + @Column("message") String text; } CassandraMappingContext context; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CompoundPrimaryKeyIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CompoundPrimaryKeyUnitTests.java similarity index 60% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CompoundPrimaryKeyIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CompoundPrimaryKeyUnitTests.java index 83474fadd..1e1d23a7e 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CompoundPrimaryKeyIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CompoundPrimaryKeyUnitTests.java @@ -1,21 +1,21 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.mapping; +package org.springframework.data.cassandra.mapping; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.lang.reflect.Field; import java.util.Date; @@ -23,44 +23,30 @@ import java.util.Date; import org.junit.Before; import org.junit.Test; import org.springframework.cassandra.core.PrimaryKeyType; -import org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntity; -import org.springframework.data.cassandra.mapping.BasicCassandraPersistentProperty; -import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; -import org.springframework.data.cassandra.mapping.CassandraPersistentProperty; -import org.springframework.data.cassandra.mapping.CassandraSimpleTypeHolder; -import org.springframework.data.cassandra.mapping.Column; -import org.springframework.data.cassandra.mapping.PrimaryKey; -import org.springframework.data.cassandra.mapping.PrimaryKeyClass; -import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.util.ClassTypeInformation; import org.springframework.util.ReflectionUtils; /** - * Integration test for {@link BasicCassandraPersistentProperty}. - * + * Unit tests for {@link BasicCassandraPersistentProperty}. + * * @author Alex Shvid * @author Matthew T. Adams */ -public class CompoundPrimaryKeyIntegrationTests { +public class CompoundPrimaryKeyUnitTests { @PrimaryKeyClass static class TimelineKey { - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - String string; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) String string; - @PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.PARTITIONED) - Date datetime; + @PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.PARTITIONED) Date datetime; } @Table static class Timeline { - @PrimaryKey - TimelineKey id; + @PrimaryKey TimelineKey id; - @Column("message") - String text; + @Column("message") String text; } CassandraPersistentEntity cpk; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedEntitiesSimpleIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/ForceQuotedEntitiesSimpleUnitTests.java similarity index 67% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedEntitiesSimpleIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/ForceQuotedEntitiesSimpleUnitTests.java index 8e53081ed..e8ae3518f 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedEntitiesSimpleIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/ForceQuotedEntitiesSimpleUnitTests.java @@ -1,13 +1,32 @@ -package org.springframework.data.cassandra.test.integration.forcequote.simple; +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import static org.junit.Assert.assertEquals; +package org.springframework.data.cassandra.mapping; + +import static org.junit.Assert.*; import org.junit.Test; -import org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntity; -import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.util.ClassTypeInformation; -public class ForceQuotedEntitiesSimpleIntegrationTests { +/** + * Unit tests for {@link BasicCassandraPersistentEntity}. + * + * @author Matthew T. Adams + */ +public class ForceQuotedEntitiesSimpleUnitTests { @Test public void testImplicitTableNameForceQuoted() { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedPropertiesSimpleIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/ForceQuotedPropertiesSimpleUnitTests.java similarity index 73% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedPropertiesSimpleIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/ForceQuotedPropertiesSimpleUnitTests.java index 8269eaf2f..c91e42ed1 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedPropertiesSimpleIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/ForceQuotedPropertiesSimpleUnitTests.java @@ -1,9 +1,23 @@ -package org.springframework.data.cassandra.test.integration.forcequote.simple; +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.springframework.cassandra.core.cql.CqlIdentifier.cqlId; -import static org.springframework.cassandra.core.cql.CqlIdentifier.quotedCqlId; +package org.springframework.data.cassandra.mapping; + +import static org.junit.Assert.*; +import static org.springframework.cassandra.core.cql.CqlIdentifier.*; import java.io.Serializable; import java.util.Arrays; @@ -12,17 +26,18 @@ import java.util.List; import org.junit.Test; import org.springframework.cassandra.core.PrimaryKeyType; import org.springframework.cassandra.core.cql.CqlIdentifier; -import org.springframework.data.cassandra.mapping.CassandraMappingContext; -import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; -import org.springframework.data.cassandra.mapping.CassandraPersistentProperty; -import org.springframework.data.cassandra.mapping.Column; -import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext; -import org.springframework.data.cassandra.mapping.PrimaryKey; -import org.springframework.data.cassandra.mapping.PrimaryKeyClass; -import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.mapping.Table; -public class ForceQuotedPropertiesSimpleIntegrationTests { +/** + * Unit tests for {@link BasicCassandraMappingContext}. + * + * @author Matthew T. Adams + */ +public class ForceQuotedPropertiesSimpleUnitTests { + + public static final String EXPLICIT_PRIMARY_KEY_NAME = "ThePrimaryKey"; + public static final String EXPLICIT_COLUMN_NAME = "AnotherColumn"; + public static final String EXPLICIT_KEY_0 = "TheFirstKeyField"; + public static final String EXPLICIT_KEY_1 = "TheSecondKeyField"; CassandraMappingContext context = new BasicCassandraMappingContext(); @@ -40,11 +55,9 @@ public class ForceQuotedPropertiesSimpleIntegrationTests { @Table public static class Implicit { - @PrimaryKey(forceQuote = true) - String primaryKey; + @PrimaryKey(forceQuote = true) String primaryKey; - @Column(forceQuote = true) - String aString; + @Column(forceQuote = true) String aString; } @Test @@ -61,16 +74,11 @@ public class ForceQuotedPropertiesSimpleIntegrationTests { @Table public static class Default { - @PrimaryKey - String primaryKey; + @PrimaryKey String primaryKey; - @Column - String aString; + @Column String aString; } - public static final String EXPLICIT_PRIMARY_KEY_NAME = "ThePrimaryKey"; - public static final String EXPLICIT_COLUMN_NAME = "AnotherColumn"; - @Test public void testExplicit() { CassandraPersistentEntity entity = context.getPersistentEntity(Explicit.class); @@ -85,11 +93,9 @@ public class ForceQuotedPropertiesSimpleIntegrationTests { @Table public static class Explicit { - @PrimaryKey(value = EXPLICIT_PRIMARY_KEY_NAME, forceQuote = true) - String primaryKey; + @PrimaryKey(value = EXPLICIT_PRIMARY_KEY_NAME, forceQuote = true) String primaryKey; - @Column(value = EXPLICIT_COLUMN_NAME, forceQuote = true) - String aString; + @Column(value = EXPLICIT_COLUMN_NAME, forceQuote = true) String aString; } @Test @@ -114,21 +120,17 @@ public class ForceQuotedPropertiesSimpleIntegrationTests { private static final long serialVersionUID = -1956747638065267667L; - @PrimaryKeyColumn(ordinal = 0, forceQuote = true, type = PrimaryKeyType.PARTITIONED) - String stringZero; + @PrimaryKeyColumn(ordinal = 0, forceQuote = true, type = PrimaryKeyType.PARTITIONED) String stringZero; - @PrimaryKeyColumn(ordinal = 1, forceQuote = true) - String stringOne; + @PrimaryKeyColumn(ordinal = 1, forceQuote = true) String stringOne; } @Table public static class ImplicitComposite { - @PrimaryKey(forceQuote = true) - ImplicitKey primaryKey; + @PrimaryKey(forceQuote = true) ImplicitKey primaryKey; - @Column(forceQuote = true) - String aString; + @Column(forceQuote = true) String aString; } @Test @@ -154,26 +156,19 @@ public class ForceQuotedPropertiesSimpleIntegrationTests { private static final long serialVersionUID = -1956747638065267667L; - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - String stringZero; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) String stringZero; - @PrimaryKeyColumn(ordinal = 1) - String stringOne; + @PrimaryKeyColumn(ordinal = 1) String stringOne; } @Table public static class DefaultComposite { - @PrimaryKey - DefaultKey primaryKey; + @PrimaryKey DefaultKey primaryKey; - @Column - String aString; + @Column String aString; } - public static final String EXPLICIT_KEY_0 = "TheFirstKeyField"; - public static final String EXPLICIT_KEY_1 = "TheSecondKeyField"; - @Test public void testExplicitComposite() { CassandraPersistentEntity key = context.getPersistentEntity(ExplicitKey.class); @@ -184,8 +179,8 @@ public class ForceQuotedPropertiesSimpleIntegrationTests { assertEquals("\"" + EXPLICIT_KEY_0 + "\"", stringZero.getColumnName().toCql()); assertEquals("\"" + EXPLICIT_KEY_1 + "\"", stringOne.getColumnName().toCql()); - List names = Arrays.asList(new CqlIdentifier[] { quotedCqlId(EXPLICIT_KEY_0), - quotedCqlId(EXPLICIT_KEY_1) }); + List names = Arrays + .asList(new CqlIdentifier[] { quotedCqlId(EXPLICIT_KEY_0), quotedCqlId(EXPLICIT_KEY_1) }); CassandraPersistentEntity entity = context.getPersistentEntity(ExplicitComposite.class); assertEquals(names, entity.getPersistentProperty("primaryKey").getColumnNames()); @@ -196,20 +191,17 @@ public class ForceQuotedPropertiesSimpleIntegrationTests { private static final long serialVersionUID = -1956747638065267667L; - @PrimaryKeyColumn(ordinal = 0, name = EXPLICIT_KEY_0, forceQuote = true, type = PrimaryKeyType.PARTITIONED) - String stringZero; + @PrimaryKeyColumn(ordinal = 0, name = EXPLICIT_KEY_0, forceQuote = true, + type = PrimaryKeyType.PARTITIONED) String stringZero; - @PrimaryKeyColumn(ordinal = 1, name = EXPLICIT_KEY_1, forceQuote = true) - String stringOne; + @PrimaryKeyColumn(ordinal = 1, name = EXPLICIT_KEY_1, forceQuote = true) String stringOne; } @Table public static class ExplicitComposite { - @PrimaryKey(forceQuote = true) - ExplicitKey primaryKey; + @PrimaryKey(forceQuote = true) ExplicitKey primaryKey; - @Column(forceQuote = true) - String aString; + @Column(forceQuote = true) String aString; } } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mappingcontext/MappingContextIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/MappingContextIntegrationUnitTests.java similarity index 63% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mappingcontext/MappingContextIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/MappingContextIntegrationUnitTests.java index 2f201544a..3128b2c07 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mappingcontext/MappingContextIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/MappingContextIntegrationUnitTests.java @@ -1,45 +1,42 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.mappingcontext; +package org.springframework.data.cassandra.mapping; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import org.junit.Test; -import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; -import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext; -import org.springframework.data.cassandra.mapping.PrimaryKey; -import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.mapping.model.MappingException; -public class MappingContextIntegrationTests { +/** + * Unit tests for {@link BasicCassandraMappingContext}. + * + * @author Matthew T. Adams + */ +public class MappingContextIntegrationUnitTests { public static class Transient {} @Table public static class X { - @PrimaryKey - String key; + @PrimaryKey String key; } @Table public static class Y { - @PrimaryKey - String key; + @PrimaryKey String key; } BasicCassandraMappingContext ctx = new BasicCassandraMappingContext(); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/MultipackageScanningIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/MultipackageScanningUnitTests.java similarity index 72% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/MultipackageScanningIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/MultipackageScanningUnitTests.java index d370ce991..1beea2194 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/MultipackageScanningIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/MultipackageScanningUnitTests.java @@ -1,22 +1,21 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.multipackagescanning; +package org.springframework.data.cassandra.mapping.multipackagescanning; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.Collection; import java.util.HashSet; @@ -24,13 +23,18 @@ import java.util.HashSet; import org.junit.Before; import org.junit.Test; import org.springframework.data.cassandra.config.CassandraEntityClassScanner; -import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext; -import org.springframework.data.cassandra.test.integration.multipackagescanning.first.First; -import org.springframework.data.cassandra.test.integration.multipackagescanning.second.Second; -import org.springframework.data.cassandra.test.integration.multipackagescanning.third.Third; +import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; +import org.springframework.data.cassandra.mapping.multipackagescanning.first.First; +import org.springframework.data.cassandra.mapping.multipackagescanning.second.Second; +import org.springframework.data.cassandra.mapping.multipackagescanning.third.Third; -public class MultipackageScanningIntegrationTests { +/** + * Unit tests for {@link BasicCassandraMappingContext}. + * + * @author Matthew T. Adams + */ +public class MultipackageScanningUnitTests { BasicCassandraMappingContext mapping; String pkg = getClass().getPackage().getName(); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/Top.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/Top.java similarity index 74% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/Top.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/Top.java index 0a6f09a16..0d721b541 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/Top.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/Top.java @@ -1,19 +1,19 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.multipackagescanning; +package org.springframework.data.cassandra.mapping.multipackagescanning; import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.Table; @@ -21,6 +21,5 @@ import org.springframework.data.cassandra.mapping.Table; @Table public class Top { - @PrimaryKey - String key; + @PrimaryKey String key; } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/first/First.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/first/First.java similarity index 85% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/first/First.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/first/First.java index 237de0b0f..75c2282f7 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/first/First.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/first/First.java @@ -1,19 +1,19 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.multipackagescanning.first; +package org.springframework.data.cassandra.mapping.multipackagescanning.first; import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.Table; @@ -21,6 +21,5 @@ import org.springframework.data.cassandra.mapping.Table; @Table public class First { - @PrimaryKey - String key; + @PrimaryKey String key; } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/second/Second.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/second/Second.java similarity index 85% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/second/Second.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/second/Second.java index 6fb615ce7..8349ae153 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/second/Second.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/second/Second.java @@ -1,19 +1,19 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.multipackagescanning.second; +package org.springframework.data.cassandra.mapping.multipackagescanning.second; import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.Table; @@ -21,6 +21,5 @@ import org.springframework.data.cassandra.mapping.Table; @Table public class Second { - @PrimaryKey - String key; + @PrimaryKey String key; } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/third/Third.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/third/Third.java similarity index 85% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/third/Third.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/third/Third.java index 60768176c..0e7062b06 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/multipackagescanning/third/Third.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/multipackagescanning/third/Third.java @@ -1,19 +1,19 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.multipackagescanning.third; +package org.springframework.data.cassandra.mapping.multipackagescanning.third; import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.Table; @@ -21,6 +21,5 @@ import org.springframework.data.cassandra.mapping.Table; @Table public class Third { - @PrimaryKey - String key; + @PrimaryKey String key; } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/repository/config/CassandraRepositoryConfigurationExtensionUnitTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/config/CassandraRepositoryConfigurationExtensionUnitTests.java similarity index 93% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/repository/config/CassandraRepositoryConfigurationExtensionUnitTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/config/CassandraRepositoryConfigurationExtensionUnitTests.java index 5e5cc4bbf..44ebc7a68 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/repository/config/CassandraRepositoryConfigurationExtensionUnitTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/config/CassandraRepositoryConfigurationExtensionUnitTests.java @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.unit.repository.config; + +package org.springframework.data.cassandra.repository.config; import static org.junit.Assert.*; @@ -28,14 +29,14 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.type.StandardAnnotationMetadata; import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.cassandra.repository.CassandraRepository; -import org.springframework.data.cassandra.repository.config.CassandraRepositoryConfigurationExtension; -import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; import org.springframework.data.repository.Repository; import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource; import org.springframework.data.repository.config.RepositoryConfiguration; import org.springframework.data.repository.config.RepositoryConfigurationSource; /** + * Unit tests for {@link CassandraRepositoryConfigurationExtension}. + * * @author Christoph Strobl */ public class CassandraRepositoryConfigurationExtensionUnitTests { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/BasicMapIdUnitTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/BasicMapIdUnitTests.java new file mode 100644 index 000000000..fe01548f5 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/BasicMapIdUnitTests.java @@ -0,0 +1,44 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.cassandra.repository.support; + +import static org.junit.Assert.*; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +/** + * Unit tests for {@link BasicMapId}. + * + * @author Matthew T. Adams + */ +public class BasicMapIdUnitTests { + @Test + public void testMapConstructor() { + Map map = new HashMap(); + map.put("field1", "value1"); + map.put("field2", 2); + + BasicMapId basicMapId = new BasicMapId(map); + + assertEquals(basicMapId.get("field1"), map.get("field1")); + assertEquals(basicMapId.get("field2"), map.get("field2")); + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/mapidfactory/MapIdFactoryTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/MapIdFactoryUnitTests.java similarity index 87% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/mapidfactory/MapIdFactoryTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/MapIdFactoryUnitTests.java index 0d199fe19..cbd82d8a4 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/mapidfactory/MapIdFactoryTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/MapIdFactoryUnitTests.java @@ -1,21 +1,37 @@ -package org.springframework.data.cassandra.test.unit.mapidfactory; +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.springframework.data.cassandra.repository.support.IdInterfaceValidator.validate; -import static org.springframework.data.cassandra.repository.support.MapIdFactory.id; +package org.springframework.data.cassandra.repository.support; + +import static org.junit.Assert.*; +import static org.springframework.data.cassandra.repository.support.IdInterfaceValidator.*; +import static org.springframework.data.cassandra.repository.support.MapIdFactory.*; import java.io.Serializable; import java.util.Random; import org.junit.Test; import org.springframework.data.cassandra.repository.MapId; -import org.springframework.data.cassandra.repository.support.IdInterfaceExceptions; -public class MapIdFactoryTest { +/** + * Unit tests for {@link MapIdFactory}. + * + * @author Matthew T. Adams + */ +public class MapIdFactoryUnitTests { interface HappyExtendingMapIdAndSerializable extends MapId, Serializable { HappyExtendingMapIdAndSerializable string(String s); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderIntegrationTests.java similarity index 93% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderIntegrationTests.java index ce14d333f..4e75ef619 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderIntegrationTests.java @@ -28,7 +28,9 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; +import org.springframework.data.cassandra.core.CassandraOperations; import org.springframework.data.cassandra.test.integration.simpletons.Book; import org.springframework.data.cassandra.test.integration.simpletons.BookHistory; import org.springframework.data.cassandra.test.integration.simpletons.BookReference; @@ -45,7 +47,7 @@ import com.datastax.driver.core.querybuilder.Select; */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class CollectionsRowValueProviderTest extends AbstractSpringDataEmbeddedCassandraIntegrationTest { +public class CollectionsRowValueProviderIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { @Configuration public static class Config extends IntegrationTestConfig { @@ -56,6 +58,8 @@ public class CollectionsRowValueProviderTest extends AbstractSpringDataEmbeddedC } } + @Autowired CassandraOperations template; + @Before public void before() throws IOException { deleteAllEntities(); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Comment.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Comment.java index 93e1877f4..80b68c562 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Comment.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Comment.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,15 +22,14 @@ import org.springframework.util.Assert; /** * This is an example of dynamic table (wide row). PartitionKey (former RowId) is pk.author. ClusteredColumn (former * Column Id) is pk.time - * + * * @author Alex Shvid * @author Matthew T. Adams */ @Table("comments") public class Comment { - @PrimaryKey - private CommentKey pk; + @PrimaryKey private CommentKey pk; private String text; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentKey.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentKey.java index 9c0a31ac0..2d8380ee7 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentKey.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentKey.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,7 +23,7 @@ import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; /** * This is an example of dynamic table (wide row) that creates each time new column with timestamp. - * + * * @author Alex Shvid * @author Matthew T. Adams */ @@ -32,11 +32,9 @@ public class CommentKey implements Serializable { private static final long serialVersionUID = -7871651389236401141L; - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private String author; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private String author; - @PrimaryKeyColumn(ordinal = 1) - private String company; + @PrimaryKeyColumn(ordinal = 1) private String company; /** * @deprecated Only for use by persistence infrastructure diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryIntegrationTests.java index 42eda1044..2b9d871cc 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryIntegrationTests.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,15 +15,13 @@ */ package org.springframework.data.cassandra.test.integration.composites; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; import org.springframework.data.cassandra.core.CassandraOperations; /** * Tests for {@link CommentRepository}. - * + * * @author Matthew T. Adams */ public class CommentRepositoryIntegrationTests { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryJavaConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryJavaConfigIntegrationTests.java index 07ffa027c..e0972bf82 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryJavaConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryJavaConfigIntegrationTests.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,7 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.data.cassandra.core.CassandraOperations; import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; -import org.springframework.data.cassandra.test.integration.repository.UserRepository; +import org.springframework.data.cassandra.test.integration.repository.simple.UserRepository; import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig; import org.springframework.test.context.ContextConfiguration; @@ -30,7 +30,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Base class for Java config tests for {@link UserRepository}. - * + * * @author Matthew T. Adams */ @RunWith(SpringJUnit4ClassRunner.class) @@ -52,11 +52,9 @@ public class CommentRepositoryJavaConfigIntegrationTests extends AbstractSpringD } } - @Autowired - protected CommentRepository repository; + @Autowired protected CommentRepository repository; - @Autowired - protected CassandraOperations template; + @Autowired protected CassandraOperations template; CommentRepositoryIntegrationTests tests; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryXmlConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryXmlConfigIntegrationTests.java index ce8e9ac42..492a95832 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryXmlConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryXmlConfigIntegrationTests.java @@ -1,12 +1,12 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2013-2016 the original author or authors + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,27 +20,26 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.cassandra.core.CassandraOperations; -import org.springframework.data.cassandra.test.integration.repository.UserRepository; +import org.springframework.data.cassandra.test.integration.repository.simple.UserRepository; import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Base class for xml config tests for {@link UserRepository}. - * + * * @author Matthew T. Adams + * @author Mark Paluch */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class CommentRepositoryXmlConfigIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { - @Autowired - protected CommentRepository repository; + @Autowired private CommentRepository repository; - @Autowired - protected CassandraOperations template; + @Autowired private CassandraOperations template; - CommentRepositoryIntegrationTests tests; + private CommentRepositoryIntegrationTests tests; @Before public void setUp() throws InterruptedException { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Notification.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Notification.java index f30554b70..ccbd952c6 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Notification.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Notification.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,7 +25,7 @@ import org.springframework.data.cassandra.mapping.Table; * This is an example of dynamic table that creates each time new column with Notification timestamp. By default it is * active Notification until user deactivate it. This table uses index on the field active to access in WHERE cause only * for active notifications. - * + * * @author Alex Shvid */ @Table("notifications") @@ -34,11 +34,9 @@ public class Notification { /* * Primary Key */ - @Id - private NotificationPK pk; + @Id private NotificationPK pk; - @Indexed - private boolean active; + @Indexed private boolean active; /* * Reference data diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java index 12fab6925..d667074c4 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -29,7 +29,7 @@ import com.datastax.driver.core.DataType; * This is an example of dynamic table that creates each time new column with Notification timestamp. By default it is * active Notification until user deactivate it. This table uses index on the field active to access in WHERE cause only * for active notifications. - * + * * @author Alex Shvid */ @PrimaryKeyClass @@ -40,15 +40,12 @@ public class NotificationPK implements Serializable { /* * Row ID */ - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private String username; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private String username; /* * Clustered Column */ - @PrimaryKeyColumn(ordinal = 1) - @CassandraType(type = DataType.Name.TIMESTAMP) - private Date time; + @PrimaryKeyColumn(ordinal = 1) @CassandraType(type = DataType.Name.TIMESTAMP) private Date time; public String getUsername() { return username; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Post.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Post.java index 35574559f..67ec8ebf5 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Post.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Post.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,7 +27,7 @@ import org.springframework.data.cassandra.mapping.Table; * static table for posts and identify them by PostId(UUID), but in this case we need to use MapReduce for Big Data to * find posts for particular user, so it is better to have index (userId) -> index (post time) architecture. It helps a * lot to build eventually a search index for the particular user. - * + * * @author Alex Shvid */ @Table("posts") @@ -36,8 +36,7 @@ public class Post { /* * Primary Key */ - @Id - private PostPK pk; + @Id private PostPK pk; private String type; // status, share diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java index 98d832488..ce05c50b9 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,7 +27,7 @@ import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; * static table for posts and identify them by PostId(UUID), but in this case we need to use MapReduce for Big Data to * find posts for particular user, so it is better to have index (userId) -> index (post time) architecture. It helps a * lot to build eventually a search index for the particular user. - * + * * @author Alex Shvid */ @@ -36,11 +36,9 @@ public class PostPK implements Serializable { private static final long serialVersionUID = 2390757126054483315L; - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private String author; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private String author; - @PrimaryKeyColumn(ordinal = 1) - private Date time; + @PrimaryKeyColumn(ordinal = 1) private Date time; public String getAuthor() { return author; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Timeline.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Timeline.java index 870a88f60..801860d25 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Timeline.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Timeline.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,7 +25,7 @@ import org.springframework.data.cassandra.mapping.Table; * value. The rest fields are places in Cassandra value. Timeline entity is used to store user's status updates that it * follows in the site. Timeline always ordered by @ColumnId field and we can retrieve last top status updates by using * limits. - * + * * @author Alex Shvid */ @Table("timeline") @@ -34,8 +34,7 @@ public class Timeline { /* * Row ID */ - @Id - private TimelinePK pk; + @Id private TimelinePK pk; /* * Reference to the post by author and postUID diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java index 55306ad6f..bfb470872 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,7 +27,7 @@ import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; * value. The rest fields are places in Cassandra value. Timeline entity is used to store user's status updates that it * follows in the site. Timeline always ordered by @ColumnId field and we can retrieve last top status updates by using * limits. - * + * * @author Alex Shvid */ @@ -39,14 +39,12 @@ public class TimelinePK implements Serializable { /* * Row ID */ - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private String username; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private String username; /* * Clustered Column */ - @PrimaryKeyColumn(ordinal = 1) - private Date time; + @PrimaryKeyColumn(ordinal = 1) private Date time; public String getUsername() { return username; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/config/CassandraNamespaceTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/config/CassandraNamespaceIntegrationTests.java similarity index 83% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/config/CassandraNamespaceTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/config/CassandraNamespaceIntegrationTests.java index 0373bf7d6..c98ec5540 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/config/CassandraNamespaceTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/config/CassandraNamespaceIntegrationTests.java @@ -1,12 +1,12 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2013-2016 the original author or authors + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,15 +24,18 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.Assert; +/** + * @author Mark Paluch + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class CassandraNamespaceTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { +public class CassandraNamespaceIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { - @Autowired - private ApplicationContext ctx; + @Autowired ApplicationContext ctx; @Test public void test() { Assert.notNull(ctx); } + } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/async/AsynchronousCassandraTemplateTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/core/AsynchronousCassandraTemplateIntegrationTests.java similarity index 57% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/async/AsynchronousCassandraTemplateTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/core/AsynchronousCassandraTemplateIntegrationTests.java index e48a5593b..f62a95fc6 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/async/AsynchronousCassandraTemplateTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/core/AsynchronousCassandraTemplateIntegrationTests.java @@ -1,24 +1,23 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2013-2016 the original author or authors + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.template.async; +package org.springframework.data.cassandra.test.integration.core; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; -import static org.springframework.data.cassandra.repository.support.BasicMapId.id; +import static org.junit.Assert.*; +import static org.junit.Assume.*; +import static org.springframework.data.cassandra.repository.support.BasicMapId.*; import java.util.Collection; import java.util.Random; @@ -26,10 +25,10 @@ import java.util.UUID; import java.util.concurrent.CancellationException; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cassandra.core.Cancellable; import org.springframework.cassandra.core.ConsistencyLevel; import org.springframework.cassandra.core.PrimaryKeyType; import org.springframework.cassandra.core.RetryPolicy; @@ -50,45 +49,182 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * Asynchronous {@link CassandraTemplate} tests. - * + * Integration tests for asynchronous {@link CassandraTemplate} operations. + * * @author Matthew T. Adams */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class AsynchronousCassandraTemplateTest extends AbstractSpringDataEmbeddedCassandraIntegrationTest { +public class AsynchronousCassandraTemplateIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { + + @Autowired CassandraOperations cassandraOperations; + + @Before + public void before() { + deleteAllEntities(); + } + + @Test + public void insertAsynchronously() throws Exception { + insertAsynchronously(ConsistencyLevel.ONE); + } + + @Test(expected = CassandraConnectionFailureException.class) + public void insertAsynchronouslyThrows() throws Exception { + insertAsynchronously(ConsistencyLevel.TWO); + } + + public void insertAsynchronously(ConsistencyLevel cl) throws Exception { + + Thing thing = Thing.random(); + ThingListener listener = new ThingListener(); + + cassandraOperations.insertAsynchronously(thing, listener, new WriteOptions(cl, RetryPolicy.LOGGING)); + listener.await(); + + if (listener.exception != null) { + throw listener.exception; + } + + assertEquals(thing, listener.entities.iterator().next()); + } + + @Test(expected = CancellationException.class) + public void insertAsynchronouslyCancelled() throws Exception { + insertOrUpdateAsynchronouslyCancelled(true); + } + + @Test(expected = CancellationException.class) + public void updateAsynchronouslyCancelled() throws Exception { + insertOrUpdateAsynchronouslyCancelled(false); + } + + public void insertOrUpdateAsynchronouslyCancelled(boolean insert) throws Exception { + + Thing thing = Thing.random(); + ThingListener listener = new ThingListener(); + + Cancellable cancellable; + + if (insert) { + cancellable = cassandraOperations.insertAsynchronously(thing, listener, null); + } else { + cancellable = cassandraOperations.updateAsynchronously(thing, listener, null); + } + cancellable.cancel(); + listener.await(); + + // if listener.success is true then the + // async operations was faster than it could be cancelled so we cannot + // verify that a CancellationException was thrown. + assumeFalse(listener.success); + + if (listener.exception != null) { + throw listener.exception; + } + + fail("should've thrown CancellationException"); + } + + @Test + public void updateAsynchronously() throws Exception { + updateAsynchronously(ConsistencyLevel.ONE); + } + + @Test(expected = CassandraConnectionFailureException.class) + public void updateAsynchronouslyThrows() throws Exception { + updateAsynchronously(ConsistencyLevel.TWO); + } + + public void updateAsynchronously(ConsistencyLevel cl) throws Exception { + + Thing thing = Thing.random(); + cassandraOperations.insert(thing); + thing.number = Thing.random().number; + + ThingListener listener = new ThingListener(); + cassandraOperations.updateAsynchronously(thing, listener, new WriteOptions(cl, RetryPolicy.LOGGING)); + + listener.await(); + if (listener.exception != null) { + throw listener.exception; + } + + assertEquals(thing, listener.entities.iterator().next()); + } + + @Test + public void deleteAsynchronously() throws Exception { + deleteAsynchronously(ConsistencyLevel.ONE); + } + + @Test(expected = CassandraConnectionFailureException.class) + public void deleteAsynchronouslyThrows() throws Exception { + deleteAsynchronously(ConsistencyLevel.TWO); + } + + public void deleteAsynchronously(ConsistencyLevel cl) throws Exception { + + Thing thing = Thing.random(); + + cassandraOperations.insert(thing); + + ThingListener listener = new ThingListener(); + cassandraOperations.deleteAsynchronously(thing, listener, new WriteOptions(cl, RetryPolicy.LOGGING)); + + listener.await(); + if (listener.exception != null) { + throw listener.exception; + } + assertFalse(cassandraOperations.exists(Thing.class, id("stuff", thing.stuff))); + } + + @Test(expected = CancellationException.class) + public void deleteAsynchronouslyCancelled() throws Exception { + + Thing thing = Thing.random(); + ThingListener listener = new ThingListener(); + cassandraOperations.deleteAsynchronously(thing, listener, null).cancel(); + listener.await(); + + // if listener.success is true then the + // async operations was faster than it could be cancelled so we cannot + // verify that a CancellationException was thrown. + assumeFalse(listener.success); + + if (listener.exception != null) { + throw listener.exception; + } + + fail("should've thrown CancellationException"); + } @Configuration - public static class Config extends IntegrationTestConfig { - } + public static class Config extends IntegrationTestConfig {} @Table public static class Thing { + private static final Random RNG = new Random(); + + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) public String stuff; + @Column public int number; + + public Thing() {} + + public Thing(String stuff, int number) { + this.stuff = stuff; + this.number = number; + } + public static final String uuid() { return UUID.randomUUID().toString(); } - static final Random RNG = new Random(); - public static Thing random() { return new Thing(uuid(), RNG.nextInt()); } - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - public String stuff; - - @Column - public int number; - - public Thing() { - } - - public Thing(String stuff, int number) { - this.stuff = stuff; - this.number = number; - } - @Override public int hashCode() { final int prime = 31; @@ -118,148 +254,31 @@ public class AsynchronousCassandraTemplateTest extends AbstractSpringDataEmbedde } } - public static class ThingWriteListener extends TestListener implements WriteListener { + public static class ThingListener extends TestListener implements WriteListener, DeletionListener { - public Exception exception; - public Collection entities; + public volatile Exception exception; + public volatile Collection entities; + public volatile boolean success; @Override public void onWriteComplete(Collection entities) { this.entities = entities; + this.success = true; countDown(); } - @Override - public void onException(Exception x) { - this.exception = x; - countDown(); - } - } - - public static class ThingDeletionListener extends TestListener implements DeletionListener { - - public Exception exception; - public Collection entities; - @Override public void onDeletionComplete(Collection entities) { this.entities = entities; + this.success = true; countDown(); } @Override public void onException(Exception x) { this.exception = x; + this.success = false; countDown(); } } - - @Autowired - CassandraOperations t; - - @Before - public void before() { - deleteAllEntities(); - } - - public void testInsertAsynchronously(ConsistencyLevel cl) throws Exception { - Thing thing = Thing.random(); - ThingWriteListener listener = new ThingWriteListener(); - t.insertAsynchronously(thing, listener, new WriteOptions(cl, RetryPolicy.LOGGING)); - listener.await(); - if (listener.exception != null) { - throw listener.exception; - } - assertEquals(thing, listener.entities.iterator().next()); - } - - @Test - public void testInsertAsynchronously() throws Exception { - testInsertAsynchronously(ConsistencyLevel.ONE); - } - - @Test(expected = CassandraConnectionFailureException.class) - public void testInsertAsynchronouslyThrows() throws Exception { - testInsertAsynchronously(ConsistencyLevel.TWO); - } - - public void testInsertOrUpdateAsynchronouslyCancelled(boolean insert) throws Exception { - Thing thing = Thing.random(); - ThingWriteListener listener = new ThingWriteListener(); - (insert ? t.insertAsynchronously(thing, listener, null) : t.updateAsynchronously(thing, listener, null)).cancel(); - listener.await(); - if (listener.exception != null) { - throw listener.exception; - } - fail("should've thrown CancellationException"); - } - - @Test(expected = CancellationException.class) - public void testInsertAsynchronouslyCancelled() throws Exception { - testInsertOrUpdateAsynchronouslyCancelled(true); - } - - @Test(expected = CancellationException.class) - @Ignore - public void testUpdateAsynchronouslyCancelled() throws Exception { - testInsertOrUpdateAsynchronouslyCancelled(false); - } - - public void testUpdateAsynchronously(ConsistencyLevel cl) throws Exception { - Thing thing = Thing.random(); - t.insert(thing); - thing.number = Thing.random().number; - ThingWriteListener listener = new ThingWriteListener(); - t.updateAsynchronously(thing, listener, new WriteOptions(cl, RetryPolicy.LOGGING)); - listener.await(); - if (listener.exception != null) { - throw listener.exception; - } - assertEquals(thing, listener.entities.iterator().next()); - } - - @Test - public void testUpdateAsynchronously() throws Exception { - testUpdateAsynchronously(ConsistencyLevel.ONE); - } - - @Test(expected = CassandraConnectionFailureException.class) - public void testUpdateAsynchronouslyThrows() throws Exception { - testUpdateAsynchronously(ConsistencyLevel.TWO); - } - - public void testDeleteAsynchronously(ConsistencyLevel cl) throws Exception { - Thing thing = Thing.random(); - t.insert(thing); - ThingDeletionListener listener = new ThingDeletionListener(); - t.deleteAsynchronously(thing, listener, new WriteOptions(cl, RetryPolicy.LOGGING)); - listener.await(); - if (listener.exception != null) { - throw listener.exception; - } - assertFalse(t.exists(Thing.class, id("stuff", thing.stuff))); - } - - @Test - public void testDeleteAsynchronously() throws Exception { - testDeleteAsynchronously(ConsistencyLevel.ONE); - } - - @Test(expected = CassandraConnectionFailureException.class) - public void testDeleteAsynchronouslyThrows() throws Exception { - testDeleteAsynchronously(ConsistencyLevel.TWO); - } - - @Test(expected = CancellationException.class) - public void testDeleteAsynchronouslyCancelled() throws Exception { - Thing thing = Thing.random(); - ThingDeletionListener listener = new ThingDeletionListener(); - t.deleteAsynchronously(thing, listener, null).cancel(); - listener.await(); - if (listener.exception != null) { - throw listener.exception; - } - fail("should've thrown CancellationException"); - } - } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/CassandraAdminTemplateTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/core/CassandraAdminTemplateIntegrationTests.java similarity index 89% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/CassandraAdminTemplateTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/core/CassandraAdminTemplateIntegrationTests.java index 0ef900b54..6e9564b5a 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/CassandraAdminTemplateTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/core/CassandraAdminTemplateIntegrationTests.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2016 the original author or authors + * Copyright 2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.template; +package org.springframework.data.cassandra.test.integration.core; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.*; @@ -27,7 +27,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cassandra.core.cql.CqlIdentifier; import org.springframework.cassandra.core.keyspace.DropTableSpecification; import org.springframework.context.annotation.Configuration; -import org.springframework.data.cassandra.convert.CassandraConverter; import org.springframework.data.cassandra.core.CassandraAdminTemplate; import org.springframework.data.cassandra.test.integration.simpletons.Book; import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; @@ -41,13 +40,13 @@ import com.datastax.driver.core.Session; import com.datastax.driver.core.TableMetadata; /** - * Test for CassandraAdminTemplate + * Integration tests for {@link CassandraAdminTemplate}. * * @author Mark Paluch */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class CassandraAdminTemplateTest extends AbstractSpringDataEmbeddedCassandraIntegrationTest { +public class CassandraAdminTemplateIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { @Configuration public static class Config extends IntegrationTestConfig { @@ -75,11 +74,10 @@ public class CassandraAdminTemplateTest extends AbstractSpringDataEmbeddedCassan } private Session getSession() { - return template.getSession(); + return cassandraAdminTemplate.getSession(); } /** - * * @see DATACASS-173 */ @Test diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/CassandraDataOperationsTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/core/CassandraOperationsIntegrationTests.java similarity index 96% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/CassandraDataOperationsTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/core/CassandraOperationsIntegrationTests.java index ba08a308f..4e38000c5 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/CassandraDataOperationsTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/core/CassandraOperationsIntegrationTests.java @@ -1,23 +1,21 @@ /* - * Copyright 2013-2016 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.template; +package org.springframework.data.cassandra.test.integration.core; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Date; @@ -28,11 +26,13 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cassandra.core.ConsistencyLevel; import org.springframework.cassandra.core.QueryOptions; import org.springframework.cassandra.core.RetryPolicy; import org.springframework.cassandra.core.WriteOptions; import org.springframework.context.annotation.Configuration; +import org.springframework.data.cassandra.core.CassandraOperations; import org.springframework.data.cassandra.test.integration.simpletons.Book; import org.springframework.data.cassandra.test.integration.simpletons.BookCondition; import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; @@ -44,14 +44,14 @@ import com.datastax.driver.core.querybuilder.QueryBuilder; import com.datastax.driver.core.querybuilder.Select; /** - * Unit Tests for CqlTemplate - * + * Integration tests for {@link CassandraOperations}. + * * @author David Webb * @author Mark Paluch */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class CassandraDataOperationsTest extends AbstractSpringDataEmbeddedCassandraIntegrationTest { +public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { @Configuration public static class Config extends IntegrationTestConfig { @@ -62,6 +62,8 @@ public class CassandraDataOperationsTest extends AbstractSpringDataEmbeddedCassa } } + @Autowired CassandraOperations template; + @Before public void before() { deleteAllEntities(); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/CompositeKeyCrudTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/CompositeKeyCrudIntegrationTests.java similarity index 63% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/CompositeKeyCrudTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/CompositeKeyCrudIntegrationTests.java index 57b4dfbf4..74d1f42e4 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/CompositeKeyCrudTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/CompositeKeyCrudIntegrationTests.java @@ -1,6 +1,21 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Date; @@ -27,18 +42,20 @@ import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy; import com.datastax.driver.core.querybuilder.QueryBuilder; import com.datastax.driver.core.querybuilder.Select; +/** + * @author Mark Paluch + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class CompositeKeyCrudTest extends AbstractSpringDataEmbeddedCassandraIntegrationTest { +public class CompositeKeyCrudIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { @Configuration @EnableCassandraRepositories(basePackageClasses = ImplicitRepository.class) public static class Config extends IntegrationTestConfig {} - @Autowired - CassandraTemplate t; + @Autowired private CassandraTemplate template1; - CorrelationEntity c1, c2; + private CorrelationEntity correlationEntity1, correlationEntity2; @Before public void setUp() throws Throwable { @@ -50,31 +67,31 @@ public class CompositeKeyCrudTest extends AbstractSpringDataEmbeddedCassandraInt map2.put("v", "1"); map2.put("labels", "4,5,6"); - c1 = new CorrelationEntity("a", "b", "c", new Date(1), "d", map1); - c2 = new CorrelationEntity("a", "b", "c", new Date(2), "e", map2); + correlationEntity1 = new CorrelationEntity("a", "b", "c", new Date(1), "d", map1); + correlationEntity2 = new CorrelationEntity("a", "b", "c", new Date(2), "e", map2); } @Test public void test() { - t.insert(c1); - t.insert(c2); + template1.insert(correlationEntity1); + template1.insert(correlationEntity2); Select select = QueryBuilder.select().from("identity_correlations"); select.where(QueryBuilder.eq("type", "a")).and(QueryBuilder.eq("value", "b")); select.setRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); select.setConsistencyLevel(ConsistencyLevel.ONE); - List correlationEntities = t.select(select, CorrelationEntity.class); + List correlationEntities = template1.select(select, CorrelationEntity.class); assertEquals(2, correlationEntities.size()); QueryOptions qo = new QueryOptions(); qo.setConsistencyLevel(org.springframework.cassandra.core.ConsistencyLevel.ONE); ArrayList entities = new ArrayList(); - entities.add(c1); - entities.add(c2); - t.delete(entities, qo); + entities.add(correlationEntity1); + entities.add(correlationEntity2); + template1.delete(entities, qo); - correlationEntities = t.select(select, CorrelationEntity.class); + correlationEntities = template1.select(select, CorrelationEntity.class); assertEquals(0, correlationEntities.size()); } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Explicit.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Explicit.java index 4f7b98502..e262dcfe6 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Explicit.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Explicit.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; import java.util.UUID; @@ -6,17 +21,18 @@ import org.springframework.data.cassandra.mapping.Column; import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.Table; +/** + * @author Matthew T. Adams + */ @Table(forceQuote = true, value = Explicit.TABLE_NAME) public class Explicit { public static final String TABLE_NAME = "JavaExplicitTable"; public static final String STRING_VALUE_COLUMN_NAME = "JavaExplicitStringValue"; - @PrimaryKey - ExplicitKey primaryKey; + @PrimaryKey ExplicitKey primaryKey; - @Column(value = STRING_VALUE_COLUMN_NAME, forceQuote = true) - String stringValue = UUID.randomUUID().toString(); + @Column(value = STRING_VALUE_COLUMN_NAME, forceQuote = true) String stringValue = UUID.randomUUID().toString(); @SuppressWarnings("unused") private Explicit() {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitKey.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitKey.java index 74e522cc7..df317f60a 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitKey.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitKey.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; import java.io.Serializable; @@ -6,6 +21,9 @@ import org.springframework.cassandra.core.PrimaryKeyType; import org.springframework.data.cassandra.mapping.PrimaryKeyClass; import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; +/** + * @author Matthew T. Adams + */ @PrimaryKeyClass public class ExplicitKey implements Serializable { @@ -14,11 +32,10 @@ public class ExplicitKey implements Serializable { private static final long serialVersionUID = 4459456944472099332L; - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED, forceQuote = true, name = EXPLICIT_KEY_ZERO) - String keyZero; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED, forceQuote = true, + name = EXPLICIT_KEY_ZERO) String keyZero; - @PrimaryKeyColumn(ordinal = 1, forceQuote = true, name = EXPLICIT_KEY_ONE) - String keyOne; + @PrimaryKeyColumn(ordinal = 1, forceQuote = true, name = EXPLICIT_KEY_ONE) String keyOne; public ExplicitKey(String keyZero, String keyOne) { this.keyZero = keyZero; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitRepository.java index 3d65630ff..60811f52f 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitRepository.java @@ -1,5 +1,23 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; +/** + * @author Matthew T. Adams + */ public interface ExplicitRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator.java index 82aa8c44d..a38644ff1 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; import org.junit.Before; @@ -8,27 +23,25 @@ import org.springframework.data.cassandra.core.CassandraTemplate; import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +/** + * @author Matthew T. Adams + */ @RunWith(SpringJUnit4ClassRunner.class) -public abstract class ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator extends - AbstractSpringDataEmbeddedCassandraIntegrationTest { +public abstract class ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator + extends AbstractSpringDataEmbeddedCassandraIntegrationTest { - ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests tests = new ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests(); + ForceQuotedCompositePrimaryKeyRepositoryTests tests = new ForceQuotedCompositePrimaryKeyRepositoryTests(); - @Autowired - ImplicitRepository i; - - @Autowired - ExplicitRepository e; - - @Autowired - CassandraTemplate t; + @Autowired ImplicitRepository implicitRepository; + @Autowired ExplicitRepository explicitRepository; + @Autowired CassandraTemplate cassandraTemplate; @Before public void before() { - tests.i = i; - tests.e = e; - tests.t = t; + tests.implicitRepository = implicitRepository; + tests.explicitRepository = explicitRepository; + tests.cassandraTemplate = cassandraTemplate; tests.before(); } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests.java index cad059156..2a1b8d9ad 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; import org.junit.Test; @@ -6,9 +21,12 @@ import org.springframework.data.cassandra.repository.config.EnableCassandraRepos import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig; import org.springframework.test.context.ContextConfiguration; +/** + * @author Matthew T. Adams + */ @ContextConfiguration -public class ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests extends - ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator { +public class ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests + extends ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator { @Configuration @EnableCassandraRepositories(basePackageClasses = ImplicitRepository.class) diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryTests.java similarity index 51% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryTests.java index 771bdc9cb..f4e07c15d 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryTests.java @@ -1,29 +1,44 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; import java.util.UUID; import org.springframework.data.cassandra.core.CassandraTemplate; -public class ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests { +/** + * @author Matthew T. Adams + */ +public class ForceQuotedCompositePrimaryKeyRepositoryTests { - ImplicitRepository i; - ExplicitRepository e; - CassandraTemplate t; + ImplicitRepository implicitRepository; + ExplicitRepository explicitRepository; + CassandraTemplate cassandraTemplate; public void before() { - t.deleteAll(Implicit.class); + cassandraTemplate.deleteAll(Implicit.class); } public String query(String columnName, String tableName, String keyZeroColumnName, String keyZero, String keyOneColumnName, String keyOne) { - return t.queryForObject(String.format("select %s from %s where %s = '%s' and %s = '%s'", columnName, tableName, - keyZeroColumnName, keyZero, keyOneColumnName, keyOne), String.class); + return cassandraTemplate.queryForObject(String.format("select %s from %s where %s = '%s' and %s = '%s'", columnName, + tableName, keyZeroColumnName, keyZero, keyOneColumnName, keyOne), String.class); } public void testImplicit() { @@ -32,11 +47,11 @@ public class ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests { Implicit entity = new Implicit(key); // insert - Implicit s = i.save(entity); + Implicit s = implicitRepository.save(entity); assertSame(s, entity); // select - Implicit f = i.findOne(key); + Implicit f = implicitRepository.findOne(key); assertNotSame(f, entity); String stringValue = query("stringvalue", "\"Implicit\"", "\"keyZero\"", f.getPrimaryKey().getKeyZero(), "\"keyOne\"", f.getPrimaryKey().getKeyOne()); @@ -44,15 +59,15 @@ public class ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests { // update f.setStringValue(f.getStringValue() + "X"); - Implicit u = i.save(f); + Implicit u = implicitRepository.save(f); assertSame(u, f); - f = i.findOne(u.getPrimaryKey()); + f = implicitRepository.findOne(u.getPrimaryKey()); assertNotSame(f, u); assertEquals(u.getStringValue(), f.getStringValue()); // delete - i.delete(key); - assertNull(i.findOne(key)); + implicitRepository.delete(key); + assertNull(implicitRepository.findOne(key)); } public void testExplicit(String tableName, String stringValueColumnName, String keyZeroColumnName, @@ -61,11 +76,11 @@ public class ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests { Explicit entity = new Explicit(key); // insert - Explicit s = e.save(entity); + Explicit s = explicitRepository.save(entity); assertSame(s, entity); // select - Explicit f = e.findOne(key); + Explicit f = explicitRepository.findOne(key); assertNotSame(f, entity); String stringValue = query(stringValueColumnName, tableName, keyZeroColumnName, f.getPrimaryKey().getKeyZero(), keyOneColumnName, f.getPrimaryKey().getKeyOne()); @@ -73,14 +88,14 @@ public class ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests { // update f.setStringValue(f.getStringValue() + "X"); - Explicit u = e.save(f); + Explicit u = explicitRepository.save(f); assertSame(u, f); - f = e.findOne(u.getPrimaryKey()); + f = explicitRepository.findOne(u.getPrimaryKey()); assertNotSame(f, u); assertEquals(u.getStringValue(), f.getStringValue()); // delete - e.delete(key); - assertNull(e.findOne(key)); + explicitRepository.delete(key); + assertNull(explicitRepository.findOne(key)); } } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests.java index 935cf605f..19a93b768 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests.java @@ -1,11 +1,29 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; import org.junit.Test; import org.springframework.test.context.ContextConfiguration; +/** + * @author Matthew T. Adams + */ @ContextConfiguration -public class ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests extends - ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator { +public class ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests + extends ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator { @Test public void testExplicit() { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Implicit.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Implicit.java index ca4182322..78d0d6b2e 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Implicit.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Implicit.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; import java.util.UUID; @@ -5,11 +20,13 @@ import java.util.UUID; import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.Table; +/** + * @author Matthew T. Adams + */ @Table(forceQuote = true) public class Implicit { - @PrimaryKey - ImplicitKey primaryKey; + @PrimaryKey ImplicitKey primaryKey; String stringValue = UUID.randomUUID().toString(); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitKey.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitKey.java index 5494a3560..71a1ba905 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitKey.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitKey.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; import java.io.Serializable; @@ -6,16 +21,17 @@ import org.springframework.cassandra.core.PrimaryKeyType; import org.springframework.data.cassandra.mapping.PrimaryKeyClass; import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; +/** + * @author Matthew T. Adams + */ @PrimaryKeyClass public class ImplicitKey implements Serializable { private static final long serialVersionUID = 4459456944472099332L; - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED, forceQuote = true) - String keyZero; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED, forceQuote = true) String keyZero; - @PrimaryKeyColumn(ordinal = 1, forceQuote = true) - String keyOne; + @PrimaryKeyColumn(ordinal = 1, forceQuote = true) String keyOne; public ImplicitKey(String keyZero, String keyOne) { this.keyZero = keyZero; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitRepository.java index e7077ddda..bf2ace3ac 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitRepository.java @@ -1,5 +1,23 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; +/** + * @author Matthew T. Adams + */ public interface ImplicitRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/entity/CorrelationEntity.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/entity/CorrelationEntity.java index 6835b1dba..c9b2255b8 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/entity/CorrelationEntity.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/entity/CorrelationEntity.java @@ -1,12 +1,34 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey.entity; -import org.springframework.cassandra.core.PrimaryKeyType; -import org.springframework.data.cassandra.mapping.*; - import java.io.Serializable; import java.util.Date; import java.util.Map; +import org.springframework.cassandra.core.PrimaryKeyType; +import org.springframework.data.cassandra.mapping.Column; +import org.springframework.data.cassandra.mapping.PrimaryKey; +import org.springframework.data.cassandra.mapping.PrimaryKeyClass; +import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.mapping.Table; + +/** + * @author Matthew T. Adams + */ @Table(value = "identity_correlations") public class CorrelationEntity { @@ -15,20 +37,17 @@ public class CorrelationEntity { private static final long serialVersionUID = 1027559675696864950L; - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private String type; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private String type; - @PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.PARTITIONED) - private String value; + @PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.PARTITIONED) private String value; - @PrimaryKeyColumn(name = "correlated_type", ordinal = 2, type = PrimaryKeyType.CLUSTERED) - private String correlatedType; + @PrimaryKeyColumn(name = "correlated_type", ordinal = 2, + type = PrimaryKeyType.CLUSTERED) private String correlatedType; - @PrimaryKeyColumn(ordinal = 3, type = PrimaryKeyType.CLUSTERED) - private Date ts; + @PrimaryKeyColumn(ordinal = 3, type = PrimaryKeyType.CLUSTERED) private Date ts; - @PrimaryKeyColumn(name = "correlated_value", ordinal = 4, type = PrimaryKeyType.CLUSTERED) - private String correlatedValue; + @PrimaryKeyColumn(name = "correlated_value", ordinal = 4, + type = PrimaryKeyType.CLUSTERED) private String correlatedValue; public IdentityEntity() {} @@ -132,11 +151,9 @@ public class CorrelationEntity { } } - @PrimaryKey(forceQuote = true) - private IdentityEntity identityEntity; + @PrimaryKey(forceQuote = true) private IdentityEntity identityEntity; - @Column - private Map extra; + @Column private Map extra; public CorrelationEntity() {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/Explicit.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/Explicit.java index de2337a6b..cabd11351 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/Explicit.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/Explicit.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.config; import java.util.UUID; @@ -5,13 +20,15 @@ import java.util.UUID; import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.Table; +/** + * @author Matthew T. Adams + */ @Table(forceQuote = true, value = Explicit.TABLE_NAME) public class Explicit { public static final String TABLE_NAME = "Xx"; - @PrimaryKey - String primaryKey; + @PrimaryKey String primaryKey; String stringValue = UUID.randomUUID().toString(); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitProperties.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitProperties.java index 632739b1e..f1cc7c69a 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitProperties.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitProperties.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.data.cassandra.test.integration.forcequote.config; import java.util.UUID; @@ -6,17 +22,18 @@ import org.springframework.data.cassandra.mapping.Column; import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.Table; +/** + * @author Matthew T. Adams + */ @Table public class ExplicitProperties { public static final String EXPLICIT_PRIMARY_KEY = "ThePrimaryKey"; public static final String EXPLICIT_STRING_VALUE = "TheStringValue"; - @PrimaryKey(forceQuote = true, value = EXPLICIT_PRIMARY_KEY) - String primaryKey; + @PrimaryKey(forceQuote = true, value = EXPLICIT_PRIMARY_KEY) String primaryKey; - @Column(forceQuote = true, value = EXPLICIT_STRING_VALUE) - String stringValue = UUID.randomUUID().toString(); + @Column(forceQuote = true, value = EXPLICIT_STRING_VALUE) String stringValue = UUID.randomUUID().toString(); public ExplicitProperties() { this(UUID.randomUUID().toString()); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitPropertiesRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitPropertiesRepository.java index f676978f8..327083f9b 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitPropertiesRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitPropertiesRepository.java @@ -1,5 +1,23 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.config; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; +/** + * @author Matthew T. Adams + */ public interface ExplicitPropertiesRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitRepository.java index 907721dbc..e31b8b3b1 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitRepository.java @@ -1,5 +1,23 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.config; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; +/** + * @author Matthew T. Adams + */ public interface ExplicitRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTests.java index f40e2818c..cf767727c 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTests.java @@ -1,99 +1,78 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.cassandra.core.CassandraOperations; +import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.data.cassandra.core.CassandraTemplate; +/** + * @author Matthew T. Adams + */ +@RunWith(SpringJUnit4ClassRunner.class) +public abstract class ForceQuotedRepositoryIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { -public class ForceQuotedRepositoryIntegrationTests { + @Autowired CassandraOperations template; + @Autowired ImplicitRepository implicitRepository; + @Autowired ImplicitPropertiesRepository implicitPropertiesRepository; + @Autowired ExplicitRepository explicitRepository; + @Autowired ExplicitPropertiesRepository explicitPropertiesRepository; - ImplicitRepository i; - ImplicitPropertiesRepository ip; - ExplicitRepository e; - ExplicitPropertiesRepository ep; - CassandraTemplate t; + ForceQuotedRepositoryTests tests; + @Before public void before() { - t.deleteAll(Implicit.class); - } - - public String query(String columnName, String tableName, String keyColumnName, String key) { - return t.queryForObject( - String.format("select %s from %s where %s = '%s'", columnName, tableName, keyColumnName, key), String.class); + tests = new ForceQuotedRepositoryTests(); + tests.implicitRepository = implicitRepository; + tests.implicitPropertiesRepository = implicitPropertiesRepository; + tests.explicitRepository = explicitRepository; + tests.explicitPropertiesRepository = explicitPropertiesRepository; + tests.cassandraTemplate = template; + + tests.before(); } + @Test public void testImplicit() { - Implicit entity = new Implicit(); - String key = entity.getPrimaryKey(); - - Implicit s = i.save(entity); - assertSame(s, entity); - - Implicit f = i.findOne(key); - assertNotSame(f, entity); - - String stringValue = query("stringvalue", "\"Implicit\"", "primarykey", f.getPrimaryKey()); - assertEquals(f.getStringValue(), stringValue); - - i.delete(key); - - assertNull(i.findOne(key)); + tests.testImplicit(); } + /** + * Not a @Test -- used by subclasses! + */ public void testExplicit(String tableName) { - Explicit entity = new Explicit(); - String key = entity.getPrimaryKey(); - - Explicit s = e.save(entity); - assertSame(s, entity); - - Explicit f = e.findOne(key); - assertNotSame(f, entity); - - String stringValue = query("stringvalue", String.format("\"%s\"", tableName), "primarykey", f.getPrimaryKey()); - assertEquals(f.getStringValue(), stringValue); - - e.delete(key); - - assertNull(e.findOne(key)); + tests.testExplicit(tableName); } + @Test public void testImplicitProperties() { - ImplicitProperties entity = new ImplicitProperties(); - String key = entity.getPrimaryKey(); - - ImplicitProperties s = ip.save(entity); - assertSame(s, entity); - - ImplicitProperties f = ip.findOne(key); - assertNotSame(f, entity); - - String stringValue = query("\"stringValue\"", "implicitproperties", "\"primaryKey\"", f.getPrimaryKey()); - assertEquals(f.getStringValue(), stringValue); - - ip.delete(key); - - assertNull(ip.findOne(key)); + tests.testImplicitProperties(); } + /** + * Not a @Test -- used by subclasses! + * + * @see ForceQuotedRepositoryJavaConfigIntegrationTests#testExplicitPropertiesWithJavaValues() + * @see ForceQuotedRepositoryXmlConfigIntegrationTests#testExplicitPropertiesWithXmlValues() + */ public void testExplicitProperties(String stringValueColumnName, String primaryKeyColumnName) { - ExplicitProperties entity = new ExplicitProperties(); - String key = entity.getPrimaryKey(); - - ExplicitProperties s = ep.save(entity); - assertSame(s, entity); - - ExplicitProperties f = ep.findOne(key); - assertNotSame(f, entity); - - String stringValue = query(String.format("\"%s\"", stringValueColumnName), "explicitproperties", - String.format("\"%s\"", primaryKeyColumnName), f.getPrimaryKey()); - assertEquals(f.getStringValue(), stringValue); - - ip.delete(key); - - assertNull(ip.findOne(key)); + tests.testExplicitProperties(stringValueColumnName, primaryKeyColumnName); } } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTestsDelegator.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTestsDelegator.java deleted file mode 100644 index 4391c6a24..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTestsDelegator.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.springframework.data.cassandra.test.integration.forcequote.config; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.cassandra.core.CassandraTemplate; -import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -public abstract class ForceQuotedRepositoryIntegrationTestsDelegator extends - AbstractSpringDataEmbeddedCassandraIntegrationTest { - - @Autowired - ImplicitRepository i; - - @Autowired - ImplicitPropertiesRepository ip; - - @Autowired - ExplicitRepository e; - - @Autowired - ExplicitPropertiesRepository ep; - - @Autowired - CassandraTemplate t; - - ForceQuotedRepositoryIntegrationTests tests; - - @Before - public void before() { - tests = new ForceQuotedRepositoryIntegrationTests(); - tests.i = i; - tests.ip = ip; - tests.e = e; - tests.ep = ep; - tests.t = t; - - tests.before(); - } - - @Test - public void testImplicit() { - tests.testImplicit(); - } - - /** - * Not a @Test -- used by subclasses! - */ - public void testExplicit(String tableName) { - tests.testExplicit(tableName); - } - - @Test - public void testImplicitProperties() { - tests.testImplicitProperties(); - } - - /** - * Not a @Test -- used by subclasses! - * - * @see ForceQuotedRepositoryJavaConfigIntegrationTests#testExplicitPropertiesWithJavaValues() - * @see ForceQuotedRepositoryXmlConfigIntegrationTests#testExplicitPropertiesWithXmlValues() - */ - public void testExplicitProperties(String stringValueColumnName, String primaryKeyColumnName) { - tests.testExplicitProperties(stringValueColumnName, primaryKeyColumnName); - } -} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryJavaConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryJavaConfigIntegrationTests.java index d120941bf..1e6024461 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryJavaConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryJavaConfigIntegrationTests.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.config; import org.junit.Test; @@ -6,11 +21,14 @@ import org.springframework.data.cassandra.repository.config.EnableCassandraRepos import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig; import org.springframework.test.context.ContextConfiguration; +/** + * @author Matthew T. Adams + */ @ContextConfiguration -public class ForceQuotedRepositoryJavaConfigIntegrationTests extends ForceQuotedRepositoryIntegrationTestsDelegator { +public class ForceQuotedRepositoryJavaConfigIntegrationTests extends ForceQuotedRepositoryIntegrationTests { @Configuration - @EnableCassandraRepositories(basePackageClasses = ForceQuotedRepositoryIntegrationTests.class) + @EnableCassandraRepositories(basePackageClasses = ForceQuotedRepositoryTests.class) public static class Config extends IntegrationTestConfig {} @Test diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryTests.java new file mode 100644 index 000000000..87e75bf9e --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryTests.java @@ -0,0 +1,116 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.forcequote.config; + +import static org.junit.Assert.*; + +import org.springframework.data.cassandra.core.CassandraOperations; + +/** + * Tests to be executed using Java/XML configuration. + * + * @author Matthew T. Adams + */ +public class ForceQuotedRepositoryTests { + + ImplicitRepository implicitRepository; + ImplicitPropertiesRepository implicitPropertiesRepository; + ExplicitRepository explicitRepository; + ExplicitPropertiesRepository explicitPropertiesRepository; + CassandraOperations cassandraTemplate; + + public void before() { + cassandraTemplate.deleteAll(Implicit.class); + } + + public String query(String columnName, String tableName, String keyColumnName, String key) { + return cassandraTemplate.queryForObject( + String.format("select %s from %s where %s = '%s'", columnName, tableName, keyColumnName, key), String.class); + } + + public void testImplicit() { + Implicit entity = new Implicit(); + String key = entity.getPrimaryKey(); + + Implicit s = implicitRepository.save(entity); + assertSame(s, entity); + + Implicit f = implicitRepository.findOne(key); + assertNotSame(f, entity); + + String stringValue = query("stringvalue", "\"Implicit\"", "primarykey", f.getPrimaryKey()); + assertEquals(f.getStringValue(), stringValue); + + implicitRepository.delete(key); + + assertNull(implicitRepository.findOne(key)); + } + + public void testExplicit(String tableName) { + Explicit entity = new Explicit(); + String key = entity.getPrimaryKey(); + + Explicit s = explicitRepository.save(entity); + assertSame(s, entity); + + Explicit f = explicitRepository.findOne(key); + assertNotSame(f, entity); + + String stringValue = query("stringvalue", String.format("\"%s\"", tableName), "primarykey", f.getPrimaryKey()); + assertEquals(f.getStringValue(), stringValue); + + explicitRepository.delete(key); + + assertNull(explicitRepository.findOne(key)); + } + + public void testImplicitProperties() { + ImplicitProperties entity = new ImplicitProperties(); + String key = entity.getPrimaryKey(); + + ImplicitProperties s = implicitPropertiesRepository.save(entity); + assertSame(s, entity); + + ImplicitProperties f = implicitPropertiesRepository.findOne(key); + assertNotSame(f, entity); + + String stringValue = query("\"stringValue\"", "implicitproperties", "\"primaryKey\"", f.getPrimaryKey()); + assertEquals(f.getStringValue(), stringValue); + + implicitPropertiesRepository.delete(key); + + assertNull(implicitPropertiesRepository.findOne(key)); + } + + public void testExplicitProperties(String stringValueColumnName, String primaryKeyColumnName) { + ExplicitProperties entity = new ExplicitProperties(); + String key = entity.getPrimaryKey(); + + ExplicitProperties s = explicitPropertiesRepository.save(entity); + assertSame(s, entity); + + ExplicitProperties f = explicitPropertiesRepository.findOne(key); + assertNotSame(f, entity); + + String stringValue = query(String.format("\"%s\"", stringValueColumnName), "explicitproperties", + String.format("\"%s\"", primaryKeyColumnName), f.getPrimaryKey()); + assertEquals(f.getStringValue(), stringValue); + + implicitPropertiesRepository.delete(key); + + assertNull(implicitPropertiesRepository.findOne(key)); + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests.java index 28e988a93..46d32f0ba 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests.java @@ -1,13 +1,31 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.config; import org.junit.Test; import org.springframework.test.context.ContextConfiguration; +/** + * @author Matthew T. Adams + */ @ContextConfiguration -public class ForceQuotedRepositoryXmlConfigIntegrationTests extends ForceQuotedRepositoryIntegrationTestsDelegator { +public class ForceQuotedRepositoryXmlConfigIntegrationTests extends ForceQuotedRepositoryIntegrationTests { // these values must match the values in - // src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests-context.xml + // ForceQuotedRepositoryXmlConfigIntegrationTests-context.xml @Test public void testExplicit() { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/Implicit.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/Implicit.java index 3f6136fae..2e2c58c60 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/Implicit.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/Implicit.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.data.cassandra.test.integration.forcequote.config; import java.util.UUID; @@ -5,11 +21,13 @@ import java.util.UUID; import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.Table; +/** + * @author Matthew T. Adams + */ @Table(forceQuote = true) public class Implicit { - @PrimaryKey - String primaryKey; + @PrimaryKey String primaryKey; String stringValue = UUID.randomUUID().toString(); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitProperties.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitProperties.java index aacef094c..04c0454a9 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitProperties.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitProperties.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.data.cassandra.test.integration.forcequote.config; import java.util.UUID; @@ -6,14 +22,15 @@ import org.springframework.data.cassandra.mapping.Column; import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.Table; +/** + * @author Matthew T. Adams + */ @Table public class ImplicitProperties { - @PrimaryKey(forceQuote = true) - String primaryKey; + @PrimaryKey(forceQuote = true) String primaryKey; - @Column(forceQuote = true) - String stringValue = UUID.randomUUID().toString(); + @Column(forceQuote = true) String stringValue = UUID.randomUUID().toString(); public ImplicitProperties() { this(UUID.randomUUID().toString()); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitPropertiesRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitPropertiesRepository.java index 46c7f54d7..a6e3f99f6 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitPropertiesRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitPropertiesRepository.java @@ -1,5 +1,23 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.config; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; +/** + * @author Matthew T. Adams + */ public interface ImplicitPropertiesRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitRepository.java index e9c3d9829..6f8dfd8d0 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitRepository.java @@ -1,5 +1,23 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.forcequote.config; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; +/** + * @author Matthew T. Adams + */ public interface ImplicitRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/proxy/CassandraTemplateMapIdProxyDelegateIntegrationTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/proxy/CassandraTemplateMapIdProxyDelegateIntegrationTests.java similarity index 69% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/proxy/CassandraTemplateMapIdProxyDelegateIntegrationTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/proxy/CassandraTemplateMapIdProxyDelegateIntegrationTests.java index db222d64f..2ac30418b 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/proxy/CassandraTemplateMapIdProxyDelegateIntegrationTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/proxy/CassandraTemplateMapIdProxyDelegateIntegrationTests.java @@ -1,11 +1,22 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.mapping.mapid.proxy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.springframework.data.cassandra.repository.support.MapIdFactory.id; +import static org.junit.Assert.*; +import static org.springframework.data.cassandra.repository.support.MapIdFactory.*; import org.junit.Before; import org.junit.Test; @@ -23,10 +34,15 @@ import org.springframework.data.cassandra.test.integration.support.IntegrationTe import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +/** + * Integration tests for {@link org.springframework.data.cassandra.core.CassandraTemplate} using {@link MapId}. + * + * @author Matthew T. Adams + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class CassandraTemplateMapIdProxyDelegateIntegrationTest extends - AbstractSpringDataEmbeddedCassandraIntegrationTest { +public class CassandraTemplateMapIdProxyDelegateIntegrationTests + extends AbstractSpringDataEmbeddedCassandraIntegrationTest { @Configuration public static class Config extends IntegrationTestConfig { @@ -37,12 +53,11 @@ public class CassandraTemplateMapIdProxyDelegateIntegrationTest extends } } - @Autowired - CassandraOperations t; + @Autowired CassandraOperations template; @Before public void before() { - assertNotNull(t); + assertNotNull(template); } @Test @@ -51,28 +66,28 @@ public class CassandraTemplateMapIdProxyDelegateIntegrationTest extends // insert SinglePkc inserted = new SinglePkc(uuid()); inserted.setValue(uuid()); - SinglePkc saved = t.insert(inserted); + SinglePkc saved = template.insert(inserted); assertSame(saved, inserted); // select SinglePkcId id = id(SinglePkcId.class).key(saved.getKey()); - SinglePkc selected = t.selectOneById(SinglePkc.class, id); + SinglePkc selected = template.selectOneById(SinglePkc.class, id); assertNotSame(selected, saved); assertEquals(saved.getKey(), selected.getKey()); assertEquals(saved.getValue(), selected.getValue()); // update selected.setValue(uuid()); - SinglePkc updated = t.update(selected); + SinglePkc updated = template.update(selected); assertSame(updated, selected); - selected = t.selectOneById(SinglePkc.class, id); + selected = template.selectOneById(SinglePkc.class, id); assertNotSame(selected, updated); assertEquals(updated.getValue(), selected.getValue()); // delete - t.delete(selected); - assertNull(t.selectOneById(SinglePkc.class, id)); + template.delete(selected); + assertNull(template.selectOneById(SinglePkc.class, id)); } public interface SinglePkcId { @@ -84,11 +99,9 @@ public class CassandraTemplateMapIdProxyDelegateIntegrationTest extends @Table public static class SinglePkc { - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - String key; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) String key; - @Column - String value; + @Column String value; /** * @deprecated for persistence use only @@ -124,12 +137,12 @@ public class CassandraTemplateMapIdProxyDelegateIntegrationTest extends // insert MultiPkc inserted = new MultiPkc(uuid(), uuid()); inserted.setValue(uuid()); - MultiPkc saved = t.insert(inserted); + MultiPkc saved = template.insert(inserted); assertSame(saved, inserted); // select MultiPkcId id = id(MultiPkcId.class).key0(saved.getKey0()).key1(saved.getKey1()); - MultiPkc selected = t.selectOneById(MultiPkc.class, id); + MultiPkc selected = template.selectOneById(MultiPkc.class, id); assertNotSame(selected, saved); assertEquals(saved.getKey0(), selected.getKey0()); assertEquals(saved.getKey1(), selected.getKey1()); @@ -137,16 +150,16 @@ public class CassandraTemplateMapIdProxyDelegateIntegrationTest extends // update selected.setValue(uuid()); - MultiPkc updated = t.update(selected); + MultiPkc updated = template.update(selected); assertSame(updated, selected); - selected = t.selectOneById(MultiPkc.class, id); + selected = template.selectOneById(MultiPkc.class, id); assertNotSame(selected, updated); assertEquals(updated.getValue(), selected.getValue()); // delete - t.delete(selected); - assertNull(t.selectOneById(MultiPkc.class, id)); + template.delete(selected); + assertNull(template.selectOneById(MultiPkc.class, id)); } public interface MultiPkcId { @@ -162,14 +175,11 @@ public class CassandraTemplateMapIdProxyDelegateIntegrationTest extends @Table public static class MultiPkc { - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - String key0; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) String key0; - @PrimaryKeyColumn(ordinal = 1) - String key1; + @PrimaryKeyColumn(ordinal = 1) String key1; - @Column - String value; + @Column String value; /** * @deprecated for persistence use only diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkc.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkc.java deleted file mode 100644 index 4331eb050..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkc.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.springframework.data.cassandra.test.integration.mapping.mapid.repo; - -import org.springframework.cassandra.core.PrimaryKeyType; -import org.springframework.data.cassandra.mapping.Column; -import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.mapping.Table; - -@Table -public class MultiPkc { - - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - String key0; - - @PrimaryKeyColumn(ordinal = 1) - String key1; - - @Column - String value; - - /** - * @deprecated for persistence use only - */ - @Deprecated - @SuppressWarnings("unused") - private MultiPkc() {} - - public MultiPkc(String key0, String key1) { - setKey0(key0); - setKey1(key1); - } - - public String getKey0() { - return key0; - } - - public void setKey0(String key0) { - this.key0 = key0; - } - - public String getKey1() { - return key1; - } - - public void setKey1(String key1) { - this.key1 = key1; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } -} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkcRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkcRepository.java deleted file mode 100644 index 1a4a3721b..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkcRepository.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.springframework.data.cassandra.test.integration.mapping.mapid.repo; - -import org.springframework.data.cassandra.repository.CassandraRepository; - -public interface MultiPkcRepository extends CassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPrimaryKeyColumns.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPrimaryKeyColumns.java new file mode 100644 index 000000000..a747f3a4d --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPrimaryKeyColumns.java @@ -0,0 +1,70 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.mapping.mapid.repo; + +import org.springframework.cassandra.core.PrimaryKeyType; +import org.springframework.data.cassandra.mapping.Column; +import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.mapping.Table; + +/** + * @author Matthew T. Adams + */ +@Table +public class MultiPrimaryKeyColumns { + + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) String key0; + + @PrimaryKeyColumn(ordinal = 1) String key1; + + @Column String value; + + /** + * @deprecated for persistence use only + */ + @Deprecated + @SuppressWarnings("unused") + private MultiPrimaryKeyColumns() {} + + public MultiPrimaryKeyColumns(String key0, String key1) { + setKey0(key0); + setKey1(key1); + } + + public String getKey0() { + return key0; + } + + public void setKey0(String key0) { + this.key0 = key0; + } + + public String getKey1() { + return key1; + } + + public void setKey1(String key1) { + this.key1 = key1; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/CqlStringUtilsTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPrimaryKeyColumnsRepository.java similarity index 55% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/CqlStringUtilsTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPrimaryKeyColumnsRepository.java index 9b72fe303..b70cc7250 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/CqlStringUtilsTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPrimaryKeyColumnsRepository.java @@ -1,18 +1,23 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.core.cql; +package org.springframework.data.cassandra.test.integration.mapping.mapid.repo; -public class CqlStringUtilsTest {} +import org.springframework.data.cassandra.repository.CassandraRepository; + +/** + * @author Matthew T. Adams + */ +public interface MultiPrimaryKeyColumnsRepository extends CassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/RepositoryMapIdIntegrationTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/RepositoryMapIdIntegrationTests.java similarity index 50% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/RepositoryMapIdIntegrationTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/RepositoryMapIdIntegrationTests.java index 2df98426d..63ca1d62e 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/RepositoryMapIdIntegrationTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/RepositoryMapIdIntegrationTests.java @@ -1,11 +1,22 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.cassandra.test.integration.mapping.mapid.repo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.springframework.data.cassandra.repository.support.BasicMapId.id; +import static org.junit.Assert.*; +import static org.springframework.data.cassandra.repository.support.BasicMapId.*; import org.junit.Before; import org.junit.Test; @@ -20,78 +31,78 @@ import org.springframework.data.cassandra.test.integration.support.IntegrationTe import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +/** + * Integration tests for repositories using {@link MapId}. + * + * @author Matthew T. Adams. + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class RepositoryMapIdIntegrationTest extends AbstractSpringDataEmbeddedCassandraIntegrationTest { +public class RepositoryMapIdIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { @Configuration - @EnableCassandraRepositories(basePackageClasses = RepositoryMapIdIntegrationTest.class) + @EnableCassandraRepositories(basePackageClasses = RepositoryMapIdIntegrationTests.class) public static class Config extends IntegrationTestConfig { @Override public String[] getEntityBasePackages() { - return new String[] { SinglePkc.class.getPackage().getName() }; + return new String[] { SinglePrimaryKeyColumn.class.getPackage().getName() }; } } - @Autowired - CassandraOperations t; - - @Autowired - SinglePkcRepository sr; - - @Autowired - MultiPkcRepository mr; + @Autowired CassandraOperations template; + @Autowired SinglePrimaryKecColumnRepository singlePrimaryKecColumnRepository; + @Autowired MultiPrimaryKeyColumnsRepository multiPrimaryKeyColumnsRepository; @Before public void before() { - assertNotNull(t); - assertNotNull(sr); - assertNotNull(mr); + assertNotNull(template); + assertNotNull(singlePrimaryKecColumnRepository); + assertNotNull(multiPrimaryKeyColumnsRepository); } @Test public void testSinglePkc() { // insert - SinglePkc inserted = new SinglePkc(uuid()); + SinglePrimaryKeyColumn inserted = new SinglePrimaryKeyColumn(uuid()); inserted.setValue(uuid()); - SinglePkc saved = sr.save(inserted); + SinglePrimaryKeyColumn saved = singlePrimaryKecColumnRepository.save(inserted); assertSame(saved, inserted); // select MapId id = id("key", saved.getKey()); - SinglePkc selected = sr.findOne(id); + SinglePrimaryKeyColumn selected = singlePrimaryKecColumnRepository.findOne(id); assertNotSame(selected, saved); assertEquals(saved.getKey(), selected.getKey()); assertEquals(saved.getValue(), selected.getValue()); // update selected.setValue(uuid()); - SinglePkc updated = sr.save(selected); + SinglePrimaryKeyColumn updated = singlePrimaryKecColumnRepository.save(selected); assertSame(updated, selected); - selected = sr.findOne(id); + selected = singlePrimaryKecColumnRepository.findOne(id); assertNotSame(selected, updated); assertEquals(updated.getValue(), selected.getValue()); // delete - sr.delete(selected); - assertNull(sr.findOne(id)); + singlePrimaryKecColumnRepository.delete(selected); + assertNull(singlePrimaryKecColumnRepository.findOne(id)); } @Test public void testMultiPkc() { // insert - MultiPkc inserted = new MultiPkc(uuid(), uuid()); + MultiPrimaryKeyColumns inserted = new MultiPrimaryKeyColumns(uuid(), uuid()); inserted.setValue(uuid()); - MultiPkc saved = mr.save(inserted); + MultiPrimaryKeyColumns saved = multiPrimaryKeyColumnsRepository.save(inserted); assertSame(saved, inserted); // select MapId id = id("key0", saved.getKey0()).with("key1", saved.getKey1()); - MultiPkc selected = mr.findOne(id); + MultiPrimaryKeyColumns selected = multiPrimaryKeyColumnsRepository.findOne(id); assertNotSame(selected, saved); assertEquals(saved.getKey0(), selected.getKey0()); assertEquals(saved.getKey1(), selected.getKey1()); @@ -99,16 +110,16 @@ public class RepositoryMapIdIntegrationTest extends AbstractSpringDataEmbeddedCa // update selected.setValue(uuid()); - MultiPkc updated = mr.save(selected); + MultiPrimaryKeyColumns updated = multiPrimaryKeyColumnsRepository.save(selected); assertSame(updated, selected); - selected = mr.findOne(id); + selected = multiPrimaryKeyColumnsRepository.findOne(id); assertNotSame(selected, updated); assertEquals(updated.getValue(), selected.getValue()); // delete - t.delete(selected); - assertNull(mr.findOne(id)); + template.delete(selected); + assertNull(multiPrimaryKeyColumnsRepository.findOne(id)); } } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkc.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkc.java deleted file mode 100644 index 1a00dad81..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkc.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.springframework.data.cassandra.test.integration.mapping.mapid.repo; - -import org.springframework.cassandra.core.PrimaryKeyType; -import org.springframework.data.cassandra.mapping.Column; -import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.mapping.Table; - -@Table -public class SinglePkc { - - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - String key; - - @Column - String value; - - /** - * @deprecated for persistence use only - */ - @Deprecated - @SuppressWarnings("unused") - private SinglePkc() {} - - public SinglePkc(String key) { - setKey(key); - } - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } -} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkcRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkcRepository.java deleted file mode 100644 index 98fd736f7..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkcRepository.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.springframework.data.cassandra.test.integration.mapping.mapid.repo; - -import org.springframework.data.cassandra.repository.CassandraRepository; - -public interface SinglePkcRepository extends CassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePrimaryKecColumnRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePrimaryKecColumnRepository.java new file mode 100644 index 000000000..ba4cf89b8 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePrimaryKecColumnRepository.java @@ -0,0 +1,23 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.mapping.mapid.repo; + +import org.springframework.data.cassandra.repository.CassandraRepository; + +/** + * @author Matthew T. Adams + */ +public interface SinglePrimaryKecColumnRepository extends CassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePrimaryKeyColumn.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePrimaryKeyColumn.java new file mode 100644 index 000000000..34086f655 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePrimaryKeyColumn.java @@ -0,0 +1,59 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.mapping.mapid.repo; + +import org.springframework.cassandra.core.PrimaryKeyType; +import org.springframework.data.cassandra.mapping.Column; +import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.mapping.Table; + +/** + * @author Matthew T. Adams + */ +@Table +public class SinglePrimaryKeyColumn { + + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) String key; + + @Column String value; + + /** + * @deprecated for persistence use only + */ + @Deprecated + @SuppressWarnings("unused") + private SinglePrimaryKeyColumn() {} + + public SinglePrimaryKeyColumn(String key) { + setKey(key); + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/template/CassandraTemplateMapIdIntegrationTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/template/CassandraTemplateMapIdIntegrationTest.java index 28a0ae56c..cfd626d9c 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/template/CassandraTemplateMapIdIntegrationTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/template/CassandraTemplateMapIdIntegrationTest.java @@ -1,11 +1,23 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.data.cassandra.test.integration.mapping.mapid.template; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.springframework.data.cassandra.repository.support.BasicMapId.id; +import static org.junit.Assert.*; +import static org.springframework.data.cassandra.repository.support.BasicMapId.*; import org.junit.Before; import org.junit.Test; @@ -23,6 +35,11 @@ import org.springframework.data.cassandra.test.integration.support.IntegrationTe import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +/** + * Integration tests for {@link org.springframework.data.cassandra.core.CassandraTemplate} with {@link MapId}. + * + * @author Matthew T. Adams + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class CassandraTemplateMapIdIntegrationTest extends AbstractSpringDataEmbeddedCassandraIntegrationTest { @@ -36,12 +53,11 @@ public class CassandraTemplateMapIdIntegrationTest extends AbstractSpringDataEmb } } - @Autowired - CassandraOperations t; + @Autowired CassandraOperations template; @Before public void before() { - assertNotNull(t); + assertNotNull(template); } @Test @@ -50,38 +66,36 @@ public class CassandraTemplateMapIdIntegrationTest extends AbstractSpringDataEmb // insert SinglePkc inserted = new SinglePkc(uuid()); inserted.setValue(uuid()); - SinglePkc saved = t.insert(inserted); + SinglePkc saved = template.insert(inserted); assertSame(saved, inserted); // select MapId id = id("key", saved.getKey()); - SinglePkc selected = t.selectOneById(SinglePkc.class, id); + SinglePkc selected = template.selectOneById(SinglePkc.class, id); assertNotSame(selected, saved); assertEquals(saved.getKey(), selected.getKey()); assertEquals(saved.getValue(), selected.getValue()); // update selected.setValue(uuid()); - SinglePkc updated = t.update(selected); + SinglePkc updated = template.update(selected); assertSame(updated, selected); - selected = t.selectOneById(SinglePkc.class, id); + selected = template.selectOneById(SinglePkc.class, id); assertNotSame(selected, updated); assertEquals(updated.getValue(), selected.getValue()); // delete - t.delete(selected); - assertNull(t.selectOneById(SinglePkc.class, id)); + template.delete(selected); + assertNull(template.selectOneById(SinglePkc.class, id)); } @Table public static class SinglePkc { - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - String key; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) String key; - @Column - String value; + @Column String value; /** * @deprecated for persistence use only @@ -117,12 +131,12 @@ public class CassandraTemplateMapIdIntegrationTest extends AbstractSpringDataEmb // insert MultiPkc inserted = new MultiPkc(uuid(), uuid()); inserted.setValue(uuid()); - MultiPkc saved = t.insert(inserted); + MultiPkc saved = template.insert(inserted); assertSame(saved, inserted); // select MapId id = id("key0", saved.getKey0()).with("key1", saved.getKey1()); - MultiPkc selected = t.selectOneById(MultiPkc.class, id); + MultiPkc selected = template.selectOneById(MultiPkc.class, id); assertNotSame(selected, saved); assertEquals(saved.getKey0(), selected.getKey0()); assertEquals(saved.getKey1(), selected.getKey1()); @@ -130,29 +144,26 @@ public class CassandraTemplateMapIdIntegrationTest extends AbstractSpringDataEmb // update selected.setValue(uuid()); - MultiPkc updated = t.update(selected); + MultiPkc updated = template.update(selected); assertSame(updated, selected); - selected = t.selectOneById(MultiPkc.class, id); + selected = template.selectOneById(MultiPkc.class, id); assertNotSame(selected, updated); assertEquals(updated.getValue(), selected.getValue()); // delete - t.delete(selected); - assertNull(t.selectOneById(MultiPkc.class, id)); + template.delete(selected); + assertNull(template.selectOneById(MultiPkc.class, id)); } @Table public static class MultiPkc { - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - String key0; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) String key0; - @PrimaryKeyColumn(ordinal = 1) - String key1; + @PrimaryKeyColumn(ordinal = 1) String key1; - @Column - String value; + @Column String value; /** * @deprecated for persistence use only diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/AbsoluteMinimumXmlConfigIntegrationTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/AbsoluteMinimumXmlConfigIntegrationTests.java similarity index 82% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/AbsoluteMinimumXmlConfigIntegrationTest.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/AbsoluteMinimumXmlConfigIntegrationTests.java index 9e001668c..a25d707d0 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/AbsoluteMinimumXmlConfigIntegrationTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/AbsoluteMinimumXmlConfigIntegrationTests.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,7 +15,7 @@ */ package org.springframework.data.cassandra.test.integration.minimal.config; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; @@ -26,18 +26,21 @@ import org.springframework.data.cassandra.test.integration.support.AbstractSprin import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +/** + * Integration tests for XML-based configuration. + * + * @author Matthew T. Adams + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class AbsoluteMinimumXmlConfigIntegrationTest extends AbstractSpringDataEmbeddedCassandraIntegrationTest { +public class AbsoluteMinimumXmlConfigIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { - @Autowired - CassandraMappingContext context; + @Autowired CassandraMappingContext context; @Test public void test() { assertNotNull(context); - context.getPersistentEntity(AbsMin.class); } } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/entities/AbsMin.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/entities/AbsMin.java index 3d4965b0b..7642eecd1 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/entities/AbsMin.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/entities/AbsMin.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,10 +18,12 @@ package org.springframework.data.cassandra.test.integration.minimal.config.entit import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.Table; +/** + * @author Matthew T. Adams + */ @Table public class AbsMin { - @PrimaryKey - String key; + @PrimaryKey String key; } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/entities/AbsMinRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/entities/AbsMinRepository.java index a6564f2c6..6c5172298 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/entities/AbsMinRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/entities/AbsMinRepository.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,4 +17,7 @@ package org.springframework.data.cassandra.test.integration.minimal.config.entit import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; +/** + * @author Matthew T. Adams + */ public interface AbsMinRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/bigintparam/BigThing.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/bigintparam/BigThing.java deleted file mode 100644 index ce2c22129..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/bigintparam/BigThing.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.springframework.data.cassandra.test.integration.querymethods.bigintparam; - -import org.springframework.cassandra.core.PrimaryKeyType; -import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.mapping.Table; - -import java.math.BigInteger; - -@Table -public class BigThing { - - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private BigInteger number; - - public BigThing() {} - - public BigThing(BigInteger number) { - setNumber(number); - } - - public BigInteger getNumber() { - return number; - } - - public void setNumber(BigInteger number) { - this.number = number; - } -} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/bigintparam/BigThingRepo.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/bigintparam/BigThingRepo.java deleted file mode 100644 index be6118efe..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/bigintparam/BigThingRepo.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.springframework.data.cassandra.test.integration.querymethods.bigintparam; - -import org.springframework.data.cassandra.repository.CassandraRepository; -import org.springframework.data.cassandra.repository.Query; - -import java.math.BigInteger; - -public interface BigThingRepo extends CassandraRepository { - - @Query("SELECT * from bigthing where number = ?0") - BigThing findThingByBigInteger(BigInteger number); - -} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/Thing.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/Thing.java deleted file mode 100644 index 09d5c55e4..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/Thing.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.springframework.data.cassandra.test.integration.querymethods.datekey; - -import java.util.Date; - -import org.springframework.cassandra.core.PrimaryKeyType; -import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.mapping.Table; -import org.springframework.util.Assert; - -@Table -public class Thing { - - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private Date date; - - protected Thing() {} - - public Thing(Date date) { - setDate(date); - } - - public Date getDate() { - return new Date(date.getTime()); - } - - public void setDate(Date date) { - Assert.notNull(date); - this.date = new Date(date.getTime()); - } -} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/ThingRepo.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/ThingRepo.java deleted file mode 100644 index fa659d385..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/ThingRepo.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.springframework.data.cassandra.test.integration.querymethods.datekey; - -import java.util.Date; - -import org.springframework.data.cassandra.repository.CassandraRepository; -import org.springframework.data.cassandra.repository.Query; - -public interface ThingRepo extends CassandraRepository { - - @Query("SELECT * from thing where date = ?0") - Thing findThingByDate(Date date); -} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/anno/QueryAnnotationIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/anno/QueryAnnotationIntegrationTests.java deleted file mode 100644 index 9b6c184a5..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/anno/QueryAnnotationIntegrationTests.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.springframework.data.cassandra.test.integration.querymethods.declared.anno; - -import org.springframework.context.annotation.Configuration; -import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; -import org.springframework.data.cassandra.test.integration.querymethods.declared.QueryIntegrationTests; -import org.springframework.test.context.ContextConfiguration; - -@ContextConfiguration -public class QueryAnnotationIntegrationTests extends QueryIntegrationTests { - - @Configuration - @EnableCassandraRepositories(basePackageClasses = PersonRepositoryWithQueryAnnotations.class) - public static class Config extends QueryIntegrationTests.Config {} -} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/NamedQueryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/NamedQueryIntegrationTests.java deleted file mode 100644 index ca629a0cc..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/NamedQueryIntegrationTests.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.springframework.data.cassandra.test.integration.querymethods.declared.named; - -import org.springframework.context.annotation.Configuration; -import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; -import org.springframework.data.cassandra.test.integration.querymethods.declared.QueryIntegrationTests; -import org.springframework.test.context.ContextConfiguration; - -@ContextConfiguration -public class NamedQueryIntegrationTests extends QueryIntegrationTests { - - @Configuration - @EnableCassandraRepositories(basePackageClasses = PersonRepositoryWithNamedQueries.class, - namedQueriesLocation = "classpath:META-INF/PersonRepositoryWithNamedQueries.properties") - public static class Config extends QueryIntegrationTests.Config {} -} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/PersonRepositoryWithNamedQueries.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/PersonRepositoryWithNamedQueries.java deleted file mode 100644 index 954ec79d8..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/PersonRepositoryWithNamedQueries.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.springframework.data.cassandra.test.integration.querymethods.declared.named; - -import org.springframework.data.cassandra.test.integration.querymethods.declared.base.PersonRepository; - -public interface PersonRepositoryWithNamedQueries extends PersonRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/derived/TODO.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/derived/TODO.java deleted file mode 100644 index 678cd8808..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/derived/TODO.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.springframework.data.cassandra.test.integration.querymethods.derived; - -// TODO -public class TODO {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/Thing.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/Thing.java deleted file mode 100644 index 09f8cba66..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/Thing.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.springframework.data.cassandra.test.integration.querymethods.intparam; - -import org.springframework.cassandra.core.PrimaryKeyType; -import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; -import org.springframework.data.cassandra.mapping.Table; - -@Table -public class Thing { - - @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) - private int number; - - public Thing() {} - - public Thing(int number) { - setNumber(number); - } - - public int getNumber() { - return number; - } - - public void setNumber(int number) { - this.number = number; - } -} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/ThingRepo.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/ThingRepo.java deleted file mode 100644 index afe78522f..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/ThingRepo.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.springframework.data.cassandra.test.integration.querymethods.intparam; - -import org.springframework.data.cassandra.repository.CassandraRepository; -import org.springframework.data.cassandra.repository.Query; - -public interface ThingRepo extends CassandraRepository { - - @Query("SELECT * from thing where number = ?0") - Thing findThingByIntPrimitive(int number); - - @Query("SELECT * from thing where number = ?0") - Thing findThingByIntReference(Integer number); -} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/CassandraOperationsProducer.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/CassandraOperationsProducer.java index e7fab7c0b..0592f1f71 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/CassandraOperationsProducer.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/CassandraOperationsProducer.java @@ -21,35 +21,52 @@ import java.util.Set; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Disposes; import javax.enterprise.inject.Produces; +import javax.inject.Singleton; -import com.google.common.collect.Sets; -import com.google.common.util.concurrent.Service; import org.springframework.cassandra.core.cql.CqlIdentifier; import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification; -import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest; +import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification; +import org.springframework.cassandra.support.RandomKeySpaceName; +import org.springframework.cassandra.test.integration.support.CassandraConnectionProperties; import org.springframework.data.cassandra.convert.MappingCassandraConverter; import org.springframework.data.cassandra.core.CassandraAdminTemplate; import org.springframework.data.cassandra.core.CassandraOperations; import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; -import org.springframework.data.cassandra.test.integration.repository.User; +import org.springframework.data.cassandra.test.integration.repository.simple.User; + +import com.datastax.driver.core.Cluster; +import com.google.common.collect.Sets; +import com.google.common.util.concurrent.Service; /** * @author Mark Paluch */ -@ApplicationScoped class CassandraOperationsProducer { + public final static String KEYSPACE_NAME = RandomKeySpaceName.create(); + @Produces - public CassandraOperations createCassandraOperations() throws Exception { - String keySpace = AbstractEmbeddedCassandraIntegrationTest.randomKeyspaceName(); + @Singleton + public Cluster createCluster() throws Exception { + CassandraConnectionProperties properties = new CassandraConnectionProperties(); + + Cluster cluster = Cluster.builder().addContactPoint(properties.getCassandraHost()) + .withPort(properties.getCassandraPort()).build(); + return cluster; + } + + @Produces + @ApplicationScoped + public CassandraOperations createCassandraOperations(Cluster cluster) throws Exception { MappingCassandraConverter cassandraConverter = new MappingCassandraConverter(); - CassandraAdminTemplate cassandraTemplate = new CassandraAdminTemplate(AbstractEmbeddedCassandraIntegrationTest - .cluster().connect(), cassandraConverter); - CreateKeyspaceSpecification createKeyspaceSpecification = new CreateKeyspaceSpecification(keySpace).ifNotExists(); + CassandraAdminTemplate cassandraTemplate = new CassandraAdminTemplate(cluster.connect(), cassandraConverter); + + CreateKeyspaceSpecification createKeyspaceSpecification = new CreateKeyspaceSpecification(KEYSPACE_NAME) + .ifNotExists(); cassandraTemplate.execute(createKeyspaceSpecification); - cassandraTemplate.execute("USE " + keySpace); + cassandraTemplate.execute("USE " + KEYSPACE_NAME); cassandraTemplate.createTable(true, CqlIdentifier.cqlId("users"), User.class, new HashMap()); @@ -62,9 +79,15 @@ class CassandraOperationsProducer { } public void close(@Disposes CassandraOperations cassandraOperations) { + + cassandraOperations.execute(DropKeyspaceSpecification.dropKeyspace(KEYSPACE_NAME)); cassandraOperations.getSession().close(); } + public void close(@Disposes Cluster cluster) { + cluster.close(); + } + @Produces public Set producerToSatisfyGuavaDependenciesWhenTesting() { return Sets.newHashSet(); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/CdiRepositoryTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/CdiRepositoryTests.java index 68ea58f5a..ec526d7fb 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/CdiRepositoryTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/CdiRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,13 +25,12 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest; -import org.springframework.data.cassandra.test.integration.repository.User; +import org.springframework.data.cassandra.test.integration.repository.simple.User; /** * @author Mohsin Husen * @author Mark Paluch */ - public class CdiRepositoryTests extends AbstractEmbeddedCassandraIntegrationTest { private static CdiTestContainer cdiContainer; @@ -40,9 +39,13 @@ public class CdiRepositoryTests extends AbstractEmbeddedCassandraIntegrationTest @BeforeClass public static void init() throws Exception { - startCassandra(); + // CDI container is booted before the @Rule can be triggered. + // Ensure that we have a usable Cassandra instance otherwise the container won't boot + // because it needs a CassandraOperations with a working Session/Cluster + cdiContainer = CdiTestContainerLoader.getCdiContainer(); cdiContainer.startApplicationScope(); + cdiContainer.startContexts(); cdiContainer.bootContainer(); } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/CdiUserRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/CdiUserRepository.java index 8a3b5dac0..0f735ede1 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/CdiUserRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/CdiUserRepository.java @@ -15,7 +15,7 @@ */ package org.springframework.data.cassandra.test.integration.repository.cdi; -import org.springframework.data.cassandra.test.integration.repository.User; +import org.springframework.data.cassandra.test.integration.repository.simple.User; import org.springframework.data.repository.CrudRepository; /** diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/SamplePersonRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/SamplePersonRepository.java index bba7a5f7e..515051797 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/SamplePersonRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/cdi/SamplePersonRepository.java @@ -16,7 +16,7 @@ package org.springframework.data.cassandra.test.integration.repository.cdi; -import org.springframework.data.cassandra.test.integration.querymethods.declared.Person; +import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Person; import org.springframework.data.repository.Repository; /** diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/bigintparam/BigIntParamIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/bigintparam/BigIntParamIntegrationTests.java similarity index 63% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/bigintparam/BigIntParamIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/bigintparam/BigIntParamIntegrationTests.java index 0de834747..c1320bbea 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/bigintparam/BigIntParamIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/bigintparam/BigIntParamIntegrationTests.java @@ -1,4 +1,24 @@ -package org.springframework.data.cassandra.test.integration.querymethods.bigintparam; +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.cassandra.test.integration.repository.querymethods.bigintparam; + +import static org.junit.Assert.*; + +import java.math.BigInteger; import org.junit.Test; import org.junit.runner.RunWith; @@ -11,10 +31,11 @@ import org.springframework.data.cassandra.test.integration.support.IntegrationTe import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.math.BigInteger; - -import static org.junit.Assert.assertNotNull; - +/** + * Integration tests for {@link BigInteger} usage in repositories. + * + * @author Pete Cable + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class BigIntParamIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { @@ -33,8 +54,7 @@ public class BigIntParamIntegrationTests extends AbstractSpringDataEmbeddedCassa } } - @Autowired - BigThingRepo repo; + @Autowired BigThingRepo repo; @Test public void testQueryWithReference() { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/bigintparam/BigThing.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/bigintparam/BigThing.java new file mode 100644 index 000000000..fd7a47934 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/bigintparam/BigThing.java @@ -0,0 +1,45 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository.querymethods.bigintparam; + +import java.math.BigInteger; + +import org.springframework.cassandra.core.PrimaryKeyType; +import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.mapping.Table; + +/** + * @author Pete Cable + */ +@Table +public class BigThing { + + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private BigInteger number; + + public BigThing() {} + + public BigThing(BigInteger number) { + setNumber(number); + } + + public BigInteger getNumber() { + return number; + } + + public void setNumber(BigInteger number) { + this.number = number; + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/bigintparam/BigThingRepo.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/bigintparam/BigThingRepo.java new file mode 100644 index 000000000..7ffee3f9e --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/bigintparam/BigThingRepo.java @@ -0,0 +1,31 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository.querymethods.bigintparam; + +import java.math.BigInteger; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.data.cassandra.repository.Query; + +/** + * @author Pete Cable + */ +public interface BigThingRepo extends CassandraRepository { + + @Query("SELECT * from bigthing where number = ?0") + BigThing findThingByBigInteger(BigInteger number); + +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/DateKeyIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/datekey/DateKeyIntegrationTests.java similarity index 52% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/DateKeyIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/datekey/DateKeyIntegrationTests.java index c3a800586..756df1238 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/DateKeyIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/datekey/DateKeyIntegrationTests.java @@ -1,6 +1,21 @@ -package org.springframework.data.cassandra.test.integration.querymethods.datekey; +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository.querymethods.datekey; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; import java.util.Date; @@ -15,16 +30,21 @@ import org.springframework.data.cassandra.test.integration.support.IntegrationTe import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +/** + * Integration tests for {@link Date} usage in repositories. + * + * @author Matthew T. Adams + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class DateKeyIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { @Configuration - @EnableCassandraRepositories(basePackageClasses = ThingRepo.class) + @EnableCassandraRepositories(basePackageClasses = DateThingRepo.class) public static class Config extends IntegrationTestConfig { @Override public String[] getEntityBasePackages() { - return new String[] { Thing.class.getPackage().getName() }; + return new String[] { DateThing.class.getPackage().getName() }; } @Override @@ -33,16 +53,15 @@ public class DateKeyIntegrationTests extends AbstractSpringDataEmbeddedCassandra } } - @Autowired - ThingRepo repo; + @Autowired DateThingRepo repo; @Test public void testQueryWithDate() { Date date = new Date(); - Thing saved = new Thing(date); + DateThing saved = new DateThing(date); repo.save(saved); - Thing found = repo.findThingByDate(date); + DateThing found = repo.findThingByDate(date); assertNotNull(found); } } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/datekey/DateThing.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/datekey/DateThing.java new file mode 100644 index 000000000..55b3aed23 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/datekey/DateThing.java @@ -0,0 +1,47 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository.querymethods.datekey; + +import java.util.Date; + +import org.springframework.cassandra.core.PrimaryKeyType; +import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.mapping.Table; +import org.springframework.util.Assert; + +/** + * @author Matthew T. Adams + */ +@Table +public class DateThing { + + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private Date date; + + protected DateThing() {} + + public DateThing(Date date) { + setDate(date); + } + + public Date getDate() { + return new Date(date.getTime()); + } + + public void setDate(Date date) { + Assert.notNull(date); + this.date = new Date(date.getTime()); + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/datekey/DateThingRepo.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/datekey/DateThingRepo.java new file mode 100644 index 000000000..f276ded4b --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/datekey/DateThingRepo.java @@ -0,0 +1,32 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository.querymethods.datekey; + +import java.util.Date; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.data.cassandra.repository.Query; + +/** + * Integration tests for {@link Date} usage in repositories. + * + * @author Matthew T. Adams + */ +public interface DateThingRepo extends CassandraRepository { + + @Query("SELECT * from datething where date = ?0") + DateThing findThingByDate(Date date); +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/Person.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/Person.java similarity index 91% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/Person.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/Person.java index b9213795d..85ef492f3 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/Person.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/Person.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.querymethods.declared; +package org.springframework.data.cassandra.test.integration.repository.querymethods.declared; import java.util.Date; @@ -27,11 +27,9 @@ import org.springframework.data.cassandra.mapping.Table; @Table public class Person { - @PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED, ordinal = 0) - private String lastname; + @PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED, ordinal = 0) private String lastname; - @PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 1) - private String firstname; + @PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 1) private String firstname; private String nickname; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/QueryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/QueryIntegrationTests.java similarity index 68% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/QueryIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/QueryIntegrationTests.java index 907cf0feb..2e062d4db 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/QueryIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/QueryIntegrationTests.java @@ -1,8 +1,21 @@ -package org.springframework.data.cassandra.test.integration.querymethods.declared; +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository.querymethods.declared; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.Collection; import java.util.Date; @@ -14,11 +27,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.cassandra.config.SchemaAction; -import org.springframework.data.cassandra.test.integration.querymethods.declared.base.PersonRepository; +import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.base.PersonRepository; import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +/** + * @author Matthew T. Adams + */ @RunWith(SpringJUnit4ClassRunner.class) public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { @@ -35,8 +51,7 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa } } - @Autowired - PersonRepository r; + @Autowired PersonRepository personRepository; @Before public void before() { @@ -50,9 +65,9 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa saved.setFirstname(uuid()); saved.setLastname(uuid()); - saved = r.save(saved); + saved = personRepository.save(saved); - List results = r.findFolksWithLastnameAsList(saved.getLastname()); + List results = personRepository.findFolksWithLastnameAsList(saved.getLastname()); assertNotNull(results); assertTrue(results.size() == 1); @@ -69,15 +84,15 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa saved.setFirstname("a"); saved.setLastname(uuid()); - saved = r.save(saved); + saved = personRepository.save(saved); Person saved2 = new Person(); saved2.setFirstname("b"); saved2.setLastname(saved.getLastname()); - saved2 = r.save(saved2); + saved2 = personRepository.save(saved2); - List results = r.findFolksWithLastnameAsList(saved.getLastname()); + List results = personRepository.findFolksWithLastnameAsList(saved.getLastname()); assertNotNull(results); assertTrue(results.size() == 2); @@ -97,9 +112,10 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa saved.setFirstname(uuid()); saved.setLastname(uuid()); - saved = r.save(saved); + saved = personRepository.save(saved); - List> results = r.findFolksWithLastnameAsListOfMapOfStringToObject(saved.getLastname()); + List> results = personRepository + .findFolksWithLastnameAsListOfMapOfStringToObject(saved.getLastname()); assertNotNull(results); assertTrue(results.size() == 1); @@ -116,9 +132,9 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa saved.setFirstname(uuid()); saved.setLastname(uuid()); - saved = r.save(saved); + saved = personRepository.save(saved); - Person found = r.findSingle(saved.getLastname(), saved.getFirstname()); + Person found = personRepository.findSingle(saved.getLastname(), saved.getFirstname()); assertNotNull(found); assertEquals(found.getLastname(), saved.getLastname()); @@ -132,15 +148,15 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa saved.setFirstname("a"); saved.setLastname(uuid()); - saved = r.save(saved); + saved = personRepository.save(saved); Person saved2 = new Person(); saved2.setFirstname("b"); saved2.setLastname(saved.getLastname()); - saved2 = r.save(saved2); + saved2 = personRepository.save(saved2); - Collection results = r.findFolksWithLastnameAsList(saved.getLastname()); + Collection results = personRepository.findFolksWithLastnameAsList(saved.getLastname()); assertNotNull(results); assertTrue(results.size() == 2); @@ -161,9 +177,9 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa saved.setLastname(uuid()); saved.setNickname(uuid()); - saved = r.save(saved); + saved = personRepository.save(saved); - String nickname = r.findSingleNickname(saved.getLastname(), saved.getFirstname()); + String nickname = personRepository.findSingleNickname(saved.getLastname(), saved.getFirstname()); assertNotNull(nickname); assertEquals(saved.getNickname(), nickname); @@ -177,9 +193,9 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa saved.setLastname(uuid()); saved.setCool(true); - saved = r.save(saved); + saved = personRepository.save(saved); - boolean value = r.findSingleCool(saved.getLastname(), saved.getFirstname()); + boolean value = personRepository.findSingleCool(saved.getLastname(), saved.getFirstname()); assertEquals(saved.isCool(), value); } @@ -192,9 +208,9 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa saved.setLastname(uuid()); saved.setBirthDate(new Date()); - saved = r.save(saved); + saved = personRepository.save(saved); - Date value = r.findSingleBirthdate(saved.getLastname(), saved.getFirstname()); + Date value = personRepository.findSingleBirthdate(saved.getLastname(), saved.getFirstname()); assertEquals(saved.getBirthDate(), value); } @@ -207,9 +223,9 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa saved.setLastname(uuid()); saved.setNumberOfChildren(1); - saved = r.save(saved); + saved = personRepository.save(saved); - int value = r.findSingleNumberOfChildren(saved.getLastname(), saved.getFirstname()); + int value = personRepository.findSingleNumberOfChildren(saved.getLastname(), saved.getFirstname()); assertEquals(saved.getNumberOfChildren(), value); } @@ -236,9 +252,9 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa saved.setFirstname(uuid()); saved.setLastname(uuid()); - saved = r.save(saved); + saved = personRepository.save(saved); - Person[] results = r.findFolksWithLastnameAsArray(saved.getLastname()); + Person[] results = personRepository.findFolksWithLastnameAsArray(saved.getLastname()); assertNotNull(results); assertTrue(results.length == 1); @@ -256,9 +272,9 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa String lastname = "O'Brian" + uuid(); saved.setLastname(lastname); - saved = r.save(saved); + saved = personRepository.save(saved); - List results = r.findFolksWithLastnameAsList(lastname); + List results = personRepository.findFolksWithLastnameAsList(lastname); assertNotNull(results); assertTrue(results.size() == 1); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/StringBasedCassandraQueryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/StringBasedCassandraQueryIntegrationTests.java similarity index 91% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/StringBasedCassandraQueryIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/StringBasedCassandraQueryIntegrationTests.java index 699d24900..28b78e1aa 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/StringBasedCassandraQueryIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/StringBasedCassandraQueryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2013 the original author or authors. + * Copyright 2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.querymethods.declared; +package org.springframework.data.cassandra.test.integration.repository.querymethods.declared; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; import java.lang.reflect.Method; @@ -40,20 +44,17 @@ import com.datastax.driver.core.SimpleStatement; import com.datastax.driver.core.querybuilder.QueryBuilder; import com.datastax.driver.core.querybuilder.Select; -import static org.hamcrest.Matchers.is; - -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; - /** * Unit tests for {@link StringBasedCassandraQuery}. + * + * @author Matthew T. Adams + * @author Oliver Gierke */ @RunWith(MockitoJUnitRunner.class) public class StringBasedCassandraQueryIntegrationTests { - @Mock - CassandraOperations operations; - + @Mock CassandraOperations operations; + RepositoryMetadata metadata; CassandraConverter converter; ProjectionFactory factory; @@ -72,7 +73,8 @@ public class StringBasedCassandraQueryIntegrationTests { public void bindsSimplePropertyCorrectly() throws Exception { Method method = SampleRepository.class.getMethod("findByLastname", String.class); - CassandraQueryMethod queryMethod = new CassandraQueryMethod(method, metadata, factory, converter.getMappingContext()); + CassandraQueryMethod queryMethod = new CassandraQueryMethod(method, metadata, factory, + converter.getMappingContext()); StringBasedCassandraQuery cassandraQuery = new StringBasedCassandraQuery(queryMethod, operations); CassandraParametersParameterAccessor accesor = new CassandraParametersParameterAccessor(queryMethod, "Matthews"); @@ -91,7 +93,8 @@ public class StringBasedCassandraQueryIntegrationTests { public void bindsMultipleParametersCorrectly() throws Exception { Method method = SampleRepository.class.getMethod("findByLastnameAndFirstname", String.class, String.class); - CassandraQueryMethod queryMethod = new CassandraQueryMethod(method, metadata, factory, converter.getMappingContext()); + CassandraQueryMethod queryMethod = new CassandraQueryMethod(method, metadata, factory, + converter.getMappingContext()); StringBasedCassandraQuery cassandraQuery = new StringBasedCassandraQuery(queryMethod, operations); CassandraParametersParameterAccessor accesor = new CassandraParametersParameterAccessor(queryMethod, "Matthews", "John"); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/anno/PersonRepositoryWithQueryAnnotations.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/anno/PersonRepositoryWithQueryAnnotations.java similarity index 59% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/anno/PersonRepositoryWithQueryAnnotations.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/anno/PersonRepositoryWithQueryAnnotations.java index 273e533c6..5d486130a 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/anno/PersonRepositoryWithQueryAnnotations.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/anno/PersonRepositoryWithQueryAnnotations.java @@ -1,18 +1,35 @@ -package org.springframework.data.cassandra.test.integration.querymethods.declared.anno; +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository.querymethods.declared.anno; import java.util.Date; import java.util.List; import java.util.Map; import org.springframework.data.cassandra.repository.Query; -import org.springframework.data.cassandra.test.integration.querymethods.declared.Person; -import org.springframework.data.cassandra.test.integration.querymethods.declared.base.PersonRepository; -import org.springframework.data.cassandra.test.integration.querymethods.declared.named.PersonRepositoryWithNamedQueries; +import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Person; +import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.base.PersonRepository; +import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.named.PersonRepositoryWithNamedQueries; import com.datastax.driver.core.ResultSet; /** * we extend {@link PersonRepositoryWithNamedQueries} here just to keep the test codebase in sync. + * + * @author Matthew T. Adams */ public interface PersonRepositoryWithQueryAnnotations extends PersonRepository { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/anno/QueryAnnotationIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/anno/QueryAnnotationIntegrationTests.java new file mode 100644 index 000000000..bae242a5f --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/anno/QueryAnnotationIntegrationTests.java @@ -0,0 +1,32 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository.querymethods.declared.anno; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; +import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.QueryIntegrationTests; +import org.springframework.test.context.ContextConfiguration; + +/** + * @author Matthew T. Adams + */ +@ContextConfiguration +public class QueryAnnotationIntegrationTests extends QueryIntegrationTests { + + @Configuration + @EnableCassandraRepositories(basePackageClasses = PersonRepositoryWithQueryAnnotations.class) + public static class Config extends QueryIntegrationTests.Config {} +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/base/PersonRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/base/PersonRepository.java similarity index 50% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/base/PersonRepository.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/base/PersonRepository.java index 4a4d97e92..f4da84590 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/base/PersonRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/base/PersonRepository.java @@ -1,15 +1,33 @@ -package org.springframework.data.cassandra.test.integration.querymethods.declared.base; +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository.querymethods.declared.base; import java.util.Date; import java.util.List; import java.util.Map; import org.springframework.data.cassandra.repository.CassandraRepository; -import org.springframework.data.cassandra.test.integration.querymethods.declared.Person; +import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Person; import org.springframework.data.repository.NoRepositoryBean; import com.datastax.driver.core.ResultSet; +/** + * @author Matthew T. Adams + */ @NoRepositoryBean public interface PersonRepository extends CassandraRepository { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/named/NamedQueryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/named/NamedQueryIntegrationTests.java new file mode 100644 index 000000000..3ea8ba907 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/named/NamedQueryIntegrationTests.java @@ -0,0 +1,31 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.cassandra.test.integration.repository.querymethods.declared.named; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; +import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.QueryIntegrationTests; +import org.springframework.test.context.ContextConfiguration; + +@ContextConfiguration +public class NamedQueryIntegrationTests extends QueryIntegrationTests { + + @Configuration + @EnableCassandraRepositories(basePackageClasses = PersonRepositoryWithNamedQueries.class, + namedQueriesLocation = "classpath:META-INF/PersonRepositoryWithNamedQueries.properties") + public static class Config extends QueryIntegrationTests.Config {} +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/support/Utils.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/named/PersonRepositoryWithNamedQueries.java similarity index 55% rename from spring-cql/src/test/java/org/springframework/cassandra/test/unit/support/Utils.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/named/PersonRepositoryWithNamedQueries.java index cb026961d..17283103b 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/support/Utils.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/declared/named/PersonRepositoryWithNamedQueries.java @@ -1,26 +1,21 @@ /* - * Copyright 2013-2014 the original author or authors. - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.cassandra.test.unit.support; -import java.util.UUID; +package org.springframework.data.cassandra.test.integration.repository.querymethods.declared.named; -public class Utils { +import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.base.PersonRepository; - public static String randomKeyspaceName() { - return "ks" + UUID.randomUUID().toString().replace("-", ""); - } - -} +public interface PersonRepositoryWithNamedQueries extends PersonRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/IntParamIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/intparam/IntParamIntegrationTests.java similarity index 55% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/IntParamIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/intparam/IntParamIntegrationTests.java index 15b7f78c0..7da32648c 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/IntParamIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/intparam/IntParamIntegrationTests.java @@ -1,6 +1,21 @@ -package org.springframework.data.cassandra.test.integration.querymethods.intparam; +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository.querymethods.intparam; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; @@ -13,16 +28,19 @@ import org.springframework.data.cassandra.test.integration.support.IntegrationTe import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +/** + * @author Matthew T. Adams + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class IntParamIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { @Configuration - @EnableCassandraRepositories(basePackageClasses = ThingRepo.class) + @EnableCassandraRepositories(basePackageClasses = IntThingRepo.class) public static class Config extends IntegrationTestConfig { @Override public String[] getEntityBasePackages() { - return new String[] { Thing.class.getPackage().getName() }; + return new String[] { IntThing.class.getPackage().getName() }; } @Override @@ -31,16 +49,15 @@ public class IntParamIntegrationTests extends AbstractSpringDataEmbeddedCassandr } } - @Autowired - ThingRepo repo; + @Autowired IntThingRepo repo; @Test public void testQueryWithIntPrimitiveAndReference() { int number = 42; - Thing saved = new Thing(42); + IntThing saved = new IntThing(42); repo.save(saved); - Thing found = repo.findThingByIntPrimitive(number); + IntThing found = repo.findThingByIntPrimitive(number); assertNotNull(found); found = repo.findThingByIntReference(new Integer(number)); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/intparam/IntThing.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/intparam/IntThing.java new file mode 100644 index 000000000..8cd223509 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/intparam/IntThing.java @@ -0,0 +1,43 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository.querymethods.intparam; + +import org.springframework.cassandra.core.PrimaryKeyType; +import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.mapping.Table; + +/** + * @author Matthew T. Adams + */ +@Table +public class IntThing { + + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private int number; + + public IntThing() {} + + public IntThing(int number) { + setNumber(number); + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/intparam/IntThingRepo.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/intparam/IntThingRepo.java new file mode 100644 index 000000000..018b0c138 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/querymethods/intparam/IntThingRepo.java @@ -0,0 +1,31 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository.querymethods.intparam; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.data.cassandra.repository.Query; + +/** + * @author Matthew T. Adams + */ +public interface IntThingRepo extends CassandraRepository { + + @Query("SELECT * from intthing where number = ?0") + IntThing findThingByIntPrimitive(int number); + + @Query("SELECT * from intthing where number = ?0") + IntThing findThingByIntReference(Integer number); +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/User.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/User.java similarity index 94% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/User.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/User.java index b78d9ff7a..2ef957966 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/User.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/User.java @@ -1,19 +1,19 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.repository; +package org.springframework.data.cassandra.test.integration.repository.simple; import java.util.Set; @@ -25,7 +25,7 @@ import org.springframework.data.cassandra.mapping.Table; * This is an example of the Users status table, where all fields are columns in Cassandra row. Some fields can be * Set,List,Map like emails. User contains base information related for separate user, like names, additional * information, emails, following users, friends. - * + * * @author Alex Shvid */ @Table("users") @@ -34,8 +34,7 @@ public class User { /* * Primary Row ID */ - @Id - private String username; + @Id private String username; /* * Public information @@ -47,8 +46,7 @@ public class User { * Secondary index, used only on fields with common information, * not effective on email, username */ - @Indexed - private String place; + @Indexed private String place; /* * User emails @@ -61,7 +59,7 @@ public class User { private String password; /* - * Birth Year + * Birth Year */ private int birthYear; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepository.java similarity index 87% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepository.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepository.java index f0d8eb100..98aafc205 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepository.java @@ -1,25 +1,25 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.repository; +package org.springframework.data.cassandra.test.integration.repository.simple; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; /** * Sample repository managing {@link User} entities. - * + * * @author Alex Shvid * @author Matthew T. Adams */ diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryIntegrationTests.java similarity index 90% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryIntegrationTests.java index 7e6fb3252..7f14d3a82 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryIntegrationTests.java @@ -1,19 +1,22 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.repository; +package org.springframework.data.cassandra.test.integration.repository.simple; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; import java.util.Arrays; import java.util.List; @@ -23,17 +26,9 @@ import org.springframework.data.cassandra.core.CassandraOperations; import com.google.common.collect.Lists; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; - -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - /** * Tests for {@link UserRepository}. - * + * * @author Alex Shvid * @author Matthew T. Adams * @author David Webb diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTestsDelegator.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryIntegrationTestsDelegator.java similarity index 77% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTestsDelegator.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryIntegrationTestsDelegator.java index 813caff21..59454a9b2 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTestsDelegator.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryIntegrationTestsDelegator.java @@ -1,43 +1,37 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.repository; +package org.springframework.data.cassandra.test.integration.repository.simple; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.cassandra.core.CassandraOperations; import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Base class for Java config tests for {@link UserRepository}. - * + * * @author Matthew T. Adams * @author David Webb */ -@RunWith(SpringJUnit4ClassRunner.class) -public abstract class UserRepositoryIntegrationTestsDelegator extends - AbstractSpringDataEmbeddedCassandraIntegrationTest { +public abstract class UserRepositoryIntegrationTestsDelegator + extends AbstractSpringDataEmbeddedCassandraIntegrationTest { - @Autowired - protected UserRepository repository; - - @Autowired - protected CassandraOperations template; + @Autowired UserRepository repository; + @Autowired CassandraOperations template; UserRepositoryIntegrationTests tests; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryJavaConfigCustomRepositoryBaseClassIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryJavaConfigCustomRepositoryBaseClassIntegrationTests.java similarity index 87% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryJavaConfigCustomRepositoryBaseClassIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryJavaConfigCustomRepositoryBaseClassIntegrationTests.java index 7848cdd62..c72d8735e 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryJavaConfigCustomRepositoryBaseClassIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryJavaConfigCustomRepositoryBaseClassIntegrationTests.java @@ -1,19 +1,19 @@ /* - * Copyright 2015 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.repository; +package org.springframework.data.cassandra.test.integration.repository.simple; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; @@ -21,6 +21,7 @@ import static org.junit.Assert.*; import java.io.Serializable; import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.aop.framework.Advised; import org.springframework.context.annotation.Configuration; import org.springframework.data.cassandra.core.CassandraOperations; @@ -29,15 +30,17 @@ import org.springframework.data.cassandra.repository.query.CassandraEntityInform import org.springframework.data.cassandra.repository.support.SimpleCassandraRepository; import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Java config tests for {@link UserRepository}. - * + * * @author Thomas Darimont */ @ContextConfiguration -public class UserRepositoryJavaConfigCustomRepositoryBaseClassIntegrationTests extends - UserRepositoryIntegrationTestsDelegator { +@RunWith(SpringJUnit4ClassRunner.class) +public class UserRepositoryJavaConfigCustomRepositoryBaseClassIntegrationTests + extends UserRepositoryIntegrationTestsDelegator { @Configuration @EnableCassandraRepositories(basePackageClasses = UserRepository.class, diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryJavaConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryJavaConfigIntegrationTests.java similarity index 84% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryJavaConfigIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryJavaConfigIntegrationTests.java index 6f6f43a0a..f320260e8 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryJavaConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryJavaConfigIntegrationTests.java @@ -1,31 +1,34 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.repository; +package org.springframework.data.cassandra.test.integration.repository.simple; +import org.junit.runner.RunWith; import org.springframework.context.annotation.Configuration; import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Java config tests for {@link UserRepository}. - * + * * @author Matthew T. Adams */ @ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) public class UserRepositoryJavaConfigIntegrationTests extends UserRepositoryIntegrationTestsDelegator { @Configuration diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryXmlConfigIntegrationTests.java similarity index 75% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryXmlConfigIntegrationTests.java index 9291308b4..b315e7085 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryXmlConfigIntegrationTests.java @@ -1,26 +1,29 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2016 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cassandra.test.integration.repository; +package org.springframework.data.cassandra.test.integration.repository.simple; +import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * xml config tests for {@link UserRepository}. - * + * * @author Matthew T. Adams */ @ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) public class UserRepositoryXmlConfigIntegrationTests extends UserRepositoryIntegrationTestsDelegator {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/Book.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/Book.java index 58502e17b..b349aa3a3 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/Book.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/Book.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,14 +22,13 @@ import org.springframework.data.cassandra.mapping.Table; /** * Test POJO - * + * * @author David Webb */ @Table("book") public class Book { - @PrimaryKey - private String isbn; + @PrimaryKey private String isbn; private String title; private String author; @@ -123,15 +122,13 @@ public class Book { } /** - * - * @param condition The condition to set. + * @param condition The condition to set. */ public void setCondition(BookCondition condition) { this.condition = condition; } /** - * * @return Returns the condition. */ public BookCondition getCondition() { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookCondition.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookCondition.java index 0de4bb85b..5c722d304 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookCondition.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookCondition.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.cassandra.test.integration.simpletons; /** diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookHistory.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookHistory.java index 58bf2d294..c64411f36 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookHistory.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookHistory.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,14 +23,13 @@ import org.springframework.data.cassandra.mapping.Table; /** * Test POJO - * + * * @author David Webb */ @Table("bookHistory") public class BookHistory { - @PrimaryKey - private String isbn; + @PrimaryKey private String isbn; private String title; private String author; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookReference.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookReference.java index 24800bd49..1f0700ed4 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookReference.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookReference.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,14 +24,13 @@ import org.springframework.data.cassandra.mapping.Table; /** * Test POJO - * + * * @author David Webb */ @Table("bookReference") public class BookReference { - @PrimaryKey - private String isbn; + @PrimaryKey private String isbn; private String title; private String author; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/LogEntry.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/LogEntry.java index 7319eb6ed..81e7c792e 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/LogEntry.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/LogEntry.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,7 +22,7 @@ import org.springframework.data.cassandra.mapping.Table; /** * This is an example of the LogEntry static table, where all fields are columns in Cassandra row. - * + * * @author Alex Shvid */ @Table("log_entry") @@ -31,8 +31,7 @@ public class LogEntry { /* * Primary Key */ - @PrimaryKey - private Date logDate; + @PrimaryKey private Date logDate; private String hostname; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/AbstractSpringDataEmbeddedCassandraIntegrationTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/AbstractSpringDataEmbeddedCassandraIntegrationTest.java index 2a19b4cff..0503034eb 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/AbstractSpringDataEmbeddedCassandraIntegrationTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/AbstractSpringDataEmbeddedCassandraIntegrationTest.java @@ -1,12 +1,12 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2013-2016 the original author or authors + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,20 +22,22 @@ import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraI import org.springframework.data.cassandra.core.CassandraOperations; import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; -public class AbstractSpringDataEmbeddedCassandraIntegrationTest extends AbstractEmbeddedCassandraIntegrationTest { +/** + * Base class to support integration tests and provide a {@link CassandraOperations} instance. + * + * @author Mark Paluch + */ +public abstract class AbstractSpringDataEmbeddedCassandraIntegrationTest + extends AbstractEmbeddedCassandraIntegrationTest { - static { - SpringCassandraBuildProperties props = new SpringCassandraBuildProperties(); - CASSANDRA_NATIVE_PORT = props.getCassandraPort(); - } + public final Logger log = LoggerFactory.getLogger(getClass()); - public Logger log = LoggerFactory.getLogger(getClass()); - - @Autowired - public CassandraOperations template; + @Autowired private CassandraOperations template; + /** + * Truncate table for all known {@link org.springframework.data.mapping.PersistentEntity entities}. + */ public void deleteAllEntities() { - for (CassandraPersistentEntity entity : template.getConverter().getMappingContext().getPersistentEntities()) { template.truncate(entity.getTableName()); } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/IntegrationTestConfig.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/IntegrationTestConfig.java index 409c5acb7..a3b5d96dd 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/IntegrationTestConfig.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/IntegrationTestConfig.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,31 +15,32 @@ */ package org.springframework.data.cassandra.test.integration.support; -import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.createKeyspace; +import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.*; import java.util.Arrays; import java.util.List; import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification; -import org.springframework.cassandra.test.unit.support.Utils; +import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification; +import org.springframework.cassandra.support.RandomKeySpaceName; +import org.springframework.cassandra.test.integration.support.CassandraConnectionProperties; import org.springframework.context.annotation.Configuration; import org.springframework.data.cassandra.config.SchemaAction; import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration; /** * Setup any spring configuration for unit tests - * + * * @author David Webb * @author Matthew T. Adams */ @Configuration public class IntegrationTestConfig extends AbstractCassandraConfiguration { - public static final SpringCassandraBuildProperties PROPS = new SpringCassandraBuildProperties(); + public static final CassandraConnectionProperties PROPS = new CassandraConnectionProperties(); public static final int PORT = PROPS.getCassandraPort(); - public static final int RPC_PORT = PROPS.getCassandraRpcPort(); - public String keyspaceName = Utils.randomKeyspaceName(); + public String keyspaceName = RandomKeySpaceName.create(); @Override protected int getPort() { @@ -60,4 +61,9 @@ public class IntegrationTestConfig extends AbstractCassandraConfiguration { protected List getKeyspaceCreations() { return Arrays.asList(createKeyspace().name(getKeyspaceName()).withSimpleReplication()); } + + @Override + protected List getKeyspaceDrops() { + return Arrays.asList(DropKeyspaceSpecification.dropKeyspace().name(getKeyspaceName())); + } } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/ManualDataSet.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/ManualDataSet.java deleted file mode 100644 index 277e97006..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/ManualDataSet.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2013-2014 the original author or authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.cassandra.test.integration.support; - -import org.cassandraunit.dataset.commons.AbstractCommonsParserDataSet; -import org.cassandraunit.dataset.commons.ParsedKeyspace; - -public class ManualDataSet extends AbstractCommonsParserDataSet { - - private String keyspaceName; - private ParsedKeyspace pks; - - public ManualDataSet(String keyspaceName) { - this.keyspaceName = keyspaceName; - - pks = new ParsedKeyspace(); - pks.setName(this.keyspaceName); - } - - @Override - protected ParsedKeyspace getParsedKeyspace() { - return pks; - } -} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/AnotherScannedEntity.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/AnotherScannedEntity.java index 5d3489f33..d24d2cbbf 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/AnotherScannedEntity.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/AnotherScannedEntity.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,14 +18,16 @@ package org.springframework.data.cassandra.test.integration.xmlentityscanning; import org.springframework.data.annotation.Id; import org.springframework.data.cassandra.mapping.Table; +/** + * @author Matthew T. Adams + */ @Table public class AnotherScannedEntity { /* * Primary Row ID */ - @Id - private String name; + @Id private String name; @SuppressWarnings("unused") private AnotherScannedEntity() {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/AnotherScannedEntityRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/AnotherScannedEntityRepository.java index 745b269c7..3a06d6944 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/AnotherScannedEntityRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/AnotherScannedEntityRepository.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,4 +17,7 @@ package org.springframework.data.cassandra.test.integration.xmlentityscanning; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; +/** + * @author Matthew T. Adams + */ public interface AnotherScannedEntityRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/ScannedEntity.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/ScannedEntity.java index 5ac06858f..9c49cb35b 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/ScannedEntity.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/ScannedEntity.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,14 +18,16 @@ package org.springframework.data.cassandra.test.integration.xmlentityscanning; import org.springframework.data.annotation.Id; import org.springframework.data.cassandra.mapping.Table; +/** + * @author Matthew T. Adams + */ @Table public class ScannedEntity { /* * Primary Row ID */ - @Id - private String name; + @Id private String name; @SuppressWarnings("unused") private ScannedEntity() {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/ScannedEntityRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/ScannedEntityRepository.java index 10e63ae01..af58151ef 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/ScannedEntityRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/ScannedEntityRepository.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,4 +17,7 @@ package org.springframework.data.cassandra.test.integration.xmlentityscanning; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; +/** + * @author Matthew T. Adams + */ public interface ScannedEntityRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/XmlEntityScanningIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/XmlEntityScanningIntegrationTests.java index cec317647..72108b09f 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/XmlEntityScanningIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/XmlEntityScanningIntegrationTests.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,17 +23,16 @@ import org.springframework.data.cassandra.test.integration.support.AbstractSprin import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +/** + * @author Matthew T. Adams + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class XmlEntityScanningIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { - @Autowired - ScannedEntityRepository repository; - @Autowired - AnotherScannedEntityRepository anotherRepository; - - @Autowired - CassandraOperations template; + @Autowired ScannedEntityRepository repository; + @Autowired AnotherScannedEntityRepository anotherRepository; + @Autowired CassandraOperations template; @Test public void testInsertScannedEntity() { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/mapid/BasicMapIdTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/mapid/BasicMapIdTest.java deleted file mode 100644 index 47fa2ee55..000000000 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/mapid/BasicMapIdTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.springframework.data.cassandra.test.unit.mapid; - -import org.junit.Test; -import org.springframework.data.cassandra.repository.support.BasicMapId; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.assertEquals; - -public class BasicMapIdTest { - @Test - public void testMapConstructor() { - Map map = new HashMap(); - map.put("field1", "value1"); - map.put("field2", 2); - - BasicMapId basicMapId = new BasicMapId(map); - - assertEquals(basicMapId.get("field1"), map.get("field1")); - assertEquals(basicMapId.get("field2"), map.get("field2")); - } -} diff --git a/spring-data-cassandra/src/test/resources/cassandra-keyspace.yaml b/spring-data-cassandra/src/test/resources/cassandra-keyspace.yaml deleted file mode 100644 index 3442321c5..000000000 --- a/spring-data-cassandra/src/test/resources/cassandra-keyspace.yaml +++ /dev/null @@ -1,3 +0,0 @@ -name: ks9487fb2da1a541e39a05e5545d64411a -replicationFactor: 1 -strategy: org.apache.cassandra.locator.SimpleStrategy \ No newline at end of file diff --git a/spring-data-cassandra/src/test/resources/cassandraOperationsTest-cql-dataload.cql b/spring-data-cassandra/src/test/resources/cassandraOperationsTest-cql-dataload.cql deleted file mode 100644 index 239ae3e25..000000000 --- a/spring-data-cassandra/src/test/resources/cassandraOperationsTest-cql-dataload.cql +++ /dev/null @@ -1,3 +0,0 @@ -create table book (isbn text, title text, author text, pages int, PRIMARY KEY (isbn)); -create table book_alt (isbn text, title text, author text, pages int, PRIMARY KEY (isbn)); -insert into book (isbn, title, author, pages) values ('999999999', 'Book of Nines', 'Nine Nine', 999); \ No newline at end of file diff --git a/spring-data-cassandra/src/test/resources/org.springframework.data.cassandra.test.integration.support.SpringCassandraBuildProperties.properties b/spring-data-cassandra/src/test/resources/config/cassandra-connection.properties similarity index 53% rename from spring-data-cassandra/src/test/resources/org.springframework.data.cassandra.test.integration.support.SpringCassandraBuildProperties.properties rename to spring-data-cassandra/src/test/resources/config/cassandra-connection.properties index 97c6cf4a8..be62cb0ef 100644 --- a/spring-data-cassandra/src/test/resources/org.springframework.data.cassandra.test.integration.support.SpringCassandraBuildProperties.properties +++ b/spring-data-cassandra/src/test/resources/config/cassandra-connection.properties @@ -1,5 +1,8 @@ +# cassandra-connection.properties is needed twice because of enabled random port generation +# Generated ports are only valid for one module build.cassandra.native_transport_port=@build.cassandra.native_transport_port@ build.cassandra.rpc_port=@build.cassandra.rpc_port@ build.cassandra.storage_port=@build.cassandra.storage_port@ build.cassandra.ssl_storage_port=@build.cassandra.ssl_storage_port@ -build.cql.init.timeout=60000 \ No newline at end of file +build.cassandra.mode=@build.cassandra.mode@ +build.cassandra.host=@build.cassandra.host@ diff --git a/spring-data-cassandra/src/test/resources/spring-data-cassandra-basic.xml b/spring-data-cassandra/src/test/resources/config/spring-data-cassandra-basic.xml similarity index 51% rename from spring-data-cassandra/src/test/resources/spring-data-cassandra-basic.xml rename to spring-data-cassandra/src/test/resources/config/spring-data-cassandra-basic.xml index 672f4dc0e..c3f5e76e6 100644 --- a/spring-data-cassandra/src/test/resources/spring-data-cassandra-basic.xml +++ b/spring-data-cassandra/src/test/resources/config/spring-data-cassandra-basic.xml @@ -1,4 +1,20 @@ + + - + - + + location="classpath:/config/cassandra-connection.properties" /> diff --git a/spring-data-cassandra/src/test/resources/cql-dataload.cql b/spring-data-cassandra/src/test/resources/cql-dataload.cql deleted file mode 100644 index e38d18d36..000000000 --- a/spring-data-cassandra/src/test/resources/cql-dataload.cql +++ /dev/null @@ -1,3 +0,0 @@ -create table book (isbn text, title text, author text, pages int, PRIMARY KEY (isbn)); -create table book_alt (isbn text, title text, author text, pages int, PRIMARY KEY (isbn)); -/*insert into book (isbn, title, author, pages) values ('999999999', 'Book of Nines', 'Nine Nine', 999);*/ \ No newline at end of file diff --git a/spring-data-cassandra/src/test/resources/spring-cassandra.yaml b/spring-data-cassandra/src/test/resources/embedded-cassandra.yaml similarity index 100% rename from spring-data-cassandra/src/test/resources/spring-cassandra.yaml rename to spring-data-cassandra/src/test/resources/embedded-cassandra.yaml diff --git a/spring-data-cassandra/src/test/resources/log4j-embedded-cassandra.properties b/spring-data-cassandra/src/test/resources/log4j-embedded-cassandra.properties deleted file mode 100644 index 9e391314e..000000000 --- a/spring-data-cassandra/src/test/resources/log4j-embedded-cassandra.properties +++ /dev/null @@ -1,6 +0,0 @@ -log4j.rootLogger=ERROR, stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n -log4j.logger.org.springframework.cassandra=ERROR -log4j.logger.org.springframework.data.cassandra=ERROR diff --git a/spring-data-cassandra/src/test/resources/log4j.properties b/spring-data-cassandra/src/test/resources/log4j.properties deleted file mode 100644 index 9e391314e..000000000 --- a/spring-data-cassandra/src/test/resources/log4j.properties +++ /dev/null @@ -1,6 +0,0 @@ -log4j.rootLogger=ERROR, stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n -log4j.logger.org.springframework.cassandra=ERROR -log4j.logger.org.springframework.data.cassandra=ERROR diff --git a/spring-data-cassandra/src/test/resources/logback-test.xml b/spring-data-cassandra/src/test/resources/logback-test.xml deleted file mode 100644 index f16ab93b9..000000000 --- a/spring-data-cassandra/src/test/resources/logback-test.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - %d %5p | %t | %-55logger{55} | %m | %n - - - - - - - - - - - - - diff --git a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryXmlConfigIntegrationTests-context.xml b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryXmlConfigIntegrationTests-context.xml index 1177ad40f..6386c3ba2 100644 --- a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryXmlConfigIntegrationTests-context.xml +++ b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryXmlConfigIntegrationTests-context.xml @@ -9,7 +9,7 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - + @@ -19,9 +19,9 @@ - + + action="CREATE_DROP" durable-writes="true"> diff --git a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/config/CassandraNamespaceTests-context.xml b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/config/CassandraNamespaceIntegrationTests-context.xml similarity index 81% rename from spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/config/CassandraNamespaceTests-context.xml rename to spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/config/CassandraNamespaceIntegrationTests-context.xml index b434f4221..fef49ff2f 100644 --- a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/config/CassandraNamespaceTests-context.xml +++ b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/config/CassandraNamespaceIntegrationTests-context.xml @@ -9,10 +9,10 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + location="classpath:/config/cassandra-connection.properties,classpath:/org/springframework/data/cassandra/test/integration/config/cassandra.properties" /> - + @@ -22,7 +22,7 @@ - diff --git a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/config/cassandra.properties b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/config/cassandra.properties index 358cf0041..86e1499cd 100644 --- a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/config/cassandra.properties +++ b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/config/cassandra.properties @@ -1,3 +1 @@ -cassandra.contactPoints=localhost -cassandra.native_transport_port=@build.cassandra.native_transport_port@ cassandra.keyspace=TestKS123 diff --git a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests-context.xml b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests-context.xml index f8ae871f1..e2889294c 100644 --- a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests-context.xml +++ b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests-context.xml @@ -10,7 +10,7 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd "> - + @@ -30,9 +30,9 @@ - + + action="CREATE_DROP" durable-writes="true"> diff --git a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests-context.xml b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests-context.xml index 381c46030..a00b2a90e 100644 --- a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests-context.xml +++ b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests-context.xml @@ -10,7 +10,7 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd "> - + @@ -40,9 +40,9 @@ - + + action="CREATE_DROP" durable-writes="true"> diff --git a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/minimal/config/AbsoluteMinimumXmlConfigIntegrationTest-context.xml b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/minimal/config/AbsoluteMinimumXmlConfigIntegrationTests-context.xml similarity index 89% rename from spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/minimal/config/AbsoluteMinimumXmlConfigIntegrationTest-context.xml rename to spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/minimal/config/AbsoluteMinimumXmlConfigIntegrationTests-context.xml index 7e2bc7eaa..042007670 100644 --- a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/minimal/config/AbsoluteMinimumXmlConfigIntegrationTest-context.xml +++ b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/minimal/config/AbsoluteMinimumXmlConfigIntegrationTests-context.xml @@ -11,9 +11,9 @@ + location="classpath:/config/cassandra-connection.properties" /> - + diff --git a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests-context.xml b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryXmlConfigIntegrationTests-context.xml similarity index 61% rename from spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests-context.xml rename to spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryXmlConfigIntegrationTests-context.xml index d5f909fcc..ec5fbec6b 100644 --- a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests-context.xml +++ b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/simple/UserRepositoryXmlConfigIntegrationTests-context.xml @@ -1,4 +1,19 @@ + - + + class="org.springframework.data.cassandra.test.integration.repository.simple.User"> - + + action="CREATE_DROP" durable-writes="true"> @@ -31,5 +46,5 @@ + base-package="org.springframework.data.cassandra.test.integration.repository.simple" /> diff --git a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/xmlentityscanning/XmlEntityScanningIntegrationTests-context.xml b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/xmlentityscanning/XmlEntityScanningIntegrationTests-context.xml index 8df2fe3d4..f130aac96 100644 --- a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/xmlentityscanning/XmlEntityScanningIntegrationTests-context.xml +++ b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/xmlentityscanning/XmlEntityScanningIntegrationTests-context.xml @@ -10,14 +10,14 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd "> - + - + + action="CREATE_DROP" durable-writes="true"> diff --git a/spring-data-cassandra/src/test/resources/spring-data-cassandra-build.properties b/spring-data-cassandra/src/test/resources/spring-data-cassandra-build.properties deleted file mode 100644 index ab9c6a319..000000000 --- a/spring-data-cassandra/src/test/resources/spring-data-cassandra-build.properties +++ /dev/null @@ -1 +0,0 @@ -cassandra.native_transport_port=@build.cassandra.native_transport_port@