use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method deleteTest.
@Test
public void deleteTest() 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());
f = target.deleteValueAsync(id, EntityWithCollections.class, "rates");
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertEquals(0, loaded.getRates().size());
}
use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method appendAtTest.
@Test
public void appendAtTest() throws Exception {
UUID id = UUID.randomUUID();
EntityWithCollections obj = new EntityWithCollections();
obj.setId(id);
List<Integer> trades = new ArrayList<Integer>();
trades.add(100);
trades.add(200);
trades.add(300);
obj.setTrades(trades);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(3, loaded.getTrades().size());
f = target.replaceAtAsync(id, EntityWithCollections.class, "trades", 3, 0);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertEquals(new Integer(3), loaded.getTrades().get(0));
assertEquals(3, loaded.getTrades().size());
f = target.replaceAtAsync(id, EntityWithCollections.class, "trades", 33, 2);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertEquals(new Integer(33), loaded.getTrades().get(2));
assertEquals(3, loaded.getTrades().size());
f = target.replaceAtAsync(id, EntityWithCollections.class, "trades", 22, 1);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertEquals(new Integer(22), loaded.getTrades().get(1));
assertEquals(3, loaded.getTrades().size());
}
use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method prependTest.
@Test
public void prependTest() 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.prependAsync(id, EntityWithCollections.class, "trades", adds);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertEquals(new Integer(6), loaded.getTrades().get(0));
assertEquals(new Integer(5), loaded.getTrades().get(1));
assertEquals(new Integer(1), loaded.getTrades().get(2));
assertEquals(new Integer(2), loaded.getTrades().get(3));
f = target.prependAsync(id, EntityWithCollections.class, "trades", 10);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertEquals(new Integer(10), loaded.getTrades().get(0));
}
use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method addToListTest.
@Test
public void addToListTest() throws Exception {
UUID id = UUID.randomUUID();
EntityWithCollections obj = new EntityWithCollections();
obj.setId(id);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(0, loaded.getTrades().size());
loaded.addTrade(200);
f = target.saveAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getTrades().contains(200));
assertEquals(1, loaded.getTrades().size());
loaded.addTrade(300);
f = target.saveAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getTrades().contains(300));
assertEquals(2, loaded.getTrades().size());
}
use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method addToMapTest.
@Test
public void addToMapTest() throws Exception {
UUID id = UUID.randomUUID();
EntityWithCollections obj = new EntityWithCollections();
obj.setId(id);
ResultSetFuture f = target.saveAsync(obj);
f.getUninterruptibly();
EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
assertEquals(0, loaded.getRates().size());
loaded.addRate("200", new BigDecimal("100"));
f = target.saveAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getRates().containsKey("200"));
assertEquals(1, loaded.getRates().size());
loaded.addRate("300", new BigDecimal("300"));
f = target.saveAsync(loaded);
f.getUninterruptibly();
loaded = target.get(EntityWithCollections.class, id);
assertTrue(loaded.getRates().containsKey("300"));
assertEquals(2, loaded.getRates().size());
}
Aggregations