use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method appendToListTest.
@Test
public void appendToListTest() 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());
f = target.appendAsync(id, EntityWithCollections.class, "trades", 3);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getTrades().contains(3));
assertEquals(new Integer(3), loaded.getTrades().get(2));
}
use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method appendAllToSetTest.
@Test
public void appendAllToSetTest() throws Exception {
UUID id = UUID.randomUUID();
EntityWithCollections obj = new EntityWithCollections();
obj.setId(id);
Set<String> refs = new HashSet<String>();
refs.add("100");
refs.add("abc");
obj.setRefs(refs);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(2, loaded.getRefs().size());
Set<String> adds = new HashSet<String>();
adds.add("fgdsfgdsfgd");
adds.add("200");
f = target.appendAsync(id, EntityWithCollections.class, "refs", adds);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getRefs().contains("fgdsfgdsfgd"));
assertEquals(4, loaded.getRefs().size());
}
use of com.datastax.driver.mapping.entity.EntityWithCollections 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.mapping.entity.EntityWithCollections 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);
}
use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method appendToMapTest.
@Test
public void appendToMapTest() throws Exception {
UUID id = UUID.randomUUID();
EntityWithCollections obj = new EntityWithCollections();
obj.setId(id);
Map<String, BigDecimal> rates = new HashMap<String, BigDecimal>();
rates.put("abc", new BigDecimal(100));
rates.put("cde", new BigDecimal(10000.554154));
obj.setRates(rates);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(2, loaded.getRates().size());
Map<String, BigDecimal> add = new HashMap<String, BigDecimal>();
add.put("bcd", new BigDecimal(0.000005555));
f = target.appendAsync(id, EntityWithCollections.class, "rates", add);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getRates().containsKey("bcd"));
assertEquals(new BigDecimal(0.000005555), loaded.getRates().get("bcd"));
assertEquals(3, loaded.getRates().size());
}
Aggregations