Updated test cases for single delete
This commit is contained in:
parent
4c5d2fe273
commit
3e39bf59c8
|
@ -12,12 +12,12 @@ import java.util.UUID;
|
|||
|
||||
@Table
|
||||
public class Book {
|
||||
@PrimaryKeyColumn(name = "isbn", ordinal = 2, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.DESCENDING)
|
||||
@PrimaryKeyColumn(name = "id", ordinal = 0, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.DESCENDING)
|
||||
private UUID id;
|
||||
@PrimaryKeyColumn(name = "title", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
|
||||
@PrimaryKeyColumn(name = "title", ordinal = 1, type = PrimaryKeyType.PARTITIONED)
|
||||
private String title;
|
||||
|
||||
@PrimaryKeyColumn(name = "publisher", ordinal = 1, type = PrimaryKeyType.PARTITIONED)
|
||||
@PrimaryKeyColumn(name = "publisher", ordinal = 2, type = PrimaryKeyType.PARTITIONED)
|
||||
private String publisher;
|
||||
@Column
|
||||
private Set<String> tags = new HashSet<>();
|
||||
|
|
|
@ -52,8 +52,8 @@ public class BookRepositoryIntegrationTest {
|
|||
Session session = cluster.connect();
|
||||
session.execute(KEYSPACE_CREATION_QUERY);
|
||||
session.execute(KEYSPACE_ACTIVATE_QUERY);
|
||||
Thread.sleep(5000);
|
||||
LOGGER.info("KeySpace created and activated.");
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
@Before
|
||||
|
|
|
@ -57,8 +57,8 @@ public class CQLQueriesIntegrationTest {
|
|||
Session session = cluster.connect();
|
||||
session.execute(KEYSPACE_CREATION_QUERY);
|
||||
session.execute(KEYSPACE_ACTIVATE_QUERY);
|
||||
Thread.sleep(2000);
|
||||
LOGGER.info("KeySpace created and activated.");
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
@Before
|
||||
|
@ -69,7 +69,7 @@ public class CQLQueriesIntegrationTest {
|
|||
@Test
|
||||
public void whenSavingBook_thenAvailableOnRetrieval_usingQueryBuilder() {
|
||||
UUID uuid = UUIDs.timeBased();
|
||||
Insert insert = QueryBuilder.insertInto(DATA_TABLE_NAME).value("isbn", uuid).value("title", "Head First Java").value("publisher", "OReilly Media").value("tags", ImmutableSet.of("Software"));
|
||||
Insert insert = QueryBuilder.insertInto(DATA_TABLE_NAME).value("id", uuid).value("title", "Head First Java").value("publisher", "OReilly Media").value("tags", ImmutableSet.of("Software"));
|
||||
cassandraTemplate.execute(insert);
|
||||
Select select = QueryBuilder.select().from("book").limit(10);
|
||||
Book retrievedBook = cassandraTemplate.selectOne(select, Book.class);
|
||||
|
@ -79,7 +79,7 @@ public class CQLQueriesIntegrationTest {
|
|||
@Test
|
||||
public void whenSavingBook_thenAvailableOnRetrieval_usingCQLStatements() {
|
||||
UUID uuid = UUIDs.timeBased();
|
||||
String insertCql = "insert into book (isbn, title, publisher, tags) values " + "(" + uuid + ", 'Head First Java', 'OReilly Media', {'Software'})";
|
||||
String insertCql = "insert into book (id, title, publisher, tags) values " + "(" + uuid + ", 'Head First Java', 'OReilly Media', {'Software'})";
|
||||
cassandraTemplate.execute(insertCql);
|
||||
Select select = QueryBuilder.select().from("book").limit(10);
|
||||
Book retrievedBook = cassandraTemplate.selectOne(select, Book.class);
|
||||
|
@ -89,16 +89,16 @@ public class CQLQueriesIntegrationTest {
|
|||
@Test
|
||||
public void whenSavingBook_thenAvailableOnRetrieval_usingPreparedStatements() {
|
||||
UUID uuid = UUIDs.timeBased();
|
||||
String insertPreparedCql = "insert into book (isbn, title, publisher, tags) values (?, ?, ?, ?)";
|
||||
List<Object> bookList = new ArrayList<>();
|
||||
List<List<?>> bookListOfList = new ArrayList<>();
|
||||
bookList.add(uuid);
|
||||
bookList.add("Head First Java");
|
||||
bookList.add("OReilly Media");
|
||||
bookList.add(ImmutableSet.of("Software"));
|
||||
bookListOfList.add(bookList);
|
||||
cassandraTemplate.ingest(insertPreparedCql, bookListOfList);
|
||||
Select select = QueryBuilder.select().from("book").limit(10);
|
||||
String insertPreparedCql = "insert into book (id, title, publisher, tags) values (?, ?, ?, ?)";
|
||||
List<Object> singleBookArgsList = new ArrayList<>();
|
||||
List<List<?>> bookList = new ArrayList<>();
|
||||
singleBookArgsList.add(uuid);
|
||||
singleBookArgsList.add("Head First Java");
|
||||
singleBookArgsList.add("OReilly Media");
|
||||
singleBookArgsList.add(ImmutableSet.of("Software"));
|
||||
bookList.add(singleBookArgsList);
|
||||
cassandraTemplate.ingest(insertPreparedCql, bookList);
|
||||
Select select = QueryBuilder.select().from("book");
|
||||
Book retrievedBook = cassandraTemplate.selectOne(select, Book.class);
|
||||
assertEquals(uuid, retrievedBook.getId());
|
||||
}
|
||||
|
|
|
@ -58,8 +58,8 @@ public class CassandraTemplateIntegrationTest {
|
|||
Session session = cluster.connect();
|
||||
session.execute(KEYSPACE_CREATION_QUERY);
|
||||
session.execute(KEYSPACE_ACTIVATE_QUERY);
|
||||
Thread.sleep(2000);
|
||||
LOGGER.info("KeySpace created and activated.");
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
@Before
|
||||
|
@ -98,16 +98,28 @@ public class CassandraTemplateIntegrationTest {
|
|||
cassandraTemplate.insert(javaBook);
|
||||
Select select = QueryBuilder.select().from("book").limit(10);
|
||||
Book retrievedBook = cassandraTemplate.selectOne(select, Book.class);
|
||||
retrievedBook.setTags(ImmutableSet.of("Computer", "Software", "Java"));
|
||||
retrievedBook.setTags(ImmutableSet.of("Java", "Programming"));
|
||||
cassandraTemplate.update(retrievedBook);
|
||||
Book retrievedUpdatedBook = cassandraTemplate.selectOne(select, Book.class);
|
||||
assertEquals(retrievedBook.getTags(), retrievedUpdatedBook.getTags());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeletingExistingBooks_thenNotAvailableOnRetrieval() {
|
||||
public void whenDeletingASelectedBook_thenNotAvailableOnRetrieval() throws InterruptedException {
|
||||
Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "OReilly Media", ImmutableSet.of("Computer", "Software"));
|
||||
cassandraTemplate.insert(javaBook);
|
||||
cassandraTemplate.delete(javaBook);
|
||||
Select select = QueryBuilder.select().from("book").limit(10);
|
||||
Book retrievedUpdatedBook = cassandraTemplate.selectOne(select, Book.class);
|
||||
assertNull(retrievedUpdatedBook);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeletingAllBooks_thenNotAvailableOnRetrieval() {
|
||||
Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software"));
|
||||
Book insertedBook = cassandraTemplate.insert(javaBook);
|
||||
Book dPatternBook = new Book(UUIDs.timeBased(), "Head Design Patterns", "O'Reilly Media", ImmutableSet.of("Computer", "Software"));
|
||||
cassandraTemplate.insert(javaBook);
|
||||
cassandraTemplate.insert(dPatternBook);
|
||||
cassandraTemplate.deleteAll(Book.class);
|
||||
Select select = QueryBuilder.select().from("book").limit(10);
|
||||
Book retrievedUpdatedBook = cassandraTemplate.selectOne(select, Book.class);
|
||||
|
|
Loading…
Reference in New Issue