diff --git a/pom.xml b/pom.xml
index 36bb9b097..335689a37 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,6 +64,7 @@
Alex Shvid
a at shvid.com
+ Project Lead
Developer
-8
diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraDataTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraDataTemplate.java
index 9b2c175a3..eea7683a1 100644
--- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraDataTemplate.java
+++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraDataTemplate.java
@@ -989,6 +989,8 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
*/
private T doSelectOne(final String query, ReadRowCallback readRowCallback) {
+ logger.info(query);
+
/*
* Run the Query
*/
diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java
index 1569092bf..fc33c7a07 100644
--- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java
+++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java
@@ -15,13 +15,21 @@
*/
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.io.IOException;
+import java.util.Arrays;
+import java.util.List;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.thrift.transport.TTransportException;
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
-import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -32,6 +40,8 @@ import org.springframework.data.cassandra.test.integration.table.User;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import com.google.common.collect.Lists;
+
/**
* Base class for tests for {@link UserRepository}.
*
@@ -48,7 +58,9 @@ public class UserRepositoryIntegrationTests {
@Autowired
protected CassandraDataOperations dataOperations;
- User alex;
+ User tom, bob, alice, scott;
+
+ List all;
@BeforeClass
public static void startCassandra() throws IOException, TTransportException, ConfigurationException,
@@ -61,31 +73,96 @@ public class UserRepositoryIntegrationTests {
repository.deleteAll();
- alex = new User();
- alex.setUsername("alex");
- alex.setFirstName("Alex");
- alex.setLastName("Shvid");
- alex.setPassword("123");
- alex.setPlace("SF");
+ tom = new User();
+ tom.setUsername("tom");
+ tom.setFirstName("Tom");
+ tom.setLastName("Ron");
+ tom.setPassword("123");
+ tom.setPlace("SF");
- dataOperations.insert(alex);
+ bob = new User();
+ bob.setUsername("bob");
+ bob.setFirstName("Bob");
+ bob.setLastName("White");
+ bob.setPassword("555");
+ bob.setPlace("NY");
+
+ alice = new User();
+ alice.setUsername("alice");
+ alice.setFirstName("Alice");
+ alice.setLastName("Red");
+ alice.setPassword("777");
+ alice.setPlace("LA");
+
+ scott = new User();
+ scott.setUsername("scott");
+ scott.setFirstName("Scott");
+ scott.setLastName("Van");
+ scott.setPassword("444");
+ scott.setPlace("Boston");
+
+ all = dataOperations.insert(Arrays.asList(tom, bob, alice, scott));
+ }
+
+ @Test
+ public void findsUserById() throws Exception {
+
+ User user = repository.findOne(bob.getUsername());
+ Assert.assertNotNull(user);
+ assertEquals(bob, user);
}
@Test
- public void findsProfileById() throws Exception {
+ public void findsAll() throws Exception {
+ List result = Lists.newArrayList(repository.findAll());
+ assertThat(result.size(), is(all.size()));
+ assertThat(result.containsAll(all), is(true));
- System.out.println("find profile by id");
}
- @After
- public void clearCassandra() {
- EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
+ @Test
+ public void findsAllWithGivenIds() {
+
+ Iterable result = repository.findAll(Arrays.asList(bob.getUsername(), tom.getUsername()));
+ assertThat(result, hasItems(bob, tom));
+ assertThat(result, not(hasItems(alice, scott)));
+ }
+
+ @Test
+ public void deletesUserCorrectly() throws Exception {
+
+ repository.delete(tom);
+
+ List result = Lists.newArrayList(repository.findAll());
+
+ assertThat(result.size(), is(all.size() - 1));
+ assertThat(result, not(hasItem(tom)));
+ }
+
+ @Test
+ public void deletesUserByIdCorrectly() {
+
+ repository.delete(tom.getUsername().toString());
+
+ List result = Lists.newArrayList(repository.findAll());
+
+ assertThat(result.size(), is(all.size() - 1));
+ assertThat(result, not(hasItem(tom)));
}
@AfterClass
public static void stopCassandra() {
+ EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
EmbeddedCassandraServerHelper.stopEmbeddedCassandra();
}
+ private static void assertEquals(User user1, User user2) {
+ Assert.assertEquals(user1.getUsername(), user2.getUsername());
+ Assert.assertEquals(user1.getFirstName(), user2.getFirstName());
+ Assert.assertEquals(user1.getLastName(), user2.getLastName());
+ Assert.assertEquals(user1.getPlace(), user2.getPlace());
+ Assert.assertEquals(user1.getPassword(), user2.getPassword());
+ }
+
}
diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/table/User.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/table/User.java
index fb2f9dfb9..2586d0273 100644
--- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/table/User.java
+++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/table/User.java
@@ -155,4 +155,29 @@ public class User {
this.birthYear = birthYear;
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((username == null) ? 0 : username.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ User other = (User) obj;
+ if (username == null) {
+ if (other.username != null)
+ return false;
+ } else if (!username.equals(other.username))
+ return false;
+ return true;
+ }
+
}