Author: julien(a)jboss.com
Date: 2007-12-26 12:08:59 -0500 (Wed, 26 Dec 2007)
New Revision: 9387
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
implement test cases that test that model navigation can invalidate the model
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26
16:32:38 UTC (rev 9386)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26
17:08:59 UTC (rev 9387)
@@ -77,7 +77,7 @@
this.root = (UIContext)root;
// Update universe
- universe.put(rootId, root);
+ put(root);
}
private UIContainerObject create(StructuralObject structuralObject)
@@ -115,7 +115,7 @@
StructuralObject.Update update = (StructuralObject.Update)change;
//
- UIContainerObject object = universe.get(update.getObject().getId());
+ UIContainerObject object = get(update.getObject());
//
if (object == null)
@@ -132,7 +132,7 @@
StructuralObject.Creation creation = (StructuralObject.Creation)change;
//
- UIContainerObject parent = universe.get(creation.getParent().getId());
+ UIContainerObject parent = get(creation.getParent());
//
if (parent == null)
@@ -152,7 +152,7 @@
UIContainerObject child = create(creation.getChild());
//
- universe.put(creation.getChild().getId(), child);
+ put(child);
//
parentContext.children.relateds.add(child);
@@ -163,7 +163,7 @@
StructuralObject.Destruction destruction =
(StructuralObject.Destruction)change;
//
- UIContainerObject parent = universe.get(destruction.getParent().getId());
+ UIContainerObject parent = get(destruction.getParent());
//
if (parent != null)
@@ -231,7 +231,7 @@
*/
UIContainerObject getObject(String id)
{
- UIContainerObject object = universe.get(id);
+ UIContainerObject object = get(id);
//
if (object != null)
@@ -249,7 +249,7 @@
object = create(structuralObject);
//
- universe.put(structuralObject.getId(), object);
+ put(object);
//
return object;
@@ -366,6 +366,16 @@
}
}
+ ManyToOne createManyToOne(UIObjectContext context)
+ {
+ return new ManyToOne(context);
+ }
+
+ OneToMany createOneToMany(UIObjectContext context)
+ {
+ return new OneToMany(context);
+ }
+
// Private
**********************************************************************************************************
// /**
@@ -404,11 +414,21 @@
// return containerObject;
// }
- public ManyToOne createManyToOne(UIObjectContext context)
+ private void put(UIContainerObject object)
{
- return new ManyToOne(context);
+ universe.put(object.getId(), object);
}
+ private UIContainerObject get(String id)
+ {
+ return universe.get(id);
+ }
+
+ private UIContainerObject get(StructuralObject so)
+ {
+ return universe.get(so.getId());
+ }
+
class ManyToOne
{
@@ -435,7 +455,7 @@
// If null it is the root so nothing is done
if (parentSO != null)
{
- UIContainerObject parent = universe.get(parentSO.getId());
+ UIContainerObject parent = UIObjectContainer.this.get(parentSO);
//
if (parent != null)
@@ -456,7 +476,7 @@
parent = create(parentSO);
//
- universe.put(parentSO.getId(), parent);
+ put(parent);
//
related = parent;
@@ -478,11 +498,6 @@
}
}
- public OneToMany createOneToMany(UIObjectContext context)
- {
- return new OneToMany(context);
- }
-
class OneToMany
{
@@ -519,7 +534,7 @@
//
for (StructuralObject childSO :
structuralStateContext.loadChildren(structuralObject))
{
- UIContainerObject child = universe.get(childSO.getId());
+ UIContainerObject child = UIObjectContainer.this.get(childSO);
//
if (child != null)
@@ -537,7 +552,7 @@
child = create(childSO);
//
- universe.put(childSO.getId(), child);
+ put(child);
}
//
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-26
16:32:38 UTC (rev 9386)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-26
17:08:59 UTC (rev 9387)
@@ -45,6 +45,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.HashSet;
+import java.util.Set;
+import java.util.Map;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -539,6 +541,112 @@
assertEquals(null, context.getObject(daaId));
}
+ public void testParentNavigationUpdatesExistingParentStatus() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+
+ //
+ String fooId = mockFoo.getId();
+ String juuId = mockJuu.getId();
+
+ //
+ UIContext context = createContext();
+
+ // Get the object
+ UIObject foo = context.getObject(fooId);
+ UIObject juu = context.getObject(juuId);
+
+ //
+ assertEquals(UIObject.Status.VALID, juu.getStatus());
+ assertEquals(UIObject.Status.VALID, foo.getStatus());
+
+ // Now update foo concurrently
+ mockFoo.setPropertyValue("abc", "def");
+
+ // Now navigate
+ UIObject foo2 = juu.getParent();
+
+ //
+ assertSame(foo, foo2);
+ assertEquals(UIObject.Status.VALID, juu.getStatus());
+ assertEquals(UIObject.Status.STALE, foo.getStatus());
+ }
+
+ public void testChildrenNavigationUpdatesExistingChildStatus() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+
+ //
+ String fooId = mockFoo.getId();
+ String juuId = mockJuu.getId();
+
+ //
+ UIContext context = createContext();
+
+ // Get the object
+ UIObject foo = context.getObject(fooId);
+ UIObject juu = context.getObject(juuId);
+
+ //
+ assertEquals(UIObject.Status.VALID, juu.getStatus());
+ assertEquals(UIObject.Status.VALID, foo.getStatus());
+
+ // Now update juu concurrently
+ mockJuu.setPropertyValue("abc", "def");
+
+ // Now navigate
+ List<? extends UIObject> fooChildren = foo.getChildren();
+
+ //
+ assertNotNull(fooChildren);
+ assertEquals(1, fooChildren.size());
+ assertSame(juu, fooChildren.iterator().next());
+ assertEquals(UIObject.Status.STALE, juu.getStatus());
+ assertEquals(UIObject.Status.VALID, foo.getStatus());
+ }
+
+ public void testChildrenNavigationCombinesExistingChildrenAndLoadAbsentChildren()
throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ MockObject mockDaa = mockFoo.addChild("daa", MockObject.Type.PAGE);
+
+ //
+ String fooId = mockFoo.getId();
+ String juuId = mockJuu.getId();
+ String daaId = mockDaa.getId();
+
+ //
+ UIContext context = createContext();
+
+ // Load foo and juu but not daa
+ UIObject foo = context.getObject(fooId);
+ UIObject juu = context.getObject(juuId);
+
+ // Now navigate
+ List<? extends UIObject> fooChildren = foo.getChildren();
+
+ //
+ assertNotNull(fooChildren);
+ Map<String, UIObject> tmp = new HashMap<String, UIObject>();
+ for (UIObject o : fooChildren)
+ {
+ tmp.put(o.getId(), o);
+ }
+
+ //
+ assertEquals(2, tmp.size());
+ assertEquals(Tools.toSet(juuId, daaId), tmp.keySet());
+ assertSame(juu, tmp.get(juuId));
+ UIObject daa = tmp.get(daaId);
+ assertSame(context.getObject(daaId), daa);
+ }
+
public void _testMove() throws Exception
{
MockObject mockRoot = model.getRoot();