Author: julien(a)jboss.com
Date: 2008-03-28 16:35:59 -0400 (Fri, 28 Mar 2008)
New Revision: 10406
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UpdateObjectTestCase.java
Modified:
branches/presentation/presentation/build.xml
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/update/CreateUpdatePhase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/update/ObjectUpdate.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPortContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/NodeDef.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectNode.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectTree.java
Log:
add test case for property updates
Modified: branches/presentation/presentation/build.xml
===================================================================
--- branches/presentation/presentation/build.xml 2008-03-28 19:57:44 UTC (rev 10405)
+++ branches/presentation/presentation/build.xml 2008-03-28 20:35:59 UTC (rev 10406)
@@ -319,6 +319,7 @@
<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model3.AddChildTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model3.RemoveChildTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model3.MoveChildTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model3.UpdateObjectTestCase"/>
</x-test>
<x-classpath>
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java 2008-03-28
19:57:44 UTC (rev 10405)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java 2008-03-28
20:35:59 UTC (rev 10406)
@@ -27,6 +27,7 @@
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import java.util.Map;
+import java.util.Set;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -36,7 +37,7 @@
{
/** . */
- public final StructuralObject structuralObject;
+ public StructuralObject structuralObject;
/** We keep track of what was loaded by the scope. */
public Map<String, UIObjectRef> childRefs;
@@ -61,6 +62,11 @@
return safeCast(getProperty(propertyName), propertyType);
}
+ public Set<String> getPropertyNames()
+ {
+ return structuralObject.getState().getProperties().keySet();
+ }
+
public Object getProperty(String propertyName) throws IllegalArgumentException,
StateException
{
if (propertyName == null)
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/update/CreateUpdatePhase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/update/CreateUpdatePhase.java 2008-03-28
19:57:44 UTC (rev 10405)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/update/CreateUpdatePhase.java 2008-03-28
20:35:59 UTC (rev 10406)
@@ -211,7 +211,7 @@
if (object != null)
{
return new ObjectUpdate.UpdateObject(
- object.getId(),
+ object.structuralObject,
childrenStatus,
addedChildrenUpdates,
removedChildrenUpdates,
@@ -255,7 +255,7 @@
}
//
- return new ObjectUpdate.UpdateObject(object.getId(),
removedChildrenUpdates);
+ return new ObjectUpdate.UpdateObject(object.structuralObject,
removedChildrenUpdates);
}
else
{
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/update/ObjectUpdate.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/update/ObjectUpdate.java 2008-03-28
19:57:44 UTC (rev 10405)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/update/ObjectUpdate.java 2008-03-28
20:35:59 UTC (rev 10406)
@@ -25,6 +25,7 @@
import org.jboss.portal.presentation.impl.model2.UIObjectImpl;
import org.jboss.portal.presentation.impl.model2.UIObjectRef;
import org.jboss.portal.presentation.model2.ViewPortContext;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import java.util.List;
import java.util.HashMap;
@@ -46,7 +47,7 @@
{
/** . */
- final String objectId;
+ final StructuralObject structuralObject;
/** . */
final Map<String, Boolean> childrenStatus;
@@ -60,9 +61,9 @@
/** . */
final List<UpdateObject> updateChildrenUpdates;
- public UpdateObject(String objectId, List<RemoveChild>
removeChildrenUpdates)
+ public UpdateObject(StructuralObject structuralObject, List<RemoveChild>
removeChildrenUpdates)
{
- if (objectId == null)
+ if (structuralObject == null)
{
throw new IllegalArgumentException("No null object id accepted");
}
@@ -72,7 +73,7 @@
}
//
- this.objectId = objectId;
+ this.structuralObject = structuralObject;
this.childrenStatus = null;
this.addedChildrenUpdates = null;
this.removedChildrenUpdates = removeChildrenUpdates;
@@ -80,13 +81,13 @@
}
public UpdateObject(
- String objectId,
+ StructuralObject structuralObject,
Map<String, Boolean> childrenStatus,
List<AddChild> addedChildrenUpdates,
List<RemoveChild> removedChildrenUpdates,
List<UpdateObject> updateChildrenUpdates)
{
- if (objectId == null)
+ if (structuralObject == null)
{
throw new IllegalArgumentException("No null object id accepted");
}
@@ -104,7 +105,7 @@
}
//
- this.objectId = objectId;
+ this.structuralObject = structuralObject;
this.childrenStatus = childrenStatus;
this.addedChildrenUpdates = addedChildrenUpdates;
this.removedChildrenUpdates = removedChildrenUpdates;
@@ -113,7 +114,7 @@
public void execute(ViewPortContext context)
{
- UIObjectImpl object = (UIObjectImpl)context.getObject(objectId);
+ UIObjectImpl object =
(UIObjectImpl)context.getObject(structuralObject.getId());
// Normally should be ok because if we have removed children updates it means
// that it was created because the existing object was referencing children
@@ -122,6 +123,13 @@
removedChildUpdate.execute(context);
}
+ // Perform state update
+ if (object.structuralObject.compareTo(structuralObject))
+ {
+ object.structuralObject = structuralObject;
+ context.updateObject(structuralObject.getId());
+ }
+
//
if (childrenStatus != null)
{
@@ -134,7 +142,7 @@
}
//
- context.createChildren(objectId);
+ context.createChildren(structuralObject.getId());
}
//
@@ -153,7 +161,7 @@
{
if (object.childRefs != null)
{
- context.destroyChildren(objectId);
+ context.destroyChildren(structuralObject.getId());
}
}
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/UIObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/UIObject.java 2008-03-28
19:57:44 UTC (rev 10405)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/UIObject.java 2008-03-28
20:35:59 UTC (rev 10406)
@@ -24,6 +24,8 @@
import org.jboss.portal.presentation.model.state.StateException;
+import java.util.Set;
+
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
@@ -55,4 +57,11 @@
* @throws org.jboss.portal.presentation.model.state.StateException any state
exception
*/
<T> T getProperty(String propertyName, Class<T> propertyType) throws
IllegalArgumentException, StateException;
+
+ /**
+ * Returns the set of property names of this object
+ *
+ * @return the property names
+ */
+ Set<String> getPropertyNames();
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPortContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPortContext.java 2008-03-28
19:57:44 UTC (rev 10405)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPortContext.java 2008-03-28
20:35:59 UTC (rev 10406)
@@ -33,6 +33,8 @@
void removeObject(String objectId);
+ void updateObject(String objectId);
+
void addObject(UIObject object);
void createChildren(String parentId);
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/NodeDef.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/NodeDef.java 2008-03-28
19:57:44 UTC (rev 10405)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/NodeDef.java 2008-03-28
20:35:59 UTC (rev 10406)
@@ -57,12 +57,16 @@
/** . */
private NodeDef parent;
+ /** . */
+ private final Map<String, String> properties;
+
private NodeDef(String name)
{
this.name = name;
this.children = new HashMap<String, NodeDef>();
this.traversal = ObjectTraversalType.RECURSIVE;
this.parent = null;
+ this.properties = new HashMap<String, String>();
}
public String getName()
@@ -90,6 +94,35 @@
this.traversal = traversal;
}
+ public void setProperty(String name, String value)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ if (value != null)
+ {
+ properties.put(name, value);
+ }
+ else
+ {
+ properties.remove(name);
+ }
+ }
+
+ public String getProperty(String name)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ return properties.get(name);
+ }
+
public NodeDef addChild(String name)
{
if (children.containsKey(name))
@@ -131,7 +164,7 @@
{
for (Map.Entry<String, NodeDef> childNodeEntry : children.entrySet())
{
- MockObject child = object.addChild(childNodeEntry.getKey(),
MockObject.Type.PORTAL);
+ MockObject child = object.addChild(childNodeEntry.getKey(),
MockObject.Type.PORTAL, properties);
childNodeEntry.getValue().populate(child);
}
}
@@ -139,6 +172,13 @@
public void assertEquals(UIObjectNode objectNode)
{
Assert.assertEquals(name, objectNode.getObject().getName());
+ Assert.assertEquals(properties.keySet(), objectNode.getProperties().keySet());
+ for (String propertyName : properties.keySet())
+ {
+ String expectedProperty = properties.get(propertyName);
+ String property = objectNode.getProperties().get(propertyName);
+ Assert.assertEquals(expectedProperty, property);
+ }
//
switch (traversal)
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectNode.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectNode.java 2008-03-28
19:57:44 UTC (rev 10405)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectNode.java 2008-03-28
20:35:59 UTC (rev 10406)
@@ -40,6 +40,9 @@
/** . */
private Map<String, UIObjectNode> children;
+ /** . */
+ private Map<String, String> properties;
+
public UIObjectNode(UIObject object)
{
if (object == null)
@@ -49,8 +52,28 @@
//
this.object = object;
+ this.properties = new HashMap<String, String>();
+
+ //
+ updateState();
}
+ public Map<String, String> getProperties()
+ {
+ return properties;
+ }
+
+ public void updateState()
+ {
+ properties.clear();
+
+ for (String name : object.getPropertyNames())
+ {
+ String value = object.getProperty(name, String.class);
+ properties.put(name, value);
+ }
+ }
+
public UIObject getObject()
{
return object;
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectTree.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectTree.java 2008-03-28
19:57:44 UTC (rev 10405)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectTree.java 2008-03-28
20:35:59 UTC (rev 10406)
@@ -77,6 +77,18 @@
return node != null ? node.getObject() : null;
}
+ public void updateObject(String objectId)
+ {
+ UIObjectNode node = nodes.get(objectId);
+ if (node == null)
+ {
+ throw new IllegalStateException("No such object " + objectId);
+ }
+
+ //
+ node.updateState();
+ }
+
public void removeObject(String objectId)
{
if (nodes.remove(objectId) == null)
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UpdateObjectTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UpdateObjectTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UpdateObjectTestCase.java 2008-03-28
20:35:59 UTC (rev 10406)
@@ -0,0 +1,73 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.test.model3;
+
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ViewPort;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UpdateObjectTestCase extends TraversalModelTestCase
+{
+
+ public void testUpdateObject()
+ {
+ test(0, null);
+ }
+
+ protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after, Object
handback)
+ {
+ NodeDef rootDef = NodeDef.create();
+ NodeDef fooDef = rootDef.addChild("foo");
+
+ //
+ rootDef.populate(mockModel);
+
+ //
+ ViewPortScope scope = new CustomScope(model, rootDef);
+ UIObjectTree context = new UIObjectTree();
+ ViewPort viewPort = model.createViewPort(context, scope);
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+
+ //
+ mockModel.getRoot().getChild("foo").setPropertyValue("juu",
"daa");
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+
+ //
+ mockModel.getRoot().getChild("foo").setPropertyValue("juu",
null);
+ mockModel.getRoot().getChild("foo").setPropertyValue("daa",
"juu");
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ }
+}