DATACASS-447 - Polishing.

Cleanup tests, remove duplications and reduce type scope of involved tables.
This commit is contained in:
Mark Paluch
2017-05-23 14:31:27 +02:00
parent a5bcc7d4b8
commit ade33b06c7
155 changed files with 1173 additions and 3463 deletions

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration;
package org.springframework.cassandra;
import java.util.UUID;
import org.junit.ClassRule;
import org.junit.Rule;
import org.springframework.cassandra.test.integration.support.CqlDataSet;
import org.springframework.cassandra.support.CqlDataSet;
import com.datastax.driver.core.Cluster;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration;
package org.springframework.cassandra;
import org.junit.ClassRule;
import org.springframework.util.Assert;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 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,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration;
package org.springframework.cassandra;
import static org.springframework.cassandra.test.integration.CassandraRule.InvocationMode.*;
import static org.springframework.cassandra.CassandraRule.InvocationMode.*;
import java.util.ArrayList;
import java.util.HashMap;
@@ -25,9 +25,9 @@ import java.util.concurrent.TimeUnit;
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.cassandra.test.integration.support.IntegrationTestNettyOptions;
import org.springframework.cassandra.support.CassandraConnectionProperties;
import org.springframework.cassandra.support.CqlDataSet;
import org.springframework.cassandra.support.IntegrationTestNettyOptions;
import org.springframework.util.Assert;
import org.springframework.util.SocketUtils;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration;
package org.springframework.cassandra;
import static java.util.concurrent.TimeUnit.*;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration;
package org.springframework.cassandra;
import org.junit.rules.ExternalResource;
import org.springframework.cassandra.support.RandomKeySpaceName;

View File

