Author: julien(a)jboss.com
Date: 2008-07-02 18:14:02 -0400 (Wed, 02 Jul 2008)
New Revision: 11272
Added:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/AbstractStructuralStateContextTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/
Removed:
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/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/mock/
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/AbstractMockImplementationTestCase.java
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
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/MockModel.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/MockObject.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/MockModelImpl.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/MockObjectImpl.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectHandle.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralStateImpl.java
Log:
actually putting that stuff in a package related to state as it is what it does
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:07:44 UTC (rev 11271)
+++
modules/presentation/trunk/portal/src/test/java/org/jboss/portal/presentation/portal/model/StructuralStateContextTestCase.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -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.mock.AbstractMockImplementationTestCase;
+import org.jboss.portal.presentation.test.state.AbstractStructuralStateContextTestCase;
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
AbstractMockImplementationTestCase<PortalNode>
+public class StructuralStateContextTestCase extends
AbstractStructuralStateContextTestCase<PortalNode>
{
/** . */
Deleted:
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/AbstractMockImplementationTestCase.java 2008-07-02
22:07:44 UTC (rev 11271)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractMockImplementationTestCase.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -1,444 +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 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);
- }
-}
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:07:44 UTC (rev 11271)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -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.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.state.mock.MockModel;
+import org.jboss.portal.presentation.test.state.mock.impl.MockModelImpl;
+import org.jboss.portal.presentation.test.state.mock.MockObject;
import org.jboss.portal.presentation.test.model3.UIObjectNode;
/**
Deleted:
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/MockModel.java 2008-07-02
22:07:44 UTC (rev 11271)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockModel.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -1,41 +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 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);
-}
Deleted:
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/MockObject.java 2008-07-02
22:07:44 UTC (rev 11271)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/MockObject.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -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;
-
-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/Resolver.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/Resolver.java 2008-07-02
22:07:44 UTC (rev 11271)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/Resolver.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -22,8 +22,8 @@
******************************************************************************/
package org.jboss.portal.presentation.test.model;
-import org.jboss.portal.presentation.test.model.mock.MockModel;
-import org.jboss.portal.presentation.test.model.mock.MockObject;
+import org.jboss.portal.presentation.test.state.mock.MockModel;
+import org.jboss.portal.presentation.test.state.mock.MockObject;
import org.jboss.portal.presentation.test.model3.UIObjectNode;
/**
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:07:44 UTC (rev 11271)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/CustomScope.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -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.mock.MockModel;
-import org.jboss.portal.presentation.test.model.mock.MockObject;
+import org.jboss.portal.presentation.test.state.mock.MockModel;
+import org.jboss.portal.presentation.test.state.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:07:44 UTC (rev 11271)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/NodeDef.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -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.mock.MockModel;
-import org.jboss.portal.presentation.test.model.mock.MockObject;
+import org.jboss.portal.presentation.test.state.mock.MockModel;
+import org.jboss.portal.presentation.test.state.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:07:44 UTC (rev 11271)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model3/TraversalModelTestCase.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -29,8 +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.mock.MockModel;
-import org.jboss.portal.presentation.test.model.mock.impl.MockModelImpl;
+import org.jboss.portal.presentation.test.state.mock.MockModel;
+import org.jboss.portal.presentation.test.state.mock.impl.MockModelImpl;
import org.jboss.portal.presentation.test.model.Resolver;
import java.util.ArrayList;
Added:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/AbstractStructuralStateContextTestCase.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/AbstractStructuralStateContextTestCase.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/AbstractStructuralStateContextTestCase.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -0,0 +1,447 @@
+/******************************************************************************
+ * 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.state;
+
+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;
+
+/**
+ * Abstract test case for testing structural state.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class AbstractStructuralStateContextTestCase<MockObject> extends
TestCase
+{
+
+ public AbstractStructuralStateContextTestCase()
+ {
+ }
+
+ public AbstractStructuralStateContextTestCase(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/state/mock
(from rev 11271,
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/mock)
Deleted:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/AbstractMockImplementationTestCase.java
===================================================================
---
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)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/AbstractMockImplementationTestCase.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -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.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);
- }
-}
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/MockModel.java
===================================================================
---
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)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/MockModel.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -20,7 +20,7 @@
* 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;
+package org.jboss.portal.presentation.test.state.mock;
import org.jboss.portal.presentation.state.structural.StructuralStateContext;
import org.jboss.portal.presentation.test.model.MockException;
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/MockObject.java
===================================================================
---
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)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/MockObject.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -20,7 +20,7 @@
* 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;
+package org.jboss.portal.presentation.test.state.mock;
import org.jboss.portal.presentation.model.ui.UIObject;
import org.jboss.portal.presentation.state.structural.StructuralObject;
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/MockModelImpl.java
===================================================================
---
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)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/MockModelImpl.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -20,7 +20,7 @@
* 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;
+package org.jboss.portal.presentation.test.state.mock.impl;
import org.jboss.portal.presentation.model.ui.UIObject;
import org.jboss.portal.presentation.model.ui.UIContext;
@@ -29,8 +29,8 @@
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.state.mock.MockObject;
+import org.jboss.portal.presentation.test.state.mock.MockModel;
import org.jboss.portal.presentation.test.model.MockException;
import java.util.ArrayList;
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/MockObjectImpl.java
===================================================================
---
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)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/MockObjectImpl.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -20,10 +20,10 @@
* 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;
+package org.jboss.portal.presentation.test.state.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.state.mock.MockObject;
import org.jboss.portal.presentation.test.model.MockException;
import java.util.ArrayList;
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectHandle.java
===================================================================
---
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)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectHandle.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -20,7 +20,7 @@
* 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;
+package org.jboss.portal.presentation.test.state.mock.impl;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java
===================================================================
---
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)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -20,7 +20,7 @@
* 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;
+package org.jboss.portal.presentation.test.state.mock.impl;
import org.jboss.portal.presentation.state.structural.StructuralObject;
import org.jboss.portal.presentation.state.structural.StructuralState;
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralStateImpl.java
===================================================================
---
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)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralStateImpl.java 2008-07-02
22:14:02 UTC (rev 11272)
@@ -20,7 +20,7 @@
* 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;
+package org.jboss.portal.presentation.test.state.mock.impl;
import org.jboss.portal.presentation.model.ui.UIObject;
import org.jboss.portal.presentation.state.structural.StructuralState;