DATACASS-255 - Cassandra Test cleanup.

Replace CassandraUnit test rule with own test rule that honors the external/embedded Cassandra preference. Move Cassandra server initialization into CassandraRule. Introduce a KeyspaceRule to provide managed keyspaces on test class level. Allow cached cluster connections by enabling CassandraRule as class rule. A test that requires a running Cassandra instance needs to either extend the AbstractEmbeddedCassandraIntegrationTest or add the test rule CassandraRule to its test.

Consolidate connection properties (before merging the spring-cql and spring-data-cassandra modules) and simplify config properties classes. Add cleanup after the test run to remove temporary keyspaces. This change allows repeating test runs on a stateful Cassandra instance (e.g. an externally started Cassandra instance). Rename config file and change references to renamed files to support the consolidated connection properties in context config files.
Removed FunkyIdentifierIntegrationTest as it only tests creating tables using reserved Cassandra words. Spring Data Cassandra does not constrain CQL identifiers so maybe later we'll add a test to verify the implemented rules.

Exclude logback-core dependency from cassandra-all. Remove jamm dependency in tests as it's not used. Removed cassandra-unit dependency as the usage is very little. Removed unnecessary hector dependency.

Rename all integration tests to end with "IntegrationTests" and unit tests to end with "UnitTests". Move unit tests to the system under test package to enable testing of package-private types and members. Add missing license headers and author tags. Reformat all test code using the Spring Data Eclipse formatting.

Original pull request: #51
This commit is contained in:
Mark Paluch
2016-02-11 20:07:58 +01:00
parent 21686dd448
commit c33d509b8e
230 changed files with 4579 additions and 2949 deletions

130
pom.xml
View File

@@ -32,9 +32,15 @@
<cassandra-unit.version>2.1.9.2</cassandra-unit.version>
<el.version>1.0</el.version>
<failsafe.version>2.16</failsafe.version>
<jamm.version>0.3.1</jamm.version>
<cassandra.version>2.1.11</cassandra.version>
<cassandra-driver-dse.version>2.1.7.1</cassandra-driver-dse.version>
<build.cassandra.mode>embedded</build.cassandra.mode>
<build.cassandra.host>localhost</build.cassandra.host>
<build.cassandra.native_transport_port>19042</build.cassandra.native_transport_port>
<build.cassandra.rpc_port>19160</build.cassandra.rpc_port>
<build.cassandra.storage_port>17000</build.cassandra.storage_port>
<build.cassandra.ssl_storage_port>17001</build.cassandra.ssl_storage_port>
</properties>
<developers>
@@ -99,12 +105,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.jbellis</groupId>
<artifactId>jamm</artifactId>
<version>${jamm.version}</version>
<scope>test</scope>
</dependency>
<!-- Logging Dependencies -->
<dependency>
@@ -144,27 +144,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-spring</artifactId>
<version>${cassandra-unit.version}</version>
<exclusions>
<exclusion>
<artifactId>cassandra-all</artifactId>
<groupId>org.apache.cassandra</groupId>
</exclusion>
<exclusion>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
@@ -192,14 +171,6 @@
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hectorclient</groupId>
<artifactId>hector-core</artifactId>
<version>1.1-4</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
@@ -222,14 +193,6 @@
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-dse</artifactId>
</dependency>
<dependency>
<groupId>com.github.jbellis</groupId>
<artifactId>jamm</artifactId>
</dependency>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-spring</artifactId>
</dependency>
</dependencies>
<build>
@@ -247,28 +210,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>build.cassandra.native_transport_port</portName>
<portName>build.cassandra.rpc_port</portName>
<portName>build.cassandra.storage_port</portName>
<portName>build.cassandra.ssl_storage_port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
@@ -282,9 +223,11 @@
<useFile>false</useFile>
<includes>
<include>**/test/unit/**/*.java</include>
<include>**/*UnitTests.java</include>
</includes>
<excludes>
<exclude>**/test/integration/**/*.java</exclude>
<exclude>**/**IntegrationTests.java</exclude>
<exclude>**/test/performance/**/*.java</exclude>
</excludes>
<systemPropertyVariables>
@@ -298,14 +241,16 @@
<version>${failsafe.version}</version>
<configuration>
<forkCount>1</forkCount>
<argLine>-Xms1g -Xmx1g -Xss256k -javaagent:${com.github.jbellis:jamm:jar}</argLine>
<argLine>-Xms1g -Xmx1g -Xss256k</argLine>
<reuseForks>true</reuseForks>
<useFile>false</useFile>
<includes>
<include>**/test/integration/**/*.java</include>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/test/unit/**/*.java</exclude>
<exclude>**/*UnitTests.java</exclude>
<exclude>**/test/performance/**/*.java</exclude>
</excludes>
<systemPropertyVariables>
@@ -356,6 +301,57 @@
</plugins>
</build>
</profile>
<profile>
<id>embedded-cassandra</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build.cassandra.mode>embedded</build.cassandra.mode>
</properties>
<build>
<plugins>
<plugin>
<!-- Random port generation requires embedded-cassandra.yaml and cassandra-connection.properties
in both modules -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>generate-test-resources</phase>
<configuration>
<portNames>
<portName>build.cassandra.native_transport_port</portName>
<portName>build.cassandra.rpc_port</portName>
<portName>build.cassandra.storage_port</portName>
<portName>build.cassandra.ssl_storage_port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>external-cassandra</id>
<properties>
<build.cassandra.mode>external</build.cassandra.mode>
<build.cassandra.native_transport_port>9042</build.cassandra.native_transport_port>
<build.cassandra.rpc_port>9160</build.cassandra.rpc_port>
<build.cassandra.storage_port>7000</build.cassandra.storage_port>
<build.cassandra.ssl_storage_port>7001</build.cassandra.ssl_storage_port>
</properties>
</profile>
</profiles>
</project>

