BaseFragmentElement rootFragmentElement = page.getRootFragment();
assertTrue(rootFragmentElement instanceof Fragment);
Fragment root = (Fragment)rootFragmentElement;
assertNotNull(root.getFragments());
FragmentImpl frag1 = new FragmentImpl();
frag1.setId("F1");
frag1.setType(Fragment.PORTLET);
frag1.setName("Portlet1");
root.getFragments().add(frag1);
FragmentImpl frag2 = new FragmentImpl();
frag2.setId("F2");
frag2.setType(Fragment.LAYOUT);
frag2.setName("TwoColumns");
frag2.setDecorator("test");
FragmentImpl frag3 = new FragmentImpl();
frag3.setId("F3");
frag3.setType(Fragment.PORTLET);
frag3.setName("Portlet3");
frag3.setDecorator("test");
frag3.setState("minimized");
frag2.getFragments().add(frag3);
root.getFragments().add(frag2);
//Check the construct
assertTrue(root.getFragments().size()==2);
Iterator i = root.getFragments().iterator();
FragmentImpl f = (FragmentImpl)i.next();
assertNotNull(f);
assertTrue(f.getName().equals("Portlet1"));
assertTrue(f.getType().equals(Fragment.PORTLET));
assertTrue(f.getId().equals("F1"));
assertNull(f.getTitle());
assertNull(f.getDecorator());
assertNull(f.getState());
assertTrue(f.getFragments().size()==0);
f = (FragmentImpl)i.next();
assertNotNull(f);
assertTrue(f.getName().equals("TwoColumns"));
assertTrue(f.getType().equals(Fragment.LAYOUT));
assertTrue(f.getFragments().size()==1);
assertTrue(f.getDecorator().equals("test"));
assertTrue(f.getFragments().size()==1);
i = f.getFragments().iterator();
frag1 = (FragmentImpl)i.next();
assertNotNull(frag1);
assertTrue(frag1.getName().equals("Portlet3"));
assertTrue(frag1.getType().equals(Fragment.PORTLET));
//Now change the inner child to a new portlet
frag2 = new FragmentImpl();
frag2.setId("FR4");
frag2.setType(Fragment.PORTLET);
frag2.setName("P4");
frag3 = (FragmentImpl)page.getFragmentById("F3");
assertNotNull(frag3);
f.getFragments().remove(frag3);
frag3 = (FragmentImpl)page.getFragmentById("F3");
assertNull(frag3);
f.getFragments().add(frag2);
assertTrue(f.getFragments().size()==1);
f = (FragmentImpl)f.getFragments().get(0);
assertNotNull(f);
assertTrue(f.getName().equals("P4"));
}