@Test
public void testSaveAndDelete() {
getDs().getCollection(Rectangle.class).drop();
final Rectangle rect = new Rectangle(10, 10);
ObjectId id = new ObjectId();
rect.setId(id);
//test delete(entity)
getDs().save(rect);
assertEquals(1, getDs().getCount(rect));
getDs().delete(rect);
assertEquals(0, getDs().getCount(rect));
//test delete(entity, id)
getDs().save(rect);
assertEquals(1, getDs().getCount(rect));
getDs().delete(rect.getClass(), 1);
assertEquals(1, getDs().getCount(rect));
getDs().delete(rect.getClass(), id);
assertEquals(0, getDs().getCount(rect));
//test delete(entity, {id})
getDs().save(rect);
assertEquals(1, getDs().getCount(rect));
getDs().delete(rect.getClass(), Arrays.asList(rect.getId()));
assertEquals(0, getDs().getCount(rect));
//test delete(entity, {id,id})
ObjectId id1 = (ObjectId) getDs().save(new Rectangle(10, 10)).getId();
ObjectId id2 = (ObjectId) getDs().save(new Rectangle(10, 10)).getId();
assertEquals(2, getDs().getCount(rect));
getDs().delete(rect.getClass(), Arrays.<ObjectId>asList(id1, id2));
assertEquals(0, getDs().getCount(rect));
//test delete(Class, {id,id})
id1 = (ObjectId) getDs().save(new Rectangle(20, 20)).getId();
id2 = (ObjectId) getDs().save(new Rectangle(20, 20)).getId();
assertEquals("datastore should have saved two entities with autogenerated ids", 2, getDs().getCount(rect));
getDs().delete(rect.getClass(), Arrays.asList(id1, id2));
assertEquals("datastore should have deleted two entities with autogenerated ids", 0, getDs().getCount(rect));
//test delete(entity, {id}) with one left
id1 = (ObjectId) getDs().save(new Rectangle(20, 20)).getId();
id2 = (ObjectId) getDs().save(new Rectangle(20, 20)).getId();
assertEquals(2, getDs().getCount(rect));
getDs().delete(rect.getClass(), Arrays.asList(id1));
assertEquals(1, getDs().getCount(rect));
getDs().getCollection(Rectangle.class).drop();
//test delete(Class, {id}) with one left
id1 = (ObjectId) getDs().save(new Rectangle(20, 20)).getId();
Key<Rectangle> save = getDs().save(new Rectangle(20, 20));
id2 = (ObjectId) save.getId();
assertEquals(2, getDs().getCount(rect));
getDs().delete(Rectangle.class, Arrays.asList(id1));
assertEquals(1, getDs().getCount(rect));
}