Updated test cases
This commit is contained in:
parent
d76fb0f66d
commit
68c7e8623c
|
@ -16,6 +16,7 @@ public class Book {
|
||||||
private UUID id;
|
private UUID id;
|
||||||
@PrimaryKeyColumn(name = "title", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
|
@PrimaryKeyColumn(name = "title", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@PrimaryKeyColumn(name = "publisher", ordinal = 1, type = PrimaryKeyType.PARTITIONED)
|
@PrimaryKeyColumn(name = "publisher", ordinal = 1, type = PrimaryKeyType.PARTITIONED)
|
||||||
private String publisher;
|
private String publisher;
|
||||||
@Column
|
@Column
|
||||||
|
@ -43,4 +44,20 @@ public class Book {
|
||||||
public Set getTags() {
|
public Set getTags() {
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublisher(String publisher) {
|
||||||
|
this.publisher = publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTags(Set<String> tags) {
|
||||||
|
this.tags = tags;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,39 +46,68 @@ public class BookRepositoryIntegrationTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
||||||
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
|
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
|
||||||
Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build();
|
Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1")
|
||||||
|
.withPort(9142).build();
|
||||||
LOGGER.info("Server Started at 127.0.0.1:9142... ");
|
LOGGER.info("Server Started at 127.0.0.1:9142... ");
|
||||||
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);
|
||||||
|
LOGGER.info(session.execute("Select * from Book").all().toArray());
|
||||||
|
Thread.sleep(5000);
|
||||||
LOGGER.info("KeySpace created and activated.");
|
LOGGER.info("KeySpace created and activated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void resetKeySpace() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
public void createTable() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
||||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<String, Object>());
|
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<String, Object>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSavingBooks_thenAvailableOnRetrieval() {
|
public void whenSavingBook_thenAvailableOnRetrieval() {
|
||||||
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"));
|
||||||
bookRepository.save(ImmutableSet.of(javaBook));
|
bookRepository.save(ImmutableSet.of(javaBook));
|
||||||
Iterable<Book> books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media");
|
Iterable<Book> books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media");
|
||||||
assertEquals(javaBook.getId(), books.iterator().next().getId());
|
assertEquals(javaBook.getId(), books.iterator().next().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUpdatingBooks_thenAvailableOnRetrieval() {
|
||||||
|
Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software"));
|
||||||
|
bookRepository.save(ImmutableSet.of(javaBook));
|
||||||
|
Iterable<Book> books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media");
|
||||||
|
javaBook.setTitle("Head First Java Second Edition");
|
||||||
|
bookRepository.save(ImmutableSet.of(javaBook));
|
||||||
|
Iterable<Book> updateBooks = bookRepository.findByTitleAndPublisher("Head First Java Second Edition", "O'Reilly Media");
|
||||||
|
assertEquals(javaBook.getTitle(), updateBooks.iterator().next().getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = java.util.NoSuchElementException.class)
|
@Test(expected = java.util.NoSuchElementException.class)
|
||||||
public void whenDeletingExistingBooks_thenNotAvailableOnRetrieval() {
|
public void whenDeletingExistingBooks_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"));
|
||||||
bookRepository.save(ImmutableSet.of(javaBook));
|
bookRepository.save(ImmutableSet.of(javaBook));
|
||||||
bookRepository.delete(javaBook);
|
bookRepository.delete(javaBook);
|
||||||
Iterable<Book> books = bookRepository.findByTitleAndPublisher("type1", "O'Reilly Media");
|
Iterable<Book> books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media");
|
||||||
assertNotEquals(javaBook.getId(), books.iterator().next().getId());
|
assertNotEquals(javaBook.getId(), books.iterator().next().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSavingBooks_thenAllShouldAvailableOnRetrieval() {
|
||||||
|
Book javaBook = new Book(UUIDs.timeBased(), "Head First Java",
|
||||||
|
"O'Reilly Media", ImmutableSet.of("Computer", "Software"));
|
||||||
|
Book dPatternBook = new Book(UUIDs.timeBased(), "Head Design Patterns",
|
||||||
|
"O'Reilly Media", ImmutableSet.of("Computer", "Software"));
|
||||||
|
bookRepository.save(ImmutableSet.of(javaBook));
|
||||||
|
bookRepository.save(ImmutableSet.of(dPatternBook));
|
||||||
|
Iterable<Book> books = bookRepository.findAll();
|
||||||
|
int bookCount = 0;
|
||||||
|
for (Book book : books) bookCount++;
|
||||||
|
assertEquals(bookCount, 2);
|
||||||
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanTable() {
|
public void dropTable() {
|
||||||
adminTemplate.dropTable(CqlIdentifier.cqlId(DATA_TABLE_NAME));
|
adminTemplate.dropTable(CqlIdentifier.cqlId(DATA_TABLE_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
|
Loading…
Reference in New Issue