View File

@@ -71,10 +71,6 @@
<artifactId>el-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-spring</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
@@ -82,8 +78,8 @@
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>

View File

@@ -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 {

View File

@@ -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() {

View File

@@ -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 <S> The type of the {@link IndexNameSpecification}
* @param <G> The type of the {@link IndexNameCqlGenerator}
*/
public abstract class IndexOperationCqlGeneratorTest<S extends IndexNameSpecification<?>, G extends IndexNameCqlGenerator<?>> {
public abstract class AbstractIndexOperationCqlGeneratorTest<S extends IndexNameSpecification<?>, G extends IndexNameCqlGenerator<?>> {
public abstract S specification();

View File

@@ -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 <S> The type of the {@link TableNameSpecification}
* @param <G> The type of the {@link TableNameCqlGenerator}
*/
public abstract class KeyspaceOperationCqlGeneratorTest<S extends KeyspaceActionSpecification<?>, G extends KeyspaceNameCqlGenerator<?>> {
public abstract class AbstractKeyspaceOperationCqlGeneratorTest<S extends KeyspaceActionSpecification<?>, G extends KeyspaceNameCqlGenerator<?>> {
public abstract S specification();

View File

@@ -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 <S> The type of the {@link TableNameSpecification}
* @param <G> The type of the {@link TableNameCqlGenerator}
*/
public abstract class TableOperationCqlGeneratorTest<S extends TableNameSpecification<?>, G extends TableNameCqlGenerator<?>> {
public abstract class AbstractTableOperationCqlGeneratorTest<S extends TableNameSpecification<?>, G extends TableNameCqlGenerator<?>> {
public abstract S specification();

View File

@@ -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<AlterKeyspaceSpecification, AlterKeyspaceCqlGenerator> {}
public static abstract class AlterKeyspaceTest
extends AbstractKeyspaceOperationCqlGeneratorTest<AlterKeyspaceSpecification, AlterKeyspaceCqlGenerator> {}
public static class CompleteTest extends AlterKeyspaceTest {
public String name = Utils.randomKeyspaceName();
public String name = RandomKeySpaceName.create();
public Boolean durableWrites = true;
public Map<Option, Object> replicationMap = new HashMap<Option, Object>();

View File

@@ -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<AlterTableSpecification, AlterTableCqlGenerator> {
}
public static abstract class AlterTableTest
extends AbstractTableOperationCqlGeneratorTest<AlterTableSpecification, AlterTableCqlGenerator> {}
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)

View File

@@ -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<CreateIndexSpecification, CreateIndexCqlGenerator> {
public static abstract class CreateIndexTest
extends AbstractIndexOperationCqlGeneratorTest<CreateIndexSpecification, CreateIndexCqlGenerator> {
public CreateIndexCqlGenerator generator() {
return new CreateIndexCqlGenerator(specification);
@@ -67,7 +72,6 @@ public class CreateIndexCqlGeneratorTests {
assertPreamble(name, tableName, cql);
assertColumn(column1, cql);
}
}

View File

@@ -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<CreateKeyspaceSpecification, CreateKeyspaceCqlGenerator> {
public static abstract class CreateKeyspaceTest
extends AbstractKeyspaceOperationCqlGeneratorTest<CreateKeyspaceSpecification, CreateKeyspaceCqlGenerator> {
@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<Option, Object> 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<Option, Object> 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<Option, Object> replicationMap = new HashMap<Option, Object>();

View File

@@ -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<CreateTableSpecification, CreateTableCqlGenerator> {
public static abstract class CreateTableTest
extends AbstractTableOperationCqlGeneratorTest<CreateTableSpecification, CreateTableCqlGenerator> {
@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<String> FUNKY_LEGAL_NAMES;
static {
List<String> funkies = new ArrayList<String>(Arrays.asList(new String[] { /* TODO */}));
List<String> funkies = new ArrayList<String>(Arrays.asList(new String[] { /* TODO */ }));
// TODO: should these work? "a \"\" x", "a\"\"\"\"x", "a b"
for (ReservedKeyword funky : ReservedKeyword.values()) {
funkies.add(funky.name());

View File

@@ -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<DropIndexSpecification, DropIndexCqlGenerator> {}
public static abstract class DropIndexTest
extends AbstractIndexOperationCqlGeneratorTest<DropIndexSpecification, DropIndexCqlGenerator> {}
public static class BasicTest extends DropIndexTest {

View File

@@ -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<DropKeyspaceSpecification, DropKeyspaceCqlGenerator> {
}
public static abstract class DropTableTest
extends AbstractKeyspaceOperationCqlGeneratorTest<DropKeyspaceSpecification, DropKeyspaceCqlGenerator> {}
public static class BasicTest extends DropTableTest {
public String name = Utils.randomKeyspaceName();
public String name = RandomKeySpaceName.create();
@Override
public DropKeyspaceSpecification specification() {

View File

@@ -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<DropTableSpecification, DropTableCqlGenerator> {}
public static abstract class DropTableTest
extends AbstractTableOperationCqlGeneratorTest<DropTableSpecification, DropTableCqlGenerator> {}
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);
// }
// }
}

View File

@@ -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() {

View File

@@ -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();

View File

@@ -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("-", "");
}
}

View File

@@ -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();
}
}

View File

@@ -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.
* <p>
* 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<Object>() {
@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));
}
}

View File

@@ -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.
* <p>
* 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.
* <p>
* 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<Object>() {
/**
* 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);
}
}

View File

@@ -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:
*
* <pre>
* {
* public class MyIntegrationTest {
* &#064;Rule public CassandraRule rule = new CassandraRule(CONFIG). //
* before(new ClassPathCQLDataSet("CreateIndexCqlGeneratorIntegrationTests-BasicTest.cql", "keyspace"));
* }
* }
* </pre>
*
* @author Mark Paluch
*/
public class CassandraRule extends ExternalResource {
private final CassandraConnectionProperties properties = new CassandraConnectionProperties();
private final String configurationFileName;
private final long startUpTimeout;
private List<SessionCallback<Void>> before = new ArrayList<SessionCallback<Void>>();
private Map<SessionCallback<?>, InvocationMode> invocationModeMap = new HashMap<SessionCallback<?>, InvocationMode>();
private List<SessionCallback<Void>> after = new ArrayList<SessionCallback<Void>>();
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<Void> sessionCallback = new SessionCallback<Void>() {
@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<Void>) 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<Void>() {
@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<Void> 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<Void> 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() {
}
}
}

View File

@@ -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<Object> sync = new AtomicReference<Object>();
private final static AtomicReference<CassandraDaemon> cassandraRef = new AtomicReference<CassandraDaemon>();
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);
}
}
}

View File

@@ -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}.
* <p>
* 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.
* <p>
* 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<Object>() {
@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;
}
}

View File

@@ -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));

View File

@@ -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) {

View File

@@ -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() {

View File

@@ -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();
}
}

View File

@@ -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 {

View File

@@ -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");
}
}

View File

@@ -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)));
}
}

