DATACASS-35: Unit Tests for CassandraOperations

This commit is contained in:
David Webb
2013-11-26 16:51:54 -05:00
parent 2adbe62c9a
commit 16f101f3ab

View File

@@ -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<ResultSet>() {
@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
*