DATACASS-115 - Completed
Fixed bug in exists() method Added integration tests for exists() method
This commit is contained in:
@@ -117,7 +117,9 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
|
||||
Select select = QueryBuilder.select().countAll().from(entity.getTableName().toCql());
|
||||
appendIdCriteria(select.where(), entity, id);
|
||||
|
||||
return count(select.getQueryString()) != 0;
|
||||
Long count = queryForObject(select, Long.class);
|
||||
|
||||
return count != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,12 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.test.integration.repository;
|
||||
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -29,6 +23,14 @@ import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link UserRepository}.
|
||||
*
|
||||
@@ -141,6 +143,18 @@ public class UserRepositoryIntegrationTests {
|
||||
assertThat(result, not(hasItem(tom)));
|
||||
}
|
||||
|
||||
public void exists() {
|
||||
|
||||
String id = "tom";
|
||||
|
||||
assertTrue(repository.exists(id));
|
||||
|
||||
repository.delete(id);
|
||||
|
||||
assertTrue(!repository.exists(id));
|
||||
|
||||
}
|
||||
|
||||
private static void assertEquals(User user1, User user2) {
|
||||
Assert.assertEquals(user1.getUsername(), user2.getUsername());
|
||||
Assert.assertEquals(user1.getFirstName(), user2.getFirstName());
|
||||
|
||||
@@ -75,4 +75,9 @@ public abstract class UserRepositoryIntegrationTestsDelegator extends
|
||||
public void deletesUserByIdCorrectly() {
|
||||
tests.deletesUserByIdCorrectly();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exists() {
|
||||
tests.exists();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user