DATACOUCH-86 - Implement Spring4 cache get with cast.

This changeset extends the CouchbaseCache to be compatible with the newly
added method of the Spring 4 cache interface.
This commit is contained in:
Michael Nitschinger
2014-05-19 12:09:15 +02:00
parent 817e112f66
commit a2cd30af3e
2 changed files with 27 additions and 0 deletions

View File

@@ -25,6 +25,8 @@ import org.springframework.data.couchbase.TestApplicationConfig;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.Serializable;
import static org.junit.Assert.*;
/**
@@ -77,6 +79,21 @@ public class CouchbaseCacheTests {
assertEquals(value, loaded.get());
}
@Test
public void testGetSetWithCast() {
CouchbaseCache cache = new CouchbaseCache(cacheName, client);
String key = "couchbase-cache-user";
User user = new User();
user.firstname = "Michael";
cache.put(key, user);
User loaded = cache.get(key, User.class);
assertNotNull(loaded);
assertEquals(user.firstname, loaded.firstname);
}
/**
* Verifies the deletion of cache objects.
*
@@ -114,4 +131,8 @@ public class CouchbaseCacheTests {
assertNull(cache.get(key));
}
static class User implements Serializable {
public String firstname;
}
}