use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method saveEntityWithStringEnumTest.
@Test
public void saveEntityWithStringEnumTest() throws Exception {
UUID uuid = UUID.randomUUID();
EntityWithStringEnum obj = new EntityWithStringEnum();
obj.setId(uuid);
obj.setPage(Page.GITHUB);
EntityWithStringEnum loaded = target.get(EntityWithStringEnum.class, uuid);
assertNull(loaded);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
loaded = target.get(EntityWithStringEnum.class, uuid);
assertEquals(obj, loaded);
obj.setPage(Page.CASSANDRA);
f = target.saveAsync(obj);
f.getUninterruptibly();
loaded = target.get(EntityWithStringEnum.class, uuid);
assertEquals(obj, loaded);
f = target.deleteAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithStringEnum.class, uuid);
assertNull(loaded);
}
use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method appendAllToListTest.
@Test
public void appendAllToListTest() throws Exception {
UUID id = UUID.randomUUID();
EntityWithCollections obj = new EntityWithCollections();
obj.setId(id);
List<Integer> trades = new ArrayList<Integer>();
trades.add(1);
trades.add(2);
obj.setTrades(trades);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(2, loaded.getTrades().size());
List<Integer> adds = new ArrayList<Integer>();
adds.add(5);
adds.add(6);
f = target.appendAsync(id, EntityWithCollections.class, "trades", adds);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getTrades().contains(5));
assertEquals(4, loaded.getTrades().size());
}
use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method saveAndGetAndDeleteMixedCaseTest.
@Test
public void saveAndGetAndDeleteMixedCaseTest() throws Exception {
int id = 12245;
EntityMixedCase obj = new EntityMixedCase();
obj.setId(id);
obj.setFirstName("firstName");
obj.setLastName("lastName");
obj.setAge(25);
EntityMixedCase loaded = target.get(EntityMixedCase.class, id);
assertNull(loaded);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
loaded = target.get(EntityMixedCase.class, id);
assertEquals(obj, loaded);
f = target.deleteAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityMixedCase.class, id);
assertNull(loaded);
}
use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method updateIndividualPropertyTest.
@Test
public void updateIndividualPropertyTest() throws Exception {
UUID uuid = UUID.randomUUID();
Simple obj = new Simple();
obj.setName("myName");
obj.setAge(55);
obj.setId(uuid);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
f = target.updateValueAsync(uuid, Simple.class, "name", "yourName");
f.getUninterruptibly();
f = target.updateValueAsync(uuid, Simple.class, "age", 25);
f.getUninterruptibly();
Simple loaded = target.get(Simple.class, uuid);
assertEquals(25, loaded.getAge());
assertEquals("yourName", loaded.getName());
// String-Enum
EntityWithStringEnum seobj = new EntityWithStringEnum();
seobj.setId(uuid);
seobj.setPage(Page.DATASTAX);
f = target.saveAsync(seobj);
f.getUninterruptibly();
f = target.updateValueAsync(uuid, EntityWithStringEnum.class, "page", Page.CASSANDRA.toString());
f.getUninterruptibly();
EntityWithStringEnum eloaded = target.get(EntityWithStringEnum.class, uuid);
assertEquals(Page.CASSANDRA, Page.getPage(eloaded.getPage()));
}
use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method testCollections.
@Test
public void testCollections() throws Exception {
EntityWithCollections obj = new EntityWithCollections();
UUID uuid = UUID.randomUUID();
obj.setId(uuid);
target.save(obj);
EntityWithCollections loaded = target.get(EntityWithCollections.class, uuid);
Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
map.put("key1", new BigDecimal(100.55));
map.put("key1", new BigDecimal(100.55555));
map.put("key1", new BigDecimal(101.5500000333));
obj.setRates(map);
List<Integer> list = new ArrayList<Integer>();
list.add(100);
list.add(200);
list.add(300);
obj.setTrades(list);
Set<String> set = new HashSet<String>();
set.add("100");
set.add("200");
set.add("300");
obj.setRefs(set);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, uuid);
assertEquals(obj, loaded);
}
Aggregations