Author: julien(a)jboss.com
Date: 2008-07-02 18:02:20 -0400 (Wed, 02 Jul 2008)
New Revision: 11270
Added:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractMockImplementationTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockException.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockModel.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockObject.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/Resolver.java
Removed:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockException.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockObject.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/AbstractModelTestCase.java
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/PresentationClientServlet.java
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/model/AjaxViewPortContext.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/ModelAdapter.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/layout/LayoutStore.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/layout/SimpleStructure.java
modules/presentation/trunk/portal/src/test/java/org/jboss/portal/presentation/portal/model/StructuralStateContextTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/AddChildTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/CustomScope.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/ModelTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/MoveChildTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/NodeDef.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/RemoveChildTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/TraversalModelTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/TypeTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/UIObjectNode.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/UpdateObjectTestCase.java
Log:
fixing test cases
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/PresentationClientServlet.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/PresentationClientServlet.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/PresentationClientServlet.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -94,6 +94,10 @@
viewPort.refresh();
//
+ HttpServletRequest req = getThreadLocalRequest();
+ req.getSession().setAttribute("ViewPort", viewPort);
+
+ //
return viewPortContext.getDelta();
}
@@ -137,8 +141,10 @@
ActionDecoder decoder =
(ActionDecoder)getServletContext().getAttribute("ActionDecoder");
//
- System.out.println("Should handle action " + action);
+ System.out.println("handling action " + action);
+ //
+ ProtocolAction protocolAction = null;
if (action instanceof OpaqueWindowAction)
{
OpaqueWindowAction windowAction = (OpaqueWindowAction)action;
@@ -174,10 +180,20 @@
body = null;
}
- ProtocolAction protocolAction = decoder.decode(new
AjaxActionDecoderContext(WebRequest.Verb.GET, path, queryParameterMap, body));
+ protocolAction = decoder.decode(new
AjaxActionDecoderContext(WebRequest.Verb.GET, path, queryParameterMap, body));
+ }
+ else if (action instanceof DestroyObjectAction)
+ {
+ DestroyObjectAction ajaxAction = (DestroyObjectAction)action;
- System.out.println("decoded protocolAction = " + protocolAction);
+ protocolAction = new DestroyUIObjectAction(ajaxAction.getObjectId());
+ }
+ //
+ if (protocolAction != null)
+ {
+ System.out.println("decoded protocol action = " + protocolAction);
+
// Now we execute
PresentationServer server = getPresentationServer();
@@ -190,52 +206,45 @@
PresentationResponse response = server.process(client, prequest);
System.out.println("response = " + response);
- System.out.println("Stale objects " + response.getStaleObjects());
+ System.out.println("stale objects " + response.getStaleObjects());
DelegatingNavigationalStateContext nsc =
client.getNavigationalStateContext();
//
Set<String> blahIds = nsc.flush();
- System.out.println("Stale objects = " + blahIds);
+ System.out.println("stale objects = " + blahIds);
//
Set<String> tmp = new
HashSet<String>(response.getStaleObjects());
tmp.addAll(blahIds);
//
- return new AjaxResponse(tmp.toArray(new String[tmp.size()]));
- }
- catch (PresentationServerException e)
- {
- e.printStackTrace();
+ HttpServletRequest req = getThreadLocalRequest();
+ ViewPort viewPort =
(ViewPort)req.getSession().getAttribute("ViewPort");
- return new AjaxResponse();
- }
- }
- else if (action instanceof DestroyObjectAction)
- {
- DestroyObjectAction ajaxAction = (DestroyObjectAction)action;
+ //
+ viewPort.refresh();
- DestroyUIObjectAction destroyAction = new
DestroyUIObjectAction(ajaxAction.getObjectId());
+ //
+ ModelUpdate[] updates =
((AjaxViewPortContext)viewPort.getContext()).getDelta();
- // Now we execute
- PresentationServer server = getPresentationServer();
+ //
+ for (int i = 0; i < updates.length; i++)
+ {
+ ModelUpdate update = updates[i];
+ System.out.println("update = " + update);
+ }
- PresentationClientImpl client = createPresentationClient();
- PresentationRequest prequest = new PresentationRequest(destroyAction);
-
- try
- {
- server.process(client, prequest);
+ //
+ return new AjaxResponse(tmp.toArray(new String[tmp.size()]));
}
catch (PresentationServerException e)
{
e.printStackTrace();
+
+ return new AjaxResponse();
}
-
- //
- return new AjaxResponse();
}
else
{
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/model/AjaxViewPortContext.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/model/AjaxViewPortContext.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/model/AjaxViewPortContext.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -118,6 +118,8 @@
public void updateObject(String objectId)
{
+ updates
+
throw new NotYetImplemented();
}
Modified:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/ModelAdapter.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/ModelAdapter.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/ModelAdapter.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -73,6 +73,12 @@
String objectId = item.getRef();
return nodeManager.getNode(objectId);
}
+ else if (o instanceof SimpleStructure)
+ {
+ SimpleStructure item = (SimpleStructure)o;
+ String objectId = item.getRef();
+ return nodeManager.getNode(objectId);
+ }
else
{
return o;
@@ -114,7 +120,7 @@
if (o instanceof SimpleStructure)
{
SimpleStructure simpleStructure = (SimpleStructure)o;
- String objectId = simpleStructure.getObjectRef();
+ String objectId = simpleStructure.getRef();
parent = nodeManager.getNode(objectId);
}
else if (o instanceof SimpleElement)
@@ -228,12 +234,12 @@
}
else
{
- throw new NotYetImplemented();
+ throw new NotYetImplemented("Cannot get type of object " + o);
}
}
else
{
- throw new NotYetImplemented();
+ throw new NotYetImplemented("Cannot get type of object " + o);
}
}
Modified:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/layout/LayoutStore.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/layout/LayoutStore.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/layout/LayoutStore.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -103,7 +103,7 @@
String objectRef = null;
if (targetElement instanceof SimpleStructure)
{
- objectRef = ((SimpleStructure)targetElement).getObjectRef();
+ objectRef = ((SimpleStructure)targetElement).getRef();
}
else if (targetElement instanceof SimpleElement)
{
@@ -173,7 +173,7 @@
String objectRef = null;
if (element instanceof SimpleStructure)
{
- objectRef = ((SimpleStructure)element).getObjectRef();
+ objectRef = ((SimpleStructure)element).getRef();
}
else if (element instanceof SimpleElement)
{
@@ -204,7 +204,7 @@
String objectRef = null;
if (element instanceof SimpleStructure)
{
- objectRef = ((SimpleStructure)element).getObjectRef();
+ objectRef = ((SimpleStructure)element).getRef();
}
else if (element instanceof SimpleElement)
{
Modified:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/layout/SimpleStructure.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/layout/SimpleStructure.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/layout/SimpleStructure.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -30,21 +30,21 @@
{
/** . */
- private final String objectRef;
+ private final String ref;
- SimpleStructure(String objectRef)
+ SimpleStructure(String ref)
{
- if (objectRef == null)
+ if (ref == null)
{
throw new IllegalArgumentException();
}
//
- this.objectRef = objectRef;
+ this.ref = ref;
}
- public String getObjectRef()
+ public String getRef()
{
- return objectRef;
+ return ref;
}
}
Modified:
modules/presentation/trunk/portal/src/test/java/org/jboss/portal/presentation/portal/model/StructuralStateContextTestCase.java
===================================================================
---
modules/presentation/trunk/portal/src/test/java/org/jboss/portal/presentation/portal/model/StructuralStateContextTestCase.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/portal/src/test/java/org/jboss/portal/presentation/portal/model/StructuralStateContextTestCase.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -27,7 +27,7 @@
import org.jboss.portal.presentation.model.ui.UIPage;
import org.jboss.portal.presentation.model.ui.UIWindow;
import org.jboss.portal.presentation.state.structural.StructuralStateContext;
-import org.jboss.portal.presentation.test.model.AbstractModelTestCase;
+import org.jboss.portal.presentation.test.model.AbstractMockImplementationTestCase;
import
org.jboss.portal.presentation.impl.state.structural.adapter.StructuralStateContextImpl;
import org.jboss.portal.presentation.impl.state.structural.adapter.StructuralAdapter;
import org.jboss.portal.presentation.portal.model.layout.LayoutStore;
@@ -46,7 +46,7 @@
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
*/
-public class StructuralStateContextTestCase extends
AbstractModelTestCase<PortalNode>
+public class StructuralStateContextTestCase extends
AbstractMockImplementationTestCase<PortalNode>
{
/** . */
Copied:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractMockImplementationTestCase.java
(from rev 11212,
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java)
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractMockImplementationTestCase.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractMockImplementationTestCase.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -0,0 +1,444 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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.model;
+
+import junit.framework.TestCase;
+import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.model.ui.UIContext;
+import org.jboss.portal.presentation.model.ui.UIPage;
+import org.jboss.portal.presentation.state.NoSuchStateException;
+import org.jboss.portal.presentation.state.StaleStateException;
+import org.jboss.portal.presentation.state.StateException;
+import org.jboss.portal.presentation.state.structural.StructuralObject;
+import org.jboss.portal.presentation.state.structural.StructuralState;
+import org.jboss.portal.presentation.state.structural.StructuralStateContext;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class AbstractMockImplementationTestCase<MockObject> extends
TestCase
+{
+
+ public AbstractMockImplementationTestCase()
+ {
+ }
+
+ public AbstractMockImplementationTestCase(String testName)
+ {
+ super(testName);
+ }
+
+ protected abstract StructuralStateContext getStructuralStateContext();
+
+ protected abstract MockObject getRoot();
+
+ protected abstract Set<String> getPropertyNames(MockObject object);
+
+ protected abstract MockObject getParent(MockObject object);
+
+ protected abstract List<? extends MockObject> getChildren(MockObject object);
+
+ protected abstract String getName(MockObject object);
+
+ protected abstract boolean isValid(MockObject object);
+
+ protected abstract Class<? extends UIObject> getType(MockObject object);
+
+ protected abstract String getId(MockObject object);
+
+ protected abstract MockObject addChild(MockObject object, String name, Class<?
extends UIObject> modelType);
+
+ protected abstract void destroy(MockObject object);
+
+ protected abstract void setProperty(MockObject object, String propertyName, String
propertyValue);
+
+ protected abstract Serializable getProperty(MockObject object, String name);
+
+ protected final StructuralObject getStructuralObject(MockObject object)
+ {
+ return getStructuralStateContext().load(getId(object));
+ }
+
+ public void testRoot()
+ {
+ MockObject mockRoot = getRoot();
+ assertNotNull(mockRoot);
+ assertEquals(Collections.EMPTY_SET, getPropertyNames(mockRoot));
+ assertNull(getParent(mockRoot));
+ assertEquals(Collections.EMPTY_LIST, getChildren(mockRoot));
+ assertEquals(UIContext.class, getType(mockRoot));
+ assertEquals("", getName(mockRoot));
+ assertEquals(true, isValid(mockRoot));
+
+ //
+ String rootId = getStructuralStateContext().getRootId();
+ assertNotNull(rootId);
+ StructuralObject root = getStructuralStateContext().load(rootId);
+ assertNotNull(root);
+ assertEquals(rootId, root.getId());
+ StructuralState state = root.getState();
+ assertEquals(UIContext.class, state.getType());
+ assertEquals(Collections.EMPTY_MAP, state.getProperties());
+ }
+
+ public void testAddChild()
+ {
+ MockObject mockRoot = getRoot();
+ // int rootV0 = mockRoot.getVersion();
+
+ //
+ String rootId = getId(mockRoot);
+ StructuralObject root = getStructuralStateContext().load(rootId);
+
+ //
+ MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
+ assertNotNull(mockFoo);
+ String fooId = getId(mockFoo);
+
+ //
+ assertNotNull(fooId);
+ assertEquals("foo", getName(mockFoo));
+ assertEquals(UIPage.class, getType(mockFoo));
+ assertSame(mockRoot, getParent(mockFoo));
+ assertEquals(Collections.singletonList(mockFoo), getChildren(mockRoot));
+ assertEquals(Collections.EMPTY_SET, getPropertyNames(mockFoo));
+ // assertTrue(mockRoot.getVersion() > rootV0);
+
+ //
+ try
+ {
+ getStructuralStateContext().loadParent(root);
+ fail();
+ }
+ catch (StaleStateException ignore)
+ {
+ }
+ try
+ {
+ getStructuralStateContext().loadChildren(root);
+ fail();
+ }
+ catch (StaleStateException ignore)
+ {
+ }
+
+ //
+ root = getStructuralStateContext().load(rootId);
+ assertNotNull(root);
+ assertEquals(rootId, root.getId());
+
+ //
+ Collection<StructuralObject> children =
getStructuralStateContext().loadChildren(root);
+ assertNotNull(children);
+ assertEquals(1, children.size());
+ StructuralObject foo = children.iterator().next();
+ assertNotNull(foo);
+ assertEquals(fooId, foo.getId());
+ StructuralState fooState = foo.getState();
+ assertNotNull(fooState);
+ assertEquals(Collections.EMPTY_MAP, fooState.getProperties());
+ assertEquals(UIPage.class, fooState.getType());
+ root = getStructuralStateContext().loadParent(foo);
+ assertNotNull(root);
+ assertEquals(rootId, root.getId());
+ }
+
+ public void testDestroy() throws MockException
+ {
+ MockObject mockRoot = getRoot();
+ MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
+ MockObject mockBar = addChild(mockFoo, "bar", UIPage.class);
+ MockObject mockJuu = addChild(mockFoo, "juu", UIPage.class);
+// int rootV0 = mockRoot.getVersion();
+// int fooV0 = mockFoo.getVersion();
+// int barV0 = mockBar.getVersion();
+ String fooId = getId(mockFoo);
+ String barId = getId(mockBar);
+ String juuId = getId(mockJuu);
+ StructuralObject foo0 = getStructuralStateContext().load(fooId);
+ StructuralObject bar0 = getStructuralStateContext().load(barId);
+ StructuralObject juu0 = getStructuralStateContext().load(juuId);
+
+ //
+ destroy(mockJuu);
+
+ //
+ StructuralObject foo1 = getStructuralStateContext().load(fooId);
+ StructuralObject bar1 = getStructuralStateContext().load(barId);
+ StructuralObject juu1 = getStructuralStateContext().load(juuId);
+// int rootV1 = mockRoot.getVersion();
+// int fooV1 = mockFoo.getVersion();
+// int barV1 = mockBar.getVersion();
+
+ //
+ assertStale(juu0);
+ assertStale(foo0);
+ assertNotStale(bar0);
+ assertNull(juu1);
+ assertNotStale(foo1);
+ assertNotStale(bar1);
+ assertEquals(Collections.singletonList(mockFoo), getChildren(mockRoot));
+ assertEquals(Collections.singletonList(mockBar), getChildren(mockFoo));
+ assertTrue(isValid(mockFoo));
+ assertTrue(isValid(mockBar));
+ assertFalse(isValid(mockJuu));
+// assertTrue(rootV1 == rootV0);
+// assertTrue(fooV1 > fooV0);
+// assertTrue(barV1 == barV0);
+
+ //
+ destroy(mockFoo);
+
+// int rootV2 = mockRoot.getVersion();
+ StructuralObject foo2 = getStructuralStateContext().load(fooId);
+ StructuralObject bar2 = getStructuralStateContext().load(barId);
+ StructuralObject juu2 = getStructuralStateContext().load(juuId);
+
+ //
+ assertStale(juu0);
+ assertStale(foo0);
+ assertStale(bar0);
+ assertNull(juu1);
+ assertStale(foo1);
+ assertStale(bar1);
+ assertNull(foo2);
+ assertNull(bar2);
+ assertNull(juu2);
+ assertEquals(Collections.emptyList(), getChildren(mockRoot));
+ assertFalse(isValid(mockFoo));
+ assertFalse(isValid(mockBar));
+ assertFalse(isValid(mockJuu));
+// assertTrue(rootV2 > rootV1);
+ }
+
+ public void testUpdateProperty() throws MockException
+ {
+ MockObject mockRoot = getRoot();
+ String rootId = getId(mockRoot);
+// int rootV0 = mockRoot.getVersion();
+
+ //
+ StructuralObject root0 = getStructuralStateContext().load(rootId);
+ StructuralState rootState0 = root0.getState();
+ assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
+
+ // Set
+ setProperty(mockRoot, "foo", "bar");
+
+ //
+// int rootV1 = mockRoot.getVersion();
+// assertTrue(rootV1 > rootV0);
+ assertEquals(Collections.singleton("foo"), getPropertyNames(mockRoot));
+ assertEquals("bar", getProperty(mockRoot, "foo"));
+ assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
+ assertStale(root0);
+ StructuralObject root1 = getStructuralStateContext().load(rootId);
+ assertNotNull(root1);
+ assertNotStale(root1);
+ StructuralState rootState1 = root1.getState();
+ assertEquals(Collections.singletonMap("foo", "bar"),
rootState1.getProperties());
+ }
+
+ public void testInvalidatedByDestruction() throws MockException
+ {
+ MockObject mockRoot = getRoot();
+
+ //
+ MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
+ MockObject mockBar = addChild(mockRoot, "bar", UIPage.class);
+
+ //
+ StructuralObject foo = getStructuralObject(mockFoo);
+
+ //
+ destroy(mockFoo);
+
+ //
+ assertValidity(foo, NoSuchStateException.class);
+ }
+
+ public void testInvalidatedByPropertyUpdate() throws MockException
+ {
+ MockObject mockRoot = getRoot();
+
+ //
+ MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
+
+ //
+ StructuralObject foo = getStructuralObject(mockFoo);
+
+ //
+ setProperty(mockFoo, "a", "b");
+
+ //
+ assertValidity(foo, StaleStateException.class);
+ }
+
+ public void testInvalidatedByChildCreation() throws MockException
+ {
+ MockObject mockRoot = getRoot();
+
+ //
+ MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
+
+ //
+ StructuralObject foo = getStructuralObject(mockFoo);
+
+ //
+ addChild(mockFoo, "juu", UIPage.class);
+
+ //
+ assertValidity(foo, StaleStateException.class);
+ }
+
+ public void testInvalidatedByChildDestruction() throws MockException
+ {
+ MockObject mockRoot = getRoot();
+
+ //
+ MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
+ MockObject mockJuu = addChild(mockFoo, "juu", UIPage.class);
+
+ //
+ StructuralObject foo = getStructuralObject(mockFoo);
+
+ //
+ destroy(mockJuu);
+
+ //
+ assertValidity(foo, StaleStateException.class);
+ }
+
+
+ public void testRefresh() throws MockException
+ {
+ MockObject mockRoot = getRoot();
+ String rootId = getId(mockRoot);
+ MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
+ String fooId = getId(mockFoo);
+ MockObject mockJuu = addChild(mockRoot, "juu", UIPage.class);
+ String juuId = getId(mockJuu);
+ MockObject mockFaa = addChild(mockRoot, "faa", UIPage.class);
+ String faaId = getId(mockFaa);
+ StructuralObject rootV0 = getStructuralStateContext().load(rootId);
+
+ //
+ MockObject mockBar = addChild(mockRoot, "bar", UIPage.class);
+ String barId = getId(mockBar);
+ destroy(mockFoo);
+ setProperty(mockJuu, "blah", "blah");
+
+ //
+ StructuralObject.Refresh comparison = getStructuralStateContext().refresh(rootV0);
+ assertNotNull(comparison);
+ Set<String> removed = comparison.getRemovedChildren();
+ assertNotNull(removed);
+ assertEquals(1, removed.size());
+ assertEquals(fooId, removed.iterator().next());
+
+ //
+ Set<StructuralObject> added = comparison.getAddedChildren();
+ assertNotNull(added);
+ assertEquals(1, added.size());
+ assertEquals(barId, added.iterator().next().getId());
+
+ //
+ Map<String, StructuralObject> stale = comparison.getStaleChildren();
+ assertNotNull(stale);
+ assertTrue(stale.size() >= 1);
+ StructuralObject juu = stale.get(getId(mockJuu));
+ assertNotNull(juu);
+ assertEquals(juuId, juu.getId());
+ assertEquals("blah",
juu.getState().getProperties().get("blah"));
+
+ //
+ Set<String> valid = comparison.getValidChildren();
+ assertNotNull(valid);
+ assertEquals(2 - stale.size(), valid.size());
+ if (valid.size() >= 1)
+ {
+ assertTrue(valid.contains(faaId));
+ }
+ }
+
+ protected final void assertValidity(StructuralObject object, Class<? extends
StateException> expected) throws MockException
+ {
+ try
+ {
+ getStructuralStateContext().validate(object);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ getStructuralStateContext().loadChildren(object);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ getStructuralStateContext().loadParent(object);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ }
+
+ protected final void assertStale(StructuralObject object)
+ {
+ try
+ {
+ getStructuralStateContext().validate(object);
+ fail();
+ }
+ catch (StateException ignore)
+ {
+ }
+ }
+
+ protected final void assertNotStale(StructuralObject object)
+ {
+ getStructuralStateContext().validate(object);
+ }
+}
Deleted:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -1,445 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, 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.model;
-
-import junit.framework.TestCase;
-import org.jboss.portal.presentation.model.ui.UIObject;
-import org.jboss.portal.presentation.model.ui.UIContext;
-import org.jboss.portal.presentation.model.ui.UIPage;
-import org.jboss.portal.presentation.state.NoSuchStateException;
-import org.jboss.portal.presentation.state.StaleStateException;
-import org.jboss.portal.presentation.state.StateException;
-import org.jboss.portal.presentation.state.structural.StructuralObject;
-import org.jboss.portal.presentation.state.structural.StructuralState;
-import org.jboss.portal.presentation.state.structural.StructuralStateContext;
-import org.jboss.portal.presentation.test.model.state.structural.MockException;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.io.Serializable;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public abstract class AbstractModelTestCase<MockObject> extends TestCase
-{
-
- public AbstractModelTestCase()
- {
- }
-
- public AbstractModelTestCase(String testName)
- {
- super(testName);
- }
-
- protected abstract StructuralStateContext getStructuralStateContext();
-
- protected abstract MockObject getRoot();
-
- protected abstract Set<String> getPropertyNames(MockObject object);
-
- protected abstract MockObject getParent(MockObject object);
-
- protected abstract List<? extends MockObject> getChildren(MockObject object);
-
- protected abstract String getName(MockObject object);
-
- protected abstract boolean isValid(MockObject object);
-
- protected abstract Class<? extends UIObject> getType(MockObject object);
-
- protected abstract String getId(MockObject object);
-
- protected abstract MockObject addChild(MockObject object, String name, Class<?
extends UIObject> modelType);
-
- protected abstract void destroy(MockObject object);
-
- protected abstract void setProperty(MockObject object, String propertyName, String
propertyValue);
-
- protected abstract Serializable getProperty(MockObject object, String name);
-
- protected final StructuralObject getStructuralObject(MockObject object)
- {
- return getStructuralStateContext().load(getId(object));
- }
-
- public void testRoot()
- {
- MockObject mockRoot = getRoot();
- assertNotNull(mockRoot);
- assertEquals(Collections.EMPTY_SET, getPropertyNames(mockRoot));
- assertNull(getParent(mockRoot));
- assertEquals(Collections.EMPTY_LIST, getChildren(mockRoot));
- assertEquals(UIContext.class, getType(mockRoot));
- assertEquals("", getName(mockRoot));
- assertEquals(true, isValid(mockRoot));
-
- //
- String rootId = getStructuralStateContext().getRootId();
- assertNotNull(rootId);
- StructuralObject root = getStructuralStateContext().load(rootId);
- assertNotNull(root);
- assertEquals(rootId, root.getId());
- StructuralState state = root.getState();
- assertEquals(UIContext.class, state.getType());
- assertEquals(Collections.EMPTY_MAP, state.getProperties());
- }
-
- public void testAddChild()
- {
- MockObject mockRoot = getRoot();
- // int rootV0 = mockRoot.getVersion();
-
- //
- String rootId = getId(mockRoot);
- StructuralObject root = getStructuralStateContext().load(rootId);
-
- //
- MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
- assertNotNull(mockFoo);
- String fooId = getId(mockFoo);
-
- //
- assertNotNull(fooId);
- assertEquals("foo", getName(mockFoo));
- assertEquals(UIPage.class, getType(mockFoo));
- assertSame(mockRoot, getParent(mockFoo));
- assertEquals(Collections.singletonList(mockFoo), getChildren(mockRoot));
- assertEquals(Collections.EMPTY_SET, getPropertyNames(mockFoo));
- // assertTrue(mockRoot.getVersion() > rootV0);
-
- //
- try
- {
- getStructuralStateContext().loadParent(root);
- fail();
- }
- catch (StaleStateException ignore)
- {
- }
- try
- {
- getStructuralStateContext().loadChildren(root);
- fail();
- }
- catch (StaleStateException ignore)
- {
- }
-
- //
- root = getStructuralStateContext().load(rootId);
- assertNotNull(root);
- assertEquals(rootId, root.getId());
-
- //
- Collection<StructuralObject> children =
getStructuralStateContext().loadChildren(root);
- assertNotNull(children);
- assertEquals(1, children.size());
- StructuralObject foo = children.iterator().next();
- assertNotNull(foo);
- assertEquals(fooId, foo.getId());
- StructuralState fooState = foo.getState();
- assertNotNull(fooState);
- assertEquals(Collections.EMPTY_MAP, fooState.getProperties());
- assertEquals(UIPage.class, fooState.getType());
- root = getStructuralStateContext().loadParent(foo);
- assertNotNull(root);
- assertEquals(rootId, root.getId());
- }
-
- public void testDestroy() throws MockException
- {
- MockObject mockRoot = getRoot();
- MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
- MockObject mockBar = addChild(mockFoo, "bar", UIPage.class);
- MockObject mockJuu = addChild(mockFoo, "juu", UIPage.class);
-// int rootV0 = mockRoot.getVersion();
-// int fooV0 = mockFoo.getVersion();
-// int barV0 = mockBar.getVersion();
- String fooId = getId(mockFoo);
- String barId = getId(mockBar);
- String juuId = getId(mockJuu);
- StructuralObject foo0 = getStructuralStateContext().load(fooId);
- StructuralObject bar0 = getStructuralStateContext().load(barId);
- StructuralObject juu0 = getStructuralStateContext().load(juuId);
-
- //
- destroy(mockJuu);
-
- //
- StructuralObject foo1 = getStructuralStateContext().load(fooId);
- StructuralObject bar1 = getStructuralStateContext().load(barId);
- StructuralObject juu1 = getStructuralStateContext().load(juuId);
-// int rootV1 = mockRoot.getVersion();
-// int fooV1 = mockFoo.getVersion();
-// int barV1 = mockBar.getVersion();
-
- //
- assertStale(juu0);
- assertStale(foo0);
- assertNotStale(bar0);
- assertNull(juu1);
- assertNotStale(foo1);
- assertNotStale(bar1);
- assertEquals(Collections.singletonList(mockFoo), getChildren(mockRoot));
- assertEquals(Collections.singletonList(mockBar), getChildren(mockFoo));
- assertTrue(isValid(mockFoo));
- assertTrue(isValid(mockBar));
- assertFalse(isValid(mockJuu));
-// assertTrue(rootV1 == rootV0);
-// assertTrue(fooV1 > fooV0);
-// assertTrue(barV1 == barV0);
-
- //
- destroy(mockFoo);
-
-// int rootV2 = mockRoot.getVersion();
- StructuralObject foo2 = getStructuralStateContext().load(fooId);
- StructuralObject bar2 = getStructuralStateContext().load(barId);
- StructuralObject juu2 = getStructuralStateContext().load(juuId);
-
- //
- assertStale(juu0);
- assertStale(foo0);
- assertStale(bar0);
- assertNull(juu1);
- assertStale(foo1);
- assertStale(bar1);
- assertNull(foo2);
- assertNull(bar2);
- assertNull(juu2);
- assertEquals(Collections.emptyList(), getChildren(mockRoot));
- assertFalse(isValid(mockFoo));
- assertFalse(isValid(mockBar));
- assertFalse(isValid(mockJuu));
-// assertTrue(rootV2 > rootV1);
- }
-
- public void testUpdateProperty() throws MockException
- {
- MockObject mockRoot = getRoot();
- String rootId = getId(mockRoot);
-// int rootV0 = mockRoot.getVersion();
-
- //
- StructuralObject root0 = getStructuralStateContext().load(rootId);
- StructuralState rootState0 = root0.getState();
- assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
-
- // Set
- setProperty(mockRoot, "foo", "bar");
-
- //
-// int rootV1 = mockRoot.getVersion();
-// assertTrue(rootV1 > rootV0);
- assertEquals(Collections.singleton("foo"), getPropertyNames(mockRoot));
- assertEquals("bar", getProperty(mockRoot, "foo"));
- assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
- assertStale(root0);
- StructuralObject root1 = getStructuralStateContext().load(rootId);
- assertNotNull(root1);
- assertNotStale(root1);
- StructuralState rootState1 = root1.getState();
- assertEquals(Collections.singletonMap("foo", "bar"),
rootState1.getProperties());
- }
-
- public void testInvalidatedByDestruction() throws MockException
- {
- MockObject mockRoot = getRoot();
-
- //
- MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
- MockObject mockBar = addChild(mockRoot, "bar", UIPage.class);
-
- //
- StructuralObject foo = getStructuralObject(mockFoo);
-
- //
- destroy(mockFoo);
-
- //
- assertValidity(foo, NoSuchStateException.class);
- }
-
- public void testInvalidatedByPropertyUpdate() throws MockException
- {
- MockObject mockRoot = getRoot();
-
- //
- MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
-
- //
- StructuralObject foo = getStructuralObject(mockFoo);
-
- //
- setProperty(mockFoo, "a", "b");
-
- //
- assertValidity(foo, StaleStateException.class);
- }
-
- public void testInvalidatedByChildCreation() throws MockException
- {
- MockObject mockRoot = getRoot();
-
- //
- MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
-
- //
- StructuralObject foo = getStructuralObject(mockFoo);
-
- //
- addChild(mockFoo, "juu", UIPage.class);
-
- //
- assertValidity(foo, StaleStateException.class);
- }
-
- public void testInvalidatedByChildDestruction() throws MockException
- {
- MockObject mockRoot = getRoot();
-
- //
- MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
- MockObject mockJuu = addChild(mockFoo, "juu", UIPage.class);
-
- //
- StructuralObject foo = getStructuralObject(mockFoo);
-
- //
- destroy(mockJuu);
-
- //
- assertValidity(foo, StaleStateException.class);
- }
-
-
- public void testRefresh() throws MockException
- {
- MockObject mockRoot = getRoot();
- String rootId = getId(mockRoot);
- MockObject mockFoo = addChild(mockRoot, "foo", UIPage.class);
- String fooId = getId(mockFoo);
- MockObject mockJuu = addChild(mockRoot, "juu", UIPage.class);
- String juuId = getId(mockJuu);
- MockObject mockFaa = addChild(mockRoot, "faa", UIPage.class);
- String faaId = getId(mockFaa);
- StructuralObject rootV0 = getStructuralStateContext().load(rootId);
-
- //
- MockObject mockBar = addChild(mockRoot, "bar", UIPage.class);
- String barId = getId(mockBar);
- destroy(mockFoo);
- setProperty(mockJuu, "blah", "blah");
-
- //
- StructuralObject.Refresh comparison = getStructuralStateContext().refresh(rootV0);
- assertNotNull(comparison);
- Set<String> removed = comparison.getRemovedChildren();
- assertNotNull(removed);
- assertEquals(1, removed.size());
- assertEquals(fooId, removed.iterator().next());
-
- //
- Set<StructuralObject> added = comparison.getAddedChildren();
- assertNotNull(added);
- assertEquals(1, added.size());
- assertEquals(barId, added.iterator().next().getId());
-
- //
- Map<String, StructuralObject> stale = comparison.getStaleChildren();
- assertNotNull(stale);
- assertTrue(stale.size() >= 1);
- StructuralObject juu = stale.get(getId(mockJuu));
- assertNotNull(juu);
- assertEquals(juuId, juu.getId());
- assertEquals("blah",
juu.getState().getProperties().get("blah"));
-
- //
- Set<String> valid = comparison.getValidChildren();
- assertNotNull(valid);
- assertEquals(2 - stale.size(), valid.size());
- if (valid.size() >= 1)
- {
- assertTrue(valid.contains(faaId));
- }
- }
-
- protected final void assertValidity(StructuralObject object, Class<? extends
StateException> expected) throws MockException
- {
- try
- {
- getStructuralStateContext().validate(object);
- fail();
- }
- catch (StateException e)
- {
- assertTrue(expected.isInstance(e));
- }
-
- //
- try
- {
- getStructuralStateContext().loadChildren(object);
- fail();
- }
- catch (StateException e)
- {
- assertTrue(expected.isInstance(e));
- }
-
- //
- try
- {
- getStructuralStateContext().loadParent(object);
- fail();
- }
- catch (StateException e)
- {
- assertTrue(expected.isInstance(e));
- }
-
- }
-
- protected final void assertStale(StructuralObject object)
- {
- try
- {
- getStructuralStateContext().validate(object);
- fail();
- }
- catch (StateException ignore)
- {
- }
- }
-
- protected final void assertNotStale(StructuralObject object)
- {
- getStructuralStateContext().validate(object);
- }
-}
Copied:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java
(from rev 11193,
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/AbstractModelTestCase.java)
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -0,0 +1,106 @@
+/******************************************************************************
+ * 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.model;
+
+import junit.framework.TestCase;
+import org.jboss.portal.presentation.impl.model.UIModelImpl;
+import
org.jboss.portal.presentation.impl.state.navigational.NavigationalStateContextImpl;
+import org.jboss.portal.presentation.model.UIModel;
+import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.test.model.MockModel;
+import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
+import org.jboss.portal.presentation.test.model.MockObject;
+import org.jboss.portal.presentation.test.model3.UIObjectNode;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class AbstractModelTestCase extends TestCase
+{
+
+ /** . */
+ protected UIModel model;
+
+ /** . */
+ protected MockModel mockModel;
+
+ /** . */
+ protected StructuralStateContext structuralStateContext;
+
+ protected void setUp() throws Exception
+ {
+ mockModel = new MockModelImpl();
+ structuralStateContext = mockModel.getStructuralStateContext();
+ model = new UIModelImpl(new NavigationalStateContextImpl(),
structuralStateContext);
+ }
+
+ /**
+ * @param objectNode the object node
+ * @return the name
+ * @see #getName(org.jboss.portal.presentation.model.ui.UIObject)
+ */
+ public String getName(UIObjectNode objectNode)
+ {
+ return getName(objectNode.getObject());
+ }
+
+ /**
+ * Returns the name of a ui object node.
+ *
+ * @param object the object
+ * @return the name
+ */
+ public String getName(UIObject object)
+ {
+ MockObject mockObject = mockModel.get(object.getId());
+
+ //
+ if (mockObject == null)
+ {
+ throw new IllegalArgumentException("No such mock object " +
object.getId());
+ }
+
+ //
+ return mockObject.getName();
+ }
+
+ public UIObjectNode getChild(UIObjectNode objectNode, String name)
+ {
+ MockObject mockObject = mockModel.get(objectNode.getObject().getId());
+
+ //
+ MockObject mockChild = mockObject.getChild(name);
+
+ //
+ if (mockChild == null)
+ {
+ return null;
+ }
+
+ //
+ return objectNode.getChild(mockChild.getId());
+ }
+
+}
\ No newline at end of file
Copied:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockException.java
(from rev 11193,
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockException.java)
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockException.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockException.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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.model;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class MockException extends RuntimeException
+{
+
+ /** . */
+ private ErrorCode code;
+
+ public MockException(ErrorCode code)
+ {
+ this.code = code;
+ }
+
+ public MockException(String s, ErrorCode code)
+ {
+ super(s);
+ this.code = code;
+ }
+
+ public enum ErrorCode
+ {
+ INVALID_OBJECT,
+ CONSTRAINT_VIOLATION
+ }
+
+ public ErrorCode getCode()
+ {
+ return code;
+ }
+}
Copied:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockModel.java
(from rev 11193,
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockModel.java)
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockModel.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockModel.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -0,0 +1,41 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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.model;
+
+import org.jboss.portal.presentation.state.structural.StructuralStateContext;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface MockModel
+{
+
+ StructuralStateContext getStructuralStateContext();
+
+ MockObject getRoot();
+
+ void destroy(MockObject object) throws MockException;
+
+ MockObject get(String id);
+}
Copied:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockObject.java
(from rev 11193,
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockObject.java)
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockObject.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockObject.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -0,0 +1,110 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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.model;
+
+import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.state.structural.StructuralObject;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface MockObject
+{
+
+ 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;
+ }
+ }
+
+ Class<? extends UIObject> getType();
+
+ String getName();
+
+ String getId();
+
+ int getVersion();
+
+ Serializable getPropertyValue(String propertyName) throws IllegalArgumentException;
+
+ void setPropertyBehavior(String propertyName, UpdateBehavior propertyBehavior) throws
IllegalArgumentException;
+
+ UpdateBehavior getPropertyBehavior(String propertyName) throws
IllegalArgumentException;
+
+ void setPropertyValue(String propertyName, Serializable propertyValue) throws
MockException;
+
+ Set<String> getPropertyNames();
+
+ MockObject addChild(String name, Class<? extends UIObject> type, Map<String,
String> state) throws IllegalArgumentException, MockException;
+
+ MockObject addChild(String name, Class<? extends UIObject> type) throws
IllegalArgumentException, MockException;
+
+ MockObject getParent();
+
+ List<? extends MockObject> getChildren();
+
+ MockObject getChild(String name);
+
+ boolean isValid();
+
+ StructuralObject takeSnapshot();
+
+ void move(MockObject destination) throws IllegalArgumentException, MockException;
+}
Added:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/Resolver.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/Resolver.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/Resolver.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -0,0 +1,58 @@
+/******************************************************************************
+ * 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.model;
+
+import org.jboss.portal.presentation.test.model.MockModel;
+import org.jboss.portal.presentation.test.model.MockObject;
+import org.jboss.portal.presentation.test.model3.UIObjectNode;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class Resolver
+{
+
+ /** . */
+ private final MockModel model;
+
+ public Resolver(MockModel model)
+ {
+ this.model = model;
+ }
+
+ public String getName(UIObjectNode objectNode)
+ {
+ MockObject mockObject = model.get(objectNode.getObject().getId());
+
+ //
+ if (mockObject == null)
+ {
+ return null;
+ }
+
+ //
+ return mockObject.getName();
+ }
+
+}
Deleted:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockException.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockException.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockException.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -1,56 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, 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.model.state.structural;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class MockException extends RuntimeException
-{
-
- /** . */
- private ErrorCode code;
-
- public MockException(ErrorCode code)
- {
- this.code = code;
- }
-
- public MockException(String s, ErrorCode code)
- {
- super(s);
- this.code = code;
- }
-
- public enum ErrorCode
- {
- INVALID_OBJECT,
- CONSTRAINT_VIOLATION
- }
-
- public ErrorCode getCode()
- {
- return code;
- }
-}
Deleted:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -1,40 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, 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.model.state.structural;
-
-import org.jboss.portal.presentation.state.structural.StructuralStateContext;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public interface MockModel
-{
-
- StructuralStateContext getStructuralStateContext();
-
- MockObject getRoot();
-
- void destroy(MockObject object) throws MockException;
-
-}
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -29,6 +29,9 @@
import org.jboss.portal.presentation.state.StateException;
import org.jboss.portal.presentation.state.structural.StructuralObject;
import org.jboss.portal.presentation.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.test.model.MockObject;
+import org.jboss.portal.presentation.test.model.MockModel;
+import org.jboss.portal.presentation.test.model.MockException;
import java.util.ArrayList;
import java.util.Collection;
@@ -64,6 +67,11 @@
return root;
}
+ public MockObject get(String id)
+ {
+ return universe.get(id);
+ }
+
public void destroy(MockObject object) throws MockException
{
destroy((MockObjectImpl)object, new ArrayList<String>());
Deleted:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockObject.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockObject.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockObject.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -1,110 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, 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.model.state.structural;
-
-import org.jboss.portal.presentation.model.ui.UIObject;
-import org.jboss.portal.presentation.state.structural.StructuralObject;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.io.Serializable;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public interface MockObject
-{
-
- 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;
- }
- }
-
- Class<? extends UIObject> getType();
-
- String getName();
-
- String getId();
-
- int getVersion();
-
- Serializable getPropertyValue(String propertyName) throws IllegalArgumentException;
-
- void setPropertyBehavior(String propertyName, UpdateBehavior propertyBehavior) throws
IllegalArgumentException;
-
- UpdateBehavior getPropertyBehavior(String propertyName) throws
IllegalArgumentException;
-
- void setPropertyValue(String propertyName, Serializable propertyValue) throws
MockException;
-
- Set<String> getPropertyNames();
-
- MockObject addChild(String name, Class<? extends UIObject> type, Map<String,
String> state) throws IllegalArgumentException, MockException;
-
- MockObject addChild(String name, Class<? extends UIObject> type) throws
IllegalArgumentException, MockException;
-
- MockObject getParent();
-
- List<? extends MockObject> getChildren();
-
- MockObject getChild(String name);
-
- boolean isValid();
-
- StructuralObject takeSnapshot();
-
- void move(MockObject destination) throws IllegalArgumentException, MockException;
-}
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -23,6 +23,8 @@
package org.jboss.portal.presentation.test.model.state.structural;
import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.test.model.MockObject;
+import org.jboss.portal.presentation.test.model.MockException;
import java.util.ArrayList;
import java.util.Collections;
Deleted:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/AbstractModelTestCase.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/AbstractModelTestCase.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/AbstractModelTestCase.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -1,55 +0,0 @@
-/******************************************************************************
- * 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 junit.framework.TestCase;
-import org.jboss.portal.presentation.impl.model.UIModelImpl;
-import
org.jboss.portal.presentation.impl.state.navigational.NavigationalStateContextImpl;
-import org.jboss.portal.presentation.model.UIModel;
-import org.jboss.portal.presentation.state.structural.StructuralStateContext;
-import org.jboss.portal.presentation.test.model.state.structural.MockModel;
-import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
- * @version $Revision: 630 $
- */
-public abstract class AbstractModelTestCase extends TestCase
-{
-
- /** . */
- protected UIModel model;
-
- /** . */
- protected MockModel mockModel;
-
- /** . */
- protected StructuralStateContext structuralStateContext;
-
- protected void setUp() throws Exception
- {
- mockModel = new MockModelImpl();
- structuralStateContext = mockModel.getStructuralStateContext();
- model = new UIModelImpl(new NavigationalStateContextImpl(),
structuralStateContext);
- }
-}
\ No newline at end of file
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/AddChildTestCase.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/AddChildTestCase.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/AddChildTestCase.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -49,13 +49,13 @@
rootDef.populate(mockModel);
//
- ViewPortScope scope = new CustomScope(model, rootDef);
+ ViewPortScope scope = new CustomScope(mockModel, model, rootDef);
UIObjectTree context = new UIObjectTree();
ViewPort viewPort = model.createViewPort(context, scope);
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
context.assertConsistency(model.getRootId());
//
@@ -65,7 +65,7 @@
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
context.assertConsistency(model.getRootId());
}
}
\ No newline at end of file
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/CustomScope.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/CustomScope.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/CustomScope.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -26,6 +26,8 @@
import org.jboss.portal.presentation.model.UIModel;
import org.jboss.portal.presentation.model.ui.UIObject;
import org.jboss.portal.presentation.model.ViewPortScope;
+import org.jboss.portal.presentation.test.model.MockModel;
+import org.jboss.portal.presentation.test.model.MockObject;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -35,6 +37,9 @@
{
/** . */
+ private final MockModel mockModel;
+
+ /** . */
private final UIModel model;
/** . */
@@ -43,7 +48,7 @@
/** . */
private NodeDef current;
- public CustomScope(UIModel model, NodeDef root)
+ public CustomScope(MockModel mockModel, UIModel model, NodeDef root)
{
if (root == null)
{
@@ -51,6 +56,7 @@
}
//
+ this.mockModel = mockModel;
this.model = model;
this.root = root;
this.current = null;
@@ -76,9 +82,18 @@
}
else
{
- NodeDef child = current.getChild(object.getId());
+ MockObject mockObject = mockModel.get(object.getId());
//
+ if (mockObject == null)
+ {
+ throw new IllegalStateException("No such mock object " +
object.getId());
+ }
+
+ //
+ NodeDef child = current.getChild(mockObject.getName());
+
+ //
if (child == null)
{
throw new IllegalStateException("No such child " +
object.getId());
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/ModelTestCase.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/ModelTestCase.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/ModelTestCase.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -56,18 +56,18 @@
rootDef.populate(mockModel);
//
- ViewPortScope scope = new CustomScope(model, rootDef);
+ ViewPortScope scope = new CustomScope(mockModel, model, rootDef);
UIObjectTree context = new UIObjectTree();
ViewPort viewPort = model.createViewPort(context, scope);
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
context.assertConsistency(model.getRootId());
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
context.assertConsistency(model.getRootId());
//
@@ -78,7 +78,7 @@
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
context.assertConsistency(model.getRootId());
}
}
\ No newline at end of file
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/MoveChildTestCase.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/MoveChildTestCase.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/MoveChildTestCase.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -48,13 +48,13 @@
rootDef.populate(mockModel);
//
- ViewPortScope scope = new CustomScope(model, rootDef);
+ ViewPortScope scope = new CustomScope(mockModel, model, rootDef);
UIObjectTree context = new UIObjectTree();
ViewPort viewPort = model.createViewPort(context, scope);
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
context.assertConsistency(model.getRootId());
//
@@ -64,7 +64,7 @@
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
context.assertConsistency(model.getRootId());
}
});
@@ -85,13 +85,13 @@
rootDef.populate(mockModel);
//
- ViewPortScope scope = new CustomScope(model, rootDef);
+ ViewPortScope scope = new CustomScope(mockModel, model, rootDef);
UIObjectTree context = new UIObjectTree();
ViewPort viewPort = model.createViewPort(context, scope);
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
context.assertConsistency(model.getRootId());
//
@@ -101,7 +101,7 @@
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
context.assertConsistency(model.getRootId());
}
});
@@ -123,13 +123,13 @@
rootDef.populate(mockModel);
//
- ViewPortScope scope = new CustomScope(model, rootDef);
+ ViewPortScope scope = new CustomScope(mockModel, model, rootDef);
UIObjectTree context = new UIObjectTree();
ViewPort viewPort = model.createViewPort(context, scope);
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
context.assertConsistency(model.getRootId());
//
@@ -142,7 +142,7 @@
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
context.assertConsistency(model.getRootId());
}
});
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/NodeDef.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/NodeDef.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/NodeDef.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -27,13 +27,15 @@
import org.jboss.portal.presentation.model.ui.UIObject;
import org.jboss.portal.presentation.model.ui.UIContext;
import org.jboss.portal.presentation.model.ui.UIPage;
-import org.jboss.portal.presentation.test.model.state.structural.MockModel;
-import org.jboss.portal.presentation.test.model.state.structural.MockObject;
+import org.jboss.portal.presentation.test.model.MockModel;
+import org.jboss.portal.presentation.test.model.MockObject;
+import org.jboss.portal.presentation.test.model.Resolver;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.Collection;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -85,6 +87,11 @@
return children.get(name);
}
+ public Collection<NodeDef> getChildren()
+ {
+ return children.values();
+ }
+
public NodeDef getParent()
{
return parent;
@@ -180,7 +187,7 @@
}
}
- public void assertEquals(UIObjectNode objectNode)
+ public void assertEquals(Resolver resolver, UIObjectNode objectNode)
{
Assert.assertEquals(properties.keySet(), objectNode.getProperties().keySet());
for (String propertyName : properties.keySet())
@@ -210,13 +217,19 @@
}
//
- Assert.assertEquals(expectedChildrenNames,
objectNode.getChildren().keySet());
-
- //
+ Set<String> childrenNames = new HashSet<String>();
for (UIObjectNode childObjectNode : objectNode.getChildren().values())
{
- child.assertEquals(childObjectNode);
+ String childName = resolver.getName(childObjectNode);
+ childrenNames.add(childName);
+ NodeDef expectedChild = children.get(childName);
+ expectedChild.assertEquals(resolver, childObjectNode);
}
+
+ //
+ Assert.assertEquals(expectedChildrenNames, childrenNames);
+
+ //
break;
}
}
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/RemoveChildTestCase.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/RemoveChildTestCase.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/RemoveChildTestCase.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -49,13 +49,13 @@
rootDef.populate(mockModel);
//
- ViewPortScope scope = new CustomScope(model, rootDef);
+ ViewPortScope scope = new CustomScope(mockModel, model, rootDef);
UIObjectTree context = new UIObjectTree();
ViewPort viewPort = model.createViewPort(context, scope);
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
//
mockModel.destroy(mockModel.getRoot().getChild("foo").getChild("juu"));
@@ -63,7 +63,7 @@
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
context.assertConsistency(model.getRootId());
}
}
\ No newline at end of file
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/TraversalModelTestCase.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/TraversalModelTestCase.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/TraversalModelTestCase.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -29,7 +29,8 @@
import org.jboss.portal.presentation.model.ObjectTraversalType;
import org.jboss.portal.presentation.model.UIModel;
import org.jboss.portal.presentation.state.structural.StructuralStateContext;
-import org.jboss.portal.presentation.test.model.state.structural.MockModel;
+import org.jboss.portal.presentation.test.model.MockModel;
+import org.jboss.portal.presentation.test.model.Resolver;
import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
import java.util.ArrayList;
@@ -53,6 +54,9 @@
/** . */
protected StructuralStateContext structuralStateContext;
+ /** . */
+ protected Resolver resolver;
+
public void test(int size, Object handback)
{
ObjectTraversalType[] before = new ObjectTraversalType[size];
@@ -65,7 +69,8 @@
mockModel = new MockModelImpl();
structuralStateContext = mockModel.getStructuralStateContext();
model = new UIModelImpl(new NavigationalStateContextImpl(),
structuralStateContext);
-
+ resolver = new Resolver(mockModel);
+
//
Assert.assertEquals(before.length + after.length, element.length);
System.arraycopy(element, 0, before, 0, before.length);
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/TypeTestCase.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/TypeTestCase.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/TypeTestCase.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -27,6 +27,7 @@
import org.jboss.portal.presentation.model.ui.UIContext;
import org.jboss.portal.presentation.model.ui.UIPage;
import org.jboss.portal.presentation.model.ui.UIWindow;
+import org.jboss.portal.presentation.test.model.AbstractModelTestCase;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -45,7 +46,7 @@
rootDef.populate(mockModel);
//
- ViewPortScope scope = new CustomScope(model, rootDef);
+ ViewPortScope scope = new CustomScope(mockModel, model, rootDef);
UIObjectTree context = new UIObjectTree();
ViewPort viewPort = model.createViewPort(context, scope);
@@ -54,14 +55,17 @@
//
UIObjectNode root =
context.getNode(mockModel.getStructuralStateContext().getRootId());
- UIObjectNode foo = root.getChild("foo");
- UIObjectNode bar = root.getChild("bar");
+ UIObjectNode foo = getChild(root, "foo");
+ UIObjectNode bar = getChild(root, "bar");
//
+ assertNotNull(foo);
+ assertNotNull(bar);
+
+ //
assertTrue(root.getObject() instanceof UIContext);
assertTrue("was not expecting: " + foo.getObject().getClass().getName(),
foo.getObject() instanceof UIPage);
assertTrue("was not expecting: " + bar.getObject().getClass().getName(),
bar.getObject() instanceof UIWindow);
-
}
}
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/UIObjectNode.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/UIObjectNode.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/UIObjectNode.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -85,9 +85,9 @@
return children;
}
- public UIObjectNode getChild(String name)
+ public UIObjectNode getChild(String id)
{
- return children.get(name);
+ return children.get(id);
}
public void addChild(UIObjectNode child)
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/UpdateObjectTestCase.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/UpdateObjectTestCase.java 2008-07-02
20:50:40 UTC (rev 11269)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/UpdateObjectTestCase.java 2008-07-02
22:02:20 UTC (rev 11270)
@@ -47,20 +47,20 @@
rootDef.populate(mockModel);
//
- ViewPortScope scope = new CustomScope(model, rootDef);
+ ViewPortScope scope = new CustomScope(mockModel, model, rootDef);
UIObjectTree context = new UIObjectTree();
ViewPort viewPort = model.createViewPort(context, scope);
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
//
mockModel.getRoot().getChild("foo").setPropertyValue("juu",
"daa");
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
//
mockModel.getRoot().getChild("foo").setPropertyValue("juu",
null);
@@ -68,6 +68,6 @@
//
viewPort.refresh();
- rootDef.assertEquals(context.getNode(model.getRootId()));
+ rootDef.assertEquals(resolver, context.getNode(model.getRootId()));
}
}