From 36a18cedaa580f8a9dfc47aec3623d0a76a2f15a Mon Sep 17 00:00:00 2001 From: Alex Shvid Date: Tue, 26 Nov 2013 11:32:01 -0800 Subject: [PATCH] cassandra repository integration test --- .../query/CassandraEntityMetadata.java | 35 ++++++++ .../CassandraRepositoryFactoryBean.java | 28 +++++++ .../test/integration/repository/Profile.java | 67 ++++++++++++++++ .../repository/ProfileRepository.java | 28 +++++++ .../ProfileRepositoryIntegrationTests.java | 79 +++++++++++++++++++ ...fileRepositoryIntegrationTests-context.xml | 61 ++++++++++++++ .../repository/cassandra.properties | 7 ++ 7 files changed, 305 insertions(+) create mode 100644 spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraEntityMetadata.java create mode 100644 spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/CassandraRepositoryFactoryBean.java create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/Profile.java create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/ProfileRepository.java create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/ProfileRepositoryIntegrationTests.java create mode 100644 spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/ProfileRepositoryIntegrationTests-context.xml create mode 100644 spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/cassandra.properties diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraEntityMetadata.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraEntityMetadata.java new file mode 100644 index 000000000..d0f49c238 --- /dev/null +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraEntityMetadata.java @@ -0,0 +1,35 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.repository.query; + +import org.springframework.data.repository.core.EntityMetadata; + +/** + * Extension of {@link EntityMetadata} to additionally expose the table name an entity shall be persisted to. + * + * @author Alex Shvid + * + * @param + */ +public interface CassandraEntityMetadata extends EntityMetadata { + + /** + * Returns the name of the table the entity shall be persisted to. + * + * @return + */ + String getTableName(); +} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/CassandraRepositoryFactoryBean.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/CassandraRepositoryFactoryBean.java new file mode 100644 index 000000000..e32ba9261 --- /dev/null +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/CassandraRepositoryFactoryBean.java @@ -0,0 +1,28 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.repository.support; + +import org.springframework.data.cassandra.repository.CassandraRepository; + +/** + * {@link org.springframework.beans.factory.FactoryBean} to create {@link CassandraRepository} instances. + * + * @author Alex Shvid + * + */ +public class CassandraRepositoryFactoryBean { + +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/Profile.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/Profile.java new file mode 100644 index 000000000..718c923b8 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/Profile.java @@ -0,0 +1,67 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository; + +/** + * Sample domain class got from Webby social network site. + * + * @author Alex Shvid + * + */ +public class Profile { + + public enum Gender { + MALE, FEMALE; + } + + private Long profileId; + private String firstName; + private String lastName; + private Gender gender; + + public Long getProfileId() { + return profileId; + } + + public void setProfileId(Long profileId) { + this.profileId = profileId; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Gender getGender() { + return gender; + } + + public void setGender(Gender gender) { + this.gender = gender; + } + +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/ProfileRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/ProfileRepository.java new file mode 100644 index 000000000..6fe41cc81 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/ProfileRepository.java @@ -0,0 +1,28 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository; + +import org.springframework.data.cassandra.repository.CassandraRepository; + +/** + * Sample repository managing {@link Profile} entities. + * + * @author Alex Shvid + * + */ +public interface ProfileRepository extends CassandraRepository { + +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/ProfileRepositoryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/ProfileRepositoryIntegrationTests.java new file mode 100644 index 000000000..8248216d6 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/ProfileRepositoryIntegrationTests.java @@ -0,0 +1,79 @@ +/* + * Copyright 2011-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.repository; + +import java.io.IOException; + +import org.apache.cassandra.exceptions.ConfigurationException; +import org.apache.thrift.transport.TTransportException; +import org.cassandraunit.utils.EmbeddedCassandraServerHelper; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.cassandra.core.CassandraDataOperations; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * Base class for tests for {@link ProfileRepository}. + * + * @author Alex Shvid + * + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class ProfileRepositoryIntegrationTests { + + // @Autowired + // protected ProfileRepository repository; + + @Autowired + CassandraDataOperations operations; + + @BeforeClass + public static void startCassandra() throws IOException, TTransportException, ConfigurationException, + InterruptedException { + EmbeddedCassandraServerHelper.startEmbeddedCassandra("cassandra.yaml"); + } + + @Before + public void setUp() throws InterruptedException { + + // repository.deleteAll(); + + } + + @Test + public void findsProfileById() throws Exception { + + System.out.println("find profile by id"); + } + + @After + public void clearCassandra() { + EmbeddedCassandraServerHelper.cleanEmbeddedCassandra(); + } + + @AfterClass + public static void stopCassandra() { + EmbeddedCassandraServerHelper.stopEmbeddedCassandra(); + } + +} diff --git a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/ProfileRepositoryIntegrationTests-context.xml b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/ProfileRepositoryIntegrationTests-context.xml new file mode 100644 index 000000000..9a5e68f7d --- /dev/null +++ b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/ProfileRepositoryIntegrationTests-context.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/cassandra.properties b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/cassandra.properties new file mode 100644 index 000000000..6a0dd3197 --- /dev/null +++ b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/repository/cassandra.properties @@ -0,0 +1,7 @@ +cassandra.contactPoints=localhost +cassandra.port=9042 +cassandra.keyspace=TestKS123 + + + +