Author: julien(a)jboss.com
Date: 2008-07-03 18:34:30 -0400 (Thu, 03 Jul 2008)
New Revision: 11289
Added:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/MockModelTestCase.java
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/AbstractStructuralStateContextTestCase.java
Log:
- mock model unit test for structural state context conformance
- unit test properties update during a refresh operation
Modified:
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 2008-07-03
21:59:22 UTC (rev 11288)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/AbstractStructuralStateContextTestCase.java 2008-07-03
22:34:30 UTC (rev 11289)
@@ -33,6 +33,7 @@
import org.jboss.portal.presentation.state.structural.StructuralState;
import org.jboss.portal.presentation.state.structural.StructuralStateContext;
import org.jboss.portal.presentation.test.state.mock.MockException;
+import org.jboss.portal.common.util.MapBuilder;
import java.util.Collection;
import java.util.Collections;
@@ -341,7 +342,7 @@
}
- public void testRefresh() throws MockException
+ public void testChildrenRefresh() throws MockException
{
MockObject mockRoot = getRoot();
String rootId = getId(mockRoot);
@@ -392,6 +393,37 @@
}
}
+ public void testPropertiesRefresh() throws MockException
+ {
+ MockObject mockRoot = getRoot();
+ String rootId = getId(mockRoot);
+
+ //
+ StructuralObject rootV0 = getStructuralStateContext().load(rootId);
+
+ //
+ setProperty(mockRoot, "foo", "foo_1");
+ setProperty(mockRoot, "bar", "bar_1");
+ setProperty(mockRoot, "daa", "daa_1");
+ StructuralObject.Refresh refresh1 = getStructuralStateContext().refresh(rootV0);
+ Map<String, Serializable> update1 = MapBuilder.hashMap("foo",
(Serializable)"foo_1").put("bar",
"bar_1").put("daa", "daa_1").get();
+ assertEquals(update1, refresh1.getPropertiesUpdate());
+
+ //
+ StructuralObject rootV1 = getStructuralStateContext().load(rootId);
+
+ //
+ setProperty(mockRoot, "foo", null);
+ setProperty(mockRoot, "bar", "bar_2");
+ setProperty(mockRoot, "juu", "juu_1");
+ StructuralObject.Refresh refresh2_1 = getStructuralStateContext().refresh(rootV1);
+ Map<String, Serializable> update2_1 = MapBuilder.hashMap("foo",
(Serializable)null).put("bar", "bar_2").put("juu",
"juu_1").get();
+ assertEquals(update2_1, refresh2_1.getPropertiesUpdate());
+ StructuralObject.Refresh refresh2_2 = getStructuralStateContext().refresh(rootV0);
+ Map<String, Serializable> update2_2 = MapBuilder.hashMap("bar",
(Serializable)"bar_2").put("daa",
"daa_1").put("juu", "juu_1").get();
+ assertEquals(update2_2, refresh2_2.getPropertiesUpdate());
+ }
+
protected final void assertValidity(StructuralObject object, Class<? extends
StateException> expected) throws MockException
{
try
Added:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/MockModelTestCase.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/MockModelTestCase.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/MockModelTestCase.java 2008-07-03
22:34:30 UTC (rev 11289)
@@ -0,0 +1,125 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.test.state.mock;
+
+import org.jboss.portal.presentation.test.state.AbstractStructuralStateContextTestCase;
+import org.jboss.portal.presentation.test.state.mock.impl.MockModelImpl;
+import org.jboss.portal.presentation.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.model.ui.UIObject;
+
+import java.util.Set;
+import java.util.List;
+import java.io.Serializable;
+
+/**
+ * Test that the mock model structural state context implementation.
+ *
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class MockModelTestCase extends
AbstractStructuralStateContextTestCase<MockObject>
+{
+
+ /** . */
+ private MockModel mockModel;
+
+ public MockModelTestCase()
+ {
+ }
+
+ public MockModelTestCase(String testName)
+ {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception
+ {
+ mockModel = new MockModelImpl();
+ }
+
+ protected StructuralStateContext getStructuralStateContext()
+ {
+ return mockModel.getStructuralStateContext();
+ }
+
+ protected MockObject getRoot()
+ {
+ return mockModel.getRoot();
+ }
+
+ protected Set<String> getPropertyNames(MockObject mockObject)
+ {
+ return mockObject.getPropertyNames();
+ }
+
+ protected MockObject getParent(MockObject mockObject)
+ {
+ return mockObject.getParent();
+ }
+
+ protected List<? extends MockObject> getChildren(MockObject mockObject)
+ {
+ return mockObject.getChildren();
+ }
+
+ protected String getName(MockObject mockObject)
+ {
+ return mockObject.getName();
+ }
+
+ protected boolean isValid(MockObject mockObject)
+ {
+ return mockObject.isValid();
+ }
+
+ protected Class<? extends UIObject> getType(MockObject mockObject)
+ {
+ return mockObject.getType();
+ }
+
+ protected String getId(MockObject mockObject)
+ {
+ return mockObject.getId();
+ }
+
+ protected MockObject addChild(MockObject mockObject, String name, Class<? extends
UIObject> modelType)
+ {
+ return mockObject.addChild(name, modelType);
+ }
+
+ protected void destroy(MockObject mockObject)
+ {
+ mockModel.destroy(mockObject);
+ }
+
+ protected void setProperty(MockObject mockObject, String propertyName, String
propertyValue)
+ {
+ mockObject.setPropertyValue(propertyName, propertyValue);
+ }
+
+ protected Serializable getProperty(MockObject mockObject, String name)
+ {
+ return mockObject.getPropertyValue(name);
+ }
+}
+