assertNotNull(rect.getId());
}
@Test
public void testSaveAndDelete() throws Exception {
Rectangle rect = new Rectangle(10, 10);
rect.setId("1");
//test delete(entity)
ds.save(rect);
assertEquals(1, ds.getCount(rect));
ds.delete(rect);
assertEquals(0, ds.getCount(rect));
//test delete(entity, id)
ds.save(rect);
assertEquals(1, ds.getCount(rect));
ds.delete(rect.getClass(), 1);
assertEquals(1, ds.getCount(rect));
ds.delete(rect.getClass(), "1");
assertEquals(0, ds.getCount(rect));
//test delete(entity, {id})
ds.save(rect);
assertEquals(1, ds.getCount(rect));
List<String> ids = new ArrayList<String>();
ids.add("1");
ds.delete(rect.getClass(), ids);
assertEquals(0, ds.getCount(rect));
//test delete(entity, {id,id})
rect.setId("1");
ds.save(rect);
rect.setId("2");
ds.save(rect);
assertEquals(2, ds.getCount(rect));
ids.clear(); ids.add("1"); ids.add("2");
ds.delete(rect.getClass(), ids);
assertEquals(0, ds.getCount(rect));
//test delete(entity, {id,id}) with autogenerated ids
ids.clear();
rect.setId(new ObjectId().toString()); // rect1
ds.save(rect);
ids.add(rect.getId());
rect.setId(new ObjectId().toString()); // rect2
ds.save(rect);
ids.add(rect.getId());
assertEquals("datastore should have saved two entities with autogenerated ids", 2, ds.getCount(rect));
ds.delete(rect.getClass(), ids);
assertEquals("datastore should have deleted two entities with autogenerated ids", 0, ds.getCount(rect));
//test delete(entity, {id}) with one left
rect.setId("1");
ds.save(rect);
rect.setId("2");
ds.save(rect);
assertEquals(2, ds.getCount(rect));
ids.clear(); ids.add("1");
ds.delete(rect.getClass(), ids);
assertEquals(1, ds.getCount(rect));
//test delete(Class, {id}) with one left
rect.setId("1");
ds.save(rect);
rect.setId("2");
ds.save(rect);
assertEquals(2, ds.getCount(rect));
ids.clear(); ids.add("1");
ds.delete(Rectangle.class, ids);
assertEquals(1, ds.getCount(rect));