@Test public void testCreateAndManageChild() { TestEntity result = entity.createAndManageChild(TestEntity.Spec.newInstance()); assertIsProxy(result); assertIsProxy(Iterables.get(entity.getChildren(), 0)); assertIsProxy(result.getParent()); assertIsProxy(managementContext.getEntityManager().getEntity(result.getId())); }
@Test public void testRestoresEntityHierarchy() throws Exception { TestEntity origE = origApp.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity origE2 = origE.createAndManageChild(EntitySpec.create(TestEntity.class)); newApp = rebind(); // Assert has expected config/fields assertEquals(newApp.getId(), origApp.getId()); assertEquals(newApp.getChildren().size(), 1); TestEntity newE = (TestEntity) Iterables.get(newApp.getChildren(), 0); assertEquals(newE.getId(), origE.getId()); assertEquals(newE.getChildren().size(), 1); TestEntity newE2 = (TestEntity) Iterables.get(newE.getChildren(), 0); assertEquals(newE2.getId(), origE2.getId()); assertNotSame(origApp, newApp); assertNotSame(origApp.getManagementContext(), newApp.getManagementContext()); assertNotSame(origE, newE); assertNotSame(origE2, newE2); }
@Test public void testRestoresUnmatchedConfig() throws Exception { TestEntity origE = origApp.createAndManageChild( EntitySpec.create(TestEntity.class).configure("myunmatchedkey", "myunmatchedval")); origE.createAndManageChild(EntitySpec.create(TestEntity.class)); newApp = rebind(); final TestEntity newE = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); final TestEntity newChildE = (TestEntity) Iterables.find(newE.getChildren(), Predicates.instanceOf(TestEntity.class)); assertEquals(newE.getAllConfigBag().getStringKey("myunmatchedkey"), "myunmatchedval"); assertEquals(newE.getLocalConfigBag().getStringKey("myunmatchedkey"), "myunmatchedval"); assertEquals(newChildE.getAllConfigBag().getStringKey("myunmatchedkey"), "myunmatchedval"); assertFalse(newChildE.getLocalConfigBag().containsKey("myunmatchedkey")); }