Package com.googlecode.objectify.test.entity

Examples of com.googlecode.objectify.test.entity.Trivial


  /** */
  @BeforeMethod
  public void createTwo() {
    fact().register(Trivial.class);

    t1 = new Trivial("foo", 11);
    k1 = ofy().save().entity(t1).now();

    t2 = new Trivial("bar", 22);
    k2 = ofy().save().entity(t2).now();

    tNone1 = new Trivial(123L, "fooNone", 33);
    tNone2 = new Trivial(456L, "barNone", 44);

    kNone1 = Key.create(tNone1);
    kNone2 = Key.create(tNone2);
  }
View Full Code Here


  @Test
  public void testMapifyTrivials() throws Exception {
    fact().register(Trivial.class);
    fact().register(HasMapifyTrivial.class);

    Trivial triv = new Trivial("foo", 123L);
    Key<Trivial> trivKey = ofy().save().entity(triv).now();

    HasMapifyTrivial hasMap = new HasMapifyTrivial();
    hasMap.trivials.put(trivKey, Ref.create(triv));
View Full Code Here

  /** */
  @BeforeMethod
  public void createTwo() {
    fact().register(Trivial.class);

    t1 = new Trivial("foo", 11);
    k1 = ofy().save().entity(t1).now();

    t2 = new Trivial("bar", 22);
    k2 = ofy().save().entity(t2).now();

    tNone1 = new Trivial(123L, "fooNone", 33);
    tNone2 = new Trivial(456L, "barNone", 44);

    kNone1 = Key.create(tNone1);
    kNone2 = Key.create(tNone2);
  }
View Full Code Here

  /** */
  @Test
  public void deferredSaveAndDeleteProcessedAtEndOfRequest() throws Exception {

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

    try (Closeable root = TestObjectifyService.begin()) {
      ofy().defer().save().entity(triv);

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

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

    try (Closeable root = TestObjectifyService.begin()) {
      Trivial loaded = ofy().load().entity(triv).now();
      assertThat(loaded, equalTo(triv));
    }

    try (Closeable root = TestObjectifyService.begin()) {
      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";
      }
    }

    try (Closeable root = TestObjectifyService.begin()) {
      Trivial loaded = ofy().load().entity(triv).now();
      assertThat(loaded, nullValue());
    }
  }
View Full Code Here

  /** */
  @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());
      }
    }
  }
View Full Code Here

  /** */
  @BeforeMethod
  public void setUpExtra() {
    fact().register(Trivial.class);

    this.triv1 = new Trivial("foo1", 1);
    this.triv2 = new Trivial("foo2", 2);

    List<Trivial> trivs = new ArrayList<>();
    trivs.add(this.triv1);
    trivs.add(this.triv2);

View Full Code Here

  /** */
  @Test
  public void testNormalSorting() throws Exception {
    Iterator<Trivial> it = ofy().load().type(Trivial.class).order("someString").iterator();

    Trivial t1 = it.next();
    Trivial t2 = it.next();

    assert t1.getId().equals(triv1.getId());
    assert t2.getId().equals(triv2.getId());
  }
View Full Code Here

  @Test
  public void testNormalReverseSorting() throws Exception {
    Iterator<Trivial> it = ofy().load().type(Trivial.class).order("-someString").iterator();

    // t2 first
    Trivial t2 = it.next();
    Trivial t1 = it.next();

    assert t1.getId().equals(triv1.getId());
    assert t2.getId().equals(triv2.getId());
  }
View Full Code Here

  /** */
  @Test
  public void testKeySorting() throws Exception {
    Iterator<Trivial> it = ofy().load().type(Trivial.class).orderKey(false).iterator();

    Trivial t1 = it.next();
    Trivial t2 = it.next();

    assert t1.getId().equals(triv1.getId());
    assert t2.getId().equals(triv2.getId());
  }
View Full Code Here

  @Test
  public void testKeyReverseSorting() throws Exception {
    Iterator<Trivial> it = ofy().load().type(Trivial.class).orderKey(true).iterator();

    // t2 first
    Trivial t2 = it.next();
    Trivial t1 = it.next();

    assert t1.getId().equals(triv1.getId());
    assert t2.getId().equals(triv2.getId());
  }
View Full Code Here

TOP

Related Classes of com.googlecode.objectify.test.entity.Trivial

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.