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