Adding initial CRUD repository implementation.

This commit is contained in:
Michael Nitschinger
2013-05-29 12:22:27 +02:00
parent a307d8f595
commit 4c320a9473
11 changed files with 376 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
package com.couchbase.spring.repository;
import com.couchbase.spring.TestApplicationConfig;
import com.couchbase.spring.core.CouchbaseTemplate;
import com.couchbase.spring.repository.support.CouchbaseRepositoryFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = TestApplicationConfig.class)
public class SimpleCouchbaseRepositoryTest {
@Autowired
private CouchbaseTemplate template;
@Test
public void simpleCrud() {
String key = "my_unique_user_key";
RepositoryFactorySupport factory = new CouchbaseRepositoryFactory(template);
UserRepository repository = factory.getRepository(UserRepository.class);
User instance = new User(key, "foobar");
repository.save(instance);
User found = repository.findOne(key);
assertEquals(instance.getKey(), found.getKey());
assertEquals(instance.getUsername(), found.getUsername());
assertTrue(repository.exists(key));
repository.delete(found);
assertNull(repository.findOne(key));
assertFalse(repository.exists(key));
}
}

View File

@@ -0,0 +1,32 @@
package com.couchbase.spring.repository;
import org.springframework.data.annotation.Id;
/**
* Created with IntelliJ IDEA.
* User: michael
* Date: 5/29/13
* Time: 10:27 AM
* To change this template use File | Settings | File Templates.
*/
public class User {
@Id
private final String key;
private final String username;
public User(String key, String username) {
this.key = key;
this.username = username;
}
public String getUsername() {
return username;
}
public String getKey() {
return key;
}
}

View File

@@ -0,0 +1,6 @@
package com.couchbase.spring.repository;
public interface UserRepository extends CouchbaseRepository<User, String>{
}