diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraOperations.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraOperations.java index 08fb5b946..eb456f134 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraOperations.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraOperations.java @@ -212,6 +212,11 @@ public interface CassandraOperations extends CqlOperations { */ void delete(List entities, QueryOptions options); + /** + * Deletes all entities of a given class. + */ + void deleteAll(Class clazz); + /** * Remove the given object from the table by id. * diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java index 94633fd67..678cdc0fb 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java @@ -753,4 +753,14 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation return batch; } + + @Override + public void deleteAll(Class clazz) { + + if (!mappingContext.contains(clazz)) { + throw new IllegalArgumentException(String.format("unknown persistent entity class [%s]", clazz.getName())); + } + + truncate(mappingContext.getPersistentEntity(clazz).getTableName()); + } } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderTest.java new file mode 100644 index 000000000..c168323bd --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderTest.java @@ -0,0 +1,164 @@ +/* + * Copyright 2011-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.collections; + +import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.createKeyspace; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.cassandra.config.SchemaAction; +import org.springframework.data.cassandra.test.integration.simpletons.Book; +import org.springframework.data.cassandra.test.integration.simpletons.BookHistory; +import org.springframework.data.cassandra.test.integration.simpletons.BookReference; +import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; +import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.datastax.driver.core.querybuilder.QueryBuilder; +import com.datastax.driver.core.querybuilder.Select; + +/** + * @author dwebb + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration +public class CollectionsRowValueProviderTest extends AbstractSpringDataEmbeddedCassandraIntegrationTest { + + @Configuration + public static class Config extends IntegrationTestConfig { + + @Override + public SchemaAction getSchemaAction() { + return SchemaAction.RECREATE; + } + + @Override + protected List getKeyspaceCreations() { + return Arrays.asList(createKeyspace().name(getKeyspaceName()).withSimpleReplication()); + } + + @Override + public String[] getEntityBasePackages() { + return new String[] { Book.class.getPackage().getName() }; + } + } + + @Before + public void before() throws IOException { + deleteAllEntities(); + } + + @Test + public void mapTest() { + + BookHistory b1 = new BookHistory(); + b1.setIsbn("123456-1"); + b1.setTitle("Spring Data Cassandra Guide"); + b1.setAuthor("Cassandra Guru"); + b1.setPages(521); + b1.setSaleDate(new Date()); + b1.setInStock(true); + + Map checkOutMap = new HashMap(); + checkOutMap.put("dwebb", 50); + checkOutMap.put("madams", 100); + checkOutMap.put("jmcpeek", 150); + + b1.setCheckOuts(checkOutMap); + + template.insert(b1); + + Select select = QueryBuilder.select().all().from("bookHistory"); + select.where(QueryBuilder.eq("isbn", "123456-1")); + + BookHistory b = template.selectOne(select.getQueryString(), BookHistory.class); + + Assert.assertNotNull(b.getCheckOuts()); + + log.info("Checkouts map data"); + for (String username : b.getCheckOuts().keySet()) { + log.info(username + " has " + b.getCheckOuts().get(username) + " checkouts of this book."); + } + + Assert.assertEquals(b.getTitle(), "Spring Data Cassandra Guide"); + Assert.assertEquals(b.getAuthor(), "Cassandra Guru"); + + } + + @Test + public void listSetTest() { + + BookReference b1 = new BookReference(); + b1.setIsbn("123456-1"); + b1.setTitle("Spring Data Cassandra Guide"); + b1.setAuthor("Cassandra Guru"); + b1.setPages(521); + b1.setSaleDate(new Date()); + b1.setInStock(true); + + Set refs = new HashSet(); + refs.add("Spring Data by O'Reilly"); + refs.add("Spring by Example"); + refs.add("Spring Recipies"); + b1.setReferences(refs); + + List marks = new LinkedList(); + marks.add(13); + marks.add(52); + marks.add(144); + b1.setBookmarks(marks); + + template.insert(b1); + + Select select = QueryBuilder.select().all().from("bookReference"); + select.where(QueryBuilder.eq("isbn", "123456-1")); + + BookReference b = template.selectOne(select.getQueryString(), BookReference.class); + + Assert.assertNotNull(b.getReferences()); + Assert.assertNotNull(b.getBookmarks()); + + log.info("Bookmark List Data"); + for (Integer mark : b.getBookmarks()) { + log.info("Bookmark set on page " + mark); + } + + log.info("Reference Set Data"); + for (String ref : b.getReferences()) { + log.info("Reference -> " + ref); + } + + Assert.assertEquals(b.getTitle(), "Spring Data Cassandra Guide"); + Assert.assertEquals(b.getAuthor(), "Cassandra Guru"); + + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryIntegrationTests.java index 0381dab17..cb6dd3f31 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryIntegrationTests.java @@ -43,10 +43,6 @@ public class CommentRepositoryIntegrationTests { repository.deleteAll(); } - public void after() { - repository.deleteAll(); - } - public void testInsert() { String author = "testAuthorInsert"; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryJavaConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryJavaConfigIntegrationTests.java index 448a1e173..2a3ea384c 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryJavaConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryJavaConfigIntegrationTests.java @@ -20,7 +20,6 @@ import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecific import java.util.ArrayList; import java.util.List; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,7 +31,7 @@ import org.springframework.data.cassandra.core.CassandraOperations; import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; import org.springframework.data.cassandra.test.integration.repository.UserRepository; import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; -import org.springframework.data.cassandra.test.integration.support.TestConfig; +import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -47,7 +46,7 @@ public class CommentRepositoryJavaConfigIntegrationTests extends AbstractSpringD @Configuration @EnableCassandraRepositories(basePackageClasses = CommentRepository.class) - public static class Config extends TestConfig { + public static class Config extends IntegrationTestConfig { @Override protected String getKeyspaceName() { @@ -88,11 +87,6 @@ public class CommentRepositoryJavaConfigIntegrationTests extends AbstractSpringD tests.before(); } - @After - public void after() { - tests.after(); - } - @Test public void testInsert() { tests.testInsert(); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryXmlConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryXmlConfigIntegrationTests.java index 471441b2d..ce8e9ac42 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryXmlConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryXmlConfigIntegrationTests.java @@ -15,7 +15,6 @@ */ package org.springframework.data.cassandra.test.integration.composites; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -49,11 +48,6 @@ public class CommentRepositoryXmlConfigIntegrationTests extends AbstractSpringDa tests.before(); } - @After - public void after() { - tests.after(); - } - @Test public void testInsert() { tests.testInsert(); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java index 32358888c..ec458b3bf 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java @@ -36,6 +36,8 @@ import com.datastax.driver.core.DataType; @PrimaryKeyClass public class NotificationPK implements Serializable { + private static final long serialVersionUID = -5041736242014855732L; + /* * Row ID */ diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java index 01e8625d2..ccc567e32 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java @@ -35,6 +35,8 @@ import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; @PrimaryKeyClass public class PostPK implements Serializable { + private static final long serialVersionUID = 2390757126054483315L; + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private String author; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java index de8c5cc42..11de07a8d 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java @@ -35,6 +35,8 @@ import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; @PrimaryKeyClass public class TimelinePK implements Serializable { + private static final long serialVersionUID = 1872200498229849025L; + /* * Row ID */ diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java index 652027f05..df98ac254 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java @@ -53,7 +53,7 @@ public class UserRepositoryIntegrationTests { this.template = template; } - public void setUp() throws InterruptedException { + public void setUp() { repository.deleteAll(); @@ -88,8 +88,9 @@ public class UserRepositoryIntegrationTests { all = template.insert(Arrays.asList(tom, bob, alice, scott)); } - public void after() { + public void before() { repository.deleteAll(); + setUp(); } public void findsUserById() throws Exception { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryJavaConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryJavaConfigIntegrationTests.java index dfc21824d..6f5e5196a 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryJavaConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryJavaConfigIntegrationTests.java @@ -31,7 +31,7 @@ import org.springframework.data.cassandra.config.SchemaAction; import org.springframework.data.cassandra.core.CassandraOperations; 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.TestConfig; +import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -46,7 +46,7 @@ public class UserRepositoryJavaConfigIntegrationTests extends AbstractSpringData @Configuration @EnableCassandraRepositories(basePackageClasses = UserRepository.class) - public static class Config extends TestConfig { + public static class Config extends IntegrationTestConfig { @Override protected String getKeyspaceName() { @@ -82,14 +82,9 @@ public class UserRepositoryJavaConfigIntegrationTests extends AbstractSpringData UserRepositoryIntegrationTests tests; @Before - public void setUp() throws InterruptedException { + public void before() { tests = new UserRepositoryIntegrationTests(repository, template); - tests.setUp(); - } - - @After - public void after() { - tests.after(); + tests.before(); } @Test diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests.java index 61aa5fec7..2b8915299 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests.java @@ -15,7 +15,6 @@ */ package org.springframework.data.cassandra.test.integration.repository; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,14 +42,9 @@ public class UserRepositoryXmlConfigIntegrationTests extends AbstractSpringDataE UserRepositoryIntegrationTests tests; @Before - public void setUp() throws InterruptedException { + public void before() { tests = new UserRepositoryIntegrationTests(repository, template); - tests.setUp(); - } - - @After - public void after() { - tests.after(); + tests.before(); } @Test diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/AbstractSpringDataEmbeddedCassandraIntegrationTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/AbstractSpringDataEmbeddedCassandraIntegrationTest.java index af62c5e89..ce6816d6b 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/AbstractSpringDataEmbeddedCassandraIntegrationTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/AbstractSpringDataEmbeddedCassandraIntegrationTest.java @@ -15,29 +15,15 @@ */ package org.springframework.data.cassandra.test.integration.support; -import static org.springframework.cassandra.core.keyspace.DropTableSpecification.dropTable; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.io.FileUtils; 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.core.io.ClassPathResource; import org.springframework.data.cassandra.core.CassandraOperations; -import org.springframework.data.cassandra.test.integration.template.CassandraDataOperationsTest.Config; -import org.springframework.util.Assert; - -import com.datastax.driver.core.TableMetadata; +import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; public class AbstractSpringDataEmbeddedCassandraIntegrationTest extends AbstractEmbeddedCassandraIntegrationTest { - public static List SCRIPT; - public static List TABLES; - static { SpringDataCassandraBuildProperties props = new SpringDataCassandraBuildProperties(); CASSANDRA_NATIVE_PORT = props.getCassandraPort(); @@ -48,51 +34,10 @@ public class AbstractSpringDataEmbeddedCassandraIntegrationTest extends Abstract @Autowired public CassandraOperations template; - /** - * Saves all table metadata, then drops & creates all tables. - */ - public void recreateAllTables() { + public void deleteAllEntities() { - saveAllTableMetadata(); - - for (TableMetadata table : TABLES) { - template.execute(dropTable(table.getName())); - template.execute(table.asCQLQuery()); + for (CassandraPersistentEntity entity : template.getConverter().getMappingContext().getPersistentEntities()) { + template.truncate(entity.getTableName()); } } - - public void saveAllTableMetadata() { - saveAllTableMetadata(false); - } - - /** - * Saves all table metadata statically. - */ - public void saveAllTableMetadata(boolean force) { - - if (TABLES != null && !force) { - return; - } - - TABLES = new ArrayList(template.getSession().getCluster().getMetadata() - .getKeyspace(Config.KEYSPACE_NAME).getTables()); - } - - public List readScriptLines(String resourceName) { - return readScriptLines(resourceName); - } - - /** - * Reads the lines from the script referenced by {@link #RESOURCE}. - */ - public List readScriptLines(String resourceName, boolean force) throws IOException { - - if (SCRIPT != null && !force) { - return SCRIPT; - } - - Assert.hasText(resourceName); - - return SCRIPT = FileUtils.readLines(new ClassPathResource(resourceName).getFile()); - } } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/TestConfig.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/IntegrationTestConfig.java similarity index 88% rename from spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/TestConfig.java rename to spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/IntegrationTestConfig.java index 1cb6dd79b..f16ff8f21 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/TestConfig.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/IntegrationTestConfig.java @@ -26,17 +26,17 @@ import org.springframework.data.cassandra.config.java.AbstractSpringDataCassandr * @author Matthew T. Adams */ @Configuration -public class TestConfig extends AbstractSpringDataCassandraConfiguration { +public class IntegrationTestConfig extends AbstractSpringDataCassandraConfiguration { public static final SpringDataCassandraBuildProperties PROPS = new SpringDataCassandraBuildProperties(); public static final int PORT = PROPS.getCassandraPort(); public static final int RPC_PORT = PROPS.getCassandraRpcPort(); - public static final String KEYSPACE_NAME = Utils.randomKeyspaceName(); + public String keyspaceName = Utils.randomKeyspaceName(); @Override protected String getKeyspaceName() { - return KEYSPACE_NAME; + return keyspaceName; } @Override diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/CassandraDataOperationsTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/CassandraDataOperationsTest.java index 60942c070..987a63624 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/CassandraDataOperationsTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/CassandraDataOperationsTest.java @@ -21,12 +21,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; import java.util.List; -import java.util.Map; -import java.util.Set; import java.util.UUID; import org.junit.Assert; @@ -40,10 +35,8 @@ import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification; import org.springframework.context.annotation.Configuration; import org.springframework.data.cassandra.config.SchemaAction; import org.springframework.data.cassandra.test.integration.simpletons.Book; -import org.springframework.data.cassandra.test.integration.simpletons.BookHistory; -import org.springframework.data.cassandra.test.integration.simpletons.BookReference; import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; -import org.springframework.data.cassandra.test.integration.support.TestConfig; +import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -61,7 +54,7 @@ import com.datastax.driver.core.querybuilder.Select; public class CassandraDataOperationsTest extends AbstractSpringDataEmbeddedCassandraIntegrationTest { @Configuration - public static class Config extends TestConfig { + public static class Config extends IntegrationTestConfig { @Override public SchemaAction getSchemaAction() { @@ -80,8 +73,8 @@ public class CassandraDataOperationsTest extends AbstractSpringDataEmbeddedCassa } @Before - public void before() throws IOException { - recreateAllTables(); + public void before() { + deleteAllEntities(); } @Test @@ -668,89 +661,4 @@ public class CassandraDataOperationsTest extends AbstractSpringDataEmbeddedCassa Assert.assertEquals(count, template.count(Book.class)); } - @Test - public void mapTest() { - - BookHistory b1 = new BookHistory(); - b1.setIsbn("123456-1"); - b1.setTitle("Spring Data Cassandra Guide"); - b1.setAuthor("Cassandra Guru"); - b1.setPages(521); - b1.setSaleDate(new Date()); - b1.setInStock(true); - - Map checkOutMap = new HashMap(); - checkOutMap.put("dwebb", 50); - checkOutMap.put("madams", 100); - checkOutMap.put("jmcpeek", 150); - - b1.setCheckOuts(checkOutMap); - - template.insert(b1); - - Select select = QueryBuilder.select().all().from("bookHistory"); - select.where(QueryBuilder.eq("isbn", "123456-1")); - - BookHistory b = template.selectOne(select.getQueryString(), BookHistory.class); - - Assert.assertNotNull(b.getCheckOuts()); - - log.info("Checkouts map data"); - for (String username : b.getCheckOuts().keySet()) { - log.info(username + " has " + b.getCheckOuts().get(username) + " checkouts of this book."); - } - - Assert.assertEquals(b.getTitle(), "Spring Data Cassandra Guide"); - Assert.assertEquals(b.getAuthor(), "Cassandra Guru"); - - } - - @Test - public void listSetTest() { - - BookReference b1 = new BookReference(); - b1.setIsbn("123456-1"); - b1.setTitle("Spring Data Cassandra Guide"); - b1.setAuthor("Cassandra Guru"); - b1.setPages(521); - b1.setSaleDate(new Date()); - b1.setInStock(true); - - Set refs = new HashSet(); - refs.add("Spring Data by O'Reilly"); - refs.add("Spring by Example"); - refs.add("Spring Recipies"); - b1.setReferences(refs); - - List marks = new LinkedList(); - marks.add(13); - marks.add(52); - marks.add(144); - b1.setBookmarks(marks); - - template.insert(b1); - - Select select = QueryBuilder.select().all().from("bookReference"); - select.where(QueryBuilder.eq("isbn", "123456-1")); - - BookReference b = template.selectOne(select.getQueryString(), BookReference.class); - - Assert.assertNotNull(b.getReferences()); - Assert.assertNotNull(b.getBookmarks()); - - log.info("Bookmark List Data"); - for (Integer mark : b.getBookmarks()) { - log.info("Bookmark set on page + " + mark); - } - - log.info("Reference Set Data"); - for (String ref : b.getReferences()) { - log.info("Reference -> " + ref); - } - - Assert.assertEquals(b.getTitle(), "Spring Data Cassandra Guide"); - Assert.assertEquals(b.getAuthor(), "Cassandra Guru"); - - } - }