Author: julien(a)jboss.com
Date: 2007-11-27 20:29:39 -0500 (Tue, 27 Nov 2007)
New Revision: 9144
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java
Log:
- test case for an update of a non existing state
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-11-28
01:12:14 UTC (rev 9143)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-11-28
01:29:39 UTC (rev 9144)
@@ -321,7 +321,7 @@
// /**
// *
// */
-// public void destroyChild(String name)
+// public void removeChild(String name)
// {
// //Make sure all children are loaded
// this.getChildren();
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-11-28
01:12:14 UTC (rev 9143)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-11-28
01:29:39 UTC (rev 9144)
@@ -77,7 +77,7 @@
*
* @param name
*/
-// public void destroyChild(String name);
+// public void removeChild(String name);
/**
*
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java 2007-11-28
01:12:14 UTC (rev 9143)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java 2007-11-28
01:29:39 UTC (rev 9144)
@@ -22,10 +22,12 @@
******************************************************************************/
package org.jboss.portal.presentation.test.model;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
+import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.model.state.structural.StructuralStateManager;
-import org.jboss.portal.presentation.model.state.structural.StructuralState;
-import org.jboss.portal.presentation.model.state.StateChangeVetoException;
-import org.jboss.portal.presentation.model.UIObject;
import java.util.ArrayList;
import java.util.HashMap;
@@ -37,7 +39,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public class MockModel implements StructuralStateManager
+public class MockModel
{
/** . */
@@ -49,24 +51,111 @@
/** . */
private final MockObjectImpl context = new MockObjectImpl();
+ private final StructuralStateManager manager = new StructuralStateManager()
+ {
+ public StructuralState load(String objectId) throws IllegalArgumentException
+ {
+ if (objectId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ MockObjectImpl object = universe.get(objectId);
+ return object != null ? object.takeSnapshot() : null;
+ }
+
+ public String getRootId()
+ {
+ return context.id;
+ }
+
+ public StructuralState create(String parentId, Class<? extends UIObject>
type, String name, Map<String, String> properties) throws StateChangeVetoException
+ {
+ throw new StateChangeVetoException();
+ }
+
+ public void destroy(String objectId) throws StateChangeVetoException
+ {
+ throw new StateChangeVetoException();
+ }
+
+ public void move(String objectId, String parentId) throws StateChangeVetoException
+ {
+ throw new StateChangeVetoException();
+ }
+
+ public void update(String objectId, Map<String, String> changes) throws
StateChangeVetoException
+ {
+ if (objectId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (changes == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ MockObjectImpl object = universe.get(objectId);
+ if (object == null)
+ {
+ throw new NoSuchStateException();
+ }
+
+ //
+ for (Map.Entry<String, String> entry : changes.entrySet())
+ {
+ String propertyName = entry.getKey();
+ MockObject.UpdateBehavior behavior =
object.propertyBehaviors.get(propertyName);
+ if (behavior instanceof MockObject.Veto)
+ {
+ throw new StateChangeVetoException("Cannot modify non behavior
property");
+ }
+ else if (behavior instanceof MockObject.Failure)
+ {
+ MockObject.Failure failure = (MockObject.Failure)behavior;
+ failure.throwAs(IllegalArgumentException.class).
+ throwAs(StateChangeVetoException.class).
+ throwAs(StateException.class);
+ }
+ else
+ {
+ String propertyValue = entry.getValue();
+ if (propertyValue != null)
+ {
+ object.propertyValues.put(propertyName, propertyValue);
+ }
+ else
+ {
+ object.propertyValues.remove(propertyName);
+ }
+ }
+ }
+ }
+ };
+
+ public StructuralStateManager getManager()
+ {
+ return manager;
+ }
+
public MockObject getContext()
{
return context;
}
- public StructuralState load(String objectId) throws IllegalArgumentException
+ public void destroy(String objectId)
{
- if (objectId == null)
+ MockObjectImpl object = universe.remove(objectId);
+ if (object.parent != null)
{
- throw new IllegalArgumentException();
+ object.parent.children.remove(object.id);
}
- MockObjectImpl object = universe.get(objectId);
- return object != null ? object.takeSnapshot() : null;
- }
- public String getRootId()
- {
- return context.id;
+ //
+ for (String childId : new ArrayList<String>(object.children.keySet()))
+ {
+ destroy(childId);
+ }
}
private class MockObjectImpl implements MockObject
@@ -85,7 +174,7 @@
private final Map<String, String> propertyValues;
/** . */
- private final Map<String, Boolean> propertyMutables;
+ private final Map<String, UpdateBehavior> propertyBehaviors;
/** . */
private final Map<String, MockObjectImpl> children;
@@ -100,7 +189,7 @@
this.type = MockObject.Type.CONTEXT;
this.children = new LinkedHashMap<String, MockObjectImpl>();
this.propertyValues = new HashMap<String, String>();
- this.propertyMutables = new HashMap<String, Boolean>();
+ this.propertyBehaviors = new HashMap<String, UpdateBehavior>();
//
universe.put(id, this);
@@ -118,7 +207,7 @@
this.type = type;
this.children = new LinkedHashMap<String, MockObjectImpl>();
this.propertyValues = new HashMap<String, String>();
- this.propertyMutables = new HashMap<String, Boolean>();
+ this.propertyBehaviors = new HashMap<String, UpdateBehavior>();
//
this.parent = parent;
@@ -174,25 +263,25 @@
return propertyValues.keySet();
}
- public void setPropertyMutable(String propertyName, Boolean propertyMutable)
+ public void setPropertyBehavior(String propertyName, UpdateBehavior
propertyBehavior)
{
if (propertyName == null)
{
throw new IllegalArgumentException();
}
- if (propertyMutable != null)
+ if (propertyBehavior != null)
{
- propertyMutables.put(name, propertyMutable);
+ propertyBehaviors.put(name, propertyBehavior);
}
else
{
- propertyMutables.remove(name);
+ propertyBehaviors.remove(name);
}
}
- public Boolean isPropertyMutable(String propertyName)
+ public UpdateBehavior getPropertyBehavior(String propertyName)
{
- return propertyMutables.get(propertyName);
+ return propertyBehaviors.get(propertyName);
}
public void setPropertyValue(String propertyName, String propertyValue)
@@ -211,58 +300,4 @@
}
}
}
-
- public StructuralState create(String parentId, Class<? extends UIObject> type,
String name, Map<String, String> properties) throws StateChangeVetoException
- {
- throw new StateChangeVetoException();
- }
-
- public void destroy(String objectId) throws StateChangeVetoException
- {
- throw new StateChangeVetoException();
- }
-
- public void move(String objectId, String parentId) throws StateChangeVetoException
- {
- throw new StateChangeVetoException();
- }
-
- public void update(String objectId, Map<String, String> changes) throws
StateChangeVetoException
- {
- if (objectId == null)
- {
- throw new IllegalArgumentException();
- }
- if (changes == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- MockObjectImpl object = universe.get(objectId);
- if (object == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- for (Map.Entry<String, String> entry : changes.entrySet())
- {
- String propertyName = entry.getKey();
- Boolean mutable = object.propertyMutables.get(propertyName);
- if (Boolean.FALSE.equals(mutable))
- {
- throw new StateChangeVetoException("Cannot modify non mutable
property");
- }
- String propertyValue = entry.getValue();
- if (propertyValue != null)
- {
- object.propertyValues.put(propertyName, propertyValue);
- }
- else
- {
- object.propertyValues.remove(propertyName);
- }
- }
- }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java 2007-11-28
01:12:14 UTC (rev 9143)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java 2007-11-28
01:29:39 UTC (rev 9144)
@@ -55,6 +55,43 @@
}
}
+ public abstract static class UpdateBehavior
+ {
+ public static UpdateBehavior veto()
+ {
+ return new Veto();
+ }
+ public static UpdateBehavior failure(Throwable throwable)
+ {
+ return new Failure(throwable);
+ }
+ }
+
+ static class Veto extends UpdateBehavior
+ {
+ }
+
+ static class Failure extends UpdateBehavior
+ {
+
+ /** . */
+ final Throwable throwable;
+
+ public Failure(Throwable throwable)
+ {
+ this.throwable = throwable;
+ }
+
+ public <T extends Throwable> Failure throwAs(Class<T> type) throws T
+ {
+ if (type.isInstance(throwable))
+ {
+ throw type.cast(throwable);
+ }
+ return this;
+ }
+ }
+
Type getType();
String getName();
@@ -63,9 +100,9 @@
String getPropertyValue(String propertyName);
- void setPropertyMutable(String propertyName, Boolean propertyMutable);
+ void setPropertyBehavior(String propertyName, UpdateBehavior propertyBehavior);
- Boolean isPropertyMutable(String propertyName);
+ UpdateBehavior getPropertyBehavior(String propertyName);
void setPropertyValue(String propertyName, String propertyValue);
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-11-28
01:12:14 UTC (rev 9143)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-11-28
01:29:39 UTC (rev 9144)
@@ -31,8 +31,8 @@
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
-import org.jboss.portal.presentation.model.state.StateException;
import java.util.Collections;
import java.util.List;
@@ -135,14 +135,14 @@
UIWindow window = container.createChild("defaultWindow", UIWindow.class);
//Destroy the container. When this is done, both container and window must be
destroyed from the UIObject tree
- page.destroyChild(container.getName());
+ page.removeChild(container.getName());
List<UIObject> pageChildren = page.getChildren();
assertTrue(pageChildren == null || pageChildren.size() == 0);
}*/
public void testSetPropertyThrowsIAE()
{
- UIContext context = new UIContextImpl(model);
+ UIContext context = new UIContextImpl(model.getManager());
//
try
@@ -167,7 +167,7 @@
public void testGetPropertyThrowsIAE()
{
- UIContext context = new UIContextImpl(model);
+ UIContext context = new UIContextImpl(model.getManager());
//
try
@@ -194,7 +194,7 @@
{
MockObject mockDefaultPortal =
model.getContext().addChild("defaultPortal", MockObject.Type.PORTAL);
MockObject mockSomeOtherPortal =
model.getContext().addChild("someOtherPortal", MockObject.Type.PORTAL);
- UIContext context = new UIContextImpl(model);
+ UIContext context = new UIContextImpl(model.getManager());
//
List<UIObject> children = context.getChildren();
@@ -224,7 +224,7 @@
{
MockObject mockDefaultPortal =
model.getContext().addChild("defaultPortal", MockObject.Type.PORTAL);
MockObject mockDefaultPage = mockDefaultPortal.addChild("defaultPage",
MockObject.Type.PAGE);
- UIContext context = new UIContextImpl(model);
+ UIContext context = new UIContextImpl(model.getManager());
//
UIPage defaultPage = (UIPage)context.getObject(mockDefaultPage.getId());
@@ -276,12 +276,29 @@
Assert.assertEquals(null, object.getProperty(scopeType, propertyName,
Blah.class)); }
}
- public void testExistingMutableStructuralProperty()
+ public void testUpdatePropertyNonExistingObject()
{
+ UIContext context = new UIContextImpl(model.getManager());
MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
+ UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
+ model.destroy(mockFoo.getId());
+
+ //
+ try
+ {
+ foo.setProperty(StateScopeType.STRUCTURAL, "foo",
"foo_value");
+ fail();
+ }
+ catch (NoSuchStateException e)
+ {
+ }
+ }
+
+ public void testUpdateExistingMutableStructuralProperty()
+ {
+ MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
mockFoo.setPropertyValue("foo", "foo_value");
- mockFoo.setPropertyMutable("foo", true);
- UIContext context = new UIContextImpl(model);
+ UIContext context = new UIContextImpl(model.getManager());
// Check initial state
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
@@ -304,12 +321,12 @@
fooAssert.assertStructuralEquals("foo", "foo_new_value");
}
- public void testExistingNonMutableStructuralProperty()
+ public void testUpdateExistingNonMutableStructuralProperty()
{
MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
mockFoo.setPropertyValue("foo", "foo_value");
- mockFoo.setPropertyMutable("foo", false);
- UIContext context = new UIContextImpl(model);
+ mockFoo.setPropertyBehavior("foo", MockObject.Failure.veto());
+ UIContext context = new UIContextImpl(model.getManager());
// Check initial state
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
@@ -339,11 +356,10 @@
fooAssert.assertStructuralEquals("foo", "foo_value");
}
- public void testNonExistingMutableStructuralProperty()
+ public void testUpdateNonExistingMutableStructuralProperty()
{
MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
- mockFoo.setPropertyMutable("foo", true);
- UIContext context = new UIContextImpl(model);
+ UIContext context = new UIContextImpl(model.getManager());
// Check initial state
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
@@ -366,11 +382,11 @@
fooAssert.assertStructuralEquals("foo", "foo_new_value");
}
- public void testNonExistingNonMutableStructuralProperty()
+ public void testUpdateNonExistingNonMutableStructuralProperty()
{
MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
- mockFoo.setPropertyMutable("foo", false);
- UIContext context = new UIContextImpl(model);
+ mockFoo.setPropertyBehavior("foo", MockObject.Failure.veto());
+ UIContext context = new UIContextImpl(model.getManager());
// Check initial state
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
@@ -400,10 +416,10 @@
fooAssert.assertStructuralEquals("foo", null);
}
- public void testContentProperty()
+ public void testUpdateContentProperty()
{
MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
- UIContext context = new UIContextImpl(model);
+ UIContext context = new UIContextImpl(model.getManager());
// Check initial state
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
@@ -419,10 +435,10 @@
fooAssert.assertContentEquals("foo", 2, Integer.class);
}
- public void testNavigationalProperty()
+ public void testUpdateNavigationalProperty()
{
MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
- UIContext context = new UIContextImpl(model);
+ UIContext context = new UIContextImpl(model.getManager());
// Check initial state
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java 2007-11-28
01:12:14 UTC (rev 9143)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java 2007-11-28
01:29:39 UTC (rev 9144)
@@ -42,7 +42,7 @@
*/
protected void setUp() throws Exception
{
- this.uiContext = new UIContextImpl(new MockModel());
+ this.uiContext = new UIContextImpl(new MockModel().getManager());
}
/**
@@ -113,7 +113,7 @@
UIWindow window = container.createChild("defaultWindow", UIWindow.class);
//Destroy the container. When this is done, both container and window must be
destroyed from the UIObject tree
- page.destroyChild(container.getName());
+ page.removeChild(container.getName());
List<UIObject> pageChildren = page.getChildren();
assertTrue(pageChildren == null || pageChildren.size() == 0);
}*/