View File

@@ -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 + ";");
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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)));
}
}

View File

@@ -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");
}
}

View File

@@ -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);
}
}

View File

@@ -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 {

View File

@@ -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
*/

View File

@@ -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<MyHost> mapHosts(Set<Host> host) throws DriverException {
List<MyHost> list = new LinkedList<CQLOperationsTest.MyHost>();
List<MyHost> list = new LinkedList<CqlOperationsIntegrationTests.MyHost>();
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<Book>() {
new ResultSetExtractor<Book>() {
@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<Book>() {
new ResultSetExtractor<Book>() {
@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<Book>() {
@@ -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<String, Object> 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<String, Object> 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<String> 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
*/

View File

@@ -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<? super Map<String, ?>> MAP_WITH_ISBN_COMPARATOR = new Comparator<Map<String, ?>>() {
@Override
public int compare(Map<String, ?> o1, Map<String, ?> 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<Map<String, Object>> expected; // subclass should set this value in doAsyncQuery
List<Map<String, ? extends Comparable>> 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<String> 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<String> 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<String, Object>();
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<String, Object>();
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<Map<String, Object>>(books.length);
expected = new ArrayList<Map<String, ? extends Comparable>>(books.length);
for (int i = 0; i < books.length; i++) {
Book b = books[i];
titles[i] = b.title;
HashMap<String, Object> row = new HashMap<String, Object>(2);
Map<String, String> row = new HashMap<String, String>(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<Map<String, Object>>(books.length);
expected = new ArrayList<Map<String, ? extends Comparable>>(books.length);
for (int i = 0; i < books.length; i++) {
Book b = books[i];
titles[i] = b.title;
HashMap<String, Object> row = new HashMap<String, Object>(2);
Map<String, String> row = new HashMap<String, String>(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);

View File

@@ -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();
}
}

View File

@@ -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;
}

View File

@@ -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<T> extends TestListener implements QueryForListListener<T> {
Exception exception;
List<T> result;
@Override
public void onQueryComplete(List<T> results) {
this.result = results;
countDown();
}
@Override
public void onException(Exception x) {
this.exception = x;
countDown();
}
}

View File

@@ -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<Map<String, Object>> implements QueryForListOfMapListener {}

View File

@@ -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<String, Object> result;
Exception exception;
@Override
public void onQueryComplete(Map<String, Object> results) {
this.result = results;
countDown();
}
@Override
public void onException(Exception x) {
this.exception = x;
countDown();
}
}

View File

@@ -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<T> extends TestListener implements QueryForObjectListener<T> {
T result;
Exception exception;
@Override
public void onQueryComplete(T result) {
this.result = result;
countDown();
}
@Override
public void onException(Exception x) {
this.exception = x;
countDown();
}
}

View File

@@ -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();

View File

@@ -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());

View File

@@ -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<String, Object>) expected, (Map<String, String>) actual);
return;
case CACHING:
assertCaching((Map<String, Object>) expected, (Map<String, String>) actual);
return;
case COMPACTION:
assertCompaction((Map<String, Object>) expected, (Map<String, String>) actual);
return;
case COMPACTION:
assertCompaction((Map<String, Object>) expected, (Map<String, String>) actual);
return;
case COMPRESSION:
assertCompression((Map<String, Object>) expected, (Map<String, String>) actual);
return;
case COMPRESSION:
assertCompression((Map<String, Object>) expected, (Map<String, String>) actual);
return;
}
log.info(actual.getClass().getName());
@@ -141,24 +145,24 @@ public class CqlTableSpecificationAssertions {
@SuppressWarnings("unchecked")
public static <T> 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;
}

View File

@@ -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 <T> The concrete unit test class to which this integration test corresponds.
*/
@@ -57,13 +56,12 @@ public class CreateIndexCqlGeneratorIntegrationTests {
public static class BasicIntegrationTest extends Base<BasicTest> {
/**
* 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() {

View File

@@ -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 <T> The concrete unit test class to which this integration test corresponds.
*/
public static abstract class Base<T extends CreateKeyspaceTest> extends AbstractEmbeddedCassandraIntegrationTest {
public static abstract class Base<T extends CreateKeyspaceTest> 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);
}
}

View File

@@ -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 <T> The concrete unit test class to which this integration test corresponds.
*/
public static abstract class Base<T extends CreateTableTest> extends AbstractKeyspaceCreatingIntegrationTest {
T unit;
public abstract T unit();
@Test
public void test() {
unit = unit();
unit.prepare();

View File

@@ -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());
}
}
}

View File

@@ -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();

View File

@@ -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() {

View File

@@ -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();

View File

@@ -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 {}

View File

@@ -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();
}
}

View File

@@ -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;
}

