@@ -46,39 +46,68 @@ public class BookRepositoryIntegrationTest {
4646 @ BeforeClass
4747 public static void startCassandraEmbedded () throws InterruptedException , TTransportException , ConfigurationException , IOException {
4848 EmbeddedCassandraServerHelper .startEmbeddedCassandra ();
49- Cluster cluster = Cluster .builder ().addContactPoints ("127.0.0.1" ).withPort (9142 ).build ();
49+ Cluster cluster = Cluster .builder ().addContactPoints ("127.0.0.1" )
50+ .withPort (9142 ).build ();
5051 LOGGER .info ("Server Started at 127.0.0.1:9142... " );
5152 Session session = cluster .connect ();
5253 session .execute (KEYSPACE_CREATION_QUERY );
5354 session .execute (KEYSPACE_ACTIVATE_QUERY );
55+ LOGGER .info (session .execute ("Select * from Book" ).all ().toArray ());
56+ Thread .sleep (5000 );
5457 LOGGER .info ("KeySpace created and activated." );
5558 }
5659
5760 @ Before
58- public void resetKeySpace () throws InterruptedException , TTransportException , ConfigurationException , IOException {
61+ public void createTable () throws InterruptedException , TTransportException , ConfigurationException , IOException {
5962 adminTemplate .createTable (true , CqlIdentifier .cqlId (DATA_TABLE_NAME ), Book .class , new HashMap <String , Object >());
6063 }
6164
6265 @ Test
63- public void whenSavingBooks_thenAvailableOnRetrieval () {
64- Book javaBook = new Book (UUIDs .timeBased (), "Head First Java" , "O'Reilly Media" , ImmutableSet .of ("Computer" , "Software" ));
66+ public void whenSavingBook_thenAvailableOnRetrieval () {
67+ Book javaBook = new Book (UUIDs .timeBased (), "Head First Java" ,
68+ "O'Reilly Media" , ImmutableSet .of ("Computer" , "Software" ));
6569 bookRepository .save (ImmutableSet .of (javaBook ));
6670 Iterable <Book > books = bookRepository .findByTitleAndPublisher ("Head First Java" , "O'Reilly Media" );
6771 assertEquals (javaBook .getId (), books .iterator ().next ().getId ());
6872 }
6973
74+ @ Test
75+ public void whenUpdatingBooks_thenAvailableOnRetrieval () {
76+ Book javaBook = new Book (UUIDs .timeBased (), "Head First Java" , "O'Reilly Media" , ImmutableSet .of ("Computer" , "Software" ));
77+ bookRepository .save (ImmutableSet .of (javaBook ));
78+ Iterable <Book > books = bookRepository .findByTitleAndPublisher ("Head First Java" , "O'Reilly Media" );
79+ javaBook .setTitle ("Head First Java Second Edition" );
80+ bookRepository .save (ImmutableSet .of (javaBook ));
81+ Iterable <Book > updateBooks = bookRepository .findByTitleAndPublisher ("Head First Java Second Edition" , "O'Reilly Media" );
82+ assertEquals (javaBook .getTitle (), updateBooks .iterator ().next ().getTitle ());
83+ }
84+
7085 @ Test (expected = java .util .NoSuchElementException .class )
7186 public void whenDeletingExistingBooks_thenNotAvailableOnRetrieval () {
7287 Book javaBook = new Book (UUIDs .timeBased (), "Head First Java" , "O'Reilly Media" , ImmutableSet .of ("Computer" , "Software" ));
7388 bookRepository .save (ImmutableSet .of (javaBook ));
7489 bookRepository .delete (javaBook );
75- Iterable <Book > books = bookRepository .findByTitleAndPublisher ("type1 " , "O'Reilly Media" );
90+ Iterable <Book > books = bookRepository .findByTitleAndPublisher ("Head First Java " , "O'Reilly Media" );
7691 assertNotEquals (javaBook .getId (), books .iterator ().next ().getId ());
7792 }
7893
94+ @ Test
95+ public void whenSavingBooks_thenAllShouldAvailableOnRetrieval () {
96+ Book javaBook = new Book (UUIDs .timeBased (), "Head First Java" ,
97+ "O'Reilly Media" , ImmutableSet .of ("Computer" , "Software" ));
98+ Book dPatternBook = new Book (UUIDs .timeBased (), "Head Design Patterns" ,
99+ "O'Reilly Media" , ImmutableSet .of ("Computer" , "Software" ));
100+ bookRepository .save (ImmutableSet .of (javaBook ));
101+ bookRepository .save (ImmutableSet .of (dPatternBook ));
102+ Iterable <Book > books = bookRepository .findAll ();
103+ int bookCount = 0 ;
104+ for (Book book : books ) bookCount ++;
105+ assertEquals (bookCount , 2 );
106+ }
107+
79108 @ After
80- public void cleanTable () {
81- adminTemplate .dropTable (CqlIdentifier .cqlId (DATA_TABLE_NAME ));
109+ public void dropTable () {
110+ adminTemplate .dropTable (CqlIdentifier .cqlId (DATA_TABLE_NAME ));
82111 }
83112
84113 @ AfterClass
0 commit comments