Author: julien(a)jboss.com
Date: 2008-07-02 18:07:44 -0400 (Wed, 02 Jul 2008)
New Revision: 11271
Added:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/AbstractMockImplementationTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/MockModel.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/MockObject.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/MockModelImpl.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/MockObjectImpl.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/StructuralObjectHandle.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/StructuralObjectImpl.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/StructuralStateImpl.java
Removed:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/
Modified:
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/AbstractModelTestCase.java
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/model3/CustomScope.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/TraversalModelTestCase.java
Log:
refactoring packages
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
22:02:20 UTC (rev 11270)
+++
modules/presentation/trunk/portal/src/test/java/org/jboss/portal/presentation/portal/model/StructuralStateContextTestCase.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -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.AbstractMockImplementationTestCase;
+import org.jboss.portal.presentation.test.model.mock.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;
Modified:
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
22:02:20 UTC (rev 11270)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -28,9 +28,9 @@
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.model.mock.MockModel;
+import org.jboss.portal.presentation.test.model.mock.impl.MockModelImpl;
+import org.jboss.portal.presentation.test.model.mock.MockObject;
import org.jboss.portal.presentation.test.model3.UIObjectNode;
/**
Modified:
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 2008-07-02
22:02:20 UTC (rev 11270)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/Resolver.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -22,8 +22,8 @@
******************************************************************************/
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.model.mock.MockModel;
+import org.jboss.portal.presentation.test.model.mock.MockObject;
import org.jboss.portal.presentation.test.model3.UIObjectNode;
/**
Copied:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/AbstractMockImplementationTestCase.java
(from rev 11270,
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/mock/AbstractMockImplementationTestCase.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/AbstractMockImplementationTestCase.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -0,0 +1,445 @@
+/******************************************************************************
+ * 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.mock;
+
+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.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 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);
+ }
+}
Copied:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/MockModel.java
(from rev 11270,
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/mock/MockModel.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/MockModel.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -0,0 +1,42 @@
+/******************************************************************************
+ * 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.mock;
+
+import org.jboss.portal.presentation.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.test.model.MockException;
+
+/**
+ * @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/mock/MockObject.java
(from rev 11270,
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/mock/MockObject.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/MockObject.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -0,0 +1,111 @@
+/******************************************************************************
+ * 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.mock;
+
+import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.state.structural.StructuralObject;
+import org.jboss.portal.presentation.test.model.MockException;
+
+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;
+}
Copied:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/MockModelImpl.java
(from rev 11270,
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/mock/impl/MockModelImpl.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/MockModelImpl.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -0,0 +1,287 @@
+/******************************************************************************
+ * 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.mock.impl;
+
+import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.model.ui.UIContext;
+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.StructuralStateContext;
+import org.jboss.portal.presentation.test.model.mock.MockObject;
+import org.jboss.portal.presentation.test.model.mock.MockModel;
+import org.jboss.portal.presentation.test.model.MockException;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class MockModelImpl implements MockModel
+{
+
+ /** . */
+ private int generator = 0;
+
+ /** . */
+ private final Map<String, MockObjectImpl> universe = new HashMap<String,
MockObjectImpl>();
+
+ /** . */
+ private final MockObjectImpl root = createObject(UIContext.class, "");
+
+ public StructuralStateContext getStructuralStateContext()
+ {
+ return structuralStateContext;
+ }
+
+ public MockObject getRoot()
+ {
+ return root;
+ }
+
+ public MockObject get(String id)
+ {
+ return universe.get(id);
+ }
+
+ public void destroy(MockObject object) throws MockException
+ {
+ destroy((MockObjectImpl)object, new ArrayList<String>());
+ }
+
+ void destroy(MockObjectImpl object, List<String> ids) throws MockException
+ {
+ universe.remove(object.getId());
+
+ // Remove children recursively
+ for (MockObjectImpl child : object.getChildren())
+ {
+ destroy(child, ids);
+ }
+
+ //
+ object.destroy();
+
+ //
+ ids.add(object.getId());
+ }
+
+ MockObjectImpl createObject(Class<? extends UIObject> type, String name)
+ {
+ MockObjectImpl mockObject = new MockObjectImpl(this, name, type, "" +
generator++);
+ universe.put(mockObject.getId(), mockObject);
+ return mockObject;
+ }
+
+ private final StructuralStateContext structuralStateContext = new
StructuralStateContext()
+ {
+ public StructuralObject load(String objectId) throws IllegalArgumentException
+ {
+ if (objectId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ MockObjectImpl object = universe.get(objectId);
+
+ //
+ return object != null ? object.takeSnapshot() : null;
+ }
+
+ public String getRootId()
+ {
+ return root.getId();
+ }
+
+ public void validate(StructuralObject object) throws StateException
+ {
+ getValidMockObject(object);
+ }
+
+ public StructuralObject.Refresh refresh(StructuralObject object) throws
IllegalArgumentException, StateException
+ {
+ MockObjectImpl mockObject = getMockObject(object, false);
+
+ //
+ StructuralObjectImpl previous = (StructuralObjectImpl)object;
+ StructuralObjectImpl current = mockObject.takeSnapshot();
+
+ //
+ StructuralObject parent = null;
+ if (previous.parentHandle != null)
+ {
+ if (!current.parentHandle.equals(previous.handle))
+ {
+ parent = getMockObject(current.parentHandle, true).takeSnapshot();
+ }
+ }
+
+ //
+ Map<String, StructuralObjectHandle> previousChildren = new
HashMap<String, StructuralObjectHandle>();
+ for (StructuralObjectHandle childHandle : previous.childrenHandles)
+ {
+ previousChildren.put(childHandle.id, childHandle);
+ }
+
+ //
+ Map<String, StructuralObjectHandle> currentChildren = new
HashMap<String, StructuralObjectHandle>();
+ for (StructuralObjectHandle childHandle : current.childrenHandles)
+ {
+ currentChildren.put(childHandle.id, childHandle);
+ }
+
+ //
+ Map<String, StructuralObjectHandle> addedChildrenHandleMap = new
HashMap<String, StructuralObjectHandle>(currentChildren);
+ addedChildrenHandleMap.keySet().removeAll(previousChildren.keySet());
+ Set<StructuralObject> addedChildren = new
HashSet<StructuralObject>();
+ for (StructuralObjectHandle handle : addedChildrenHandleMap.values())
+ {
+ StructuralObject snapshot = getMockObject(handle, true).takeSnapshot();
+ addedChildren.add(snapshot);
+ }
+
+ //
+ Map<String, StructuralObjectHandle> removedChildrenHandleMap = new
HashMap<String, StructuralObjectHandle>(previousChildren);
+ removedChildrenHandleMap.keySet().removeAll(currentChildren.keySet());
+ Set<String> removedChildren = new HashSet<String>();
+ for (StructuralObjectHandle handle : removedChildrenHandleMap.values())
+ {
+ removedChildren.add(handle.id);
+ }
+
+ //
+ Map<String, StructuralObjectHandle> commonCurrentChildrenHandleMap = new
HashMap<String, StructuralObjectHandle>(currentChildren);
+ commonCurrentChildrenHandleMap.keySet().retainAll(previousChildren.keySet());
+
+ //
+ Map<String, StructuralObjectHandle> commonPreviousChildrenHandleMap = new
HashMap<String, StructuralObjectHandle>(previousChildren);
+ commonPreviousChildrenHandleMap.keySet().retainAll(currentChildren.keySet());
+
+ //
+ Set<StructuralObjectHandle> validChildrenHandleSet = new
HashSet<StructuralObjectHandle>(commonPreviousChildrenHandleMap.values());
+ validChildrenHandleSet.retainAll(commonCurrentChildrenHandleMap.values());
+ Set<String> validChildren = new HashSet<String>();
+ for (StructuralObjectHandle handle : validChildrenHandleSet)
+ {
+ validChildren.add(handle.id);
+ }
+
+ //
+ Set<StructuralObjectHandle> staleChildrenHandleSet = new
HashSet<StructuralObjectHandle>(commonPreviousChildrenHandleMap.values());
+ staleChildrenHandleSet.removeAll(commonCurrentChildrenHandleMap.values());
+
+ //
+ Map<String, StructuralObject> staleChildrenHandleMap = new
HashMap<String, StructuralObject>();
+ for (StructuralObjectHandle previousHandle : staleChildrenHandleSet)
+ {
+ String id = previousHandle.id;
+ StructuralObjectHandle handle = commonCurrentChildrenHandleMap.get(id);
+ StructuralObject snapshot = getMockObject(handle, true).takeSnapshot();
+ staleChildrenHandleMap.put(id, snapshot);
+ }
+
+ //
+ return new StructuralObject.Refresh(parent, current, addedChildren,
removedChildren, staleChildrenHandleMap, validChildren);
+ }
+
+ public Collection<StructuralObject> loadChildren(StructuralObject parent)
+ {
+ MockObject mockParent = getValidMockObject(parent);
+
+ //
+ List<StructuralObject> tmp = new ArrayList<StructuralObject>();
+ for (MockObject mockChild : mockParent.getChildren())
+ {
+ tmp.add(mockChild.takeSnapshot());
+ }
+ return tmp;
+ }
+
+ public StructuralObject loadParent(StructuralObject child) throws StateException
+ {
+ MockObject mockchild = getValidMockObject(child);
+ MockObject mockParent = mockchild.getParent();
+ return mockParent != null ? mockParent.takeSnapshot() : null;
+ }
+
+ private MockObjectImpl getValidMockObject(StructuralObject object) throws
StateException
+ {
+ return getMockObject(object, true);
+ }
+
+ private MockObjectImpl getMockObject(StructuralObject object, boolean
validateVersion)
+ {
+ if (object == null)
+ {
+ throw new IllegalArgumentException("No null object accepted");
+ }
+
+ //
+ StructuralObjectImpl structuralObject = (StructuralObjectImpl)object;
+
+ //
+ return getMockObject(structuralObject.handle, validateVersion);
+ }
+
+ private MockObjectImpl getMockObject(StructuralObjectHandle handle, boolean
validateVersion)
+ {
+ if (handle == null)
+ {
+ throw new IllegalArgumentException("No null object accepted");
+ }
+
+ //
+ MockObjectImpl mockObject = universe.get(handle.id);
+
+ //
+ if (mockObject == null)
+ {
+ throw new NoSuchStateException();
+ }
+
+ //
+ if (!mockObject.isValid())
+ {
+ throw new StaleStateException();
+ }
+
+ //
+ if (validateVersion && (mockObject.getVersion() != handle.version))
+ {
+ throw new StaleStateException("Version has changed obtained=" +
mockObject.getVersion() + " wanted=" + handle.version);
+ }
+
+ //
+ return mockObject;
+ }
+ };
+}
\ No newline at end of file
Copied:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/MockObjectImpl.java
(from rev 11270,
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/mock/impl/MockObjectImpl.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/MockObjectImpl.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -0,0 +1,333 @@
+/******************************************************************************
+ * 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.mock.impl;
+
+import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.test.model.mock.MockObject;
+import org.jboss.portal.presentation.test.model.MockException;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+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 $
+ */
+class MockObjectImpl implements MockObject
+{
+
+ /** . */
+ private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
+
+ /** . */
+ private final Class<? extends UIObject> type;
+
+ /** . */
+ private final String name;
+
+ /** . */
+ private final Map<String, Serializable> propertyValues;
+
+ /** . */
+ private final Map<String, UpdateBehavior> propertyBehaviors;
+
+ /** . */
+ private final LinkedHashMap<String, MockObjectImpl> children;
+
+ /** . */
+ private final MockModelImpl model;
+
+ /** . */
+ private MockObjectImpl parent;
+
+ /** . */
+ private boolean valid;
+
+ /** The version id. */
+ private StructuralObjectHandle handle;
+
+ MockObjectImpl(MockModelImpl model, String name, Class<? extends UIObject> type,
String id)
+ {
+ this.model = model;
+ this.name = name;
+ this.type = type;
+ this.children = new LinkedHashMap<String, MockObjectImpl>();
+ this.propertyValues = new HashMap<String, Serializable>();
+ this.propertyBehaviors = new HashMap<String, UpdateBehavior>();
+ this.valid = true;
+ this.handle = new StructuralObjectHandle(id, 0);
+ }
+
+ public Class<? extends UIObject> getType()
+ {
+ return type;
+ }
+
+ public boolean isValid()
+ {
+ return valid;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getId()
+ {
+ return handle.id;
+ }
+
+ public Serializable getPropertyValue(String propertyName)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ return propertyValues.get(propertyName);
+ }
+
+ public MockObjectImpl getParent()
+ {
+ return parent;
+ }
+
+ public List<MockObjectImpl> getChildren()
+ {
+ return Collections.unmodifiableList(new
ArrayList<MockObjectImpl>(children.values()));
+ }
+
+ public MockObjectImpl getChild(String name)
+ {
+ if (!valid)
+ {
+ throw new MockException(MockException.ErrorCode.INVALID_OBJECT);
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ for (MockObjectImpl child : children.values())
+ {
+ if (child.name.equals(name))
+ {
+ return child;
+ }
+ }
+
+ //
+ return null;
+ }
+
+ public MockObjectImpl addChild(String name, Class<? extends UIObject> type)
throws MockException
+ {
+ return addChild(name, type, EMPTY_STATE);
+ }
+
+ public Set<String> getPropertyNames()
+ {
+ return Collections.unmodifiableSet(propertyValues.keySet());
+ }
+
+ public MockObjectImpl addChild(String name, Class<? extends UIObject> type,
Map<String, String> state) throws MockException
+ {
+ if (!valid)
+ {
+ throw new MockException(MockException.ErrorCode.INVALID_OBJECT);
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (getChild(name) != null)
+ {
+ throw new MockException(MockException.ErrorCode.CONSTRAINT_VIOLATION);
+ }
+
+ //
+ MockObjectImpl child = model.createObject(type, name);
+
+ //
+ for (Map.Entry<String, String> entry : state.entrySet())
+ {
+ if (entry.getValue() == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ child.propertyValues.put(entry.getKey(), entry.getValue());
+ }
+
+ //
+ child.parent = this;
+ children.put(child.handle.id, child);
+ handle = handle.nextHandle();
+
+ //
+ return child;
+ }
+
+ public void setPropertyBehavior(String propertyName, UpdateBehavior propertyBehavior)
+ {
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyBehavior != null)
+ {
+ propertyBehaviors.put(propertyName, propertyBehavior);
+ }
+ else
+ {
+ propertyBehaviors.remove(propertyName);
+ }
+ }
+
+ public UpdateBehavior getPropertyBehavior(String propertyName)
+ {
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ return propertyBehaviors.get(propertyName);
+ }
+
+ public void setPropertyValue(String propertyName, Serializable propertyValue) throws
MockException
+ {
+ if (!valid)
+ {
+ throw new MockException(MockException.ErrorCode.INVALID_OBJECT);
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyValue != null)
+ {
+ propertyValues.put(propertyName, propertyValue);
+ }
+ else
+ {
+ propertyValues.remove(propertyName);
+ }
+
+ //
+ handle = handle.nextHandle();
+ }
+
+ public int getVersion()
+ {
+ return handle.version;
+ }
+
+ public StructuralObjectImpl takeSnapshot()
+ {
+ StructuralObjectHandle parentHandle = parent == null ? null : parent.handle;
+
+ //
+ List<StructuralObjectHandle> childrenHandles = new
ArrayList<StructuralObjectHandle>();
+ for (MockObjectImpl child : children.values())
+ {
+ childrenHandles.add(child.handle);
+ }
+
+ //
+ StructuralStateImpl state = new StructuralStateImpl(type, new HashMap<String,
Serializable>(propertyValues));
+
+ //
+ return new StructuralObjectImpl(handle, parentHandle, childrenHandles, state);
+ }
+
+ public void move(MockObject destination) throws IllegalStateException, MockException
+ {
+ move((MockObjectImpl)destination);
+ }
+
+ private void move(MockObjectImpl destination) throws MockException
+ {
+ if (!valid)
+ {
+ throw new MockException(MockException.ErrorCode.INVALID_OBJECT);
+ }
+ if (destination == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ // The source cannot an ancestor of the destination
+ for (MockObject current = destination;current != null;current =
current.getParent())
+ {
+ if (current == this)
+ {
+ throw new MockException(MockException.ErrorCode.CONSTRAINT_VIOLATION);
+ }
+ }
+
+ // No duplicate child name
+ for (MockObjectImpl child : destination.children.values())
+ {
+ if (name.equals(child.name))
+ {
+ throw new MockException(MockException.ErrorCode.CONSTRAINT_VIOLATION);
+ }
+ }
+
+ //
+ parent.children.remove(handle.id);
+ parent.handle = parent.handle.nextHandle();
+
+ //
+ destination.children.put(handle.id, this);
+ destination.handle = destination.handle.nextHandle();
+
+ //
+ parent = destination;
+ handle = handle.nextHandle();
+ }
+
+ public void destroy() throws MockException
+ {
+ if (!valid)
+ {
+ throw new MockException(MockException.ErrorCode.INVALID_OBJECT);
+ }
+
+ // Detach from parent
+ if (parent != null)
+ {
+ parent.children.remove(handle.id);
+ parent.handle = parent.handle.nextHandle();
+ parent = null;
+ }
+
+ // We cannot use it anymore
+ valid = false;
+ }
+}
Copied:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/StructuralObjectHandle.java
(from rev 11193,
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectHandle.java)
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/StructuralObjectHandle.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/StructuralObjectHandle.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -0,0 +1,81 @@
+/******************************************************************************
+ * 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.mock.impl;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+class StructuralObjectHandle
+{
+
+ /** . */
+ final String id;
+
+ /** . */
+ final int version;
+
+ StructuralObjectHandle(String id, int version)
+ {
+ if (id == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.id = id;
+ this.version = version;
+ }
+
+ public int hashCode()
+ {
+ return id.hashCode() * version;
+ }
+
+ public boolean equals(Object o)
+ {
+ if (o == this)
+ {
+ return true;
+ }
+ if (o instanceof StructuralObjectHandle)
+ {
+ StructuralObjectHandle that = (StructuralObjectHandle)o;
+
+ //
+ return id.equals(that.id) && version == that.version;
+ }
+ return false;
+ }
+
+ StructuralObjectHandle nextHandle()
+ {
+ return new StructuralObjectHandle(id, version + 1);
+ }
+
+ public String toString()
+ {
+ return "StructuralObjectHandle[id=" + id + ",version=" +
version + "]";
+ }
+
+}
Copied:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/StructuralObjectImpl.java
(from rev 11193,
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java)
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/StructuralObjectImpl.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/StructuralObjectImpl.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -0,0 +1,86 @@
+/******************************************************************************
+ * 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.mock.impl;
+
+import org.jboss.portal.presentation.state.structural.StructuralObject;
+import org.jboss.portal.presentation.state.structural.StructuralState;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+class StructuralObjectImpl implements StructuralObject
+{
+
+ /** . */
+ final StructuralObjectHandle handle;
+
+ /** . */
+ final StructuralObjectHandle parentHandle;
+
+ /** . */
+ final List<StructuralObjectHandle> childrenHandles;
+
+ /** . */
+ private final StructuralStateImpl state;
+
+ public StructuralObjectImpl(
+ StructuralObjectHandle handle,
+ StructuralObjectHandle parentHandle,
+ List<StructuralObjectHandle> childrenHandles,
+ StructuralStateImpl state)
+ {
+ this.handle = handle;
+ this.parentHandle = parentHandle;
+ this.childrenHandles = childrenHandles;
+ this.state = state;
+ }
+
+ public String getId()
+ {
+ return handle.id;
+ }
+
+ public StructuralState getState()
+ {
+ return state;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof StructuralObjectImpl)
+ {
+ StructuralObjectImpl that = (StructuralObjectImpl)obj;
+
+ //
+ return handle.equals(that.handle);
+ }
+ return false;
+ }
+}
Copied:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/StructuralStateImpl.java
(from rev 11212,
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/state/structural/StructuralStateImpl.java)
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/StructuralStateImpl.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock/impl/StructuralStateImpl.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -0,0 +1,59 @@
+/******************************************************************************
+ * 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.mock.impl;
+
+import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.state.structural.StructuralState;
+
+import java.util.Map;
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+class StructuralStateImpl implements StructuralState
+{
+
+ /** . */
+ private final Class<? extends UIObject> type;
+
+ /** . */
+ private final Map<String, Serializable> properties;
+
+ public StructuralStateImpl(Class<? extends UIObject> type, Map<String,
Serializable> properties)
+ {
+ this.type = type;
+ this.properties = properties;
+ }
+
+ public Class<? extends UIObject> getType()
+ {
+ return type;
+ }
+
+ public Map<String, Serializable> getProperties()
+ {
+ return properties;
+ }
+}
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
22:02:20 UTC (rev 11270)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/CustomScope.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -26,8 +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;
+import org.jboss.portal.presentation.test.model.mock.MockModel;
+import org.jboss.portal.presentation.test.model.mock.MockObject;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
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
22:02:20 UTC (rev 11270)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/NodeDef.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -27,8 +27,8 @@
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.MockModel;
-import org.jboss.portal.presentation.test.model.MockObject;
+import org.jboss.portal.presentation.test.model.mock.MockModel;
+import org.jboss.portal.presentation.test.model.mock.MockObject;
import org.jboss.portal.presentation.test.model.Resolver;
import java.util.HashMap;
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
22:02:20 UTC (rev 11270)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/TraversalModelTestCase.java 2008-07-02
22:07:44 UTC (rev 11271)
@@ -29,9 +29,9 @@
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.MockModel;
+import org.jboss.portal.presentation.test.model.mock.MockModel;
+import org.jboss.portal.presentation.test.model.mock.impl.MockModelImpl;
import org.jboss.portal.presentation.test.model.Resolver;
-import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
import java.util.ArrayList;
import java.util.Arrays;