View File

@@ -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<T> extends TestListener implements QueryForListListener<T> {
Exception exception;
List<T> result;
@Override
public void onQueryComplete(List<T> results) {
this.result = results;
countDown();
}
@Override
public void onException(Exception x) {
this.exception = x;
countDown();
}
}

View File

@@ -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<Map<String, Object>> implements QueryForListOfMapListener {}

View File

@@ -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<String, Object> result;
Exception exception;
@Override
public void onQueryComplete(Map<String, Object> results) {
this.result = results;
countDown();
}
@Override
public void onException(Exception x) {
this.exception = x;
countDown();
}
}

View File

@@ -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<T> extends TestListener implements QueryForObjectListener<T> {
T result;
Exception exception;
@Override
public void onQueryComplete(T result) {
this.result = result;
countDown();
}
@Override
public void onException(Exception x) {
this.exception = x;
countDown();
}
}

View File

@@ -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();
}
}

View File

@@ -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<String, Integer>() {
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<String, Long>() {
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<String, Boolean>() {
public Boolean convert(String value) {
return Boolean.parseBoolean(value);
}
});
}
private <T> T convert(String propertyName, Class<T> type, Converter<String, T> 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
}
}

View File

@@ -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<String> getCqlStatements() {
return getLines();
}
@SneakyThrows
private List<String> 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);
}
}

