Ejemplo n.º 1
0
  @Test
  public void testFind() {
    Product p = new Product("foo", "bar");
    Product pp = dao.save(p);

    String id = KeyFactory.keyToString(pp.getKey());
    Product fp = dao.find(id);

    assertThat("retrieved object matches the persisted one", fp, is(pp));
  }
Ejemplo n.º 2
0
  @Test
  public void testFindAll() {
    Product p2 = dao.save(new Product("foo2", "bar2"));
    Product p1 = dao.save(new Product("foo1", "bar1"));

    List<Product> ps = dao.findAll();

    assertThat("two objects where found", ps.size(), is(2));
    assertThat("retrieved object matches the persisted one", p1, is(ps.get(0)));
    assertThat("retrieved object matches the persisted one", p2, is(ps.get(1)));
  }
Ejemplo n.º 3
0
  @Test(expected = EntityNotFoundException.class)
  public void testDelete() {
    Product p = new Product("foo", "bar");
    Product pp = dao.save(p);

    assumeNotNull(pp.getKey());

    String id = KeyFactory.keyToString(pp.getKey());
    Product fp = dao.find(id);

    dao.delete(fp);

    dao.find(id); // throws EntityNotFoundException
  }
Ejemplo n.º 4
0
  @Test
  public void testSave() {
    Product p = new Product("foo", "bar");
    Product pp = dao.save(p);

    assertThat("persisted product has a key", pp.getKey(), notNullValue());
  }