示例#1
0
  @Test
  public void testSaveAndDelete() throws Exception {
    String ns = "hotels";
    Rectangle rect = new Rectangle(10, 10);
    rect.setId("1");

    // test delete(entity, id)
    ads.save(ns, rect);
    assertEquals(1, ads.getCount(ns));
    ads.delete(ns, 1);
    assertEquals(1, ads.getCount(ns));
    ads.delete(ns, "1");
    assertEquals(0, ads.getCount(ns));
  }
示例#2
0
  @Test
  public void testGet() throws Exception {
    String ns = "hotels";
    Rectangle rect = new Rectangle(10, 10);
    rect.setId("1");

    // test delete(entity, id)
    ads.save(ns, rect);
    assertEquals(1, ads.getCount(ns));
    Rectangle rectLoaded = ads.get(ns, Rectangle.class, rect.getId());
    assertEquals(rect.getId(), rectLoaded.getId());
    assertEquals(rect.getArea(), rectLoaded.getArea(), 0);
  }
示例#3
0
  @Test
  public void testFind() throws Exception {
    String ns = "hotels";
    Rectangle rect = new Rectangle(10, 10);
    rect.setId("1");

    // test delete(entity, id)
    ads.save(ns, rect);
    assertEquals(1, ads.getCount(ns));
    Rectangle rectLoaded = ads.find(ns, Rectangle.class).get();
    assertEquals(rect.getId(), rectLoaded.getId());
    assertEquals(rect.getArea(), rectLoaded.getArea(), 0);

    rect = new Rectangle(2, 1);
    rect.setId("2");
    ads.save(rect); // saved to default collection name (kind)
    assertEquals(1, ads.getCount(rect));

    rect.setId("3");
    ads.save(rect); // saved to default collection name (kind)
    assertEquals(2, ads.getCount(rect));

    rect = new Rectangle(4, 3);
    rect.setId("3");
    ads.save(ns, rect);
    assertEquals(2, ads.getCount(ns));
    List<Rectangle> rects = ads.find(ns, Rectangle.class).asList();

    rectLoaded = rects.get(1);
    assertEquals(rect.getId(), rectLoaded.getId());
    assertEquals(rect.getArea(), rectLoaded.getArea(), 0);

    rectLoaded = ads.find(ns, Rectangle.class, "_id !=", "-1", 1, 1).get();
  }
示例#4
0
  @Test
  public void testSaveAndDelete() throws Exception {
    final 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));
    final 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));
  }
示例#5
0
 public void testIdUpdatedOnSave() throws Exception {
   final Rectangle rect = new Rectangle(10, 10);
   ds.save(rect);
   assertNotNull(rect.getId());
 }