Author: julien(a)jboss.com
Date: 2008-03-26 21:07:32 -0400 (Wed, 26 Mar 2008)
New Revision: 10387
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/MoveChildTestCase.java
Modified:
branches/presentation/presentation/build.xml
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectNode.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectTree.java
Log:
start to add a move test case (which is the critical feature to implement)
Modified: branches/presentation/presentation/build.xml
===================================================================
--- branches/presentation/presentation/build.xml 2008-03-27 00:58:57 UTC (rev 10386)
+++ branches/presentation/presentation/build.xml 2008-03-27 01:07:32 UTC (rev 10387)
@@ -311,12 +311,13 @@
-->
</x-sysproperty>
<x-test>
- <!--<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.MockModelTestCase"/>-->
- <!--<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.ModelTestCase"/>-->
- <!--<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.EventTestCase"/>-->
+ <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.MockModelTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.ModelTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.EventTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model2.ModelTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model2.AddChildTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model2.RemoveChildTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model2.MoveChildTestCase"/>
</x-test>
<x-classpath>
<path refid="jboss.portal/modules/common.classpath"/>
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/MoveChildTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/MoveChildTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/MoveChildTestCase.java 2008-03-27
01:07:32 UTC (rev 10387)
@@ -0,0 +1,72 @@
+/******************************************************************************
+ * 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.model2;
+
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ViewPort;
+import org.jboss.portal.presentation.test.model.state.structural.MockObject;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class MoveChildTestCase extends TraversalModelTestCase
+{
+
+ public void testMoveChild()
+ {
+ test(0);
+ }
+
+ protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after)
+ {
+ NodeDef rootDef = NodeDef.create();
+ NodeDef fooDef = rootDef.addChild("foo");
+ NodeDef juuDef = fooDef.addChild("juu");
+ NodeDef barDef = rootDef.addChild("bar");
+
+ //
+ 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()));
+ context.assertConsistency(model.getRootId());
+
+ //
+
mockModel.getRoot().getChild("foo").getChild("juu").move(mockModel.getRoot().getChild("bar"));
+ fooDef.removeChild("juu");
+ barDef.addChild("juu");
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+ }
+}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectNode.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectNode.java 2008-03-27
00:58:57 UTC (rev 10386)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectNode.java 2008-03-27
01:07:32 UTC (rev 10387)
@@ -101,7 +101,7 @@
children.remove(key);
}
- public void createrChildren()
+ public void createChildren()
{
if (children != null)
{
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectTree.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectTree.java 2008-03-27
00:58:57 UTC (rev 10386)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectTree.java 2008-03-27
01:07:32 UTC (rev 10387)
@@ -27,7 +27,6 @@
import java.util.Map;
import java.util.HashMap;
-import java.util.Set;
import java.util.ArrayList;
import java.util.HashSet;
@@ -80,37 +79,85 @@
public void removeObject(String objectId)
{
- nodes.remove(objectId);
+ if (nodes.remove(objectId) == null)
+ {
+ throw new IllegalStateException("No such object " + objectId);
+ }
}
public void addObject(UIObject object)
{
- nodes.put(object.getId(), new UIObjectNode(object));
+ String id = object.getId();
+
+ //
+ if (nodes.containsKey(id))
+ {
+ throw new IllegalStateException("Object with id " + id + " is
already loaded");
+ }
+
+ //
+ nodes.put(id, new UIObjectNode(object));
}
public void addChild(String parentId, String childId)
{
UIObjectNode parent = nodes.get(parentId);
+ if (parent == null)
+ {
+ throw new IllegalStateException("No such object " + parentId);
+ }
+
+ //
UIObjectNode child = nodes.get(childId);
+ if (child == null)
+ {
+ throw new IllegalStateException("No such object " + childId);
+ }
+
+ //
parent.addChild(child);
}
public void removeChild(String parentId, String childId)
{
UIObjectNode parent = nodes.get(parentId);
+ if (parent == null)
+ {
+ throw new IllegalStateException("No such object " + parentId);
+ }
+
+ //
UIObjectNode child = nodes.get(childId);
+ if (child == null)
+ {
+ throw new IllegalStateException("No such object " + childId);
+ }
+
+ //
parent.removeChild(child);
}
public void initChildren(String parentId)
{
- UIObjectNode parent =nodes.get(parentId);
- parent.createrChildren();
+ UIObjectNode parent = nodes.get(parentId);
+ if (parent == null)
+ {
+ throw new IllegalStateException("No such object " + parentId);
+ }
+
+ //
+ parent.createChildren();
}
public void destroyChildren(String parentId)
{
UIObjectNode parent =nodes.get(parentId);
+ if (parent == null)
+ {
+ throw new IllegalStateException("No such object " + parentId);
+ }
+
+ //
parent.destroyChildren();
}
}