Package com.googlecode.objectify.test.entity

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


    fact().register(Trivial.class);

    values = Maps.newHashMap();

    for (int i=10; i<15; i++) {
      Trivial triv = new Trivial((long)i, "str"+i, i);
      Key<Trivial> key = ofy().save().entity(triv).now();
      values.put(key, triv);
    }

    keysIt = ofy().load().type(Trivial.class).chunk(BATCH_SIZE).keys().iterator();
View Full Code Here


  public void setUpExtra() {
    fact().register(Trivial.class);

    entities = new ArrayList<>();
    for (long i = 1; i <= MAX_ID; i++)
      entities.add(new Trivial(i, "foo", i));

    Map<Key<Trivial>, Trivial> saved = ofy().save().entities(entities).now();
    keys = new ArrayList<>(saved.keySet());
  }
View Full Code Here

    QueryResultIterator<Trivial> i1 = q1.iterator();

    int which = 0;
    while (i1.hasNext()) {
      which++;
      Trivial triv = i1.next();
      assert triv == entities.get(which-1);
    }

    assert which == MAX_ID;
  }
View Full Code Here

    assert which == 20;
  }

  /** Asserts that the next value in the cursor is the specified position */
  private void assertCursorAt(Cursor cursor, int position) {
    Trivial triv = query().startAt(cursor).first().now();
    assert triv.getSomeNumber() == position;
  }
View Full Code Here

    QueryResultIterator<Trivial> i1 = q1.iterator();

    int which = 0;
    while (i1.hasNext()) {
      which++;
      Trivial trivial = i1.next();
      l1.add(trivial);

      if (which == 15)
        cursor = i1.getCursor();
    }

    assert l1.size() == 20;

    List<Trivial> l2 = new ArrayList<>();

    Query<Trivial> q2 = query().limit(20).startAt(cursor);
    QueryResultIterator<Trivial> i2 = q2.iterator();

    while (i2.hasNext()) {
      Trivial trivial = i2.next();
      l2.add(trivial);
    }
    assert l2.size() == 15;

    assert l2.get(0) == l1.get(15);
View Full Code Here

  @Test
  public void testOrderOfBulkGet()
  {
    fact().register(Trivial.class);

    Trivial t1 = new Trivial("foo", 5);
    Trivial t2 = new Trivial("bar", 6);

    Key<Trivial> k1 = ofy().save().entity(t1).now();
    Key<Trivial> k2 = ofy().save().entity(t2).now();

    // get k1, then k2
View Full Code Here

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

    // Note that 5 is not the id, it's part of the payload
    Trivial triv = new Trivial("foo", 5);
    Key<Trivial> k = ofy().save().entity(triv).now();

    assert k.getKind().equals(triv.getClass().getSimpleName());
    assert k.getId() == triv.getId();

    Key<Trivial> created = Key.create(Trivial.class, k.getId());
    assert k.equals(created);

    Trivial fetched = ofy().load().key(k).now();

    assert fetched.getId().equals(k.getId());
    assert fetched.getSomeNumber() == triv.getSomeNumber();
    assert fetched.getSomeString().equals(triv.getSomeString());
  }
View Full Code Here

  /** */
  @Test
  public void savingEntityWithSameIdOverwritesData() throws Exception {
    fact().register(Trivial.class);

    Trivial triv = new Trivial("foo", 5);
    Key<Trivial> k = ofy().save().entity(triv).now();

    Trivial triv2 = new Trivial(k.getId(), "bar", 6);
    Key<Trivial> k2 = ofy().save().entity(triv2).now();

    assert k2.equals(k);

    Trivial fetched = ofy().load().key(k).now();

    assert fetched.getId() == k.getId();
    assert fetched.getSomeNumber() == triv2.getSomeNumber();
    assert fetched.getSomeString().equals(triv2.getSomeString());
  }
View Full Code Here

  /** */
  @Test
  public void testBatchOperations() throws Exception {
    fact().register(Trivial.class);

    Trivial triv1 = new Trivial("foo", 5);
    Trivial triv2 = new Trivial("foo2", 6);

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

    Map<Key<Trivial>, Trivial> map = ofy().save().entities(objs).now();
    List<Key<Trivial>> keys = new ArrayList<>(map.keySet());

    // Verify the put keys
    assert keys.size() == objs.size();
    for (int i=0; i<objs.size(); i++)
    {
      assert keys.get(i).getId() == objs.get(i).getId();
    }

    // Now fetch and verify the data
    Map<Key<Trivial>, Trivial> fetched = ofy().load().keys(keys);

    assert fetched.size() == keys.size();
    for (Trivial triv: objs)
    {
      Trivial fetchedTriv = fetched.get(Key.create(triv));
      assert triv.getSomeNumber() == fetchedTriv.getSomeNumber();
      assert triv.getSomeString().equals(fetchedTriv.getSomeString());
    }
  }
View Full Code Here

  /** */
  @Test
  public void testConsistencySetting() throws Exception {
    fact().register(Trivial.class);

    Trivial triv = new Trivial("foo", 5);
    ofy().consistency(Consistency.EVENTUAL).save().entity(triv).now();
  }
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.