Exemplo n.º 1
0
  @Test
  public void deferredSaveWithAutogeneratedId() throws Exception {

    Trivial triv = new Trivial("foo", 5);

    try (Closeable root = TestObjectifyService.begin()) {
      ofy().defer().save().entity(triv);
    }
  }
Exemplo n.º 2
0
  @Test
  public void deferredSaveAndDeleteProcessedAtEndOfTransaction() throws Exception {

    final Trivial triv = new Trivial(123L, "foo", 5);

    try (Closeable root = TestObjectifyService.begin()) {

      ofy()
          .transact(
              new VoidWork() {
                @Override
                public void vrun() {
                  ofy().defer().save().entity(triv);

                  // Can load out of session
                  assertThat(ofy().load().entity(triv).now(), is(triv));

                  // But not datastore
                  try {
                    ds().get(null, Key.create(triv).getRaw());
                    assert false : "Entity should not have been saved yet";
                  } catch (EntityNotFoundException e) {
                    // correct
                  }
                }
              });

      {
        Trivial loaded = ofy().load().entity(triv).now();
        assertThat(loaded, equalTo(triv));
      }

      ofy()
          .transact(
              new VoidWork() {
                @Override
                public void vrun() {
                  ofy().defer().delete().entity(triv);

                  // Deleted in session
                  assertThat(ofy().load().entity(triv).now(), nullValue());

                  // But not datastore
                  try {
                    ds().get(null, Key.create(triv).getRaw());
                  } catch (EntityNotFoundException e) {
                    assert false : "Entity should not have been deleted yet";
                  }
                }
              });

      {
        Trivial loaded = ofy().load().entity(triv).now();
        assertThat(loaded, nullValue());
      }
    }
  }
Exemplo n.º 3
0
  @BeforeMethod
  public void setUp() throws Exception {
    TestObjectifyService.setFactory(new TestObjectifyFactory());

    fact().register(Trivial.class);
  }