@Test public void testTwoLevelsOfFetch() throws Exception { fact.register(ListNode.class); TestObjectify ofy = fact.begin(); ListNode node3 = new ListNode(); node3.foo = "foo3"; ofy.put(node3); ListNode node2 = new ListNode(); node2.foo = "foo2"; node2.next = Ref.create(node3); ofy.put(node2); ListNode node1 = new ListNode(); node1.foo = "foo1"; node1.next = Ref.create(node2); ofy.put(node1); ofy.clear(); ListNode fetched = ofy.get(Key.create(node1)); assert fetched.foo.equals(node1.foo); assert fetched.next.get().id.equals(node2.id); assert fetched.next.get().foo.equals(node2.foo); assert fetched.next.get().next.get().id.equals(node3.id); assert fetched.next.get().next.get().foo.equals(node3.foo); assert fetched.next.get().next.get().next == null; }
@Test public void testMissingTail() throws Exception { fact.register(ListNode.class); TestObjectify ofy = fact.begin(); // Node2 should not exist but should have a concrete id for node1 ListNode node2 = new ListNode(); node2.id = 999L; ListNode node1 = new ListNode(); node1.foo = "foo1"; node1.next = Ref.create(Key.create(node2)); ofy.put(node1); ofy.clear(); ListNode fetched = ofy.get(Key.create(node1)); assert fetched.foo.equals(node1.foo); assert fetched.next.get() == null; // it was fetched, so this should be initialized and null. }