Author: julien(a)jboss.com
Date: 2007-12-18 17:03:28 -0500 (Tue, 18 Dec 2007)
New Revision: 9364
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
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/UIObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
more complete test case for destruction
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18
21:20:11 UTC (rev 9363)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18
22:03:28 UTC (rev 9364)
@@ -126,7 +126,7 @@
}
}
- public void resolveConflicts()
+ public void refresh()
{
switch (context.status)
{
@@ -144,6 +144,10 @@
public <T> T getProperty(StateScopeType scopeType, String propertyName,
Class<T> propertyType)
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
if (scopeType == null)
{
throw new IllegalArgumentException();
@@ -178,6 +182,10 @@
public <T> void setProperty(StateScopeType scopeType, String propertyName, T
propertyValue) throws StateChangeVetoException
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
if (scopeType == null)
{
throw new IllegalArgumentException();
@@ -248,6 +256,16 @@
public AbstractUIObject getChild(String name)
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException("No null name accepted");
+ }
+
+ //
for (AbstractUIObject child : getChildren())
{
if (child.getName().equals(name))
@@ -255,16 +273,30 @@
return child;
}
}
+
+ //
return null;
}
public String getName()
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
return context.structuralObject.getState().getName();
}
public final UIObject getParent()
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
if (!parent.loaded)
{
parent.object = context.container.getParent(context.structuralObject);
@@ -277,11 +309,23 @@
public final List<AbstractUIObject> getChildren()
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
return children;
}
public <T extends UIObject> T createChild(String name, Class<T> type)
throws IllegalArgumentException
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
StructuralObject.Creation creation;
try
{
@@ -313,6 +357,10 @@
public void destroyChild(String name) throws IllegalArgumentException, StateException
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
if (name == null)
{
throw new IllegalArgumentException();
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-18
21:20:11 UTC (rev 9363)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-18
22:03:28 UTC (rev 9364)
@@ -184,7 +184,14 @@
StructuralObject structuralObject = this.structuralStateContext.load(id);
//
- return update(structuralObject);
+ if (structuralObject != null)
+ {
+ return update(structuralObject);
+ }
+ else
+ {
+ return null;
+ }
}
else
{
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-18
21:20:11 UTC (rev 9363)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-18
22:03:28 UTC (rev 9364)
@@ -82,6 +82,16 @@
container.addModelListener(listener);
}
+ public UIObject.Status getStatus()
+ {
+ return status;
+ }
+
+ public boolean isValid()
+ {
+ return status == UIObject.Status.VALID;
+ }
+
// Package protected
************************************************************************************************
void updateStatus(StateException e)
@@ -100,4 +110,9 @@
}
}
+ void invalidate()
+ {
+ status = UIObject.Status.INVALID;
+ }
+
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java 2007-12-18
21:20:11 UTC (rev 9363)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java 2007-12-18
22:03:28 UTC (rev 9364)
@@ -22,6 +22,8 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model.container;
+import org.jboss.portal.presentation.model.UIObject;
+
import java.util.AbstractList;
import java.util.List;
@@ -46,6 +48,10 @@
public AbstractUIObject get(int i)
{
+ if (!object.context.isValid())
+ {
+ throw new IllegalStateException("Relationship not valid");
+ }
if (content == null)
{
content =
object.context.container.getChildren(object.context.structuralObject);
@@ -55,6 +61,10 @@
public int size()
{
+ if (!object.context.isValid())
+ {
+ throw new IllegalStateException("Relationship not valid");
+ }
if (content == null)
{
content =
object.context.container.getChildren(object.context.structuralObject);
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-18
21:20:11 UTC (rev 9363)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-18
22:03:28 UTC (rev 9364)
@@ -70,7 +70,7 @@
* <li><code>INVALID</code> status leads to throw an
<code>IllegalStateException</code></li>
* </ul>
*/
- void resolveConflicts();
+ void refresh();
/**
* Return the current status.
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-18
21:20:11 UTC (rev 9363)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18
22:03:28 UTC (rev 9364)
@@ -456,22 +456,89 @@
eventAssert.next(portal.getId(), new
StructuralStateModification.Creation(UIPortal.class, "foo", new
HashMap<String, String>()));
}
- public void testDestroyChild() throws Exception
+ public void testDestroyChildUpdatesLoadedDescendant() throws Exception
{
- MockObject mockFoo = model.getRoot().addChild("foo",
MockObject.Type.PORTAL);
- MockObject mockBar = model.getRoot().addChild("bar",
MockObject.Type.PORTAL);
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ MockObject mockDaa = mockJuu.addChild("daa", MockObject.Type.PAGE);
+ //
+ String daaId = mockDaa.getId();
+
+ //
UIContext context = createContext();
- UIPortal foo = (UIPortal)context.getChild("foo");
- UIPage juu = (UIPage)foo.getChild("juu");
+ // Load only the descendant
+ UIObject daa = context.getObject(daaId);
+ List<? extends UIObject> daaChildren = daa.getChildren();
+ // Destroy foo
context.destroyChild("foo");
- List<? extends UIObject> rootChildren = context.getChildren();
+ // Check daa state
+ assertEquals(UIObject.Status.INVALID, daa.getStatus());
+ assertEquals(null, context.getObject(daaId));
+ try
+ {
+ daaChildren.size();
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+ }
+ public void testDestroyChildUpdatesLoadedSubtree() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ MockObject mockDaa = mockJuu.addChild("daa", MockObject.Type.PAGE);
+ //
+ String fooId = mockFoo.getId();
+ String juuId = mockJuu.getId();
+ String daaId = mockDaa.getId();
+ //
+ UIContext context = createContext();
+
+ // Load subtree entirely
+ UIObject foo = context.getChild("foo");
+ UIObject juu = foo.getChild("juu");
+ UIObject daa = juu.getChild("daa");
+ List<? extends UIObject> fooChildren = foo.getChildren();
+ List<? extends UIObject> juuChildren = juu.getChildren();
+ List<? extends UIObject> daaChildren = daa.getChildren();
+
+ //
+ foo.destroyChild("juu");
+
+ //
+ try
+ {
+ juuChildren.size();
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+ try
+ {
+ daaChildren.size();
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+ assertEquals(0, fooChildren.size());
+ assertEquals(UIObject.Status.VALID, foo.getStatus());
+ assertEquals(UIObject.Status.INVALID, juu.getStatus());
+ assertEquals(UIObject.Status.INVALID, daa.getStatus());
+ assertSame(foo, context.getObject(fooId));
+ assertEquals(null, context.getObject(juuId));
+ assertEquals(null, context.getObject(daaId));
}
+
}