View File

@@ -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));
}
}

View File

@@ -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();
}
}

View File

@@ -0,0 +1 @@
DROP KEYSPACE CqlOperationsIntegrationTests;

View File

@@ -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);
truncate table book;
truncate table book_alt;
insert into book (isbn, title, author, pages) values ('999999999', 'Book of Nines', 'Nine Nine', 999);

View File

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

View File

@@ -1 +1 @@
create table mytable (id uuid primary key, column1 text);
create table if not exists mytable (id uuid primary key, column1 text);

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- pattern>%d %5p %40.40c:%4L - %m%n</pattern-->
<pattern>%d %5p | %t | %-55logger{55} | %m | %n</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="error" />
<logger name="org.springframework.cassandra" level="DEBUG" />
<logger name="com.datastax" level="error" />
<root level="error">
<appender-ref ref="console" />
</root>
</configuration>

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %5p | %t | %-55logger{55} | %m | %n</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="ERROR" />
<logger name="org.springframework.cassandra" level="ERROR" />
<logger name="com.datastax" level="ERROR" />
<!-- See https://issues.apache.org/jira/browse/CASSANDRA-8220 -->
<logger name="org.apache.cassandra.service.CassandraDaemon" level="OFF" />
<!-- Suppress "Cannot connect to any host" messages caused by open sessions and
and an already shut down embedded Cassandra instance because of concurrent shutdown hooks -->
<logger name="com.datastax.driver.core.ControlConnection" level="OFF" />
<logger name="com.datastax.driver.core.Session" level="OFF" />
<!-- This one is noisy and subject to be refactored -->
<logger name="org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntityMetadataVerifier" level="OFF" />
<root level="ERROR">
<appender-ref ref="console" />
</root>
</configuration>

