Author: julien(a)jboss.com
Date: 2007-12-18 19:35:40 -0500 (Tue, 18 Dec 2007)
New Revision: 9368
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
Log:
more testing of mock model
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-18
22:57:38 UTC (rev 9367)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-19
00:35:40 UTC (rev 9368)
@@ -89,6 +89,11 @@
// Package protected
************************************************************************************************
+ /**
+ * Process a change.
+ *
+ * @param change the change to process
+ */
void update(StructuralObject.Change change)
{
if (change instanceof StructuralObject.Update)
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-18
22:57:38 UTC (rev 9367)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-19
00:35:40 UTC (rev 9368)
@@ -39,17 +39,6 @@
{
/**
- * Validate the state of the provided object. The operation is idempotent and does not
modify any state.
- * If validation is succesfull the method returns otherwise it throws an exception
that indicates
- * the nature of the non validation failure.
- *
- * @param object the object to check
- * @throws IllegalArgumentException if the provided object is null
- * @throws StateException any useful exception that would make the object non valid
- */
- void validate(StructuralObject object) throws IllegalArgumentException,
StateException;
-
- /**
* Load the state of the specified object.
*
* @param objectId the object id
@@ -86,6 +75,17 @@
String getRootId();
/**
+ * Validate the state of the provided object. The operation is idempotent and does not
modify any state.
+ * If validation is succesfull the method returns otherwise it throws an exception
that indicates
+ * the nature of the non validation failure.
+ *
+ * @param object the object to check
+ * @throws IllegalArgumentException if the provided object is null
+ * @throws StateException any useful exception that would make the object non valid
+ */
+ void validate(StructuralObject object) throws IllegalArgumentException,
StateException;
+
+ /**
* Create an object.
*
* @param parent the parent
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-18
22:57:38 UTC (rev 9367)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-19
00:35:40 UTC (rev 9368)
@@ -25,8 +25,10 @@
import junit.framework.TestCase;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.state.StaleStateException;
import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
@@ -37,6 +39,7 @@
import java.util.Collections;
import java.util.List;
+import java.util.HashMap;
/**
* Test that the mock model we are using behaves in an expected manner
@@ -403,6 +406,180 @@
}
}
+ public void testInvalidatedByDestruction() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+
+ //
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PAGE);
+
+ //
+ StructuralObject foo = mockFoo.takeSnapshot();
+
+ //
+ model.destroy(mockFoo);
+
+ //
+ assertValidity(foo, NoSuchStateException.class);
+ }
+
+ public void testInvalidatedByPropertyUpdate() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+
+ //
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+
+ //
+ StructuralObject foo = mockFoo.takeSnapshot();
+
+ //
+ mockFoo.setPropertyValue("a", "b");
+
+ //
+ assertValidity(foo, StaleStateException.class);
+ }
+
+ public void testInvalidatedByChildCreation() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+
+ //
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+
+ //
+ StructuralObject foo = mockFoo.takeSnapshot();
+
+ //
+ mockFoo.addChild("juu", MockObject.Type.PAGE);
+
+ //
+ assertValidity(foo, StaleStateException.class);
+ }
+
+ public void testInvalidatedByChildDestruction() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+
+ //
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+
+ //
+ StructuralObject foo = mockFoo.takeSnapshot();
+
+ //
+ model.destroy(mockJuu);
+
+ //
+ assertValidity(foo, StaleStateException.class);
+ }
+
+ public void testInvalidatedByMove() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+
+ //
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+ MockObject mockBar = mockFoo.addChild("bar", MockObject.Type.PAGE);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+
+ //
+ StructuralObject foo = mockFoo.takeSnapshot();
+ StructuralObject bar = mockBar.takeSnapshot();
+ StructuralObject juu = mockJuu.takeSnapshot();
+
+ //
+ mockBar.move(mockJuu);
+
+ //
+ assertValidity(foo, StaleStateException.class);
+ assertValidity(bar, StaleStateException.class);
+ assertValidity(juu, StaleStateException.class);
+ }
+
+ private void assertValidity(StructuralObject object, Class<? extends
StateException> expected) throws MockException
+ {
+ //
+ try
+ {
+ ssc.validate(object);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ ssc.loadChildren(object);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ ssc.loadParent(object);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ StructuralObject bar = model.getRoot().addChild("bar",
MockObject.Type.PAGE).takeSnapshot();
+ ssc.move(object, bar);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ ssc.create(object, UIPage.class, "juu", new HashMap<String,
String>());
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ ssc.destroy(object);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ ssc.update(object, new HashMap<String, String>());
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+ }
+
private void assertStale(StructuralObject object)
{
try
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-18
22:57:38 UTC (rev 9367)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-19
00:35:40 UTC (rev 9368)
@@ -288,10 +288,10 @@
throw new NoSuchStateException();
}
- //
+ // An invalid mock object should not be in the universe
if (!mockObject.isValid())
{
- throw new StaleStateException();
+ throw new AssertionError();
}
//
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2007-12-18
22:57:38 UTC (rev 9367)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2007-12-19
00:35:40 UTC (rev 9368)
@@ -266,10 +266,15 @@
//
parent.children.remove(id);
+ parent.version++;
+
+ //
destination.children.put(id, this);
+ destination.version++;
+
+ //
parent = destination;
version++;
- destination.version++;
}
public void destroy() throws MockException