Adding test cases for Cassandra Templates and CQL Queries

This commit is contained in:
sameira 2015-12-09 16:20:30 +05:30 committed by David Morley
parent b45706cc60
commit 908883db12
2 changed files with 18 additions and 23 deletions

View File

@ -57,7 +57,7 @@ public class CQLQueriesIntegrationTest {
Session session = cluster.connect(); Session session = cluster.connect();
session.execute(KEYSPACE_CREATION_QUERY); session.execute(KEYSPACE_CREATION_QUERY);
session.execute(KEYSPACE_ACTIVATE_QUERY); session.execute(KEYSPACE_ACTIVATE_QUERY);
Thread.sleep(1000); Thread.sleep(2000);
LOGGER.info("KeySpace created and activated."); LOGGER.info("KeySpace created and activated.");
} }
@ -96,7 +96,7 @@ public class CQLQueriesIntegrationTest {
bookList.add("Head First Java"); bookList.add("Head First Java");
bookList.add("OReilly Media"); bookList.add("OReilly Media");
bookList.add(ImmutableSet.of("Software")); bookList.add(ImmutableSet.of("Software"));
bookList.add(bookList); bookListOfList.add(bookList);
cassandraTemplate.ingest(insertPreparedCql, bookListOfList); cassandraTemplate.ingest(insertPreparedCql, bookListOfList);
Select select = QueryBuilder.select().from("book").limit(10); Select select = QueryBuilder.select().from("book").limit(10);
Book retrievedBook = cassandraTemplate.selectOne(select, Book.class); Book retrievedBook = cassandraTemplate.selectOne(select, Book.class);

View File

@ -1,14 +1,11 @@
package org.baeldung.spring.data.cassandra.repository; package org.baeldung.spring.data.cassandra.repository;
import static junit.framework.TestCase.assertNull; import com.datastax.driver.core.Cluster;
import static org.hamcrest.CoreMatchers.is; import com.datastax.driver.core.Session;
import static org.junit.Assert.assertEquals; import com.datastax.driver.core.querybuilder.QueryBuilder;
import static org.junit.Assert.assertThat; import com.datastax.driver.core.querybuilder.Select;
import com.datastax.driver.core.utils.UUIDs;
import java.io.IOException; import com.google.common.collect.ImmutableSet;
import java.util.HashMap;
import java.util.List;
import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -16,11 +13,7 @@ import org.apache.thrift.transport.TTransportException;
import org.baeldung.spring.data.cassandra.config.CassandraConfig; import org.baeldung.spring.data.cassandra.config.CassandraConfig;
import org.baeldung.spring.data.cassandra.model.Book; import org.baeldung.spring.data.cassandra.model.Book;
import org.cassandraunit.utils.EmbeddedCassandraServerHelper; import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
import org.junit.After; import org.junit.*;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.core.cql.CqlIdentifier; import org.springframework.cassandra.core.cql.CqlIdentifier;
@ -29,12 +22,14 @@ import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.datastax.driver.core.Cluster; import java.io.IOException;
import com.datastax.driver.core.Session; import java.util.HashMap;
import com.datastax.driver.core.querybuilder.QueryBuilder; import java.util.List;
import com.datastax.driver.core.querybuilder.Select;
import com.datastax.driver.core.utils.UUIDs; import static junit.framework.TestCase.assertNull;
import com.google.common.collect.ImmutableSet; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = CassandraConfig.class) @ContextConfiguration(classes = CassandraConfig.class)
@ -62,7 +57,7 @@ public class CassandraTemplateIntegrationTest {
Session session = cluster.connect(); Session session = cluster.connect();
session.execute(KEYSPACE_CREATION_QUERY); session.execute(KEYSPACE_CREATION_QUERY);
session.execute(KEYSPACE_ACTIVATE_QUERY); session.execute(KEYSPACE_ACTIVATE_QUERY);
Thread.sleep(5000); Thread.sleep(2000);
LOGGER.info("KeySpace created and activated."); LOGGER.info("KeySpace created and activated.");
} }