From 16f101f3abe833d3af98d498f5f0fc5127da2596 Mon Sep 17 00:00:00 2001 From: David Webb Date: Tue, 26 Nov 2013 16:51:54 -0500 Subject: [PATCH] DATACASS-35: Unit Tests for CassandraOperations --- .../template/CassandraOperationsTest.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/template/CassandraOperationsTest.java b/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/template/CassandraOperationsTest.java index 1b3fa1c71..f4a363d88 100644 --- a/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/template/CassandraOperationsTest.java +++ b/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/template/CassandraOperationsTest.java @@ -39,6 +39,7 @@ import org.springframework.cassandra.core.PreparedStatementBinder; import org.springframework.cassandra.core.ResultSetExtractor; import org.springframework.cassandra.core.ResultSetFutureExtractor; import org.springframework.cassandra.core.RingMember; +import org.springframework.cassandra.core.RowCallbackHandler; import org.springframework.cassandra.core.RowIterator; import org.springframework.cassandra.core.SessionCallback; import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest; @@ -375,6 +376,73 @@ public class CassandraOperationsTest extends AbstractEmbeddedCassandraIntegratio } + @Test + public void queryTestCqlStringRowCallbackHandler() { + + final String isbn = "999999999"; + + final Book b1 = getBook(isbn); + + cassandraTemplate.query("select * from book where isbn='" + isbn + "'", new RowCallbackHandler() { + + @Override + public void processRow(Row row) throws DriverException { + + assertNotNull(row); + + Book b = new Book(); + b.setIsbn(row.getString("isbn")); + b.setTitle(row.getString("title")); + b.setAuthor(row.getString("author")); + b.setPages(row.getInt("pages")); + + assertBook(b1, b); + + } + }); + + } + + @Test + public void processTestResultSetRowCallbackHandler() { + + final String isbn = "999999999"; + + final Book b1 = getBook(isbn); + + ResultSet rs = cassandraTemplate.queryAsynchronously("select * from book where isbn='" + isbn + "'", + new ResultSetFutureExtractor() { + + @Override + public ResultSet extractData(ResultSetFuture rs) throws DriverException, DataAccessException { + + ResultSet frs = rs.getUninterruptibly(); + return frs; + } + }); + + assertNotNull(rs); + + cassandraTemplate.process(rs, new RowCallbackHandler() { + + @Override + public void processRow(Row row) throws DriverException { + + assertNotNull(row); + + Book b = new Book(); + b.setIsbn(row.getString("isbn")); + b.setTitle(row.getString("title")); + b.setAuthor(row.getString("author")); + b.setPages(row.getInt("pages")); + + assertBook(b1, b); + + } + }); + + } + /** * Assert that a Book matches the arguments expected *