Author: julien(a)jboss.com
Date: 2008-03-26 18:30:17 -0400 (Wed, 26 Mar 2008)
New Revision: 10382
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/RemoveChildTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/TraversalModelTestCase.java
Modified:
branches/presentation/presentation/build.xml
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AddChildTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/ModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/NodeDef.java
Log:
test case for node removal
Modified: branches/presentation/presentation/build.xml
===================================================================
--- branches/presentation/presentation/build.xml 2008-03-26 21:30:57 UTC (rev 10381)
+++ branches/presentation/presentation/build.xml 2008-03-26 22:30:17 UTC (rev 10382)
@@ -316,6 +316,7 @@
<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"/>
</x-test>
<x-classpath>
<path refid="jboss.portal/modules/common.classpath"/>
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java 2008-03-26
21:30:57 UTC (rev 10381)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java 2008-03-26
22:30:17 UTC (rev 10382)
@@ -179,13 +179,22 @@
UIObjectImpl.ChildRef childRef = object.childrenRefs.get(childId);
//
- childRef.loaded = loaded;
-
- //
- if (!loaded)
+ if (loaded)
{
- throw new UnsupportedOperationException("todo");
+ if (!childRef.loaded)
+ {
+ childRef.loaded = true;
+ context.addChild(objectId, childId);
+ }
}
+ else
+ {
+ if (childRef.loaded)
+ {
+ childRef.loaded = false;
+ context.removeChild(objectId, childId);
+ }
+ }
}
else
{
@@ -222,7 +231,13 @@
//
for (String childId : refresh.getRemovedChildren())
{
- throw new UnsupportedOperationException("todo");
+ if (hadChildren)
+ {
+ object.childrenRefs.remove(childId);
+ context.removeChild(objectId, childId);
+ UIObjectImpl removedChild = (UIObjectImpl)context.getObject(childId);
+ evict(removedChild);
+ }
}
//
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AddChildTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AddChildTestCase.java 2008-03-26
21:30:57 UTC (rev 10381)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AddChildTestCase.java 2008-03-26
22:30:17 UTC (rev 10382)
@@ -31,73 +31,39 @@
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
*/
-public class AddChildTestCase extends AbstractModelTestCase
+public class AddChildTestCase extends TraversalModelTestCase
{
- private class Test
+ public void testAddChild()
{
+ test(1);
+ }
- /** . */
- private ObjectTraversalType traversal1;
+ protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after)
+ {
+ NodeDef rootDef = NodeDef.create();
+ NodeDef fooDef = rootDef.addChild("foo");
+ fooDef.setTraversal(before[0]);
- /** . */
- private ObjectTraversalType traversal2;
+ //
+ rootDef.populate(mockModel);
- private Test(
- ObjectTraversalType traversal1,
- ObjectTraversalType traversal2)
- {
- this.traversal1 = traversal1;
- this.traversal2 = traversal2;
- }
+ //
+ ViewPortScope scope = new CustomScope(model, rootDef);
+ UIObjectTree context = new UIObjectTree();
+ ViewPort viewPort = model.createViewPort(context, scope);
- public void test()
- {
- NodeDef rootDef = NodeDef.create();
- NodeDef fooDef = rootDef.addChild("foo");
- fooDef.setTraversal(traversal1);
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
- //
- rootDef.populate(mockModel);
+ //
+ mockModel.getRoot().getChild("foo").addChild("juu",
MockObject.Type.PORTAL);
+ fooDef.addChild("juu");
+ fooDef.setTraversal(after[0]);
- //
- 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").addChild("juu",
MockObject.Type.PORTAL);
- fooDef.addChild("juu");
- fooDef.setTraversal(traversal2);
-
- //
- viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
- }
-
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
}
-
- public void test1()
- {
- new Test(ObjectTraversalType.RECURSIVE, ObjectTraversalType.RECURSIVE).test();
- }
-
- public void test2()
- {
- new Test(ObjectTraversalType.RECURSIVE, ObjectTraversalType.SINGLE).test();
- }
-
- public void test3()
- {
- new Test(ObjectTraversalType.SINGLE, ObjectTraversalType.RECURSIVE).test();
- }
-
- public void test4()
- {
- new Test(ObjectTraversalType.SINGLE, ObjectTraversalType.SINGLE).test();
- }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/ModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/ModelTestCase.java 2008-03-26
21:30:57 UTC (rev 10381)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/ModelTestCase.java 2008-03-26
22:30:17 UTC (rev 10382)
@@ -26,149 +26,56 @@
import org.jboss.portal.presentation.model2.ViewPort;
import org.jboss.portal.presentation.model2.ObjectTraversalType;
-import java.util.Collection;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-
-import junit.framework.TestCase;
-import junit.framework.Assert;
-
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
*/
-public class ModelTestCase extends TestCase
+public class ModelTestCase extends TraversalModelTestCase
{
- private class Test extends AbstractModelTestCase
+ public void testRefresh1() throws Exception
{
+ test(4);
+ }
- /** . */
- private ObjectTraversalType[] traversal1;
+ protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after)
+ {
+ NodeDef rootDef = NodeDef.create();
+ NodeDef fooDef = rootDef.addChild("foo");
+ NodeDef barDef = rootDef.addChild("bar");
+ NodeDef juuDef = fooDef.addChild("juu");
+ NodeDef daaDef = fooDef.addChild("daa");
- /** . */
- private ObjectTraversalType[] traversal2;
+ //
+ fooDef.setTraversal(before[0]);
+ barDef.setTraversal(before[1]);
+ juuDef.setTraversal(before[2]);
+ daaDef.setTraversal(before[3]);
- private Test(ObjectTraversalType[] traversal1, ObjectTraversalType[] traversal2)
- {
- this.traversal1 = traversal1;
- this.traversal2 = traversal2;
- }
+ //
+ rootDef.populate(mockModel);
- public void test()
- {
- NodeDef rootDef = NodeDef.create();
- NodeDef fooDef = rootDef.addChild("foo");
- NodeDef barDef = rootDef.addChild("bar");
- NodeDef juuDef = fooDef.addChild("juu");
- NodeDef daaDef = fooDef.addChild("daa");
+ //
+ ViewPortScope scope = new CustomScope(model, rootDef);
+ UIObjectTree context = new UIObjectTree();
+ ViewPort viewPort = model.createViewPort(context, scope);
- //
- fooDef.setTraversal(traversal1[0]);
- barDef.setTraversal(traversal1[1]);
- juuDef.setTraversal(traversal1[2]);
- daaDef.setTraversal(traversal1[3]);
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
- //
- rootDef.populate(mockModel);
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
- //
- ViewPortScope scope = new CustomScope(model, rootDef);
- UIObjectTree context = new UIObjectTree();
- ViewPort viewPort = model.createViewPort(context, scope);
+ //
+ fooDef.setTraversal(after[0]);
+ barDef.setTraversal(after[1]);
+ juuDef.setTraversal(after[2]);
+ daaDef.setTraversal(after[3]);
- //
- viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
-
- //
- viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
-
- //
- fooDef.setTraversal(traversal2[0]);
- barDef.setTraversal(traversal2[1]);
- juuDef.setTraversal(traversal2[2]);
- daaDef.setTraversal(traversal2[3]);
-
- //
- viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
- }
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
}
-
- public void testRefresh1() throws Exception
- {
- ObjectTraversalType[] traversal1 = new ObjectTraversalType[4];
- ObjectTraversalType[] traversal2 = new ObjectTraversalType[4];
- Collection<ObjectTraversalType[]> enumeration = generate(traversal1.length +
traversal2.length);
-/*
- Collection<ObjectTraversalType[]> enumeration = Collections.singletonList(
- new ObjectTraversalType[]{
- ObjectTraversalType.SKIP,
- ObjectTraversalType.SKIP,
- ObjectTraversalType.SKIP,
- ObjectTraversalType.SKIP,
- ObjectTraversalType.SKIP,
- ObjectTraversalType.SINGLE,
- ObjectTraversalType.SKIP,
- ObjectTraversalType.SKIP,
- }
- );
-*/
- for (ObjectTraversalType[] element : enumeration)
- {
- Assert.assertEquals(traversal1.length + traversal2.length, element.length);
- System.arraycopy(element, 0, traversal1, 0, traversal1.length);
- System.arraycopy(element, traversal1.length, traversal2, 0, traversal2.length);
- Test test = new Test(traversal1, traversal2);
- test.setUp();
- boolean failed = true;
- try
- {
- test.test();
- failed = false;
- }
- finally
- {
- if (failed)
- {
- System.out.println("Arrays.asList(traversal1) = " +
Arrays.asList(traversal1));
- System.out.println("Arrays.asList(traversal2) = " +
Arrays.asList(traversal2));
- }
- }
- }
-
- }
-
- private Collection<ObjectTraversalType[]> generate(int size)
- {
- if (size == 0)
- {
- return Collections.singleton(new ObjectTraversalType[0]);
- }
- else
- {
- Collection<ObjectTraversalType[]> enumeration = generate(size - 1);
-
- //
- ArrayList<ObjectTraversalType[]> augmentedEnumeration = new
ArrayList<ObjectTraversalType[]>(enumeration.size() * 3);
-
- //
- for (ObjectTraversalType type : ObjectTraversalType.values())
- {
- for (ObjectTraversalType[] element : enumeration)
- {
- ObjectTraversalType[] augmentedElement = new ObjectTraversalType[1 +
element.length];
- System.arraycopy(element, 0, augmentedElement, 1, element.length);
- augmentedElement[0] = type;
- augmentedEnumeration.add(augmentedElement);
- }
- }
-
- //
- return augmentedEnumeration;
- }
- }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/NodeDef.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/NodeDef.java 2008-03-26
21:30:57 UTC (rev 10381)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/NodeDef.java 2008-03-26
22:30:17 UTC (rev 10382)
@@ -108,6 +108,20 @@
return child;
}
+ public void removeChild(String name)
+ {
+ NodeDef child = children.remove(name);
+
+ //
+ if (child == null)
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ child.parent = null;
+ }
+
public void populate(MockModel model)
{
populate(model.getRoot());
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/RemoveChildTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/RemoveChildTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/RemoveChildTestCase.java 2008-03-26
22:30:17 UTC (rev 10382)
@@ -0,0 +1,68 @@
+/******************************************************************************
+ * 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.ViewPortScope;
+import org.jboss.portal.presentation.model2.ViewPort;
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class RemoveChildTestCase extends TraversalModelTestCase
+{
+
+ public void testRemoveChild()
+ {
+ test(1);
+ }
+
+ protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after)
+ {
+ NodeDef rootDef = NodeDef.create();
+ NodeDef fooDef = rootDef.addChild("foo");
+ NodeDef barDef = fooDef.addChild("bar");
+ NodeDef juuDef = fooDef.addChild("juu");
+
+ //
+ 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.destroy(mockModel.getRoot().getChild("foo").getChild("juu"));
+ fooDef.removeChild("juu");
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/TraversalModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/TraversalModelTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/TraversalModelTestCase.java 2008-03-26
22:30:17 UTC (rev 10382)
@@ -0,0 +1,128 @@
+/******************************************************************************
+ * 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.UIModel;
+import org.jboss.portal.presentation.test.model.state.structural.MockModel;
+import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.impl.model2.UIModelImpl;
+import
org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class TraversalModelTestCase extends TestCase
+{
+
+ /** . */
+ protected UIModel model;
+
+ /** . */
+ protected MockModel mockModel;
+
+ /** . */
+ protected StructuralStateContext structuralStateContext;
+
+ public void test(int size)
+ {
+ ObjectTraversalType[] before = new ObjectTraversalType[size];
+ ObjectTraversalType[] after = new ObjectTraversalType[size];
+ Collection<ObjectTraversalType[]> enumeration = generate(before.length +
after.length);
+
+ //
+ for (ObjectTraversalType[] element : enumeration)
+ {
+ mockModel = new MockModelImpl();
+ structuralStateContext = mockModel.getStructuralStateContext();
+ model = new UIModelImpl(new NavigationalStateContextImpl(),
structuralStateContext);
+
+ //
+ Assert.assertEquals(before.length + after.length, element.length);
+ System.arraycopy(element, 0, before, 0, before.length);
+ System.arraycopy(element, before.length, after, 0, after.length);
+ boolean failed = true;
+ try
+ {
+ test(before, after);
+ failed = false;
+ }
+ finally
+ {
+ if (failed)
+ {
+ System.out.println("Arrays.asList(before) = " +
Arrays.asList(before));
+ System.out.println("Arrays.asList(after) = " +
Arrays.asList(after));
+ }
+
+ //
+ mockModel = null;
+ structuralStateContext = null;
+ model = null;
+ }
+ }
+ }
+
+ protected abstract void test(ObjectTraversalType[] before, ObjectTraversalType[]
after);
+
+ public static Collection<ObjectTraversalType[]> generate(int size)
+ {
+ if (size == 0)
+ {
+ return Collections.singleton(new ObjectTraversalType[0]);
+ }
+ else
+ {
+ Collection<ObjectTraversalType[]> enumeration = generate(size - 1);
+
+ //
+ ArrayList<ObjectTraversalType[]> augmentedEnumeration = new
ArrayList<ObjectTraversalType[]>(enumeration.size() * 3);
+
+ //
+ for (ObjectTraversalType type : ObjectTraversalType.values())
+ {
+ for (ObjectTraversalType[] element : enumeration)
+ {
+ ObjectTraversalType[] augmentedElement = new ObjectTraversalType[1 +
element.length];
+ System.arraycopy(element, 0, augmentedElement, 1, element.length);
+ augmentedElement[0] = type;
+ augmentedEnumeration.add(augmentedElement);
+ }
+ }
+
+ //
+ return augmentedEnumeration;
+ }
+ }
+
+}