@@ -22,6 +22,7 @@ import static org.mockito.Mockito.*;
import static org.mockito.Mockito.anyString;
import org.junit.Test;
import org.springframework.cassandra.support.IntegrationTestNettyOptions;
import org.springframework.test.util.ReflectionTestUtils;
import com.datastax.driver.core.*;
@@ -344,6 +345,36 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
assertThat(getPolicies(bean).getTimestampGenerator()).isEqualTo(mockTimestampGenerator);
}
@Test
public void configuredProtocolVersionShouldBeSet() throws Exception {
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
bean.setNettyOptions(IntegrationTestNettyOptions.INSTANCE);
bean.setProtocolVersion(ProtocolVersion.V2);
bean.afterPropertiesSet();
assertThat(getProtocolVersionEnum(bean)).isEqualTo(ProtocolVersion.V2);
}
@Test
public void defaultProtocolVersionShouldBeSet() throws Exception {
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
bean.afterPropertiesSet();
assertThat(getProtocolVersionEnum(bean)).isNull();
}
private ProtocolVersion getProtocolVersionEnum(CassandraCqlClusterFactoryBean cassandraCqlClusterFactoryBean)
throws Exception {
// initialize connection factory
return (ProtocolVersion) ReflectionTestUtils.getField(
cassandraCqlClusterFactoryBean.getObject().getConfiguration().getProtocolOptions(), "initialProtocolVersion");
}
private Policies getPolicies(CassandraCqlClusterFactoryBean bean) throws Exception {
return getConfiguration(bean).getPolicies();
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright 2017 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.config.java;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.support.AbstractTestJavaConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import com.datastax.driver.core.Session;
/**
* @author Matthew T. Adams
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = ConfigIntegrationTests.Config.class)
public class ConfigIntegrationTests extends AbstractKeyspaceCreatingIntegrationTest {
@Configuration
static class Config extends AbstractTestJavaConfig {
@Override
protected String getKeyspaceName() {
return null;
}
}
@Autowired Session session;
@Test
public void test() {
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-2017 the original author or authors.
* Copyright 2017 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,17 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.config.java;
package org.springframework.cassandra.config.java;
import static org.assertj.core.api.Assertions.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.config.java.AbstractCqlTemplateConfiguration;
import org.springframework.cassandra.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.core.CqlTemplate;
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.test.integration.support.IntegrationTestNettyOptions;
import org.springframework.cassandra.support.IntegrationTestNettyOptions;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
@@ -41,7 +40,7 @@ import com.datastax.driver.core.Session;
public class CqlTemplateConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrationTest {
@Configuration
public static class Config extends AbstractCqlTemplateConfiguration {
static class Config extends AbstractCqlTemplateConfiguration {
@Override
protected String getKeyspaceName() {

View File

@@ -0,0 +1,82 @@
/*
* Copyright 2017 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.config.java;
import static org.assertj.core.api.Assertions.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.config.KeyspaceAttributes;
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
import org.springframework.cassandra.core.keyspace.KeyspaceOption;
import org.springframework.cassandra.support.AbstractTestJavaConfig;
import org.springframework.cassandra.support.KeyspaceTestUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import com.datastax.driver.core.Session;
/**
* @author Matthew T. Adams
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = KeyspaceCreatingJavaConfigIntegrationTests.KeyspaceCreatingJavaConfig.class)
public class KeyspaceCreatingJavaConfigIntegrationTests extends AbstractKeyspaceCreatingIntegrationTest {
@Autowired Session session;
@Test
public void test() {
assertThat(session).isNotNull();
KeyspaceTestUtils.assertKeyspaceExists(KeyspaceCreatingJavaConfig.KEYSPACE_NAME, session);
session.execute("DROP KEYSPACE " + KeyspaceCreatingJavaConfig.KEYSPACE_NAME + ";");
}
/**
* @author Matthew T. Adams
* @author Mark Paluch
*/
@Configuration
static class KeyspaceCreatingJavaConfig extends AbstractTestJavaConfig {
public static final String KEYSPACE_NAME = "foo";
@Override
protected String getKeyspaceName() {
return KEYSPACE_NAME;
}
@Override
protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
ArrayList<CreateKeyspaceSpecification> list = new ArrayList<>();
CreateKeyspaceSpecification specification = CreateKeyspaceSpecification.createKeyspace().name(getKeyspaceName());
specification.with(KeyspaceOption.REPLICATION, KeyspaceAttributes.newSimpleReplication(1L));
list.add(specification);
return list;
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.config.xml;
package org.springframework.cassandra.config.xml;
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.cassandra.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.support.KeyspaceTestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -36,9 +36,9 @@ public class FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests extends Abs
@Test
public void test() {
IntegrationTestUtils.assertKeyspaceExists("full1", session);
IntegrationTestUtils.assertKeyspaceExists("full2", session);
IntegrationTestUtils.assertKeyspaceExists("script1", session);
IntegrationTestUtils.assertKeyspaceExists("script2", session);
KeyspaceTestUtils.assertKeyspaceExists("full1", session);
KeyspaceTestUtils.assertKeyspaceExists("full2", session);
KeyspaceTestUtils.assertKeyspaceExists("script1", session);
KeyspaceTestUtils.assertKeyspaceExists("script2", session);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.config.xml;
package org.springframework.cassandra.config.xml;
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.cassandra.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.support.KeyspaceTestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -36,6 +36,6 @@ public class MinimalKeyspaceCreatingXmlConfigIntegrationTests extends AbstractEm
@Test
public void test() {
IntegrationTestUtils.assertKeyspaceExists("minimal", session);
KeyspaceTestUtils.assertKeyspaceExists("minimal", session);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.config.xml;
package org.springframework.cassandra.config.xml;
import static org.assertj.core.api.AssertionsForInterfaceTypes.*;
@@ -21,10 +21,10 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.cassandra.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.KeyspaceRule;
import org.springframework.cassandra.core.CqlOperations;
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.cassandra.support.KeyspaceTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -59,7 +59,7 @@ public class MinimalXmlConfigIntegrationTests extends AbstractEmbeddedCassandraI
@Test
public void test() {
IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, session);
KeyspaceTestUtils.assertKeyspaceExists(KEYSPACE, session);
CqlOperations cqlOperations = context.getBean(CqlOperations.class);
assertThat(cqlOperations.describeRing()).isNotEmpty();

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.config.xml;
package org.springframework.cassandra.config.xml;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.core.CqlOperations;
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.test.integration.config.IntegrationTestUtils;
import org.springframework.cassandra.support.KeyspaceTestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -51,8 +51,7 @@ public class PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests
@Test
public void keyspaceExists() {
IntegrationTestUtils.assertSession(session);
IntegrationTestUtils.assertKeyspaceExists("ppncxct", session);
KeyspaceTestUtils.assertKeyspaceExists("ppncxct", session);
assertThat(ops).isNotNull();
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.config.xml;
package org.springframework.cassandra.config.xml;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.config.xml;
package org.springframework.cassandra.config.xml;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.config.xml;
package org.springframework.cassandra.config.xml;
import static org.assertj.core.api.Assertions.*;
@@ -24,10 +24,10 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.cassandra.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.KeyspaceRule;
import org.springframework.cassandra.config.ClusterBuilderConfigurer;
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.cassandra.support.KeyspaceTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -87,7 +87,7 @@ public class XmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrat
@Test
public void keyspaceExists() {
IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, session);
KeyspaceTestUtils.assertKeyspaceExists(KEYSPACE, session);
}
@Test

View File

@@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import com.datastax.driver.core.querybuilder.QueryBuilder;

View File

@@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import com.datastax.driver.core.querybuilder.QueryBuilder;

View File

@@ -23,9 +23,9 @@ import reactor.test.StepVerifier;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.core.session.DefaultBridgedReactiveSession;
import org.springframework.cassandra.core.session.ReactiveResultSet;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import com.datastax.driver.core.KeyspaceMetadata;
import com.datastax.driver.core.exceptions.SyntaxError;

View File

@@ -24,10 +24,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.core.session.DefaultBridgedReactiveSession;
import org.springframework.cassandra.core.session.DefaultReactiveSessionFactory;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import com.datastax.driver.core.querybuilder.QueryBuilder;

View File

@@ -23,12 +23,12 @@ import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.core.keyspace.AlterTableSpecification;
import org.springframework.cassandra.core.keyspace.TableOption;
import org.springframework.cassandra.core.keyspace.TableOption.CachingOption;
import org.springframework.cassandra.core.keyspace.TableOption.KeyCachingOption;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.test.integration.support.CassandraVersion;
import org.springframework.cassandra.support.CassandraVersion;
import org.springframework.data.util.Version;
import com.datastax.driver.core.ColumnMetadata;

View File

@@ -20,9 +20,9 @@ import static org.springframework.cassandra.core.cql.generator.AlterUserTypeCqlG
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.core.keyspace.AlterUserTypeSpecification;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.test.integration.support.CassandraVersion;
import org.springframework.cassandra.support.CassandraVersion;
import org.springframework.data.util.Version;
import com.datastax.driver.core.DataType;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.core.cql.generator;
package org.springframework.cassandra.core.cql.generator;
import static org.assertj.core.api.Assertions.*;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.core.cql.generator;
package org.springframework.cassandra.core.cql.generator;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.core.cql.generator;
package org.springframework.cassandra.core.cql.generator;
import static org.assertj.core.api.Assertions.*;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,15 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.core.cql.generator;
import static org.springframework.cassandra.test.integration.core.cql.generator.CqlIndexSpecificationAssertions.*;
package org.springframework.cassandra.core.cql.generator;
import org.junit.Test;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
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.integration.support.CqlDataSet;
import org.springframework.cassandra.support.CqlDataSet;
/**
* Integration tests that reuse unit tests.
@@ -50,7 +48,7 @@ public class CreateIndexCqlGeneratorIntegrationTests {
session.execute(unit.cql);
assertIndex(unit.specification, keyspace, session);
CqlIndexSpecificationAssertions.assertIndex(unit.specification, keyspace, session);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,15 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.core.cql.generator;
import static org.springframework.cassandra.test.integration.core.cql.generator.CqlKeyspaceSpecificationAssertions.*;
package org.springframework.cassandra.core.cql.generator;
import org.junit.Test;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
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.
@@ -49,7 +47,7 @@ public class CreateKeyspaceCqlGeneratorIntegrationTests {
session.execute(unit.cql);
assertKeyspace(unit.specification, unit.keyspace, session);
CqlKeyspaceSpecificationAssertions.assertKeyspace(unit.specification, unit.keyspace, session);
dropKeyspace(unit.keyspace);
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,15 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.core.cql.generator;
import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.*;
package org.springframework.cassandra.core.cql.generator;
import org.junit.Test;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
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;
/**
* Integration tests that reuse unit tests.
@@ -51,7 +49,7 @@ public class CreateTableCqlGeneratorIntegrationTests {
session.execute(unit.cql);
assertTable(unit.specification, keyspace, session);
CqlTableSpecificationAssertions.assertTable(unit.specification, keyspace, session);
}
}

View File

@@ -20,8 +20,8 @@ import static org.springframework.cassandra.core.cql.generator.CreateUserTypeCql
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.core.keyspace.CreateUserTypeSpecification;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.KeyspaceMetadata;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,17 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.core.cql.generator;
import static org.springframework.cassandra.test.integration.core.cql.generator.CqlIndexSpecificationAssertions.*;
package org.springframework.cassandra.core.cql.generator;
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.AbstractKeyspaceCreatingIntegrationTest;
/**
* Integration tests that reuse unit tests.
@@ -55,11 +51,11 @@ public class IndexLifecycleCqlGeneratorIntegrationTests extends AbstractKeyspace
log.info(createTest.cql);
session.execute(createTest.cql);
assertIndex(createTest.specification, keyspace, session);
CqlIndexSpecificationAssertions.assertIndex(createTest.specification, keyspace, session);
log.info(dropTest.cql);
session.execute(dropTest.cql);
assertNoIndex(createTest.specification, keyspace, session);
CqlIndexSpecificationAssertions.assertNoIndex(createTest.specification, keyspace, session);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,19 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.core.cql.generator;
import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.*;
package org.springframework.cassandra.core.cql.generator;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.core.keyspace.DropTableSpecification;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
/**
* Test CREATE TABLE / ALTER TABLE / DROP TABLE
@@ -54,7 +49,7 @@ public class TableLifecycleIntegrationTests extends AbstractKeyspaceCreatingInte
session.execute(createTableTest.cql);
assertTable(createTableTest.specification, keyspace, session);
CqlTableSpecificationAssertions.assertTable(createTableTest.specification, keyspace, session);
DropTableTest dropTest = new DropTableTest();
dropTest.prepare();
@@ -63,7 +58,7 @@ public class TableLifecycleIntegrationTests extends AbstractKeyspaceCreatingInte
session.execute(dropTest.cql);
assertNoTable(dropTest.specification, keyspace, session);
CqlTableSpecificationAssertions.assertNoTable(dropTest.specification, keyspace, session);
}
public class DropTableTest extends DropTableCqlGeneratorUnitTests.DropTableTest {

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,15 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.core.cql.generator;
import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.*;
package org.springframework.cassandra.core.cql.generator;
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.AbstractKeyspaceCreatingIntegrationTest;
/**
* Test CREATE TABLE for all Options and assert against C* TableMetaData
@@ -44,6 +41,6 @@ public class TableOptionsIntegrationTests extends AbstractKeyspaceCreatingIntegr
session.execute(optionsTest.cql);
assertTable(optionsTest.specification, keyspace, session);
CqlTableSpecificationAssertions.assertTable(optionsTest.specification, keyspace, session);
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.support;
package org.springframework.cassandra.support;
import org.springframework.cassandra.config.java.AbstractSessionConfiguration;
import org.springframework.context.annotation.Configuration;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.support;
package org.springframework.cassandra.support;
import java.io.InputStream;
import java.util.Properties;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.support;
package org.springframework.cassandra.support;
import lombok.experimental.UtilityClass;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.support;
package org.springframework.cassandra.support;
import lombok.SneakyThrows;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.support;
package org.springframework.cassandra.support;
import io.netty.channel.EventLoopGroup;
import io.netty.util.Timer;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,26 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration.config;
package org.springframework.cassandra.support;
import static org.assertj.core.api.Assertions.*;
import org.springframework.cassandra.core.CqlTemplate;
import com.datastax.driver.core.Session;
/**
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class IntegrationTestUtils {
public static void assertCqlTemplate(CqlTemplate cqlTemplate) {
assertThat(cqlTemplate).isNotNull();
}
public static void assertSession(Session session) {
assertThat(session).isNotNull();
}
public class KeyspaceTestUtils {
public static void assertKeyspaceExists(String keyspace, Session session) {
assertThat(session.getCluster().getMetadata().getKeyspace(keyspace)).isNotNull();

View File

@@ -1,74 +0,0 @@
/*
* Copyright 2016-2017 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;
import static org.assertj.core.api.Assertions.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.config.CassandraCqlClusterFactoryBean;
import org.springframework.cassandra.test.integration.support.IntegrationTestNettyOptions;
import org.springframework.test.util.ReflectionTestUtils;
import com.datastax.driver.core.ProtocolVersion;
/**
* Unit tests for {@link CassandraCqlClusterFactoryBean}.
*
* @author Kirk Clemens
* @author Mark Paluch
*/
public class CassandraCqlClusterFactoryBeanIntegrationTests {
private CassandraCqlClusterFactoryBean cassandraCqlClusterFactoryBean;
@Before
public void setUp() throws Exception {
cassandraCqlClusterFactoryBean = new CassandraCqlClusterFactoryBean();
}
@After
public void tearDown() throws Exception {
cassandraCqlClusterFactoryBean.destroy();
}
@Test
public void configuredProtocolVersionShouldBeSet() throws Exception {
cassandraCqlClusterFactoryBean.setNettyOptions(IntegrationTestNettyOptions.INSTANCE);
cassandraCqlClusterFactoryBean.setProtocolVersion(ProtocolVersion.V2);
cassandraCqlClusterFactoryBean.afterPropertiesSet();
assertThat(getProtocolVersionEnum(cassandraCqlClusterFactoryBean)).isEqualTo(ProtocolVersion.V2);
}
@Test
public void defaultProtocolVersionShouldBeSet() throws Exception {
cassandraCqlClusterFactoryBean.afterPropertiesSet();
assertThat(getProtocolVersionEnum(cassandraCqlClusterFactoryBean)).isNull();
}
private ProtocolVersion getProtocolVersionEnum(CassandraCqlClusterFactoryBean cassandraCqlClusterFactoryBean)
throws Exception {
// initialize connection factory
return (ProtocolVersion) ReflectionTestUtils.getField(
cassandraCqlClusterFactoryBean.getObject().getConfiguration().getProtocolOptions(), "initialProtocolVersion");
}
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright 2013-2017 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.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.datastax.driver.core.Session;
/**
* Base class for Cassandra integration tests.
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)
public abstract class AbstractIntegrationTest extends AbstractEmbeddedCassandraIntegrationTest {
@Autowired protected Session session;
}

View File

@@ -1,28 +0,0 @@
/*
* Copyright 2013-2017 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.test.integration.support.AbstractTestJavaConfig;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Config extends AbstractTestJavaConfig {
@Override
protected String getKeyspaceName() {
return null;
}
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2013-2017 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.junit.Test;
import org.springframework.test.context.ContextConfiguration;
/**
* @author Matthew T. Adams
*/
@ContextConfiguration(classes = Config.class)
public class ConfigIntegrationTests extends AbstractIntegrationTest {
@Test
public void test() {
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,51 +0,0 @@
/*
* Copyright 2013-2017 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 java.util.ArrayList;
import java.util.List;
import org.springframework.cassandra.config.KeyspaceAttributes;
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
import org.springframework.cassandra.core.keyspace.KeyspaceOption;
import org.springframework.cassandra.test.integration.support.AbstractTestJavaConfig;
import org.springframework.context.annotation.Configuration;
/**
* @author Matthew T. Adams
* @author Mark Paluch
*/
@Configuration
public class KeyspaceCreatingJavaConfig extends AbstractTestJavaConfig {
public static final String KEYSPACE_NAME = "foo";
@Override
protected String getKeyspaceName() {
return KEYSPACE_NAME;
}
@Override
protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
ArrayList<CreateKeyspaceSpecification> list = new ArrayList<>();
CreateKeyspaceSpecification specification = CreateKeyspaceSpecification.createKeyspace().name(getKeyspaceName());
specification.with(KeyspaceOption.REPLICATION, KeyspaceAttributes.newSimpleReplication(1L));
list.add(specification);
return list;
}
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2013-2017 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 static org.assertj.core.api.Assertions.*;
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 KeyspaceCreatingJavaConfigIntegrationTests extends AbstractIntegrationTest {
@Test
public void test() {
assertThat(session).isNotNull();
IntegrationTestUtils.assertKeyspaceExists(KeyspaceCreatingJavaConfig.KEYSPACE_NAME, session);
session.execute("DROP KEYSPACE " + KeyspaceCreatingJavaConfig.KEYSPACE_NAME + ";");
}
}

View File

@@ -1,98 +0,0 @@
/*
* Copyright 2016-2017 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;
/**
* Test POJO
*
* @author David Webb
*/
public class Book {
private String isbn;
private String title;
private String author;
private int pages;
/**
* @return Returns the isbn.
*/
public String getIsbn() {
return isbn;
}
/**
* @param isbn The isbn to set.
*/
public void setIsbn(String isbn) {
this.isbn = isbn;
}
/**
* @return Returns the title.
*/
public String getTitle() {
return title;
}
/**
* @param title The title to set.
*/
public void setTitle(String title) {
this.title = title;
}
/**
* @return Returns the author.
*/
public String getAuthor() {
return author;
}
/**
* @param author The author to set.
*/
public void setAuthor(String author) {
this.author = author;
}
/**
* @return Returns the pages.
*/
public int getPages() {
return pages;
}
/**
* @param pages The pages to set.
*/
public void setPages(int pages) {
this.pages = pages;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("isbn -> " + isbn).append("\n");
sb.append("tile -> " + title).append("\n");
sb.append("author -> " + author).append("\n");
sb.append("pages -> " + pages).append("\n");
return sb.toString();
}
}

View File

@@ -1,71 +0,0 @@
/*
* Copyright 2016-2017 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;
import org.springframework.cassandra.core.AsynchronousQueryListener;
import org.springframework.cassandra.test.integration.support.CallbackSynchronizationSupport;
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
* @author Mark Paluch
*/
public class BookListener extends CallbackSynchronizationSupport implements AsynchronousQueryListener {
private Book book;
private boolean done;
@Override
public void onQueryComplete(ResultSetFuture resultSetFuture) {
Row row;
try {
row = resultSetFuture.get().one();
} catch (Exception e) {
throw new RuntimeException("Failed to get ResultSet from ResultSetFuture", e);
}
book = new Book();
book.setIsbn(row.getString("isbn"));
book.setTitle(row.getString("title"));
book.setAuthor(row.getString("author"));
book.setPages(row.getInt("pages"));
done = true;
countDown();
}
/**
* @return Returns the done.
*/
public boolean isDone() {
return done;
}
/**
* @return Returns the book.
*/
public Book getBook() {
return book;
}
}

View File

@@ -1,80 +0,0 @@
/*
* Copyright 2016-2017 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.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.springframework.util.Assert;
/**
* Convenient listener base class that includes a {@link CountDownLatch} in order to test asynchronous behavior. This
* class can be extended
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
public abstract class CallbackSynchronizationSupport {
private final CountDownLatch latch;
/**
* Create a new {@link CallbackSynchronizationSupport}
*/
protected CallbackSynchronizationSupport() {
this(1);
}
/**
* Create a new {@link CallbackSynchronizationSupport} for a given {@code latchCount} of callbacks.
*
* @param latchCount {@link CallbackSynchronizationSupport} for a given {@code latchCount} of callbacks
*/
protected CallbackSynchronizationSupport(int latchCount) {
latch = new CountDownLatch(latchCount);
}
/**
* Await results without a timeout.
*
* @throws InterruptedException
*/
public final void await() throws InterruptedException {
latch.await();
}
/**
* Await the results with a timeout.
*
* @param timeout must be greater or equal to 0
* @param timeUnit must not be {@literal null}.
* @throws InterruptedException
*/
public final void await(long timeout, TimeUnit timeUnit) throws InterruptedException {
Assert.isTrue(timeout >= 0, "Timeout must be greater or equal to 0");
Assert.notNull(timeUnit, "TimeUnit must not be null");
latch.await(timeout, timeUnit);
}
/**
* Indicate an incoming event and count down the latch by {@literal 1}.
*/
protected final void countDown() {
latch.countDown();
}
}

View File

@@ -20,21 +20,22 @@ import static org.assertj.core.api.Assertions.*;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.cassandra.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.KeyspaceRule;
import org.springframework.cassandra.config.CassandraCqlClusterFactoryBean;
import org.springframework.cassandra.core.SessionCallback;
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.test.integration.KeyspaceRule;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Person;
import org.springframework.data.cassandra.domain.Person;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.KeyspaceMetadata;
@@ -232,8 +233,8 @@ public class SchemaActionIntegrationTests extends AbstractEmbeddedCassandraInteg
}
@Override
public String[] getEntityBasePackages() {
return new String[] { Person.class.getPackage().getName() };
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {
return Collections.singleton(Person.class);
}
@Override

View File

@@ -25,7 +25,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.SimpleUserTypeResolver;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.util.ReflectionTestUtils;

View File

@@ -36,13 +36,13 @@ import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.test.integration.support.CassandraVersion;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.support.CassandraVersion;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.domain.AllPossibleTypes;
import org.springframework.data.cassandra.test.integration.support.SchemaTestUtils;
import org.springframework.data.cassandra.repository.support.SchemaTestUtils;
import org.springframework.data.util.Version;
import com.datastax.driver.core.Duration;

View File

@@ -30,13 +30,13 @@ import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.Table;
import org.springframework.data.cassandra.test.integration.support.SchemaTestUtils;
import org.springframework.data.cassandra.repository.support.SchemaTestUtils;
import org.springframework.data.convert.CustomConversions;
import org.springframework.util.StringUtils;

View File

@@ -42,8 +42,8 @@ import org.springframework.data.cassandra.mapping.SimpleUserTypeResolver;
import org.springframework.data.cassandra.mapping.Table;
import org.springframework.data.cassandra.mapping.UserDefinedType;
import org.springframework.data.cassandra.mapping.UserTypeResolver;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.repository.support.IntegrationTestConfig;
import org.springframework.data.convert.CustomConversions;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

View File

@@ -54,10 +54,10 @@ import org.springframework.core.SpringVersion;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.data.cassandra.RowMockUtil;
import org.springframework.data.cassandra.domain.CompositeKey;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.domain.TypeWithCompositeKey;
import org.springframework.data.cassandra.domain.TypeWithKeyClass;
import org.springframework.data.cassandra.domain.TypeWithMapId;
import org.springframework.data.cassandra.domain.User;
import org.springframework.data.cassandra.domain.UserToken;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
@@ -674,7 +674,7 @@ public class MappingCassandraConverterUnitTests {
Delete delete = QueryBuilder.delete().from("table");
mappingCassandraConverter.write("42", delete.where(), mappingContext.getRequiredPersistentEntity(Person.class));
mappingCassandraConverter.write("42", delete.where(), mappingContext.getRequiredPersistentEntity(User.class));
assertThat(getWherePredicates(delete)).containsEntry("id", "42");
}
@@ -684,10 +684,10 @@ public class MappingCassandraConverterUnitTests {
Delete delete = QueryBuilder.delete().from("table");
Person person = new Person();
person.setId("42");
User user = new User();
user.setId("42");
mappingCassandraConverter.write(person, delete.where(), mappingContext.getRequiredPersistentEntity(Person.class));
mappingCassandraConverter.write(user, delete.where(), mappingContext.getRequiredPersistentEntity(User.class));
assertThat(getWherePredicates(delete)).containsEntry("id", "42");
}
@@ -697,8 +697,7 @@ public class MappingCassandraConverterUnitTests {
Delete delete = QueryBuilder.delete().from("table");
mappingCassandraConverter.write(new Person(), delete.where(),
mappingContext.getRequiredPersistentEntity(Person.class));
mappingCassandraConverter.write(new User(), delete.where(), mappingContext.getRequiredPersistentEntity(User.class));
}
@Test // DATACASS-308
@@ -707,7 +706,7 @@ public class MappingCassandraConverterUnitTests {
Delete delete = QueryBuilder.delete().from("table");
mappingCassandraConverter.write(id("id", "42"), delete.where(),
mappingContext.getRequiredPersistentEntity(Person.class));
mappingContext.getRequiredPersistentEntity(User.class));
assertThat(getWherePredicates(delete)).containsEntry("id", "42");
}

View File

@@ -21,16 +21,16 @@ import java.util.concurrent.Future;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.core.AsyncCqlTemplate;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.query.Columns;
import org.springframework.data.cassandra.core.query.Criteria;
import org.springframework.data.cassandra.core.query.Query;
import org.springframework.data.cassandra.core.query.Update;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.domain.User;
import org.springframework.data.cassandra.domain.UserToken;
import org.springframework.data.cassandra.test.integration.support.SchemaTestUtils;
import org.springframework.data.cassandra.repository.support.SchemaTestUtils;
import org.springframework.data.domain.Sort;
import org.springframework.util.concurrent.ListenableFuture;
@@ -52,9 +52,9 @@ public class AsyncCassandraTemplateIntegrationTests extends AbstractKeyspaceCrea
CassandraTemplate cassandraTemplate = new CassandraTemplate(session, converter);
template = new AsyncCassandraTemplate(new AsyncCqlTemplate(session), converter);
SchemaTestUtils.potentiallyCreateTableFor(Person.class, cassandraTemplate);
SchemaTestUtils.potentiallyCreateTableFor(User.class, cassandraTemplate);
SchemaTestUtils.potentiallyCreateTableFor(UserToken.class, cassandraTemplate);
SchemaTestUtils.truncate(Person.class, cassandraTemplate);
SchemaTestUtils.truncate(User.class, cassandraTemplate);
SchemaTestUtils.truncate(UserToken.class, cassandraTemplate);
}
@@ -97,78 +97,78 @@ public class AsyncCassandraTemplateIntegrationTests extends AbstractKeyspaceCrea
@Test // DATACASS-292
public void insertShouldInsertEntity() {
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
assertThat(getUninterruptibly(template.selectOneById(person.getId(), Person.class))).isNull();
assertThat(getUninterruptibly(template.selectOneById(user.getId(), User.class))).isNull();
ListenableFuture<Person> insert = template.insert(person);
ListenableFuture<User> insert = template.insert(user);
assertThat(getUninterruptibly(insert)).isEqualTo(person);
assertThat(getUninterruptibly(template.selectOneById(person.getId(), Person.class))).isEqualTo(person);
assertThat(getUninterruptibly(insert)).isEqualTo(user);
assertThat(getUninterruptibly(template.selectOneById(user.getId(), User.class))).isEqualTo(user);
}
@Test // DATACASS-292
public void shouldInsertAndCountEntities() throws Exception {
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
getUninterruptibly(template.insert(person));
getUninterruptibly(template.insert(user));
ListenableFuture<Long> count = template.count(Person.class);
ListenableFuture<Long> count = template.count(User.class);
assertThat(getUninterruptibly(count)).isEqualTo(1L);
}
@Test // DATACASS-292
public void updateShouldUpdateEntity() throws Exception {
Person person = new Person("heisenberg", "Walter", "White");
getUninterruptibly(template.insert(person));
User user = new User("heisenberg", "Walter", "White");
getUninterruptibly(template.insert(user));
person.setFirstname("Walter Hartwell");
Person updated = getUninterruptibly(template.update(person));
user.setFirstname("Walter Hartwell");
User updated = getUninterruptibly(template.update(user));
assertThat(updated).isNotNull();
assertThat(getUninterruptibly(template.selectOneById(person.getId(), Person.class))).isEqualTo(person);
assertThat(getUninterruptibly(template.selectOneById(user.getId(), User.class))).isEqualTo(user);
}
@Test // DATACASS-343
public void updateShouldUpdateEntityByQuery() throws Exception {
Person person = new Person("heisenberg", "Walter", "White");
template.insert(person).get();
User user = new User("heisenberg", "Walter", "White");
template.insert(user).get();
Query query = Query.query(Criteria.where("id").is("heisenberg"));
boolean result = getUninterruptibly(
template.update(query, Update.empty().set("firstname", "Walter Hartwell"), Person.class));
template.update(query, Update.empty().set("firstname", "Walter Hartwell"), User.class));
assertThat(result).isTrue();
assertThat(getUninterruptibly(template.selectOneById(person.getId(), Person.class)).getFirstname())
assertThat(getUninterruptibly(template.selectOneById(user.getId(), User.class)).getFirstname())
.isEqualTo("Walter Hartwell");
}
@Test // DATACASS-343
public void deleteByQueryShouldRemoveEntity() throws Exception {
Person person = new Person("heisenberg", "Walter", "White");
template.insert(person).get();
User user = new User("heisenberg", "Walter", "White");
template.insert(user).get();
Query query = Query.query(Criteria.where("id").is("heisenberg"));
assertThat(getUninterruptibly(template.delete(query, Person.class))).isTrue();
assertThat(getUninterruptibly(template.delete(query, User.class))).isTrue();
assertThat(getUninterruptibly(template.selectOneById(person.getId(), Person.class))).isNull();
assertThat(getUninterruptibly(template.selectOneById(user.getId(), User.class))).isNull();
}
@Test // DATACASS-343
public void deleteColumnsByQueryShouldRemoveColumn() throws Exception {
Person person = new Person("heisenberg", "Walter", "White");
template.insert(person).get();
User user = new User("heisenberg", "Walter", "White");
template.insert(user).get();
Query query = Query.query(Criteria.where("id").is("heisenberg")).columns(Columns.from("lastname"));
assertThat(getUninterruptibly(template.delete(query, Person.class))).isTrue();
assertThat(getUninterruptibly(template.delete(query, User.class))).isTrue();
Person loaded = getUninterruptibly(template.selectOneById(person.getId(), Person.class));
User loaded = getUninterruptibly(template.selectOneById(user.getId(), User.class));
assertThat(loaded.getFirstname()).isEqualTo("Walter");
assertThat(loaded.getLastname()).isNull();
}
@@ -176,25 +176,25 @@ public class AsyncCassandraTemplateIntegrationTests extends AbstractKeyspaceCrea
@Test // DATACASS-292
public void deleteShouldRemoveEntity() throws Exception {
Person person = new Person("heisenberg", "Walter", "White");
getUninterruptibly(template.insert(person));
User user = new User("heisenberg", "Walter", "White");
getUninterruptibly(template.insert(user));
Person deleted = getUninterruptibly(template.delete(person));
User deleted = getUninterruptibly(template.delete(user));
assertThat(deleted).isNotNull();
assertThat(getUninterruptibly(template.selectOneById(person.getId(), Person.class))).isNull();
assertThat(getUninterruptibly(template.selectOneById(user.getId(), User.class))).isNull();
}
@Test // DATACASS-292
public void deleteByIdShouldRemoveEntity() throws Exception {
Person person = new Person("heisenberg", "Walter", "White");
getUninterruptibly(template.insert(person));
User user = new User("heisenberg", "Walter", "White");
getUninterruptibly(template.insert(user));
Boolean deleted = getUninterruptibly(template.deleteById(person.getId(), Person.class));
Boolean deleted = getUninterruptibly(template.deleteById(user.getId(), User.class));
assertThat(deleted).isTrue();
assertThat(getUninterruptibly(template.selectOneById(person.getId(), Person.class))).isNull();
assertThat(getUninterruptibly(template.selectOneById(user.getId(), User.class))).isNull();
}
private static <T> T getUninterruptibly(Future<T> future) {

View File

@@ -37,7 +37,7 @@ import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.domain.User;
import org.springframework.util.concurrent.ListenableFuture;
import com.datastax.driver.core.ColumnDefinitions;
@@ -71,6 +71,7 @@ public class AsyncCassandraTemplateUnitTests {
public void setUp() {
template = new AsyncCassandraTemplate(session);
when(session.executeAsync(any(Statement.class))).thenReturn(new TestResultSetFuture(resultSet));
when(row.getColumnDefinitions()).thenReturn(columnDefinitions);
}
@@ -90,11 +91,11 @@ public class AsyncCassandraTemplateUnitTests {
when(row.getObject(1)).thenReturn("Walter");
when(row.getObject(2)).thenReturn("White");
ListenableFuture<List<Person>> list = template.select("SELECT * FROM person", Person.class);
ListenableFuture<List<User>> list = template.select("SELECT * FROM users", User.class);
assertThat(getUninterruptibly(list)).hasSize(1).contains(new Person("myid", "Walter", "White"));
assertThat(getUninterruptibly(list)).hasSize(1).contains(new User("myid", "Walter", "White"));
verify(session).executeAsync(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users");
}
@Test // DATACASS-292
@@ -112,14 +113,14 @@ public class AsyncCassandraTemplateUnitTests {
when(row.getObject(1)).thenReturn("Walter");
when(row.getObject(2)).thenReturn("White");
List<Person> list = new ArrayList<>();
List<User> list = new ArrayList<>();
ListenableFuture<Void> result = template.select("SELECT * FROM person", list::add, Person.class);
ListenableFuture<Void> result = template.select("SELECT * FROM users", list::add, User.class);
assertThat(getUninterruptibly(result)).isNull();
assertThat(list).hasSize(1).contains(new Person("myid", "Walter", "White"));
assertThat(list).hasSize(1).contains(new User("myid", "Walter", "White"));
verify(session).executeAsync(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users");
}
@Test // DATACASS-292
@@ -127,7 +128,7 @@ public class AsyncCassandraTemplateUnitTests {
when(resultSet.iterator()).thenThrow(new NoHostAvailableException(Collections.emptyMap()));
ListenableFuture<List<Person>> list = template.select("SELECT * FROM person", Person.class);
ListenableFuture<List<User>> list = template.select("SELECT * FROM users", User.class);
try {
list.get();
@@ -154,11 +155,11 @@ public class AsyncCassandraTemplateUnitTests {
when(row.getObject(1)).thenReturn("Walter");
when(row.getObject(2)).thenReturn("White");
ListenableFuture<Person> future = template.selectOne("SELECT * FROM person WHERE id='myid';", Person.class);
ListenableFuture<User> future = template.selectOne("SELECT * FROM users WHERE id='myid';", User.class);
assertThat(getUninterruptibly(future)).isEqualTo(new Person("myid", "Walter", "White"));
assertThat(getUninterruptibly(future)).isEqualTo(new User("myid", "Walter", "White"));
verify(session).executeAsync(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person WHERE id='myid';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users WHERE id='myid';");
}
@Test // DATACASS-292
@@ -176,11 +177,11 @@ public class AsyncCassandraTemplateUnitTests {
when(row.getObject(1)).thenReturn("Walter");
when(row.getObject(2)).thenReturn("White");
ListenableFuture<Person> future = template.selectOneById("myid", Person.class);
ListenableFuture<User> future = template.selectOneById("myid", User.class);
assertThat(getUninterruptibly(future)).isEqualTo(new Person("myid", "Walter", "White"));
assertThat(getUninterruptibly(future)).isEqualTo(new User("myid", "Walter", "White"));
verify(session).executeAsync(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person WHERE id='myid';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users WHERE id='myid';");
}
@Test // DATACASS-292
@@ -188,11 +189,11 @@ public class AsyncCassandraTemplateUnitTests {
when(resultSet.iterator()).thenReturn(Collections.singleton(row).iterator());
ListenableFuture<Boolean> future = template.exists("myid", Person.class);
ListenableFuture<Boolean> future = template.exists("myid", User.class);
assertThat(getUninterruptibly(future)).isTrue();
verify(session).executeAsync(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person WHERE id='myid';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users WHERE id='myid';");
}
@Test // DATACASS-292
@@ -200,11 +201,11 @@ public class AsyncCassandraTemplateUnitTests {
when(resultSet.iterator()).thenReturn(Collections.emptyIterator());
ListenableFuture<Boolean> future = template.exists("myid", Person.class);
ListenableFuture<Boolean> future = template.exists("myid", User.class);
assertThat(getUninterruptibly(future)).isFalse();
verify(session).executeAsync(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person WHERE id='myid';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users WHERE id='myid';");
}
@Test // DATACASS-292
@@ -214,11 +215,11 @@ public class AsyncCassandraTemplateUnitTests {
when(row.getLong(0)).thenReturn(42L);
when(columnDefinitions.size()).thenReturn(1);
ListenableFuture<Long> future = template.count(Person.class);
ListenableFuture<Long> future = template.count(User.class);
assertThat(getUninterruptibly(future)).isEqualTo(42L);
verify(session).executeAsync(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT count(*) FROM person;");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT count(*) FROM users;");
}
@Test // DATACASS-292
@@ -226,14 +227,14 @@ public class AsyncCassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(true);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
ListenableFuture<Person> future = template.insert(person);
ListenableFuture<User> future = template.insert(user);
assertThat(getUninterruptibly(future)).isEqualTo(person);
assertThat(getUninterruptibly(future)).isEqualTo(user);
verify(session).executeAsync(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString())
.isEqualTo("INSERT INTO person (firstname,id,lastname) VALUES ('Walter','heisenberg','White');");
.isEqualTo("INSERT INTO users (firstname,id,lastname) VALUES ('Walter','heisenberg','White');");
}
@Test // DATACASS-292
@@ -243,7 +244,7 @@ public class AsyncCassandraTemplateUnitTests {
when(session.executeAsync(any(Statement.class)))
.thenReturn(TestResultSetFuture.failed(new NoHostAvailableException(Collections.emptyMap())));
ListenableFuture<Person> future = template.insert(new Person("heisenberg", "Walter", "White"));
ListenableFuture<User> future = template.insert(new User("heisenberg", "Walter", "White"));
try {
future.get();
@@ -260,9 +261,9 @@ public class AsyncCassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(false);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
ListenableFuture<Person> future = template.insert(person);
ListenableFuture<User> future = template.insert(user);
assertThat(getUninterruptibly(future)).isNull();
}
@@ -272,14 +273,14 @@ public class AsyncCassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(true);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
ListenableFuture<Person> future = template.update(person);
ListenableFuture<User> future = template.update(user);
assertThat(getUninterruptibly(future)).isEqualTo(person);
assertThat(getUninterruptibly(future)).isEqualTo(user);
verify(session).executeAsync(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString())
.isEqualTo("UPDATE person SET firstname='Walter',lastname='White' WHERE id='heisenberg';");
.isEqualTo("UPDATE users SET firstname='Walter',lastname='White' WHERE id='heisenberg';");
}
@Test // DATACASS-292
@@ -289,7 +290,7 @@ public class AsyncCassandraTemplateUnitTests {
when(session.executeAsync(any(Statement.class)))
.thenReturn(TestResultSetFuture.failed(new NoHostAvailableException(Collections.emptyMap())));
ListenableFuture<Person> future = template.update(new Person("heisenberg", "Walter", "White"));
ListenableFuture<User> future = template.update(new User("heisenberg", "Walter", "White"));
try {
future.get();
@@ -306,9 +307,9 @@ public class AsyncCassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(false);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
ListenableFuture<Person> future = template.update(person);
ListenableFuture<User> future = template.update(user);
assertThat(getUninterruptibly(future)).isNull();
}
@@ -318,13 +319,13 @@ public class AsyncCassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(true);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
ListenableFuture<Boolean> future = template.deleteById(person.getId(), Person.class);
ListenableFuture<Boolean> future = template.deleteById(user.getId(), User.class);
assertThat(getUninterruptibly(future)).isTrue();
verify(session).executeAsync(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("DELETE FROM person WHERE id='heisenberg';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("DELETE FROM users WHERE id='heisenberg';");
}
@Test // DATACASS-292
@@ -332,13 +333,13 @@ public class AsyncCassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(true);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
ListenableFuture<Person> future = template.delete(person);
ListenableFuture<User> future = template.delete(user);
assertThat(getUninterruptibly(future)).isEqualTo(person);
assertThat(getUninterruptibly(future)).isEqualTo(user);
verify(session).executeAsync(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("DELETE FROM person WHERE id='heisenberg';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("DELETE FROM users WHERE id='heisenberg';");
}
@Test // DATACASS-292
@@ -348,7 +349,7 @@ public class AsyncCassandraTemplateUnitTests {
when(session.executeAsync(any(Statement.class)))
.thenReturn(TestResultSetFuture.failed(new NoHostAvailableException(Collections.emptyMap())));
ListenableFuture<Person> future = template.delete(new Person("heisenberg", "Walter", "White"));
ListenableFuture<User> future = template.delete(new User("heisenberg", "Walter", "White"));
try {
future.get();
@@ -365,9 +366,9 @@ public class AsyncCassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(false);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
ListenableFuture<Person> future = template.delete(person);
ListenableFuture<User> future = template.delete(user);
assertThat(getUninterruptibly(future)).isNull();
}
@@ -375,10 +376,10 @@ public class AsyncCassandraTemplateUnitTests {
@Test // DATACASS-292
public void truncateShouldRemoveEntities() {
template.truncate(Person.class);
template.truncate(User.class);
verify(session).executeAsync(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("TRUNCATE person;");
assertThat(statementCaptor.getValue().toString()).isEqualTo("TRUNCATE users;");
}
private static <T> T getUninterruptibly(Future<T> future) {

View File

@@ -21,12 +21,12 @@ import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.core.cql.CqlIdentifier;
import org.springframework.cassandra.core.cql.generator.DropTableCqlGenerator;
import org.springframework.cassandra.core.keyspace.DropTableSpecification;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.test.integration.simpletons.Book;
import org.springframework.data.cassandra.domain.User;
import com.datastax.driver.core.KeyspaceMetadata;
import com.datastax.driver.core.Metadata;
@@ -60,28 +60,28 @@ public class CassandraAdminTemplateIntegrationTests extends AbstractKeyspaceCrea
}
@Test // DATACASS-173
public void testCreateTables() throws Exception {
public void testCreateTables() {
assertThat(getKeyspaceMetadata().getTables()).hasSize(0);
cassandraAdminTemplate.createTable(true, CqlIdentifier.cqlId("book"), Book.class, null);
cassandraAdminTemplate.createTable(true, CqlIdentifier.cqlId("users"), User.class, null);
assertThat(getKeyspaceMetadata().getTables()).hasSize(1);
cassandraAdminTemplate.createTable(true, CqlIdentifier.cqlId("book"), Book.class, null);
cassandraAdminTemplate.createTable(true, CqlIdentifier.cqlId("users"), User.class, null);
assertThat(getKeyspaceMetadata().getTables()).hasSize(1);
}
@Test
public void testDropTable() throws Exception {
public void testDropTable() {
cassandraAdminTemplate.createTable(true, CqlIdentifier.cqlId("book"), Book.class, null);
cassandraAdminTemplate.createTable(true, CqlIdentifier.cqlId("users"), User.class, null);
assertThat(getKeyspaceMetadata().getTables()).hasSize(1);
cassandraAdminTemplate.dropTable(Book.class);
cassandraAdminTemplate.dropTable(User.class);
assertThat(getKeyspaceMetadata().getTables()).hasSize(0);
cassandraAdminTemplate.createTable(true, CqlIdentifier.cqlId("book"), Book.class, null);
cassandraAdminTemplate.dropTable(CqlIdentifier.cqlId("book"));
cassandraAdminTemplate.createTable(true, CqlIdentifier.cqlId("users"), User.class, null);
cassandraAdminTemplate.dropTable(CqlIdentifier.cqlId("users"));
assertThat(getKeyspaceMetadata().getTables()).hasSize(0);
}

View File

@@ -23,11 +23,11 @@ import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.data.cassandra.domain.FlatGroup;
import org.springframework.data.cassandra.domain.Group;
import org.springframework.data.cassandra.domain.GroupKey;
import org.springframework.data.cassandra.test.integration.support.SchemaTestUtils;
import org.springframework.data.cassandra.repository.support.SchemaTestUtils;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;

View File

@@ -26,19 +26,19 @@ import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.core.CqlTemplate;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.test.integration.support.CassandraVersion;
import org.springframework.cassandra.support.CassandraVersion;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.query.Columns;
import org.springframework.data.cassandra.core.query.Criteria;
import org.springframework.data.cassandra.core.query.Query;
import org.springframework.data.cassandra.core.query.Update;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.domain.BookReference;
import org.springframework.data.cassandra.domain.User;
import org.springframework.data.cassandra.domain.UserToken;
import org.springframework.data.cassandra.repository.support.BasicMapId;
import org.springframework.data.cassandra.test.integration.simpletons.BookReference;
import org.springframework.data.cassandra.test.integration.support.SchemaTestUtils;
import org.springframework.data.cassandra.repository.support.SchemaTestUtils;
import org.springframework.data.domain.Sort;
import org.springframework.data.util.Version;
@@ -67,10 +67,10 @@ public class CassandraTemplateIntegrationTests extends AbstractKeyspaceCreatingI
template = new CassandraTemplate(new CqlTemplate(session), converter);
SchemaTestUtils.potentiallyCreateTableFor(Person.class, template);
SchemaTestUtils.potentiallyCreateTableFor(User.class, template);
SchemaTestUtils.potentiallyCreateTableFor(UserToken.class, template);
SchemaTestUtils.potentiallyCreateTableFor(BookReference.class, template);
SchemaTestUtils.truncate(Person.class, template);
SchemaTestUtils.truncate(User.class, template);
SchemaTestUtils.truncate(UserToken.class, template);
SchemaTestUtils.truncate(BookReference.class, template);
}
@@ -136,77 +136,77 @@ public class CassandraTemplateIntegrationTests extends AbstractKeyspaceCreatingI
@Test // DATACASS-292
public void insertShouldInsertEntity() {
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
assertThat(template.selectOneById(person.getId(), Person.class)).isNull();
assertThat(template.selectOneById(user.getId(), User.class)).isNull();
Person inserted = template.insert(person);
User inserted = template.insert(user);
assertThat(inserted).isEqualTo(person);
assertThat(template.selectOneById(person.getId(), Person.class)).isEqualTo(person);
assertThat(inserted).isEqualTo(user);
assertThat(template.selectOneById(user.getId(), User.class)).isEqualTo(user);
}
@Test // DATACASS-292
public void shouldInsertAndCountEntities() {
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
template.insert(person);
template.insert(user);
long count = template.count(Person.class);
long count = template.count(User.class);
assertThat(count).isEqualTo(1L);
}
@Test // DATACASS-292
public void updateShouldUpdateEntity() {
Person person = new Person("heisenberg", "Walter", "White");
template.insert(person);
User user = new User("heisenberg", "Walter", "White");
template.insert(user);
person.setFirstname("Walter Hartwell");
user.setFirstname("Walter Hartwell");
Person updated = template.update(person);
User updated = template.update(user);
assertThat(updated).isNotNull();
assertThat(template.selectOneById(person.getId(), Person.class)).isEqualTo(person);
assertThat(template.selectOneById(user.getId(), User.class)).isEqualTo(user);
}
@Test // DATACASS-343
public void updateShouldUpdateEntityByQuery() {
Person person = new Person("heisenberg", "Walter", "White");
User person = new User("heisenberg", "Walter", "White");
template.insert(person);
Query query = Query.query(Criteria.where("id").is("heisenberg"));
boolean result = template.update(query, Update.empty().set("firstname", "Walter Hartwell"), Person.class);
boolean result = template.update(query, Update.empty().set("firstname", "Walter Hartwell"), User.class);
assertThat(result).isTrue();
assertThat(template.selectOneById(person.getId(), Person.class).getFirstname()).isEqualTo("Walter Hartwell");
assertThat(template.selectOneById(person.getId(), User.class).getFirstname()).isEqualTo("Walter Hartwell");
}
@Test // DATACASS-343
public void deleteByQueryShouldRemoveEntity() {
Person person = new Person("heisenberg", "Walter", "White");
template.insert(person);
User user = new User("heisenberg", "Walter", "White");
template.insert(user);
Query query = Query.query(Criteria.where("id").is("heisenberg"));
assertThat(template.delete(query, Person.class)).isTrue();
assertThat(template.delete(query, User.class)).isTrue();
assertThat(template.selectOneById(person.getId(), Person.class)).isNull();
assertThat(template.selectOneById(user.getId(), User.class)).isNull();
}
@Test // DATACASS-343
public void deleteColumnsByQueryShouldRemoveColumn() {
Person person = new Person("heisenberg", "Walter", "White");
template.insert(person);
User user = new User("heisenberg", "Walter", "White");
template.insert(user);
Query query = Query.query(Criteria.where("id").is("heisenberg")).columns(Columns.from("lastname"));
assertThat(template.delete(query, Person.class)).isTrue();
assertThat(template.delete(query, User.class)).isTrue();
Person loaded = template.selectOneById(person.getId(), Person.class);
User loaded = template.selectOneById(user.getId(), User.class);
assertThat(loaded.getFirstname()).isEqualTo("Walter");
assertThat(loaded.getLastname()).isNull();
}
@@ -214,47 +214,47 @@ public class CassandraTemplateIntegrationTests extends AbstractKeyspaceCreatingI
@Test // DATACASS-292
public void deleteShouldRemoveEntity() {
Person person = new Person("heisenberg", "Walter", "White");
template.insert(person);
User user = new User("heisenberg", "Walter", "White");
template.insert(user);
Person deleted = template.delete(person);
User deleted = template.delete(user);
assertThat(deleted).isNotNull();
assertThat(template.selectOneById(person.getId(), Person.class)).isNull();
assertThat(template.selectOneById(user.getId(), User.class)).isNull();
}
@Test // DATACASS-292
public void deleteByIdShouldRemoveEntity() {
Person person = new Person("heisenberg", "Walter", "White");
template.insert(person);
User user = new User("heisenberg", "Walter", "White");
template.insert(user);
Boolean deleted = template.deleteById(person.getId(), Person.class);
Boolean deleted = template.deleteById(user.getId(), User.class);
assertThat(deleted).isTrue();
assertThat(template.selectOneById(person.getId(), Person.class)).isNull();
assertThat(template.selectOneById(user.getId(), User.class)).isNull();
}
@Test // DATACASS-182
public void stream() {
Person person = new Person("heisenberg", "Walter", "White");
template.insert(person);
User user = new User("heisenberg", "Walter", "White");
template.insert(user);
Stream<Person> stream = template.stream("SELECT * FROM person", Person.class);
Stream<User> stream = template.stream("SELECT * FROM users", User.class);
assertThat(stream.collect(Collectors.toList())).hasSize(1).contains(person);
assertThat(stream.collect(Collectors.toList())).hasSize(1).contains(user);
}
@Test // DATACASS-343
public void streamByQuery() {
Person person = new Person("heisenberg", "Walter", "White");
User person = new User("heisenberg", "Walter", "White");
template.insert(person);
Query query = Query.query(Criteria.where("id").is("heisenberg"));
Stream<Person> stream = template.stream(query, Person.class);
Stream<User> stream = template.stream(query, User.class);
assertThat(stream.collect(Collectors.toList())).hasSize(1).contains(person);
}
@@ -262,14 +262,14 @@ public class CassandraTemplateIntegrationTests extends AbstractKeyspaceCreatingI
@Test // DATACASS-182
public void updateShouldRemoveFields() {
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
template.insert(person);
template.insert(user);
person.setFirstname(null);
template.update(person);
user.setFirstname(null);
template.update(user);
Person loaded = template.selectOneById(person.getId(), Person.class);
User loaded = template.selectOneById(user.getId(), User.class);
assertThat(loaded.getFirstname()).isNull();
assertThat(loaded.getId()).isEqualTo("heisenberg");
@@ -278,14 +278,14 @@ public class CassandraTemplateIntegrationTests extends AbstractKeyspaceCreatingI
@Test // DATACASS-182, DATACASS-420
public void insertShouldNotRemoveFields() {
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
template.insert(person);
template.insert(user);
person.setFirstname(null);
template.insert(person);
user.setFirstname(null);
template.insert(user);
Person loaded = template.selectOneById(person.getId(), Person.class);
User loaded = template.selectOneById(user.getId(), User.class);
assertThat(loaded.getFirstname()).isEqualTo("Walter");
assertThat(loaded.getId()).isEqualTo("heisenberg");

View File

@@ -34,9 +34,7 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.test.integration.simpletons.Book;
import org.springframework.data.cassandra.domain.User;
import com.datastax.driver.core.ColumnDefinitions;
import com.datastax.driver.core.DataType;
@@ -67,7 +65,8 @@ public class CassandraTemplateUnitTests {
@Before
public void setUp() {
template = new CassandraTemplate(session, new MappingCassandraConverter());
template = new CassandraTemplate(session);
when(session.execute(any(Statement.class))).thenReturn(resultSet);
when(row.getColumnDefinitions()).thenReturn(columnDefinitions);
}
@@ -87,11 +86,11 @@ public class CassandraTemplateUnitTests {
when(row.getObject(1)).thenReturn("Walter");
when(row.getObject(2)).thenReturn("White");
List<Person> list = template.select("SELECT * FROM person", Person.class);
List<User> list = template.select("SELECT * FROM users", User.class);
assertThat(list).hasSize(1).contains(new Person("myid", "Walter", "White"));
assertThat(list).hasSize(1).contains(new User("myid", "Walter", "White"));
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users");
}
@Test // DATACASS-292
@@ -100,7 +99,7 @@ public class CassandraTemplateUnitTests {
when(resultSet.iterator()).thenThrow(new NoHostAvailableException(Collections.emptyMap()));
try {
template.select("SELECT * FROM person", Person.class);
template.select("SELECT * FROM users", User.class);
fail("Missing CassandraConnectionFailureException");
} catch (CassandraConnectionFailureException e) {
@@ -123,11 +122,11 @@ public class CassandraTemplateUnitTests {
when(row.getObject(1)).thenReturn("Walter");
when(row.getObject(2)).thenReturn("White");
Person person = template.selectOne("SELECT * FROM person WHERE id='myid';", Person.class);
User user = template.selectOne("SELECT * FROM users WHERE id='myid';", User.class);
assertThat(person).isEqualTo(new Person("myid", "Walter", "White"));
assertThat(user).isEqualTo(new User("myid", "Walter", "White"));
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person WHERE id='myid';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users WHERE id='myid';");
}
@Test // DATACASS-292
@@ -145,11 +144,11 @@ public class CassandraTemplateUnitTests {
when(row.getObject(1)).thenReturn("Walter");
when(row.getObject(2)).thenReturn("White");
Person person = template.selectOneById("myid", Person.class);
User user = template.selectOneById("myid", User.class);
assertThat(person).isEqualTo(new Person("myid", "Walter", "White"));
assertThat(user).isEqualTo(new User("myid", "Walter", "White"));
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person WHERE id='myid';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users WHERE id='myid';");
}
@Test // DATACASS-292
@@ -157,11 +156,11 @@ public class CassandraTemplateUnitTests {
when(resultSet.iterator()).thenReturn(Collections.singleton(row).iterator());
boolean exists = template.exists("myid", Person.class);
boolean exists = template.exists("myid", User.class);
assertThat(exists).isTrue();
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person WHERE id='myid';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users WHERE id='myid';");
}
@Test // DATACASS-292
@@ -169,11 +168,11 @@ public class CassandraTemplateUnitTests {
when(resultSet.iterator()).thenReturn(Collections.emptyIterator());
boolean exists = template.exists("myid", Person.class);
boolean exists = template.exists("myid", User.class);
assertThat(exists).isFalse();
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person WHERE id='myid';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users WHERE id='myid';");
}
@Test // DATACASS-292
@@ -183,11 +182,11 @@ public class CassandraTemplateUnitTests {
when(row.getLong(0)).thenReturn(42L);
when(columnDefinitions.size()).thenReturn(1);
long count = template.count(Person.class);
long count = template.count(User.class);
assertThat(count).isEqualTo(42L);
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT count(*) FROM person;");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT count(*) FROM users;");
}
@Test // DATACASS-292
@@ -195,14 +194,14 @@ public class CassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(true);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
Person inserted = template.insert(person);
User inserted = template.insert(user);
assertThat(inserted).isEqualTo(person);
assertThat(inserted).isEqualTo(user);
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString())
.isEqualTo("INSERT INTO person (firstname,id,lastname) VALUES ('Walter','heisenberg','White');");
.isEqualTo("INSERT INTO users (firstname,id,lastname) VALUES ('Walter','heisenberg','White');");
}
@Test // DATACASS-292
@@ -212,7 +211,7 @@ public class CassandraTemplateUnitTests {
when(session.execute(any(Statement.class))).thenThrow(new NoHostAvailableException(Collections.emptyMap()));
try {
template.insert(new Person("heisenberg", "Walter", "White"));
template.insert(new User("heisenberg", "Walter", "White"));
fail("Missing CassandraConnectionFailureException");
} catch (CassandraConnectionFailureException e) {
@@ -225,9 +224,9 @@ public class CassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(false);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
Person inserted = template.insert(person);
User inserted = template.insert(user);
assertThat(inserted).isNull();
}
@@ -237,14 +236,14 @@ public class CassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(true);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
Person updated = template.update(person);
User updated = template.update(user);
assertThat(updated).isEqualTo(person);
assertThat(updated).isEqualTo(user);
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString())
.isEqualTo("UPDATE person SET firstname='Walter',lastname='White' WHERE id='heisenberg';");
.isEqualTo("UPDATE users SET firstname='Walter',lastname='White' WHERE id='heisenberg';");
}
@Test // DATACASS-292
@@ -254,7 +253,7 @@ public class CassandraTemplateUnitTests {
when(session.execute(any(Statement.class))).thenThrow(new NoHostAvailableException(Collections.emptyMap()));
try {
template.update(new Person("heisenberg", "Walter", "White"));
template.update(new User("heisenberg", "Walter", "White"));
fail("Missing CassandraConnectionFailureException");
} catch (CassandraConnectionFailureException e) {
@@ -267,9 +266,9 @@ public class CassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(false);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
Person updated = template.update(person);
User updated = template.update(user);
assertThat(updated).isNull();
}
@@ -279,13 +278,13 @@ public class CassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(true);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
boolean deleted = template.deleteById(person.getId(), Person.class);
boolean deleted = template.deleteById(user.getId(), User.class);
assertThat(deleted).isTrue();
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("DELETE FROM person WHERE id='heisenberg';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("DELETE FROM users WHERE id='heisenberg';");
}
@Test // DATACASS-292
@@ -293,13 +292,13 @@ public class CassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(true);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
Person deleted = template.delete(person);
User deleted = template.delete(user);
assertThat(deleted).isEqualTo(person);
assertThat(deleted).isEqualTo(user);
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("DELETE FROM person WHERE id='heisenberg';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("DELETE FROM users WHERE id='heisenberg';");
}
@Test // DATACASS-292
@@ -309,7 +308,7 @@ public class CassandraTemplateUnitTests {
when(session.execute(any(Statement.class))).thenThrow(new NoHostAvailableException(Collections.emptyMap()));
try {
template.delete(new Person("heisenberg", "Walter", "White"));
template.delete(new User("heisenberg", "Walter", "White"));
fail("Missing CassandraConnectionFailureException");
} catch (CassandraConnectionFailureException e) {
@@ -322,9 +321,9 @@ public class CassandraTemplateUnitTests {
when(resultSet.wasApplied()).thenReturn(false);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
Person deleted = template.delete(person);
User deleted = template.delete(user);
assertThat(deleted).isNull();
}
@@ -332,17 +331,17 @@ public class CassandraTemplateUnitTests {
@Test // DATACASS-292
public void truncateShouldRemoveEntities() {
template.truncate(Person.class);
template.truncate(User.class);
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("TRUNCATE person;");
assertThat(statementCaptor.getValue().toString()).isEqualTo("TRUNCATE users;");
}
@Test // DATACASS-292
@Ignore
public void batchOperationsShouldCallSession() {
template.batchOps().insert(new Book()).execute();
template.batchOps().insert(new User()).execute();
verify(session).execute(Mockito.any(Batch.class));
}

View File

@@ -23,17 +23,17 @@ import reactor.test.StepVerifier;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.core.ReactiveCqlTemplate;
import org.springframework.cassandra.core.session.DefaultBridgedReactiveSession;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.query.Columns;
import org.springframework.data.cassandra.core.query.Criteria;
import org.springframework.data.cassandra.core.query.Query;
import org.springframework.data.cassandra.core.query.Update;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.domain.User;
import org.springframework.data.cassandra.domain.UserToken;
import org.springframework.data.cassandra.test.integration.support.SchemaTestUtils;
import org.springframework.data.cassandra.repository.support.SchemaTestUtils;
import org.springframework.data.domain.Sort;
import com.datastax.driver.core.utils.UUIDs;
@@ -56,87 +56,87 @@ public class ReactiveCassandraTemplateIntegrationTests extends AbstractKeyspaceC
template = new ReactiveCassandraTemplate(new ReactiveCqlTemplate(session), converter);
SchemaTestUtils.potentiallyCreateTableFor(Person.class, cassandraTemplate);
SchemaTestUtils.potentiallyCreateTableFor(User.class, cassandraTemplate);
SchemaTestUtils.potentiallyCreateTableFor(UserToken.class, cassandraTemplate);
SchemaTestUtils.truncate(Person.class, cassandraTemplate);
SchemaTestUtils.truncate(User.class, cassandraTemplate);
SchemaTestUtils.truncate(UserToken.class, cassandraTemplate);
}
@Test // DATACASS-335
public void insertShouldInsertEntity() {
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
Mono<Person> insert = template.insert(person);
StepVerifier.create(template.selectOneById(person.getId(), Person.class)).verifyComplete();
Mono<User> insert = template.insert(user);
StepVerifier.create(template.selectOneById(user.getId(), User.class)).verifyComplete();
StepVerifier.create(insert).expectNext(person).verifyComplete();
StepVerifier.create(insert).expectNext(user).verifyComplete();
StepVerifier.create(template.selectOneById(person.getId(), Person.class)).expectNext(person).verifyComplete();
StepVerifier.create(template.selectOneById(user.getId(), User.class)).expectNext(user).verifyComplete();
}
@Test // DATACASS-335
public void shouldInsertAndCountEntities() {
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
StepVerifier.create(template.insert(person)).expectNextCount(1).verifyComplete();
StepVerifier.create(template.insert(user)).expectNextCount(1).verifyComplete();
StepVerifier.create(template.count(Person.class)).expectNext(1L).verifyComplete();
StepVerifier.create(template.count(User.class)).expectNext(1L).verifyComplete();
}
@Test // DATACASS-335
public void updateShouldUpdateEntity() {
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
StepVerifier.create(template.insert(person)).expectNextCount(1).verifyComplete();
StepVerifier.create(template.insert(user)).expectNextCount(1).verifyComplete();
person.setFirstname("Walter Hartwell");
user.setFirstname("Walter Hartwell");
StepVerifier.create(template.insert(person)).expectNextCount(1).verifyComplete();
StepVerifier.create(template.insert(user)).expectNextCount(1).verifyComplete();
StepVerifier.create(template.selectOneById(person.getId(), Person.class)).expectNext(person).verifyComplete();
StepVerifier.create(template.selectOneById(user.getId(), User.class)).expectNext(user).verifyComplete();
}
@Test // DATACASS-343
public void updateShouldUpdateEntityByQuery() {
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
template.insert(person).block();
template.insert(user).block();
Query query = Query.query(Criteria.where("id").is("heisenberg"));
boolean result = template.update(query, Update.empty().set("firstname", "Walter Hartwell"), Person.class).block();
boolean result = template.update(query, Update.empty().set("firstname", "Walter Hartwell"), User.class).block();
assertThat(result).isTrue();
assertThat(template.selectOneById(person.getId(), Person.class).block().getFirstname())
assertThat(template.selectOneById(user.getId(), User.class).block().getFirstname())
.isEqualTo("Walter Hartwell");
}
@Test // DATACASS-343
public void deleteByQueryShouldRemoveEntity() {
Person person = new Person("heisenberg", "Walter", "White");
template.insert(person).block();
User user = new User("heisenberg", "Walter", "White");
template.insert(user).block();
Query query = Query.query(Criteria.where("id").is("heisenberg"));
assertThat(template.delete(query, Person.class).block()).isTrue();
assertThat(template.delete(query, User.class).block()).isTrue();
assertThat(template.selectOneById(person.getId(), Person.class).block()).isNull();
assertThat(template.selectOneById(user.getId(), User.class).block()).isNull();
}
@Test // DATACASS-343
public void deleteColumnsByQueryShouldRemoveColumn() {
Person person = new Person("heisenberg", "Walter", "White");
template.insert(person).block();
User user = new User("heisenberg", "Walter", "White");
template.insert(user).block();
Query query = Query.query(Criteria.where("id").is("heisenberg")).columns(Columns.from("lastname"));
assertThat(template.delete(query, Person.class).block()).isTrue();
assertThat(template.delete(query, User.class).block()).isTrue();
Person loaded = template.selectOneById(person.getId(), Person.class).block();
User loaded = template.selectOneById(user.getId(), User.class).block();
assertThat(loaded.getFirstname()).isEqualTo("Walter");
assertThat(loaded.getLastname()).isNull();
}
@@ -144,25 +144,25 @@ public class ReactiveCassandraTemplateIntegrationTests extends AbstractKeyspaceC
@Test // DATACASS-335
public void deleteShouldRemoveEntity() {
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
StepVerifier.create(template.insert(person)).expectNextCount(1).verifyComplete();
StepVerifier.create(template.insert(user)).expectNextCount(1).verifyComplete();
StepVerifier.create(template.delete(person)).expectNext(person).verifyComplete();
StepVerifier.create(template.delete(user)).expectNext(user).verifyComplete();
StepVerifier.create(template.selectOneById(person.getId(), Person.class)).verifyComplete();
StepVerifier.create(template.selectOneById(user.getId(), User.class)).verifyComplete();
}
@Test // DATACASS-335
public void deleteByIdShouldRemoveEntity() {
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
StepVerifier.create(template.insert(person)).expectNextCount(1).verifyComplete();
StepVerifier.create(template.insert(user)).expectNextCount(1).verifyComplete();
StepVerifier.create(template.deleteById(person.getId(), Person.class)).expectNext(true).verifyComplete();
StepVerifier.create(template.deleteById(user.getId(), User.class)).expectNext(true).verifyComplete();
StepVerifier.create(template.selectOneById(person.getId(), Person.class)).verifyComplete();
StepVerifier.create(template.selectOneById(user.getId(), User.class)).verifyComplete();
}
@Test // DATACASS-343

View File

@@ -36,7 +36,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cassandra.core.session.ReactiveResultSet;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.domain.User;
import com.datastax.driver.core.ColumnDefinitions;
import com.datastax.driver.core.DataType;
@@ -85,12 +85,12 @@ public class ReactiveCassandraTemplateUnitTests {
when(row.getObject(1)).thenReturn("Walter");
when(row.getObject(2)).thenReturn("White");
StepVerifier.create(template.select("SELECT * FROM person", Person.class)) //
.expectNext(new Person("myid", "Walter", "White")) //
StepVerifier.create(template.select("SELECT * FROM users", User.class)) //
.expectNext(new User("myid", "Walter", "White")) //
.verifyComplete();
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users");
}
@Test // DATACASS-335
@@ -98,7 +98,7 @@ public class ReactiveCassandraTemplateUnitTests {
when(reactiveResultSet.rows()).thenThrow(new NoHostAvailableException(Collections.emptyMap()));
StepVerifier.create(template.select("SELECT * FROM person", Person.class)) //
StepVerifier.create(template.select("SELECT * FROM users", User.class)) //
.consumeErrorWith(e -> {
assertThat(e).hasRootCauseInstanceOf(NoHostAvailableException.class);
}).verify();
@@ -119,12 +119,12 @@ public class ReactiveCassandraTemplateUnitTests {
when(row.getObject(1)).thenReturn("Walter");
when(row.getObject(2)).thenReturn("White");
StepVerifier.create(template.selectOneById("myid", Person.class)) //
.expectNext(new Person("myid", "Walter", "White")) //
StepVerifier.create(template.selectOneById("myid", User.class)) //
.expectNext(new User("myid", "Walter", "White")) //
.verifyComplete();
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person WHERE id='myid';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users WHERE id='myid';");
}
@Test // DATACASS-335
@@ -132,10 +132,10 @@ public class ReactiveCassandraTemplateUnitTests {
when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
StepVerifier.create(template.exists("myid", Person.class)).expectNext(true).verifyComplete();
StepVerifier.create(template.exists("myid", User.class)).expectNext(true).verifyComplete();
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person WHERE id='myid';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users WHERE id='myid';");
}
@Test // DATACASS-335
@@ -143,10 +143,10 @@ public class ReactiveCassandraTemplateUnitTests {
when(reactiveResultSet.rows()).thenReturn(Flux.empty());
StepVerifier.create(template.exists("myid", Person.class)).expectNext(false).verifyComplete();
StepVerifier.create(template.exists("myid", User.class)).expectNext(false).verifyComplete();
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM person WHERE id='myid';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT * FROM users WHERE id='myid';");
}
@Test // DATACASS-335
@@ -156,10 +156,10 @@ public class ReactiveCassandraTemplateUnitTests {
when(row.getLong(0)).thenReturn(42L);
when(columnDefinitions.size()).thenReturn(1);
StepVerifier.create(template.count(Person.class)).expectNext(42L).verifyComplete();
StepVerifier.create(template.count(User.class)).expectNext(42L).verifyComplete();
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT count(*) FROM person;");
assertThat(statementCaptor.getValue().toString()).isEqualTo("SELECT count(*) FROM users;");
}
@Test // DATACASS-335
@@ -167,12 +167,12 @@ public class ReactiveCassandraTemplateUnitTests {
when(reactiveResultSet.wasApplied()).thenReturn(true);
Person person = new Person("heisenberg", "Walter", "White");
StepVerifier.create(template.insert(person)).expectNext(person).verifyComplete();
User user = new User("heisenberg", "Walter", "White");
StepVerifier.create(template.insert(user)).expectNext(user).verifyComplete();
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString())
.isEqualTo("INSERT INTO person (firstname,id,lastname) VALUES ('Walter','heisenberg','White');");
.isEqualTo("INSERT INTO users (firstname,id,lastname) VALUES ('Walter','heisenberg','White');");
}
@Test // DATACASS-335
@@ -182,7 +182,7 @@ public class ReactiveCassandraTemplateUnitTests {
when(session.execute(any(Statement.class)))
.thenReturn(Mono.error(new NoHostAvailableException(Collections.emptyMap())));
StepVerifier.create(template.insert(new Person("heisenberg", "Walter", "White"))) //
StepVerifier.create(template.insert(new User("heisenberg", "Walter", "White"))) //
.consumeErrorWith(e -> {
assertThat(e).hasRootCauseInstanceOf(NoHostAvailableException.class);
@@ -194,9 +194,9 @@ public class ReactiveCassandraTemplateUnitTests {
when(reactiveResultSet.wasApplied()).thenReturn(false);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
StepVerifier.create(template.insert(person)).verifyComplete();
StepVerifier.create(template.insert(user)).verifyComplete();
}
@Test // DATACASS-335
@@ -204,13 +204,13 @@ public class ReactiveCassandraTemplateUnitTests {
when(reactiveResultSet.wasApplied()).thenReturn(true);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
StepVerifier.create(template.update(person)).expectNext(person).verifyComplete();
StepVerifier.create(template.update(user)).expectNext(user).verifyComplete();
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString())
.isEqualTo("UPDATE person SET firstname='Walter',lastname='White' WHERE id='heisenberg';");
.isEqualTo("UPDATE users SET firstname='Walter',lastname='White' WHERE id='heisenberg';");
}
@Test // DATACASS-335
@@ -218,9 +218,9 @@ public class ReactiveCassandraTemplateUnitTests {
when(reactiveResultSet.wasApplied()).thenReturn(false);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
StepVerifier.create(template.update(person)).verifyComplete();
StepVerifier.create(template.update(user)).verifyComplete();
}
@Test // DATACASS-335
@@ -228,12 +228,12 @@ public class ReactiveCassandraTemplateUnitTests {
when(reactiveResultSet.wasApplied()).thenReturn(true);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
StepVerifier.create(template.delete(person)).expectNext(person).verifyComplete();
StepVerifier.create(template.delete(user)).expectNext(user).verifyComplete();
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("DELETE FROM person WHERE id='heisenberg';");
assertThat(statementCaptor.getValue().toString()).isEqualTo("DELETE FROM users WHERE id='heisenberg';");
}
@Test // DATACASS-335
@@ -241,17 +241,17 @@ public class ReactiveCassandraTemplateUnitTests {
when(reactiveResultSet.wasApplied()).thenReturn(false);
Person person = new Person("heisenberg", "Walter", "White");
User user = new User("heisenberg", "Walter", "White");
StepVerifier.create(template.delete(person)).verifyComplete();
StepVerifier.create(template.delete(user)).verifyComplete();
}
@Test // DATACASS-335
public void truncateShouldRemoveEntities() {
StepVerifier.create(template.truncate(Person.class)).verifyComplete();
StepVerifier.create(template.truncate(User.class)).verifyComplete();
verify(session).execute(statementCaptor.capture());
assertThat(statementCaptor.getValue().toString()).isEqualTo("TRUNCATE person;");
assertThat(statementCaptor.getValue().toString()).isEqualTo("TRUNCATE users;");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 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,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.simple;
package org.springframework.data.cassandra.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.cassandra.mapping.UserDefinedType;
@@ -24,8 +26,10 @@ import org.springframework.data.cassandra.mapping.UserDefinedType;
*/
@UserDefinedType("address")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AddressType {
String street;
String city;
String country;
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.simpletons;
package org.springframework.data.cassandra.domain;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
import java.util.Set;
import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;
@@ -27,23 +27,14 @@ import org.springframework.data.cassandra.mapping.Table;
* Test POJO
*
* @author David Webb
* @author Mark Paluch
*/
@Table("book")
@Table("bookReference")
@Data
@NoArgsConstructor
public class Book {
public class BookReference {
@PrimaryKey private String isbn;
private String title;
private String author;
private int pages;
private Date saleDate;
private boolean isInStock;
private BookCondition condition;
public Book(String isbn) {
this.isbn = isbn;
}
private Set<String> references;
private List<Integer> bookmarks;
}

View File

@@ -19,7 +19,13 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import org.springframework.cassandra.core.PrimaryKeyType;
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.mapping.Table;
/**
@@ -31,7 +37,24 @@ import org.springframework.data.cassandra.mapping.Table;
@NoArgsConstructor
public class Person {
@Id String id;
String firstname;
String lastname;
@PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED, ordinal = 0) private String lastname;
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 1) private String firstname;
private String nickname;
private Date birthDate;
private int numberOfChildren;
private boolean cool;
private LocalDate createdDate;
private ZoneId zoneId;
private AddressType mainAddress;
private List<AddressType> alternativeAddresses;
public Person(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 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,23 +13,40 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.querymethods.declared;
package org.springframework.data.cassandra.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.cassandra.mapping.UserDefinedType;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.mapping.Table;
/**
* @author Alex Shvid
* @author Mark Paluch
*/
@UserDefinedType
@AllArgsConstructor
@NoArgsConstructor
@Table("users")
@Data
public class Address {
@NoArgsConstructor
@EqualsAndHashCode(of = "id")
public class User {
String city;
String country;
/*
* Primary Row ID
*/
@Id private String id;
/*
* Public information
*/
private String firstname;
private String lastname;
public User(String id, String firstname, String lastname) {
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
}
}

View File

@@ -31,8 +31,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.repository.support.IntegrationTestConfig;
import org.springframework.data.convert.CustomConversions;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 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.
@@ -14,20 +14,31 @@
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.querymethods.bigintparam;
package org.springframework.data.cassandra.repository;
import static org.assertj.core.api.Assertions.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigInteger;
import java.util.Collections;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.core.PrimaryKeyType;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.mapping.Table;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.repository.support.IntegrationTestConfig;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -41,11 +52,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class BigIntParamIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
@Configuration
@EnableCassandraRepositories(basePackageClasses = BigThingRepo.class)
@EnableCassandraRepositories(basePackageClasses = BigThingRepo.class, considerNestedRepositories = true,
includeFilters = @Filter(pattern = ".*BigThingRepo", type = FilterType.REGEX))
public static class Config extends IntegrationTestConfig {
@Override
public String[] getEntityBasePackages() {
return new String[] { BigThing.class.getPackage().getName() };
protected Set<Class<?>> getInitialEntitySet() {
return Collections.singleton(BigThing.class);
}
@Override
@@ -65,4 +78,25 @@ public class BigIntParamIntegrationTests extends AbstractSpringDataEmbeddedCassa
BigThing found = repo.findThingByBigInteger(new BigInteger("42"));
assertThat(found).isNotNull();
}
/**
* @author Pete Cable
*/
@Table
@Data
@AllArgsConstructor
@NoArgsConstructor
static class BigThing {
@PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private BigInteger number;
}
/**
* @author Pete Cable
*/
interface BigThingRepo extends CassandraRepository<BigThing> {
@Query("SELECT * from bigthing where number = ?0")
BigThing findThingByBigInteger(BigInteger number);
}
}

View File

@@ -33,13 +33,13 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.reactivestreams.Publisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.domain.User;
import org.springframework.data.cassandra.repository.config.EnableReactiveCassandraRepositories;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.cassandra.repository.support.IntegrationTestConfig;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.data.repository.reactive.RxJava1CrudRepository;
import org.springframework.data.repository.reactive.RxJava2CrudRepository;
@@ -68,18 +68,18 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
@Override
public String[] getEntityBasePackages() {
return new String[] { Person.class.getPackage().getName() };
return new String[] { User.class.getPackage().getName() };
}
}
@Autowired Session session;
@Autowired ReactiveCassandraTemplate template;
@Autowired MixedPersonRepository reactiveRepository;
@Autowired PersonRepostitory reactivePersonRepostitory;
@Autowired RxJava1PersonRepostitory rxJava1PersonRepostitory;
@Autowired RxJava2PersonRepostitory rxJava2PersonRepostitory;
@Autowired MixedUserRepository reactiveRepository;
@Autowired UserRepostitory reactiveUserRepostitory;
@Autowired RxJava1UserRepostitory rxJava1UserRepostitory;
@Autowired RxJava2UserRepostitory rxJava2UserRepostitory;
Person dave, oliver, carter, boyd;
User dave, oliver, carter, boyd;
@Before
public void setUp() throws Exception {
@@ -94,10 +94,10 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
StepVerifier.create(reactiveRepository.deleteAll()).verifyComplete();
dave = new Person("42", "Dave", "Matthews");
oliver = new Person("4", "Oliver August", "Matthews");
carter = new Person("49", "Carter", "Beauford");
boyd = new Person("45", "Boyd", "Tinsley");
dave = new User("42", "Dave", "Matthews");
oliver = new User("4", "Oliver August", "Matthews");
carter = new User("49", "Carter", "Beauford");
boyd = new User("45", "Boyd", "Tinsley");
StepVerifier.create(reactiveRepository.saveAll(Arrays.asList(oliver, dave, carter, boyd))).expectNextCount(4)
.verifyComplete();
@@ -105,18 +105,18 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
@Test // DATACASS-335
public void reactiveStreamsMethodsShouldWork() {
StepVerifier.create(reactivePersonRepostitory.existsById(dave.getId())).expectNext(true).verifyComplete();
StepVerifier.create(reactiveUserRepostitory.existsById(dave.getId())).expectNext(true).verifyComplete();
}
@Test // DATACASS-335
public void reactiveStreamsQueryMethodsShouldWork() {
StepVerifier.create(reactivePersonRepostitory.findByLastname(boyd.getLastname())).expectNext(boyd).verifyComplete();
StepVerifier.create(reactiveUserRepostitory.findByLastname(boyd.getLastname())).expectNext(boyd).verifyComplete();
}
@Test // DATACASS-360
public void dtoProjectionShouldWork() {
StepVerifier.create(reactivePersonRepostitory.findProjectedByLastname(boyd.getLastname()))
StepVerifier.create(reactiveUserRepostitory.findProjectedByLastname(boyd.getLastname()))
.consumeNextWith(actual -> {
assertThat(actual.firstname).isEqualTo(boyd.getFirstname());
@@ -127,7 +127,7 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
@Test // DATACASS-335
public void simpleRxJava1MethodsShouldWork() {
rxJava1PersonRepostitory.existsById(dave.getId()) //
rxJava1UserRepostitory.existsById(dave.getId()) //
.test() //
.awaitTerminalEvent() //
.assertResult(true) //
@@ -138,7 +138,7 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
@Test // DATACASS-335
public void existsWithSingleRxJava1IdMethodsShouldWork() {
rxJava1PersonRepostitory.existsById(Single.just(dave.getId())) //
rxJava1UserRepostitory.existsById(Single.just(dave.getId())) //
.test() //
.awaitTerminalEvent() //
.assertResult(true) //
@@ -149,7 +149,7 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
@Test // DATACASS-335
public void singleRxJava1QueryMethodShouldWork() {
rxJava1PersonRepostitory.findManyByLastname(dave.getLastname()) //
rxJava1UserRepostitory.findManyByLastname(dave.getLastname()) //
.test() //
.awaitTerminalEvent() //
.assertValueCount(2) //
@@ -160,7 +160,7 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
@Test // DATACASS-335
public void singleProjectedRxJava1QueryMethodShouldWork() {
List<ProjectedPerson> values = rxJava1PersonRepostitory.findProjectedByLastname(carter.getLastname()) //
List<ProjectedUser> values = rxJava1UserRepostitory.findProjectedByLastname(carter.getLastname()) //
.test() //
.awaitTerminalEvent() //
.assertValueCount(1) //
@@ -168,14 +168,14 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
.assertNoErrors() //
.getOnNextEvents();
ProjectedPerson projectedPerson = values.get(0);
assertThat(projectedPerson.getFirstname()).isEqualTo(carter.getFirstname());
ProjectedUser projectedUser = values.get(0);
assertThat(projectedUser.getFirstname()).isEqualTo(carter.getFirstname());
}
@Test // DATACASS-335
public void observableRxJava1QueryMethodShouldWork() {
rxJava1PersonRepostitory.findByLastname(boyd.getLastname()) //
rxJava1UserRepostitory.findByLastname(boyd.getLastname()) //
.test() //
.awaitTerminalEvent() //
.assertValue(boyd) //
@@ -186,7 +186,7 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
@Test // DATACASS-398
public void simpleRxJava2MethodsShouldWork() {
rxJava2PersonRepostitory.existsById(dave.getId()) //
rxJava2UserRepostitory.existsById(dave.getId()) //
.test()//
.assertValue(true) //
.assertNoErrors() //
@@ -197,7 +197,7 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
@Test // DATACASS-398
public void existsWithSingleRxJava2IdMethodsShouldWork() {
rxJava2PersonRepostitory.existsById(io.reactivex.Single.just(dave.getId())).test() //
rxJava2UserRepostitory.existsById(io.reactivex.Single.just(dave.getId())).test() //
.assertValue(true) //
.assertNoErrors() //
.assertComplete() //
@@ -207,7 +207,7 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
@Test // DATACASS-398
public void flowableRxJava2QueryMethodShouldWork() {
rxJava2PersonRepostitory.findManyByLastname(dave.getLastname()) //
rxJava2UserRepostitory.findManyByLastname(dave.getLastname()) //
.test() //
.assertValueCount(2) //
.assertNoErrors() //
@@ -218,7 +218,7 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
@Test // DATACASS-398
public void singleProjectedRxJava2QueryMethodShouldWork() {
rxJava2PersonRepostitory.findProjectedByLastname(Maybe.just(carter.getLastname())) //
rxJava2UserRepostitory.findProjectedByLastname(Maybe.just(carter.getLastname())) //
.test() //
.assertValue(actual -> {
assertThat(actual.getFirstname()).isEqualTo(carter.getFirstname());
@@ -232,7 +232,7 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
@Test // DATACASS-398
public void observableProjectedRxJava2QueryMethodShouldWork() {
rxJava2PersonRepostitory.findProjectedByLastname(Single.just(carter.getLastname())) //
rxJava2UserRepostitory.findProjectedByLastname(Single.just(carter.getLastname())) //
.test() //
.assertValue(actual -> {
assertThat(actual.getFirstname()).isEqualTo(carter.getFirstname());
@@ -246,7 +246,7 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
@Test // DATACASS-398
public void maybeRxJava2QueryMethodShouldWork() {
rxJava2PersonRepostitory.findByLastname(boyd.getLastname()) //
rxJava2UserRepostitory.findByLastname(boyd.getLastname()) //
.test() //
.assertValue(boyd) //
.assertNoErrors() //
@@ -274,55 +274,55 @@ public class ConvertingReactiveCassandraRepositoryTests extends AbstractKeyspace
}
@Repository
interface PersonRepostitory extends ReactiveCrudRepository<Person, String> {
interface UserRepostitory extends ReactiveCrudRepository<User, String> {
Publisher<Person> findByLastname(String lastname);
Publisher<User> findByLastname(String lastname);
Flux<PersonDto> findProjectedByLastname(String lastname);
Flux<UserDto> findProjectedByLastname(String lastname);
}
@Repository
interface RxJava1PersonRepostitory extends RxJava1CrudRepository<Person, String> {
interface RxJava1UserRepostitory extends RxJava1CrudRepository<User, String> {
Observable<Person> findManyByLastname(String lastname);
Observable<User> findManyByLastname(String lastname);
Single<Person> findByLastname(String lastname);
Single<User> findByLastname(String lastname);
Single<ProjectedPerson> findProjectedByLastname(String lastname);
Single<ProjectedUser> findProjectedByLastname(String lastname);
}
@Repository
interface RxJava2PersonRepostitory extends RxJava2CrudRepository<Person, String> {
interface RxJava2UserRepostitory extends RxJava2CrudRepository<User, String> {
Flowable<Person> findManyByLastname(String lastname);
Flowable<User> findManyByLastname(String lastname);
Maybe<Person> findByLastname(String lastname);
Maybe<User> findByLastname(String lastname);
io.reactivex.Single<ProjectedPerson> findProjectedByLastname(Maybe<String> lastname);
io.reactivex.Single<ProjectedUser> findProjectedByLastname(Maybe<String> lastname);
io.reactivex.Observable<ProjectedPerson> findProjectedByLastname(Single<String> lastname);
io.reactivex.Observable<ProjectedUser> findProjectedByLastname(Single<String> lastname);
}
@Repository
interface MixedPersonRepository extends ReactiveCassandraRepository<Person, String> {
interface MixedUserRepository extends ReactiveCassandraRepository<User, String> {
Single<Person> findByLastname(String lastname);
Single<User> findByLastname(String lastname);
Mono<Person> findByLastname(Single<String> lastname);
Mono<User> findByLastname(Single<String> lastname);
}
interface ProjectedPerson {
interface ProjectedUser {
String getId();
String getFirstname();
}
static class PersonDto {
static class UserDto {
public String firstname, lastname;
public PersonDto(String firstname, String lastname) {
public UserDto(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 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,20 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.querymethods.datekey;
package org.springframework.data.cassandra.repository;
import static org.assertj.core.api.Assertions.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Collections;
import java.util.Date;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.core.PrimaryKeyType;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.mapping.Table;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.repository.support.IntegrationTestConfig;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -40,11 +51,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class DateKeyIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
@Configuration
@EnableCassandraRepositories(basePackageClasses = DateThingRepo.class)
@EnableCassandraRepositories(basePackageClasses = DateThingRepo.class, considerNestedRepositories = true,
includeFilters = @Filter(pattern = ".*DateThingRepo", type = FilterType.REGEX))
public static class Config extends IntegrationTestConfig {
@Override
public String[] getEntityBasePackages() {
return new String[] { DateThing.class.getPackage().getName() };
protected Set<Class<?>> getInitialEntitySet() {
return Collections.singleton(DateThing.class);
}
@Override
@@ -57,6 +70,7 @@ public class DateKeyIntegrationTests extends AbstractSpringDataEmbeddedCassandra
@Test
public void testQueryWithDate() {
Date date = new Date();
DateThing saved = new DateThing(date);
repo.save(saved);
@@ -64,4 +78,27 @@ public class DateKeyIntegrationTests extends AbstractSpringDataEmbeddedCassandra
DateThing found = repo.findThingByDate(date);
assertThat(found).isNotNull();
}
/**
* @author Matthew T. Adams
*/
@Table
@Data
@AllArgsConstructor
@NoArgsConstructor
static class DateThing {
@PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private Date date;
}
/**
* Integration tests for {@link Date} usage in repositories.
*
* @author Matthew T. Adams
*/
interface DateThingRepo extends CassandraRepository<DateThing> {
@Query("SELECT * from datething where date = ?0")
DateThing findThingByDate(Date date);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 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,18 +13,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.querymethods.intparam;
package org.springframework.data.cassandra.repository;
import static org.assertj.core.api.Assertions.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Collections;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.core.PrimaryKeyType;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.mapping.Table;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.repository.support.IntegrationTestConfig;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -36,11 +48,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class IntParamIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
@Configuration
@EnableCassandraRepositories(basePackageClasses = IntThingRepo.class)
@EnableCassandraRepositories(basePackageClasses = IntThingRepo.class, considerNestedRepositories = true,
includeFilters = @Filter(pattern = ".*IntThingRepo", type = FilterType.REGEX))
public static class Config extends IntegrationTestConfig {
@Override
public String[] getEntityBasePackages() {
return new String[] { IntThing.class.getPackage().getName() };
protected Set<Class<?>> getInitialEntitySet() {
return Collections.singleton(IntThing.class);
}
@Override
@@ -53,6 +67,7 @@ public class IntParamIntegrationTests extends AbstractSpringDataEmbeddedCassandr
@Test
public void testQueryWithIntPrimitiveAndReference() {
int number = 42;
IntThing saved = new IntThing(42);
repo.save(saved);
@@ -63,4 +78,22 @@ public class IntParamIntegrationTests extends AbstractSpringDataEmbeddedCassandr
found = repo.findThingByIntReference(new Integer(number));
assertThat(found).isNotNull();
}
@Table
@Data
@AllArgsConstructor
@NoArgsConstructor
static class IntThing {
@PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private int number;
}
interface IntThingRepo extends CassandraRepository<IntThing> {
@Query("SELECT * from intthing where number = ?0")
IntThing findThingByIntPrimitive(int number);
@Query("SELECT * from intthing where number = ?0")
IntThing findThingByIntReference(Integer number);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 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,44 +13,57 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.querymethods.declared;
package org.springframework.data.cassandra.repository;
import static org.assertj.core.api.Assertions.*;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.base.PersonRepository;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.repository.support.IntegrationTestConfig;
import org.springframework.data.cassandra.repository.support.SchemaTestUtils;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.ResultSet;
/**
* Integration tests for use with {@link PersonRepository}.
* Integration tests for use with {@link PersonRepositoryWithNamedQueries}.
*
* @author Matthew T. Adams
* @author Mark Paluch
* @soundtrack Mary Jane Kelly - Volbeat
*/
@RunWith(SpringJUnit4ClassRunner.class)
public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
public class NamedQueryIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
@Configuration
@EnableCassandraRepositories(basePackageClasses = PersonRepositoryWithNamedQueries.class,
namedQueriesLocation = "classpath:META-INF/PersonRepositoryWithNamedQueries.properties",
considerNestedRepositories = true,
includeFilters = @Filter(pattern = ".*PersonRepositoryWithNamedQueries", type = FilterType.REGEX))
public static class Config extends IntegrationTestConfig {
@Override
public String[] getEntityBasePackages() {
return new String[] { Person.class.getPackage().getName() };
protected Set<Class<?>> getInitialEntitySet() {
return Collections.singleton(Person.class);
}
@Override
@@ -59,12 +72,12 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa
}
}
@Autowired PersonRepository personRepository;
@Autowired Session session;
@Autowired PersonRepositoryWithNamedQueries personRepository;
@Autowired CassandraOperations cassandraOperations;
@Before
public void before() {
deleteAllEntities();
SchemaTestUtils.truncate(Person.class, cassandraOperations);
}
@Test
@@ -319,10 +332,35 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa
personRepository.save(person);
}
Stream<Person> allPeople = personRepository.findAllPeople();
Stream<Person> allPeople = personRepository.findPeopleBy();
long count = allPeople.peek(person -> assertThat(person).isInstanceOf(Person.class)).count();
assertThat(count).isEqualTo(before + 100L);
}
public interface PersonRepositoryWithNamedQueries extends CassandraRepository<Person> {
List<Person> findFolksWithLastnameAsList(String lastname);
ResultSet findFolksWithLastnameAsResultSet(String last);
Person[] findFolksWithLastnameAsArray(String lastname);
Person findSingle(String last, String first);
List<Map<String, Object>> findFolksWithLastnameAsListOfMapOfStringToObject(String last);
String findSingleNickname(String last, String first);
Date findSingleBirthdate(String last, String first);
boolean findSingleCool(String last, String first);
int findSingleNumberOfChildren(String last, String first);
Optional<Person> findOptionalWithLastnameAndFirstname(String last, String first);
Stream<Person> findPeopleBy();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.querymethods.derived;
package org.springframework.data.cassandra.repository;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
@@ -21,24 +21,29 @@ import static org.junit.Assume.*;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.test.integration.support.CassandraVersion;
import org.springframework.cassandra.support.CassandraVersion;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.domain.AddressType;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.repository.QueryDerivationIntegrationTests.PersonRepository.NumberOfChildren;
import org.springframework.data.cassandra.repository.QueryDerivationIntegrationTests.PersonRepository.PersonDto;
import org.springframework.data.cassandra.repository.QueryDerivationIntegrationTests.PersonRepository.PersonProjection;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Address;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Person;
import org.springframework.data.cassandra.test.integration.repository.querymethods.derived.PersonRepository.NumberOfChildren;
import org.springframework.data.cassandra.test.integration.repository.querymethods.derived.PersonRepository.PersonDto;
import org.springframework.data.cassandra.test.integration.repository.querymethods.derived.PersonRepository.PersonProjection;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.repository.support.IntegrationTestConfig;
import org.springframework.data.domain.Sort;
import org.springframework.data.util.Version;
import org.springframework.test.context.ContextConfiguration;
@@ -57,12 +62,13 @@ import com.datastax.driver.core.Session;
public class QueryDerivationIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
@Configuration
@EnableCassandraRepositories
@EnableCassandraRepositories(considerNestedRepositories = true,
includeFilters = @Filter(pattern = ".*PersonRepository", type = FilterType.REGEX))
public static class Config extends IntegrationTestConfig {
@Override
public String[] getEntityBasePackages() {
return new String[] { Person.class.getPackage().getName() };
protected Set<Class<?>> getInitialEntitySet() {
return Collections.singleton(Person.class);
}
@Override
@@ -83,14 +89,15 @@ public class QueryDerivationIntegrationTests extends AbstractSpringDataEmbeddedC
@Before
public void before() {
deleteAllEntities();
Person person = new Person("Walter", "White");
person.setNumberOfChildren(2);
person.setMainAddress(new Address("Albuquerque", "USA"));
person.setAlternativeAddresses(Arrays.asList(new Address("Albuquerque", "USA"), new Address("New Hampshire", "USA"),
new Address("Grocery Store", "Mexico")));
person.setMainAddress(new AddressType("Albuquerque", "USA"));
person.setAlternativeAddresses(Arrays.asList(new AddressType("Albuquerque", "USA"),
new AddressType("New Hampshire", "USA"), new AddressType("Grocery Store", "Mexico")));
walter = personRepository.save(person);
skyler = personRepository.save(new Person("Skyler", "White"));
@@ -161,8 +168,8 @@ public class QueryDerivationIntegrationTests extends AbstractSpringDataEmbeddedC
Collection<PersonProjection> collection = personRepository.findPersonProjectedBy();
assertThat(collection).hasSize(3).extracting("firstname").contains(flynn.getFirstname(), skyler.getFirstname(),
walter.getFirstname());
Assertions.assertThat(collection).hasSize(3).extracting("firstname").contains(flynn.getFirstname(),
skyler.getFirstname(), walter.getFirstname());
}
@Test // DATACASS-359
@@ -170,8 +177,8 @@ public class QueryDerivationIntegrationTests extends AbstractSpringDataEmbeddedC
Collection<PersonDto> collection = personRepository.findPersonDtoBy();
assertThat(collection).hasSize(3).extracting("firstname").contains(flynn.getFirstname(), skyler.getFirstname(),
walter.getFirstname());
Assertions.assertThat(collection).hasSize(3).extracting("firstname").contains(flynn.getFirstname(),
skyler.getFirstname(), walter.getFirstname());
}
@Test // DATACASS-359
@@ -190,8 +197,8 @@ public class QueryDerivationIntegrationTests extends AbstractSpringDataEmbeddedC
PersonDto heisenberg = personRepository.findDtoByNicknameStartsWith("Heisen", PersonDto.class);
assertThat(heisenberg.firstname).isEqualTo("Walter");
assertThat(heisenberg.lastname).isEqualTo("White");
Assertions.assertThat(heisenberg.firstname).isEqualTo("Walter");
Assertions.assertThat(heisenberg.lastname).isEqualTo("White");
}
@Test // DATACASS-7
@@ -270,4 +277,61 @@ public class QueryDerivationIntegrationTests extends AbstractSpringDataEmbeddedC
assertThat(personRepository.findByNicknameContains("eisenber")).isEqualTo(walter);
}
/**
* @author Mark Paluch
*/
static interface PersonRepository extends CassandraRepository<Person> {
List<Person> findByLastname(String lastname);
List<Person> findByLastname(String lastname, Sort sort);
List<Person> findByLastnameOrderByFirstnameAsc(String lastname);
Person findByFirstnameAndLastname(String firstname, String lastname);
Person findByMainAddress(AddressType address);
@Query("select * from person where mainaddress = ?0")
Person findByAddress(AddressType address);
Person findByCreatedDate(LocalDate createdDate);
Person findByNicknameStartsWith(String prefix);
Person findByNicknameContains(String contains);
Person findByNumberOfChildren(NumberOfChildren numberOfChildren);
Collection<PersonProjection> findPersonProjectedBy();
Collection<PersonDto> findPersonDtoBy();
<T> T findDtoByNicknameStartsWith(String prefix, Class<T> projectionType);
@Query("select * from person where firstname = ?0 and lastname = 'White'")
List<Person> findByFirstname(String firstname);
enum NumberOfChildren {
ZERO, ONE, TWO,
}
interface PersonProjection {
String getFirstname();
String getLastname();
}
class PersonDto {
public String firstname, lastname;
public PersonDto(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
}
}
}

View File

@@ -20,6 +20,8 @@ import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
@@ -30,15 +32,15 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
import org.springframework.data.cassandra.domain.Group;
import org.springframework.data.cassandra.domain.GroupKey;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.domain.User;
import org.springframework.data.cassandra.repository.support.IntegrationTestConfig;
import org.springframework.data.cassandra.repository.support.ReactiveCassandraRepositoryFactory;
import org.springframework.data.cassandra.repository.support.SimpleReactiveCassandraRepository;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.repository.query.DefaultEvaluationContextProvider;
@@ -63,8 +65,8 @@ public class ReactiveCassandraRepositoryIntegrationTests extends AbstractKeyspac
public static class Config extends IntegrationTestConfig {
@Override
public String[] getEntityBasePackages() {
return new String[] { Person.class.getPackage().getName() };
protected Set<Class<?>> getInitialEntitySet() {
return new HashSet<>(Arrays.asList(Group.class, User.class));
}
}
@@ -74,10 +76,10 @@ public class ReactiveCassandraRepositoryIntegrationTests extends AbstractKeyspac
ReactiveCassandraRepositoryFactory factory;
ClassLoader classLoader;
BeanFactory beanFactory;
PersonRepository repository;
UserRepository repository;
GroupRepository groupRepostitory;
Person dave, oliver, carter, boyd;
User dave, oliver, carter, boyd;
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
@@ -93,10 +95,10 @@ public class ReactiveCassandraRepositoryIntegrationTests extends AbstractKeyspac
public void setUp() throws Exception {
KeyspaceMetadata keyspace = session.getCluster().getMetadata().getKeyspace(session.getLoggedKeyspace());
TableMetadata person = keyspace.getTable("person");
TableMetadata users = keyspace.getTable("users");
if (person.getIndex("IX_lastname") == null) {
session.execute("CREATE INDEX IX_lastname ON person (lastname);");
if (users.getIndex("IX_lastname") == null) {
session.execute("CREATE INDEX IX_lastname ON users (lastname);");
Thread.sleep(500);
}
@@ -106,15 +108,15 @@ public class ReactiveCassandraRepositoryIntegrationTests extends AbstractKeyspac
factory.setBeanFactory(beanFactory);
factory.setEvaluationContextProvider(DefaultEvaluationContextProvider.INSTANCE);
repository = factory.getRepository(PersonRepository.class);
repository = factory.getRepository(UserRepository.class);
groupRepostitory = factory.getRepository(GroupRepository.class);
StepVerifier.create(repository.deleteAll().concatWith(groupRepostitory.deleteAll())).verifyComplete();
dave = new Person("42", "Dave", "Matthews");
oliver = new Person("4", "Oliver August", "Matthews");
carter = new Person("49", "Carter", "Beauford");
boyd = new Person("45", "Boyd", "Tinsley");
dave = new User("42", "Dave", "Matthews");
oliver = new User("4", "Oliver August", "Matthews");
carter = new User("49", "Carter", "Beauford");
boyd = new User("45", "Boyd", "Tinsley");
StepVerifier.create(repository.saveAll(Arrays.asList(oliver, dave, carter, boyd))).expectNextCount(4)
.verifyComplete();
@@ -162,16 +164,16 @@ public class ReactiveCassandraRepositoryIntegrationTests extends AbstractKeyspac
.verifyComplete();
}
interface PersonRepository extends ReactiveCassandraRepository<Person, String> {
interface UserRepository extends ReactiveCassandraRepository<User, String> {
Flux<Person> findByLastname(String lastname);
Flux<User> findByLastname(String lastname);
Mono<Person> findOneByLastname(String lastname);
Mono<User> findOneByLastname(String lastname);
Mono<Person> findByLastname(Publisher<String> lastname);
Mono<User> findByLastname(Publisher<String> lastname);
@Query("SELECT * FROM person WHERE lastname = ?0")
Flux<Person> findStringQuery(Mono<String> lastname);
@Query("SELECT * FROM users WHERE lastname = ?0")
Flux<User> findStringQuery(Mono<String> lastname);
}
interface GroupRepository extends ReactiveCassandraRepository<Group, GroupKey> {

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.cdi;
package org.springframework.data.cassandra.repository.cdi;
import java.util.Collections;
import java.util.Set;
@@ -27,17 +27,17 @@ import org.springframework.cassandra.core.cql.generator.CreateKeyspaceCqlGenerat
import org.springframework.cassandra.core.cql.generator.DropKeyspaceCqlGenerator;
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
import org.springframework.cassandra.support.CassandraConnectionProperties;
import org.springframework.cassandra.support.RandomKeySpaceName;
import org.springframework.cassandra.test.integration.support.CassandraConnectionProperties;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.CassandraAdminTemplate;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.CassandraPersistentEntitySchemaCreator;
import org.springframework.data.cassandra.core.CassandraPersistentEntitySchemaDropper;
import org.springframework.data.cassandra.domain.User;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.mapping.SimpleUserTypeResolver;
import org.springframework.data.cassandra.test.integration.repository.simple.User;
import com.datastax.driver.core.Cluster;
import com.google.common.collect.Sets;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.cdi;
package org.springframework.data.cassandra.repository.cdi;
import javax.inject.Inject;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.cdi;
package org.springframework.data.cassandra.repository.cdi;
import static org.assertj.core.api.Assertions.*;
@@ -25,8 +25,8 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.repository.simple.User;
import org.springframework.cassandra.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.domain.User;
/**
* @author Mohsin Husen
@@ -75,29 +75,29 @@ public class CdiRepositoryTests extends AbstractEmbeddedCassandraIntegrationTest
repository.deleteAll();
User bean = new User();
bean.setUsername("username");
bean.setFirstName("first");
bean.setLastName("last");
bean.setId("username");
bean.setFirstname("first");
bean.setLastname("last");
repository.save(bean);
assertThat(repository.existsById(bean.getUsername())).isTrue();
assertThat(repository.existsById(bean.getId())).isTrue();
Optional<User> retrieved = repository.findById(bean.getUsername());
Optional<User> retrieved = repository.findById(bean.getId());
assertThat(retrieved).hasValueSatisfying(actual -> {
assertThat(actual.getUsername()).isEqualTo(bean.getUsername());
assertThat(actual.getFirstName()).isEqualTo(bean.getFirstName());
assertThat(actual.getLastName()).isEqualTo(bean.getLastName());
assertThat(actual.getId()).isEqualTo(bean.getId());
assertThat(actual.getFirstname()).isEqualTo(bean.getFirstname());
assertThat(actual.getLastname()).isEqualTo(bean.getLastname());
});
assertThat(repository.count()).isEqualTo(1);
assertThat(repository.existsById(bean.getUsername())).isTrue();
assertThat(repository.existsById(bean.getId())).isTrue();
repository.delete(bean);
assertThat(repository.count()).isEqualTo(0);
assertThat(repository.findById(bean.getUsername())).isNotPresent();
assertThat(repository.findById(bean.getId())).isNotPresent();
}
@Test // DATACASS-249
@@ -107,13 +107,13 @@ public class CdiRepositoryTests extends AbstractEmbeddedCassandraIntegrationTest
qualifiedUserRepository.deleteAll();
User bean = new User();
bean.setUsername("username");
bean.setFirstName("first");
bean.setLastName("last");
bean.setId("username");
bean.setFirstname("first");
bean.setLastname("last");
qualifiedUserRepository.save(bean);
assertThat(qualifiedUserRepository.existsById(bean.getUsername())).isTrue();
assertThat(qualifiedUserRepository.existsById(bean.getId())).isTrue();
}
@Test // DATACASS-149

View File

@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.cdi;
package org.springframework.data.cassandra.repository.cdi;
import java.util.Optional;
import org.springframework.data.cassandra.test.integration.repository.simple.User;
import org.springframework.data.cassandra.domain.User;
import org.springframework.data.repository.CrudRepository;
/**

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.cdi;
package org.springframework.data.cassandra.repository.cdi;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@@ -14,9 +14,9 @@
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.cdi;
package org.springframework.data.cassandra.repository.cdi;
import org.springframework.data.cassandra.test.integration.repository.simple.User;
import org.springframework.data.cassandra.domain.User;
import org.springframework.data.repository.CrudRepository;
/**

View File

@@ -14,9 +14,9 @@
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.cdi;
package org.springframework.data.cassandra.repository.cdi;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Person;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.repository.Repository;
/**

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.cdi;
package org.springframework.data.cassandra.repository.cdi;
/**
* @author Mark Paluch

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.cdi;
package org.springframework.data.cassandra.repository.cdi;
/**
* @author Mark Paluch

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.repository.cdi;
package org.springframework.data.cassandra.repository.cdi;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@@ -29,6 +29,8 @@ import org.springframework.context.annotation.FilterType;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.UserTypeResolver;
import org.springframework.data.cassandra.repository.ReactiveCassandraRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -50,7 +52,12 @@ public class ReactiveCassandraRepositoriesRegistrarUnitTests {
@Bean
public ReactiveCassandraTemplate reactiveCassandraTemplate() throws Exception {
return new ReactiveCassandraTemplate(mock(ReactiveSession.class), new MappingCassandraConverter());
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
mappingContext.setUserTypeResolver(mock(UserTypeResolver.class));
MappingCassandraConverter converter = new MappingCassandraConverter(mappingContext);
return new ReactiveCassandraTemplate(mock(ReactiveSession.class), converter);
}
}

View File

@@ -23,7 +23,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.base.PersonRepository;
import org.springframework.data.cassandra.repository.NamedQueryIntegrationTests.PersonRepositoryWithNamedQueries;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -31,7 +31,7 @@ import com.datastax.driver.core.KeyspaceMetadata;
import com.datastax.driver.core.UDTValue;
/**
* Integration tests for query argument conversion through {@link PersonRepository}.
* Integration tests for query argument conversion through {@link PersonRepositoryWithNamedQueries}.
*
* @author Mark Paluch
*/

View File

@@ -32,8 +32,8 @@ import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.mapping.SimpleUserTypeResolver;
import org.springframework.data.cassandra.mapping.UserTypeResolver;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.repository.support.IntegrationTestConfig;
import org.springframework.data.convert.CustomConversions;
import org.springframework.util.StringUtils;

View File

@@ -23,8 +23,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.data.cassandra.repository.NamedQueryIntegrationTests.PersonRepositoryWithNamedQueries;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.base.PersonRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -32,7 +32,7 @@ import com.datastax.driver.core.KeyspaceMetadata;
import com.datastax.driver.core.UDTValue;
/**
* Integration tests for query argument conversion through {@link PersonRepository}.
* Integration tests for query argument conversion through {@link PersonRepositoryWithNamedQueries}.
*
* @author Mark Paluch
*/

View File

@@ -26,6 +26,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
@@ -42,8 +43,8 @@ import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraType;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.repository.support.IntegrationTestConfig;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.repository.CrudRepository;
import org.springframework.test.context.ContextConfiguration;
@@ -69,8 +70,8 @@ public class RepositoryQueryMethodParameterTypesIntegrationTests
public static class Config extends IntegrationTestConfig {
@Override
public String[] getEntityBasePackages() {
return new String[] { AllPossibleTypes.class.getPackage().getName() };
protected Set<Class<?>> getInitialEntitySet() {
return Collections.singleton(AllPossibleTypes.class);
}
@Override

View File

@@ -21,10 +21,12 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
@@ -35,8 +37,8 @@ import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.domain.AllPossibleTypes;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.repository.support.IntegrationTestConfig;
import org.springframework.data.repository.CrudRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -59,8 +61,8 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
public static class Config extends IntegrationTestConfig {
@Override
public String[] getEntityBasePackages() {
return new String[] { AllPossibleTypes.class.getPackage().getName() };
protected Set<Class<?>> getInitialEntitySet() {
return Collections.singleton(AllPossibleTypes.class);
}
@Override

View File

@@ -16,6 +16,7 @@
package org.springframework.data.cassandra.repository.query;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.cassandra.repository.query.StubParameterAccessor.*;
import java.io.Serializable;
@@ -38,13 +39,13 @@ import org.springframework.data.cassandra.core.StatementFactory;
import org.springframework.data.cassandra.core.query.Query;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
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.cassandra.mapping.UserTypeResolver;
import org.springframework.data.cassandra.repository.support.MappingCassandraEntityInformation;
import org.springframework.data.repository.query.parser.PartTree;
@@ -57,14 +58,17 @@ import com.datastax.driver.core.RegularStatement;
*/
public class CassandraQueryCreatorUnitTests {
CassandraMappingContext context;
BasicCassandraMappingContext context;
CassandraConverter converter;
@Rule public ExpectedException exception = ExpectedException.none();
@Before
public void setUp() throws SecurityException, NoSuchMethodException {
context = new BasicCassandraMappingContext();
context.setUserTypeResolver(mock(UserTypeResolver.class));
converter = new MappingCassandraConverter(context);
}

View File

@@ -22,7 +22,7 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.domain.User;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
import org.springframework.data.projection.ProjectionFactory;
@@ -50,8 +50,8 @@ public class CassandraQueryMethodUnitTests {
CassandraQueryMethod queryMethod = queryMethod(SampleRepository.class, "method");
CassandraEntityMetadata<?> metadata = queryMethod.getEntityInformation();
assertThat(metadata.getJavaType()).isAssignableFrom(Person.class);
assertThat(metadata.getTableName().toCql()).isEqualTo("person");
assertThat(metadata.getJavaType()).isAssignableFrom(User.class);
assertThat(metadata.getTableName().toCql()).isEqualTo("users");
}
@Test(expected = IllegalArgumentException.class) // DATACASS-7
@@ -79,9 +79,9 @@ public class CassandraQueryMethodUnitTests {
}
@SuppressWarnings("unused")
interface SampleRepository extends Repository<Person, Long> {
interface SampleRepository extends Repository<User, Long> {
List<Person> method();
List<User> method();
}
}

View File

@@ -34,13 +34,13 @@ import org.springframework.cassandra.core.cql.CqlIdentifier;
import org.springframework.data.cassandra.convert.CassandraConverter;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.domain.AddressType;
import org.springframework.data.cassandra.domain.Group;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.UserTypeResolver;
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Address;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Person;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
@@ -124,7 +124,7 @@ public class PartTreeCassandraQueryUnitTests {
when(userTypeResolverMock.resolveType(CqlIdentifier.cqlId("address"))).thenReturn(userTypeMock);
when(userTypeMock.newValue()).thenReturn(udtValueMock);
String query = deriveQueryFromMethod("findByMainAddress", new Address());
String query = deriveQueryFromMethod("findByMainAddress", new AddressType());
assertThat(query).isEqualTo("SELECT * FROM person WHERE mainaddress={};");
}
@@ -177,7 +177,9 @@ public class PartTreeCassandraQueryUnitTests {
return partTreeQuery.createQuery(new ConvertingParameterAccessor(mockCassandraOperations.getConverter(), accessor));
}
private PartTreeCassandraQuery createQueryForMethod(Class<?> repositoryInterface,String methodName, Class<?>... paramTypes) {Class<?>[] userTypes = Arrays.stream(paramTypes)//
private PartTreeCassandraQuery createQueryForMethod(Class<?> repositoryInterface, String methodName,
Class<?>... paramTypes) {
Class<?>[] userTypes = Arrays.stream(paramTypes)//
.map(it -> it.getName().contains("Mockito") ? it.getSuperclass() : it)//
.toArray(size -> new Class<?>[size]);
try {
@@ -214,11 +216,11 @@ public class PartTreeCassandraQueryUnitTests {
Person findPersonBy();
Person findByMainAddress(Address address);
Person findByMainAddress(AddressType address);
Person findByMainAddress(UDTValue udtValue);
Person findByMainAddressIn(Collection<Address> address);
Person findByMainAddressIn(Collection<AddressType> address);
Person findByFirstnameIn(Collection<String> firstname);

View File

@@ -31,12 +31,11 @@ import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.cassandra.convert.CassandraConverter;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.mapping.UserTypeResolver;
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.projection.ProjectionFactory;
@@ -54,16 +53,17 @@ public class ReactivePartTreeCassandraQueryUnitTests {
@Rule public ExpectedException exception = ExpectedException.none();
@Mock ReactiveCassandraOperations mockCassandraOperations;
@Mock UserTypeResolver userTypeResolver;
private CassandraMappingContext mappingContext;
private CassandraConverter converter;
private BasicCassandraMappingContext mappingContext;
@Before
public void setUp() {
mappingContext = new BasicCassandraMappingContext();
converter = new MappingCassandraConverter(mappingContext);
when(mockCassandraOperations.getConverter()).thenReturn(converter);
mappingContext = new BasicCassandraMappingContext();
mappingContext.setUserTypeResolver(userTypeResolver);
when(mockCassandraOperations.getConverter()).thenReturn(new MappingCassandraConverter(mappingContext));
}
@Test // DATACASS-335

View File

@@ -28,9 +28,9 @@ import org.springframework.cassandra.core.ReactiveCqlOperations;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Person;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.Repository;

View File

@@ -35,12 +35,12 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cassandra.core.cql.CqlIdentifier;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.domain.AddressType;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.UserTypeResolver;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.cassandra.support.UserTypeBuilder;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Address;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Person;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.Repository;
@@ -312,9 +312,9 @@ public class StringBasedCassandraQueryUnitTests {
when(userTypeResolver.resolveType(CqlIdentifier.cqlId("address"))).thenReturn(addressType);
StringBasedCassandraQuery cassandraQuery = getQueryMethod("findByMainAddress", Address.class);
StringBasedCassandraQuery cassandraQuery = getQueryMethod("findByMainAddress", AddressType.class);
CassandraParameterAccessor accessor = new ConvertingParameterAccessor(converter,
new CassandraParametersParameterAccessor(cassandraQuery.getQueryMethod(), new Address()));
new CassandraParametersParameterAccessor(cassandraQuery.getQueryMethod(), new AddressType()));
SimpleStatement stringQuery = cassandraQuery.createQuery(accessor);
@@ -383,7 +383,7 @@ public class StringBasedCassandraQueryUnitTests {
Person findByCreatedDate(LocalDate createdDate);
@Query("SELECT * FROM person WHERE address=?0;")
Person findByMainAddress(Address address);
Person findByMainAddress(AddressType address);
@Query("SELECT * FROM person WHERE address=?0;")
Person findByMainAddress(UDTValue udtValue);

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,14 +13,12 @@
* 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.data.cassandra.repository.support;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
@@ -32,8 +30,6 @@ import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
public abstract class AbstractSpringDataEmbeddedCassandraIntegrationTest
extends AbstractEmbeddedCassandraIntegrationTest {
public final Logger log = LoggerFactory.getLogger(getClass());
@Autowired private CassandraOperations template;
/**

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2013-2017 the original author or authors
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.support;
package org.springframework.data.cassandra.repository.support;
import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.*;
@@ -22,9 +22,9 @@ import java.util.List;
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
import org.springframework.cassandra.support.CassandraConnectionProperties;
import org.springframework.cassandra.support.IntegrationTestNettyOptions;
import org.springframework.cassandra.support.RandomKeySpaceName;
import org.springframework.cassandra.test.integration.support.CassandraConnectionProperties;
import org.springframework.cassandra.test.integration.support.IntegrationTestNettyOptions;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.config.java.AbstractReactiveCassandraConfiguration;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.cassandra.test.integration.support;
package org.springframework.data.cassandra.repository.support;
import org.springframework.cassandra.core.SessionCallback;
import org.springframework.cassandra.core.cql.generator.CreateTableCqlGenerator;

View File

@@ -29,12 +29,11 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.domain.User;
import org.springframework.data.cassandra.repository.TypedIdCassandraRepository;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.data.repository.query.DefaultEvaluationContextProvider;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -54,7 +53,7 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
@Override
public String[] getEntityBasePackages() {
return new String[] { Person.class.getPackage().getName() };
return new String[] { User.class.getPackage().getName() };
}
}
@@ -63,9 +62,9 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
CassandraRepositoryFactory factory;
ClassLoader classLoader;
BeanFactory beanFactory;
PersonRepostitory repository;
UserRepostitory repository;
Person dave, oliver, carter, boyd;
User dave, oliver, carter, boyd;
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
@@ -86,14 +85,14 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
factory.setBeanFactory(beanFactory);
factory.setEvaluationContextProvider(DefaultEvaluationContextProvider.INSTANCE);
repository = factory.getRepository(PersonRepostitory.class);
repository = factory.getRepository(UserRepostitory.class);
repository.deleteAll();
dave = new Person("42", "Dave", "Matthews");
oliver = new Person("4", "Oliver August", "Matthews");
carter = new Person("49", "Carter", "Beauford");
boyd = new Person("45", "Boyd", "Tinsley");
dave = new User("42", "Dave", "Matthews");
oliver = new User("4", "Oliver August", "Matthews");
carter = new User("49", "Carter", "Beauford");
boyd = new User("45", "Boyd", "Tinsley");
repository.saveAll(Arrays.asList(oliver, dave, carter, boyd));
}
@@ -125,33 +124,33 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
@Test // DATACASS-396
public void findByIdShouldReturnObject() {
Optional<Person> person = repository.findById(dave.getId());
Optional<User> User = repository.findById(dave.getId());
assertThat(person).contains(dave);
assertThat(User).contains(dave);
}
@Test // DATACASS-396
public void findByIdShouldCompleteWithoutValueForAbsentObject() {
Optional<Person> person = repository.findById("unknown");
Optional<User> User = repository.findById("unknown");
assertThat(person).isEmpty();
assertThat(User).isEmpty();
}
@Test // DATACASS-396, DATACASS-416
public void findAllShouldReturnAllResults() {
List<Person> persons = repository.findAll();
List<User> Users = repository.findAll();
assertThat(persons).hasSize(4);
assertThat(Users).hasSize(4);
}
@Test // DATACASS-396, DATACASS-416
public void findAllByIterableOfIdShouldReturnResults() {
List<Person> persons = repository.findAllById(Arrays.asList(dave.getId(), boyd.getId()));
List<User> Users = repository.findAllById(Arrays.asList(dave.getId(), boyd.getId()));
assertThat(persons).hasSize(2);
assertThat(Users).hasSize(2);
}
@Test // DATACASS-396
@@ -167,9 +166,9 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
repository.deleteAll();
Person person = new Person("36", "Homer", "Simpson");
User User = new User("36", "Homer", "Simpson");
repository.insert(person);
repository.insert(User);
assertThat(repository.count()).isEqualTo(1);
}
@@ -190,11 +189,11 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
dave.setFirstname("Hello, Dave");
dave.setLastname("Bowman");
Person saved = repository.save(dave);
User saved = repository.save(dave);
assertThat(saved).isEqualTo(saved);
Optional<Person> loaded = repository.findById(dave.getId());
Optional<User> loaded = repository.findById(dave.getId());
assertThat(loaded).isPresent();
@@ -207,15 +206,15 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
@Test // DATACASS-396
public void saveEntityShouldInsertNewEntity() {
Person person = new Person("36", "Homer", "Simpson");
User User = new User("36", "Homer", "Simpson");
Person saved = repository.save(person);
User saved = repository.save(User);
assertThat(saved).isEqualTo(person);
assertThat(saved).isEqualTo(User);
Optional<Person> loaded = repository.findById(person.getId());
Optional<User> loaded = repository.findById(User.getId());
assertThat(loaded).contains(person);
assertThat(loaded).contains(User);
}
@Test // DATACASS-396, DATACASS-416
@@ -223,7 +222,7 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
repository.deleteAll();
List<Person> saved = repository.saveAll(Arrays.asList(dave, oliver, boyd));
List<User> saved = repository.saveAll(Arrays.asList(dave, oliver, boyd));
assertThat(saved).hasSize(3);
@@ -233,20 +232,20 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
@Test // DATACASS-396, DATACASS-416
public void saveIterableOfMixedEntitiesShouldInsertEntity() {
Person person = new Person("36", "Homer", "Simpson");
User User = new User("36", "Homer", "Simpson");
dave.setFirstname("Hello, Dave");
dave.setLastname("Bowman");
List<Person> saved = repository.saveAll(Arrays.asList(person, dave));
List<User> saved = repository.saveAll(Arrays.asList(User, dave));
assertThat(saved).hasSize(2);
Optional<Person> persistentDave = repository.findById(dave.getId());
Optional<User> persistentDave = repository.findById(dave.getId());
assertThat(persistentDave).contains(dave);
Optional<Person> persistentHomer = repository.findById(person.getId());
assertThat(persistentHomer).contains(person);
Optional<User> persistentHomer = repository.findById(User.getId());
assertThat(persistentHomer).contains(User);
}
@Test // DATACASS-396, DATACASS-416
@@ -254,7 +253,7 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
repository.deleteAll();
List<Person> result = repository.findAll();
List<User> result = repository.findAll();
assertThat(result).isEmpty();
}
@@ -264,7 +263,7 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
repository.deleteById(dave.getId());
Optional<Person> loaded = repository.findById(dave.getId());
Optional<User> loaded = repository.findById(dave.getId());
assertThat(loaded).isEmpty();
}
@@ -274,7 +273,7 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
repository.delete(dave);
Optional<Person> loaded = repository.findById(dave.getId());
Optional<User> loaded = repository.findById(dave.getId());
assertThat(loaded).isEmpty();
}
@@ -284,10 +283,10 @@ public class SimpleCassandraRepositoryIntegrationTests extends AbstractKeyspaceC
repository.deleteAll(Arrays.asList(dave, boyd));
Optional<Person> loaded = repository.findById(boyd.getId());
Optional<User> loaded = repository.findById(boyd.getId());
assertThat(loaded).isEmpty();
}
interface PersonRepostitory extends TypedIdCassandraRepository<Person, String> {}
interface UserRepostitory extends TypedIdCassandraRepository<User, String> {}
}

View File

@@ -30,10 +30,10 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.domain.Person;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.mapping.UserTypeResolver;
import org.springframework.data.cassandra.test.integration.repository.querymethods.declared.Person;
/**
* Unit tests for {@link SimpleCassandraRepository}.

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