/** Test key from kind and name. */ public void testKeyFromKindAndName() { Key key = new Key(kind, name); assertEquals(kind, key.getKind()); assertEquals(name, key.getName()); assertNull(key.getParent()); assertEquals(0L, key.getId()); }
@Test public void testMarshall_Embedded() { RootEntity rootObject = new RootEntity(); // one entity ChildEntity childObject = new ChildEntity("Test City"); ChildEntity embeddedObject = new ChildEntity("Old Test City"); embeddedObject.setId(1L); embeddedObject.setType("EmbeddedType"); rootObject.setId("TestUser"); rootObject.setCount(25); childObject.setParent(rootObject); rootObject.setNewChildEntity(childObject); // one entity rootObject.setEmbeddedEntity(embeddedObject); // not included, @Embedded IdentityHashMap<Object, Entity> stack = testMarshaller.marshall(null, rootObject); Entity rootObjectEntity = stack.get(rootObject); Entity childObjectEntity = stack.get(childObject); EmbeddedEntity ee = (EmbeddedEntity) rootObjectEntity.getProperty("embeddedEntity"); Key childKey = (Key) rootObjectEntity.getProperty("newChildEntity"); Key parentKey = childKey.getParent(); assertEquals(2, stack.size()); assertNotNull(parentKey); assertEquals(EmbeddedEntity.class, ee.getClass()); assertTrue(childKey instanceof Key); assertEquals(rootObjectEntity.getKey().getId(), parentKey.getId()); assertEquals(rootObjectEntity.getKey().getName(), parentKey.getName()); assertEquals(1L, ee.getProperties().get("id")); assertEquals("EmbeddedType", ee.getProperties().get("type")); }
/** Test key from kind, parent and name. */ public void testKeyFromKindParentAndName() { Key parent = new Key(kind); Key key = new Key(kind, parent, name); assertEquals(kind, key.getKind()); assertEquals(name, key.getName()); assertEquals(parent, key.getParent()); assertEquals(0L, key.getId()); }
/** Test key from kind, parent and id. */ public void testKeyFromKindParentAndId() { Key parent = new Key(kind); Key key = new Key(kind, parent, id); assertEquals(kind, key.getKind()); assertNull(key.getName()); assertEquals(id, key.getId()); assertEquals(parent, key.getParent()); }
public String toString() { StringBuilder b = new StringBuilder(); Key k = KeyFactory.stringToKey(key); b.append("Question (").append(k.getId()).append(") : ").append(" Text=").append(questionText); b.append(" Date Posted=").append(datePosted); b.append(" ParentInfo = ").append(k.getParent().toString()); b.append("\n"); for (Comment c : comments) { b.append("\t\t").append(c.toString()).append("\n"); } return b.toString(); }
@Test public void testMarshall_Child() { RootEntity rootObject = new RootEntity(); // one entity ChildEntity childObject = new ChildEntity("Test City"); rootObject.setId("TestUser"); rootObject.setCount(25); childObject.setParent(rootObject); rootObject.setNewChildEntity(childObject); // one entity IdentityHashMap<Object, Entity> stack = testMarshaller.marshall(null, rootObject); Entity rootObjectEntity = stack.get(rootObject); Entity childObjectEntity = stack.get(childObject); Key childKey = (Key) rootObjectEntity.getProperty("newChildEntity"); Key parentKey = childKey.getParent(); assertEquals(2, stack.size()); assertNotNull(parentKey); assertTrue(childKey instanceof Key); assertEquals(rootObjectEntity.getKey().getId(), parentKey.getId()); assertEquals(rootObjectEntity.getKey().getName(), parentKey.getName()); }