pojo.setVal("yar");
BidirTopList bidir1 = new BidirBottomList();
BidirTopList bidir2 = new BidirTopList();
bidir1.setChildVal("yam1");
bidir2.setChildVal("yam2");
UnidirTop unidir1 = newUnidir(UnidirLevel.Top);
UnidirTop unidir2 = newUnidir(UnidirLevel.Bottom);
unidir2.setName("max");
unidir2.setStr("another str");
HasKeyPkJPA hasKeyPk1 = new HasKeyPkJPA();
HasKeyPkJPA hasKeyPk2 = new HasKeyPkJPA();
hasKeyPk2.setStr("yar 2");
pojo.getUnidirChildren().add(unidir1);
pojo.getUnidirChildren().add(unidir2);
pojo.getHasKeyPks().add(hasKeyPk1);
pojo.getHasKeyPks().add(hasKeyPk2);
pojo.getBidirChildren().add(bidir1);
pojo.getBidirChildren().add(bidir2);
startEnd.start();
em.persist(pojo);
startEnd.end();
assertCountsInDatastore(HasOneToManyListJPA.class, BidirTopList.class, 1, 2);
String bidir1Id = pojo.getBidirChildren().get(0).getId();
String bookId = pojo.getUnidirChildren().get(0).getId();
Key hasKeyPk1Key = pojo.getHasKeyPks().get(0).getId();
pojo.getBidirChildren().remove(0);
pojo.getUnidirChildren().remove(0);
pojo.getHasKeyPks().remove(0);
startEnd.start();
em.merge(pojo);
startEnd.end();
startEnd.start();
pojo = em.find(pojo.getClass(), pojo.getId());
assertNotNull(pojo.getId());
assertEquals(1, pojo.getUnidirChildren().size());
assertEquals(1, pojo.getHasKeyPks().size());
assertEquals(1, pojo.getBidirChildren().size());
assertNotNull(bidir2.getId());
assertNotNull(bidir2.getParent());
assertNotNull(unidir2.getId());
assertNotNull(hasKeyPk2.getId());
assertEquals(bidir2.getId(), pojo.getBidirChildren().get(0).getId());
assertEquals(hasKeyPk2.getId(), pojo.getHasKeyPks().get(0).getId());
assertEquals(unidir2.getId(), pojo.getUnidirChildren().get(0).getId());
Entity pojoEntity = ds.get(KeyFactory.stringToKey(pojo.getId()));
assertNotNull(pojoEntity);
assertEquals(4, pojoEntity.getProperties().size());
assertEquals(Collections.singletonList(KeyFactory.stringToKey(bidir2.getId())), pojoEntity.getProperty("bidirChildren"));
assertEquals(Collections.singletonList(KeyFactory.stringToKey(unidir2.getId())), pojoEntity.getProperty("unidirChildren"));
assertEquals(Collections.singletonList(hasKeyPk2.getId()), pojoEntity.getProperty("hasKeyPks"));
startEnd.end();
try {
ds.get(KeyFactory.stringToKey(bidir1Id));
fail("expected EntityNotFoundException");
} catch (EntityNotFoundException enfe) {
// good
}
try {
ds.get(KeyFactory.stringToKey(bookId));
fail("expected EntityNotFoundException");
} catch (EntityNotFoundException enfe) {
// good
}
try {
ds.get(hasKeyPk1Key);
fail("expected EntityNotFoundException");
} catch (EntityNotFoundException enfe) {
// good
}
Entity bidirChildEntity = ds.get(KeyFactory.stringToKey(bidir2.getId()));
assertNotNull(bidirChildEntity);
assertEquals(bidir2.getClass().getName(), bidirChildEntity.getProperty("DTYPE"));
assertEquals(bidir2.getPropertyCount(), bidirChildEntity.getProperties().size());
assertEquals("yam2", bidirChildEntity.getProperty("childVal"));
assertEquals(KeyFactory.stringToKey(bidir2.getId()), bidirChildEntity.getKey());
assertKeyParentEquals(pojo.getId(), bidirChildEntity, bidir2.getId());
Entity unidirEntity = ds.get(KeyFactory.stringToKey(unidir2.getId()));
assertNotNull(unidirEntity);
assertEquals(UnidirLevel.Bottom.discriminator, unidirEntity.getProperty("DTYPE"));
assertEquals("max", unidirEntity.getProperty("name"));
assertEquals("another str", unidirEntity.getProperty("str"));
assertEquals(KeyFactory.stringToKey(unidir2.getId()), unidirEntity.getKey());
assertKeyParentEquals(pojo.getId(), unidirEntity, unidir2.getId());
Entity hasKeyPkEntity = ds.get(hasKeyPk2.getId());
assertNotNull(hasKeyPkEntity);
assertEquals("yar 2", hasKeyPkEntity.getProperty("str"));
assertEquals(hasKeyPk2.getId(), hasKeyPkEntity.getKey());