View File

@@ -8,7 +8,7 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder
location="classpath:org.springframework.cassandra.test.integration.support.SpringCqlBuildProperties.properties,classpath:/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest.properties" />
location="classpath:/config/cassandra-connection.properties,classpath:/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests.properties" />
<cass:cluster port="${build.cassandra.native_transport_port}">
<cass:keyspace action="CREATE_DROP" durable-writes="true"
@@ -26,16 +26,16 @@
</cass:replication>
</cass:keyspace>
<cass:startup-cql><![CDATA[
CREATE KEYSPACE script1 WITH durable_writes = true AND replication = { 'replication_factor' : 1, 'class' : 'SimpleStrategy' };
CREATE KEYSPACE IF NOT EXISTS script1 WITH durable_writes = true AND replication = { 'replication_factor' : 1, 'class' : 'SimpleStrategy' };
]]></cass:startup-cql>
<cass:startup-cql><![CDATA[
${script2}
]]></cass:startup-cql>
<cass:shutdown-cql><![CDATA[
DROP KEYSPACE script1
DROP KEYSPACE script1;
]]></cass:shutdown-cql>
<cass:shutdown-cql><![CDATA[
DROP KEYSPACE script2
DROP KEYSPACE script2;
]]></cass:shutdown-cql>
</cass:cluster>

View File

@@ -0,0 +1 @@
script2=CREATE KEYSPACE IF NOT EXISTS script2 WITH durable_writes = true AND replication = { 'replication_factor' : 1, 'class' : 'SimpleStrategy' };

View File

@@ -1 +0,0 @@
script2=CREATE KEYSPACE script2 WITH durable_writes = true AND replication = { 'replication_factor' : 1, 'class' : 'SimpleStrategy' };

View File

@@ -8,7 +8,7 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder
location="classpath:org.springframework.cassandra.test.integration.support.SpringCqlBuildProperties.properties" />
location="classpath:/config/cassandra-connection.properties" />
<cass:cluster port="${build.cassandra.native_transport_port}">
<cass:keyspace action="CREATE_DROP" name="minimal" />

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder
location="classpath:org.springframework.cassandra.test.integration.support.SpringCqlBuildProperties.properties" />
location="classpath:/config/cassandra-connection.properties" />
<cass:cluster port="${build.cassandra.native_transport_port}" />

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder
location="classpath:org.springframework.cassandra.test.integration.support.SpringCqlBuildProperties.properties" />
location="classpath:/config/cassandra-connection.properties" />
<cassandra:cluster contact-points="localhost"
port="${build.cassandra.native_transport_port}">

View File

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

View File

@@ -71,18 +71,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-spring</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
@@ -90,8 +78,8 @@
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
@@ -118,12 +106,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hectorclient</groupId>
<artifactId>hector-core</artifactId>
<scope>test</scope>
</dependency>
<!-- JSR 303 Validation -->
<dependency>
<groupId>javax.validation</groupId>
@@ -164,5 +146,4 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -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;

View File

@@ -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
*/

View File

@@ -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;
}
}

View File

@@ -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<CassandraPersistentProperty> 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;
}

View File

@@ -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() {

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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<TimelineKey> cpk;

View File

@@ -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() {

View File

@@ -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<CqlIdentifier> names = Arrays.asList(new CqlIdentifier[] { quotedCqlId(EXPLICIT_KEY_0),
quotedCqlId(EXPLICIT_KEY_1) });
List<CqlIdentifier> 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;
}
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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;
}

Some files were not shown because too many files have changed in this diff Show More