JBoss Portal SVN: r9266 - in branches/JBoss_Portal_Branch_2_6/core-wsrp/src: resources/portal-wsrp-admin-war and 1 other directories.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2007-12-03 22:05:02 -0500 (Mon, 03 Dec 2007)
New Revision: 9266
Modified:
branches/JBoss_Portal_Branch_2_6/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ConsumerBean.java
branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/WEB-INF/jsf/consumers/editConsumer.xhtml
branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/style.css
Log:
- JBPORTAL-1834: Fixed bad interaction design with respect to entering registration properties. Instead of using
immediate text field, use a button to update the properties when needed.
Modified: branches/JBoss_Portal_Branch_2_6/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ConsumerBean.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ConsumerBean.java 2007-12-04 01:29:57 UTC (rev 9265)
+++ branches/JBoss_Portal_Branch_2_6/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ConsumerBean.java 2007-12-04 03:05:02 UTC (rev 9266)
@@ -240,7 +240,7 @@
public boolean isRegistrationLocallyModified()
{
- return registrationLocallyModified;
+ return isRegistered() && registrationLocallyModified;
}
public boolean isRegistrationChecked()
@@ -309,7 +309,7 @@
}
}
- return manager.listConsumers();
+ return ConsumerManagerBean.CONFIGURE_CONSUMER;
}
beanContext.createErrorMessage("Couldn't update Consumer!");
@@ -320,7 +320,6 @@
{
registry.updateProducerInfo(prodInfo);
modified = false;
- registrationLocallyModified = false;
}
public String refreshConsumer()
@@ -355,26 +354,26 @@
// get updated registration info
RegistrationInfo newReg = getExpectedRegistrationInfo();
- // check that we have the proper state: need to check before saving modifications as this will reset the modified status
- if (newReg == null && !isRegistrationLocallyModified())
- {
- IllegalStateException e =
- new IllegalStateException("Registration not locally modified: there should be expected registration from producer!");
- log.debug(e);
- throw e;
- }
-
// make sure we save any modified registration properties
saveToRegistry(info);
// save old info in case something goes wrong
RegistrationInfo oldReg = getProducerInfo().getRegistrationInfo();
- // if we want to change an existing registration property (for example, to upgrade service) then there are
- // no expected information, we're just using the modified local version
+ // check that we have the proper state
if (newReg == null)
{
+ // if we want to change an existing registration property (for example, to upgrade service) then there are
+ // no expected information, we're just using the modified local version
newReg = oldReg;
+
+ if (!isRegistrationLocallyModified())
+ {
+ IllegalStateException e =
+ new IllegalStateException("Registration not locally modified: there should be expected registration from producer!");
+ log.debug(e);
+ throw e;
+ }
}
try
@@ -426,7 +425,7 @@
private Object modifyIfNeeded(Object oldValue, Object newValue, String target, boolean checkURL)
{
- if ((oldValue != null && !oldValue.equals(newValue)) || (oldValue == null && newValue != null))
+ if (isOldAndNewEqual(oldValue, newValue))
{
if (checkURL)
{
@@ -448,6 +447,11 @@
return oldValue;
}
+ private boolean isOldAndNewEqual(Object oldValue, Object newValue)
+ {
+ return (oldValue != null && !oldValue.equals(newValue)) || (oldValue == null && newValue != null);
+ }
+
// Listeners
public void useWSDLListener(ValueChangeEvent event)
@@ -460,11 +464,9 @@
public void regPropListener(ValueChangeEvent event)
{
- // todo: should use modifyIfNeeded but it might be tricky as the name of the property that has been changed
- // cannot be easily retrieved (we cannot use it as an id directly), could use title but that would be hackish
- registrationLocallyModified = true;
-
- // bypass the rest of the life cycle and re-display page
- FacesContext.getCurrentInstance().renderResponse();
+ if (!registrationLocallyModified)
+ {
+ registrationLocallyModified = isOldAndNewEqual(event.getOldValue(), event.getNewValue());
+ }
}
}
\ No newline at end of file
Modified: branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/WEB-INF/jsf/consumers/editConsumer.xhtml
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/WEB-INF/jsf/consumers/editConsumer.xhtml 2007-12-04 01:29:57 UTC (rev 9265)
+++ branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/WEB-INF/jsf/consumers/editConsumer.xhtml 2007-12-04 03:05:02 UTC (rev 9266)
@@ -95,8 +95,8 @@
<td>#{prop.name}</td>
<td>#{prop.description.label.value}</td>
<td>
- <h:inputText value="#{prop.value}" size="50" onchange="this.form.submit()"
- immediate="true" valueChangeListener="#{consumer.regPropListener}"
+ <h:inputText value="#{prop.value}" size="50"
+ valueChangeListener="#{consumer.regPropListener}"
disabled="#{consumer.registrationModified}"/>
<h:outputText styleClass="portlet-msg-error" value="#{prop.status}"
rendered="#{prop.determinedInvalid}"/>
@@ -104,6 +104,9 @@
</tr>
</c:forEach>
</table>
+ <h:commandLink action="#{consumer.update}" value="Update properties"
+ rendered="#{consumer.registered}"
+ styleClass="portlet-form-button portlet-section-buttonrow"/>
</c:when>
<c:otherwise>
Registration is indicated as required without registration properties.
Modified: branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/style.css
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/style.css 2007-12-04 01:29:57 UTC (rev 9265)
+++ branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/style.css 2007-12-04 03:05:02 UTC (rev 9266)
@@ -1,4 +1,4 @@
-@import url(basestyles.css);
+@import url( basestyles.css );
.wsrp-consumers-ui table {
border: 0;
@@ -105,10 +105,10 @@
color: #315896;
font-size: 11px;
padding: 3px 0 3px 3px;
- background-image:url(img/section-subHeader-bg.gif);
- background-position:left top;
- background-repeat:repeat-x;
- border:1px solid #b9c6d7;
+ background-image: url( img/section-subHeader-bg.gif );
+ background-position: left top;
+ background-repeat: repeat-x;
+ border: 1px solid #b9c6d7;
}
.wsrp-consumers-ui .portlet-section-header {
@@ -278,6 +278,7 @@
.wsrp-consumers-ui .registration-prop-table {
text-align: left;
width: 100%;
+ margin-bottom: .3em;
}
.wsrp-consumers-ui .registration-prop-table.active {
16 years, 5 months
JBoss Portal SVN: r9265 - branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/WEB-INF/jsf/consumers.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2007-12-03 20:29:57 -0500 (Mon, 03 Dec 2007)
New Revision: 9265
Modified:
branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/WEB-INF/jsf/consumers/editConsumer.xhtml
Log:
- Should use onchange instead of onblur. The current solution is not ideal, might need revisiting after 2.6.3.
Modified: branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/WEB-INF/jsf/consumers/editConsumer.xhtml
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/WEB-INF/jsf/consumers/editConsumer.xhtml 2007-12-04 01:28:39 UTC (rev 9264)
+++ branches/JBoss_Portal_Branch_2_6/core-wsrp/src/resources/portal-wsrp-admin-war/WEB-INF/jsf/consumers/editConsumer.xhtml 2007-12-04 01:29:57 UTC (rev 9265)
@@ -95,7 +95,7 @@
<td>#{prop.name}</td>
<td>#{prop.description.label.value}</td>
<td>
- <h:inputText value="#{prop.value}" size="50" onblur="this.form.submit()"
+ <h:inputText value="#{prop.value}" size="50" onchange="this.form.submit()"
immediate="true" valueChangeListener="#{consumer.regPropListener}"
disabled="#{consumer.registrationModified}"/>
<h:outputText styleClass="portlet-msg-error" value="#{prop.status}"
16 years, 5 months
JBoss Portal SVN: r9264 - branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2007-12-03 20:28:39 -0500 (Mon, 03 Dec 2007)
New Revision: 9264
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/RefreshResult.java
Log:
- JBPORTAL-1828: Fixed remaining problem with duplicated colons.
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/RefreshResult.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/RefreshResult.java 2007-12-04 01:02:12 UTC (rev 9263)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/RefreshResult.java 2007-12-04 01:28:39 UTC (rev 9264)
@@ -37,6 +37,7 @@
private boolean specificCode;
private final String meaning;
private ServiceDescription serviceDescription;
+ private static final String COLON = ".\n";
public RefreshResult(boolean specificCode, String specificCodeMeaning)
{
@@ -76,9 +77,10 @@
if (message != null && message.length() > 1)
{
status.append(message);
- if (appendColon)
+ // only happen a colon if the message is not ending with one already.
+ if (appendColon && (status.lastIndexOf(COLON) != status.length() - 2))
{
- status.append(".\n");
+ status.append(COLON);
}
}
return status;
16 years, 5 months
JBoss Portal SVN: r9263 - in branches/presentation/presentation: src/main/org/jboss/portal/presentation/test/model and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-03 20:02:12 -0500 (Mon, 03 Dec 2007)
New Revision: 9263
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java
Modified:
branches/presentation/presentation/build.xml
Log:
moved MockModelTestCase in the model package so it can not use package protected method from the model.state.structural package
Modified: branches/presentation/presentation/build.xml
===================================================================
--- branches/presentation/presentation/build.xml 2007-12-04 00:58:53 UTC (rev 9262)
+++ branches/presentation/presentation/build.xml 2007-12-04 01:02:12 UTC (rev 9263)
@@ -313,7 +313,7 @@
</x-sysproperty>
<x-test>
<test todir="${test.reports}" name="org.jboss.portal.presentation.test.model.ModelTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.presentation.test.model.state.structural.MockModelTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.presentation.test.model.MockModelTestCase"/>
</x-test>
<x-classpath>
<path refid="jboss.portal/modules/common.classpath"/>
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java 2007-12-04 00:58:53 UTC (rev 9262)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java 2007-12-04 01:02:12 UTC (rev 9263)
@@ -1,356 +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.UIObject;
-import org.jboss.portal.presentation.model.state.NoSuchStateException;
-import org.jboss.portal.presentation.model.state.StateChangeVetoException;
-import org.jboss.portal.presentation.model.state.StateException;
-import org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateContext;
-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;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-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 MockModel
-{
-
- /** . */
- private int generator = 0;
-
- /** . */
- private final Map<String, MockObjectImpl> universe = new HashMap<String, MockObjectImpl>();
-
- /** . */
- private final MockObjectImpl root = new MockObjectImpl();
-
- private final StructuralStateContext structuralStateContext = new AbstractStructuralStateContext()
- {
- 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.id;
- }
-
- public void update(StructuralObject structuralObject, Map<String, String> changes) throws StateChangeVetoException
- {
- MockObjectImpl object = universe.get(((MockStructuralObject)structuralObject).getId());
- if (object == null)
- {
- throw new NoSuchStateException();
- }
-
- //
- for (Map.Entry<String, String> entry : changes.entrySet())
- {
- String propertyName = entry.getKey();
- MockObject.UpdateBehavior behavior = object.propertyBehaviors.get(propertyName);
- if (behavior instanceof MockObject.Veto)
- {
- throw new StateChangeVetoException("Cannot modify non behavior property");
- }
- else if (behavior instanceof MockObject.Failure)
- {
- MockObject.Failure failure = (MockObject.Failure)behavior;
- failure.throwAs(IllegalArgumentException.class).
- throwAs(StateChangeVetoException.class).
- throwAs(StateException.class);
- }
- else
- {
- String propertyValue = entry.getValue();
- if (propertyValue != null)
- {
- object.propertyValues.put(propertyName, propertyValue);
- }
- else
- {
- object.propertyValues.remove(propertyName);
- }
- }
- }
- }
-
- public List<StructuralObject> loadChildren(StructuralObject object)
- {
- MockStructuralObject mockStructuralObject = (MockStructuralObject)object;
- MockObjectImpl mockObject = universe.get(mockStructuralObject.id);
- List<StructuralObject> tmp = new ArrayList<StructuralObject>();
- for (MockObjectImpl mockChild : mockObject.children.values())
- {
- tmp.add(mockChild.takeSnapshot());
- }
- return tmp;
- }
-
- public StructuralObject loadParent(StructuralObject object)
- {
- MockStructuralObject mockStructuralObject = (MockStructuralObject)object;
- MockObjectImpl mockObject = universe.get(mockStructuralObject.id);
- return mockObject.parent.takeSnapshot();
- }
- };
-
- public StructuralStateContext getStructuralStateContext()
- {
- return structuralStateContext;
- }
-
- public MockObject getRoot()
- {
- return root;
- }
-
- public void destroy(String objectId)
- {
- MockObjectImpl object = universe.remove(objectId);
- if (object.parent != null)
- {
- object.parent.children.remove(object.id);
- }
-
- //
- for (String childId : new ArrayList<String>(object.children.keySet()))
- {
- destroy(childId);
- }
- }
-
- private class MockObjectImpl implements MockObject
- {
-
- /** . */
- private final MockObject.Type type;
-
- /** . */
- private final String name;
-
- /** . */
- private final String id = "" + generator++;
-
- /** . */
- private final Map<String, String> propertyValues;
-
- /** . */
- private final Map<String, UpdateBehavior> propertyBehaviors;
-
- /** . */
- private final Map<String, MockObjectImpl> children;
-
- /** . */
- private MockObjectImpl parent;
-
- private MockObjectImpl()
- {
- this.parent = null;
- this.name = "";
- this.type = MockObject.Type.CONTEXT;
- this.children = new LinkedHashMap<String, MockObjectImpl>();
- this.propertyValues = new HashMap<String, String>();
- this.propertyBehaviors = new HashMap<String, UpdateBehavior>();
-
- //
- universe.put(id, this);
- }
-
- private MockObjectImpl(MockObjectImpl parent, String name, MockObject.Type type)
- {
- if (parent.children.containsKey(name))
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.name = name;
- this.type = type;
- this.children = new LinkedHashMap<String, MockObjectImpl>();
- this.propertyValues = new HashMap<String, String>();
- this.propertyBehaviors = new HashMap<String, UpdateBehavior>();
-
- //
- this.parent = parent;
- parent.children.put(id, this);
-
- //
- universe.put(id, this);
- }
-
- public MockObject.Type getType()
- {
- return type;
- }
-
- public String getName()
- {
- return name;
- }
-
- public String getId()
- {
- return id;
- }
-
- public StructuralObject takeSnapshot()
- {
- return new MockStructuralObject(id, new MockStructuralState(type.clazz, name, new HashMap<String, String>(propertyValues)));
- }
-
- public String getPropertyValue(String propertyName)
- {
- return propertyValues.get(propertyName);
- }
-
- public MockObject addChild(String name, MockObject.Type type)
- {
- if (name == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- return new MockObjectImpl(this, name, type);
- }
-
- public Set<String> getPropertyNames()
- {
- return propertyValues.keySet();
- }
-
- public void setPropertyBehavior(String propertyName, UpdateBehavior propertyBehavior)
- {
- if (propertyName == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyBehavior != null)
- {
- propertyBehaviors.put(name, propertyBehavior);
- }
- else
- {
- propertyBehaviors.remove(name);
- }
- }
-
- public UpdateBehavior getPropertyBehavior(String propertyName)
- {
- return propertyBehaviors.get(propertyName);
- }
-
- public void setPropertyValue(String propertyName, String propertyValue)
- {
- if (propertyName == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyValue != null)
- {
- propertyValues.put(propertyName, propertyValue);
- }
- else
- {
- propertyValues.remove(propertyName);
- }
- }
- }
-
- public class MockStructuralState implements StructuralState
- {
-
- /** . */
- private final Class<? extends UIObject> type;
-
- /** . */
- private final String name;
-
- /** . */
- private final Map<String, String> properties;
-
- public MockStructuralState(Class<? extends UIObject> type, String name, Map<String, String> properties)
- {
- this.type = type;
- this.name = name;
- this.properties = properties;
- }
-
- public Class<? extends UIObject> getType()
- {
- return type;
- }
-
- public String getName()
- {
- return name;
- }
-
- public Map<String, String> getProperties()
- {
- return properties;
- }
- }
-
- public class MockStructuralObject implements StructuralObject
- {
-
- /** . */
- private final String id;
-
- /** . */
- private final MockStructuralState state;
-
- public MockStructuralObject(String id, MockStructuralState state)
- {
- this.id = id;
- this.state = state;
- }
-
- public String getId()
- {
- return id;
- }
-
- public StructuralState getState()
- {
- return state;
- }
- }
-}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java (from rev 9262, branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelTestCase.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-04 01:02:12 UTC (rev 9263)
@@ -0,0 +1,280 @@
+/******************************************************************************
+ * 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.UIContext;
+import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.state.StaleStateException;
+import org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateChangeListener;
+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.StructuralStateChangeListener;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.test.model.state.structural.MockModel;
+import org.jboss.portal.presentation.test.model.state.structural.MockObject;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Test that the mock model we are using behaves in an expected manner
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class MockModelTestCase extends TestCase
+{
+
+ /** . */
+ private MockModel model;
+
+ /** . */
+ private StructuralStateContext ssc;
+
+ /** . */
+ private Map<String, StructuralObject> universe;
+
+ /** . */
+ private final StructuralStateChangeListener listener = new AbstractStructuralStateChangeListener()
+ {
+ public void update(StructuralObject object)
+ {
+ universe.put(object.getId(), object);
+ }
+ };
+
+ protected void setUp() throws Exception
+ {
+ model = new MockModel();
+ ssc = model.getStructuralStateContext();
+ universe = new HashMap<String, StructuralObject>();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ model = null;
+ ssc = null;
+ universe = null;
+ }
+
+ public void testRoot()
+ {
+ MockObject mockRoot = model.getRoot();
+ assertNotNull(mockRoot);
+ assertEquals(Collections.EMPTY_SET, mockRoot.getPropertyNames());
+ assertNull(mockRoot.getParent());
+ assertEquals(Collections.EMPTY_LIST, mockRoot.getChildren());
+ assertEquals(MockObject.Type.CONTEXT, mockRoot.getType());
+ assertEquals("", mockRoot.getName());
+ assertEquals(true, mockRoot.isValid());
+
+ //
+ String rootId = ssc.getRootId();
+ assertNotNull(rootId);
+ StructuralObject root = ssc.load(rootId);
+ assertNotNull(root);
+ assertEquals(rootId, root.getId());
+ StructuralState state = root.getState();
+ assertEquals(UIContext.class, state.getType());
+ assertEquals("", state.getName());
+ assertEquals(Collections.EMPTY_MAP, state.getProperties());
+ }
+
+ public void testSetProperty()
+ {
+ MockObject mockRoot = model.getRoot();
+ String rootId = mockRoot.getId();
+ int rootV0 = mockRoot.getVersion();
+
+ //
+ StructuralObject root0 = ssc.load(rootId);
+ StructuralState rootState0 = root0.getState();
+ assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
+
+ // Set
+ ssc.update(listener, root0, Collections.singletonMap("foo", "bar"));
+
+ //
+ int rootV1 = mockRoot.getVersion();
+ assertTrue(rootV1 > rootV0);
+ assertEquals(Collections.singleton("foo"), mockRoot.getPropertyNames());
+ assertEquals("bar", mockRoot.getPropertyValue("foo"));
+ assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
+ assertStale(root0);
+ StructuralObject root1_0 = universe.get(rootId);
+ assertNotNull(root1_0);
+ assertNotStale(root1_0);
+ StructuralState rootState1_0 = root1_0.getState();
+ assertEquals(Collections.singletonMap("foo", "bar"), rootState1_0.getProperties());
+ StructuralObject root1_1 = ssc.load(rootId);
+ assertNotNull(root1_1);
+ assertNotStale(root1_1);
+ StructuralState rootState1_1 = root1_1.getState();
+ assertEquals(Collections.singletonMap("foo", "bar"), rootState1_1.getProperties());
+ }
+
+ public void testUpdateProperty()
+ {
+ MockObject mockRoot = model.getRoot();
+ String rootId = mockRoot.getId();
+ int rootV0 = mockRoot.getVersion();
+
+ //
+ StructuralObject root0 = ssc.load(rootId);
+ StructuralState rootState0 = root0.getState();
+ assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
+
+ // Set
+ mockRoot.setPropertyValue("foo", "bar");
+
+ //
+ int rootV1 = mockRoot.getVersion();
+ assertTrue(rootV1 > rootV0);
+ assertEquals(Collections.singleton("foo"), mockRoot.getPropertyNames());
+ assertEquals("bar", mockRoot.getPropertyValue("foo"));
+ assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
+ assertStale(root0);
+ StructuralObject root1 = ssc.load(rootId);
+ assertNotNull(root1);
+ assertNotStale(root1);
+ StructuralState rootState1 = root1.getState();
+ assertEquals(Collections.singletonMap("foo", "bar"), rootState1.getProperties());
+
+ // Update
+ ssc.update(listener, root1, Collections.singletonMap("foo", "bar2"));
+
+ //
+ int rootV2 = mockRoot.getVersion();
+ assertTrue(rootV2 > rootV1);
+ assertEquals(Collections.singleton("foo"), mockRoot.getPropertyNames());
+ assertEquals("bar2", mockRoot.getPropertyValue("foo"));
+ assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
+ assertStale(root0);
+ assertStale(root1);
+
+ //
+ StructuralObject root2_0 = universe.get(rootId);
+ assertNotNull(root2_0);
+ assertNotStale(root2_0);
+ StructuralState rootState2_0 = root2_0.getState();
+ assertEquals(Collections.singletonMap("foo", "bar2"), rootState2_0.getProperties());
+ StructuralObject root2_1 = ssc.load(rootId);
+ assertNotNull(root2_1);
+ assertNotStale(root2_1);
+ StructuralState rootState2_1 = root2_1.getState();
+ assertEquals(Collections.singletonMap("foo", "bar2"), rootState2_1.getProperties());
+ }
+
+ private void assertStale(StructuralObject object)
+ {
+ try
+ {
+ ssc.loadParent(object);
+ fail();
+ }
+ catch (StaleStateException ignore)
+ {
+ }
+ try
+ {
+ ssc.loadChildren(object);
+ fail();
+ }
+ catch (StaleStateException ignore)
+ {
+ }
+ }
+
+ private void assertNotStale(StructuralObject object)
+ {
+ ssc.loadParent(object);
+ ssc.loadChildren(object);
+ }
+
+ public void testAddChild()
+ {
+ MockObject mockRoot = model.getRoot();
+ int rootV0 = mockRoot.getVersion();
+
+ //
+ String rootId = mockRoot.getId();
+ StructuralObject root = ssc.load(rootId);
+
+ //
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ assertNotNull(mockFoo);
+ String fooId = mockFoo.getId();
+
+ //
+ assertNotNull(fooId);
+ assertEquals("foo", mockFoo.getName());
+ assertEquals(MockObject.Type.PORTAL, mockFoo.getType());
+ assertSame(mockRoot, mockFoo.getParent());
+ assertEquals(Collections.singletonList(mockFoo), mockRoot.getChildren());
+ assertEquals(Collections.EMPTY_SET, mockFoo.getPropertyNames());
+ assertTrue(mockRoot.getVersion() > rootV0);
+
+ //
+ try
+ {
+ ssc.loadParent(root);
+ fail();
+ }
+ catch (StaleStateException ignore)
+ {
+ }
+ try
+ {
+ ssc.loadChildren(root);
+ fail();
+ }
+ catch (StaleStateException ignore)
+ {
+ }
+
+ //
+ root = ssc.load(rootId);
+ assertNotNull(root);
+ assertEquals(rootId, root.getId());
+
+ //
+ List<StructuralObject> children = ssc.loadChildren(root);
+ assertNotNull(children);
+ assertEquals(1, children.size());
+ StructuralObject foo = children.get(0);
+ assertNotNull(foo);
+ assertEquals(fooId, foo.getId());
+ StructuralState fooState = foo.getState();
+ assertNotNull(fooState);
+ assertEquals("foo", fooState.getName());
+ assertEquals(Collections.EMPTY_MAP, fooState.getProperties());
+ assertEquals(UIPortal.class, fooState.getType());
+ root = ssc.loadParent(foo);
+ assertNotNull(root);
+ assertEquals(rootId, root.getId());
+ }
+
+}
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java 2007-12-04 00:58:53 UTC (rev 9262)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java 2007-12-04 01:02:12 UTC (rev 9263)
@@ -1,120 +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.UIContext;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.model.UIPortal;
-import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.state.structural.StructuralState;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public interface MockObject
-{
-
- /**
- *
- */
- public enum Type
- {
-
- PORTAL(UIPortal.class), PAGE(UIPage.class), WINDOW(UIWindow.class), CONTEXT(UIContext.class);
-
- /** . */
- final Class<? extends UIObject> clazz;
-
- Type(Class<? extends UIObject> clazz)
- {
- this.clazz = clazz;
- }
- }
-
- 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;
- }
- }
-
- Type getType();
-
- String getName();
-
- String getId();
-
- String getPropertyValue(String propertyName);
-
- void setPropertyBehavior(String propertyName, UpdateBehavior propertyBehavior);
-
- UpdateBehavior getPropertyBehavior(String propertyName);
-
- void setPropertyValue(String propertyName, String propertyValue);
-
- Set<String> getPropertyNames();
-
- MockObject addChild(String name, Type type);
-
- /**
- * Creates and returns a snapshot of the state.
- *
- * @return the state snapshot
- */
- StructuralObject takeSnapshot();
-}
16 years, 5 months
JBoss Portal SVN: r9262 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: model/state/structural and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-03 19:58:53 -0500 (Mon, 03 Dec 2007)
New Revision: 9262
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateChangeListener.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelTestCase.java
Log:
added remove(String id) method in StructuralStateChangeListener
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-04 00:54:41 UTC (rev 9261)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-04 00:58:53 UTC (rev 9262)
@@ -69,6 +69,11 @@
// Update its structural view
tmp.structuralObject = object;
}
+
+ public void remove(String id)
+ {
+ objects.remove(id);
+ }
};
private static StructuralObject getRootState(StructuralStateContext loader)
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateChangeListener.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateChangeListener.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateChangeListener.java 2007-12-04 00:58:53 UTC (rev 9262)
@@ -0,0 +1,38 @@
+/******************************************************************************
+ * 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.model.state.structural;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class AbstractStructuralStateChangeListener implements StructuralStateChangeListener
+{
+ public void update(StructuralObject object)
+ {
+ }
+
+ public void remove(String id)
+ {
+ }
+}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java 2007-12-04 00:54:41 UTC (rev 9261)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java 2007-12-04 00:58:53 UTC (rev 9262)
@@ -28,5 +28,17 @@
*/
public interface StructuralStateChangeListener
{
+ /**
+ * Updates the structural object.
+ *
+ * @param object the object to update
+ */
void update(StructuralObject object);
+
+ /**
+ * Removes the structural object with the specified id.
+ *
+ * @param id the id to remove
+ */
+ void remove(String id);
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelTestCase.java 2007-12-04 00:54:41 UTC (rev 9261)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelTestCase.java 2007-12-04 00:58:53 UTC (rev 9262)
@@ -26,15 +26,16 @@
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.UIPortal;
import org.jboss.portal.presentation.model.state.StaleStateException;
+import org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateChangeListener;
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.StructuralStateChangeListener;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.HashMap;
/**
* Test that the mock model we are using behaves in an expected manner
@@ -55,7 +56,7 @@
private Map<String, StructuralObject> universe;
/** . */
- private final StructuralStateChangeListener listener = new StructuralStateChangeListener()
+ private final StructuralStateChangeListener listener = new AbstractStructuralStateChangeListener()
{
public void update(StructuralObject object)
{
16 years, 5 months
JBoss Portal SVN: r9261 - branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-03 19:54:41 -0500 (Mon, 03 Dec 2007)
New Revision: 9261
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChangeVetoException.java
Log:
make StateChangeVetoException extends StateException
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChangeVetoException.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChangeVetoException.java 2007-12-04 00:49:30 UTC (rev 9260)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChangeVetoException.java 2007-12-04 00:54:41 UTC (rev 9261)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public class StateChangeVetoException extends RuntimeException
+public class StateChangeVetoException extends StateException
{
public StateChangeVetoException()
{
16 years, 5 months
JBoss Portal SVN: r9260 - in branches/presentation/presentation: src/main/org/jboss/portal/presentation/test/model/state/structural and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-03 19:49:30 -0500 (Mon, 03 Dec 2007)
New Revision: 9260
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelTestCase.java
Modified:
branches/presentation/presentation/build.xml
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
Log:
test the mock model standalone also
Modified: branches/presentation/presentation/build.xml
===================================================================
--- branches/presentation/presentation/build.xml 2007-12-03 23:38:42 UTC (rev 9259)
+++ branches/presentation/presentation/build.xml 2007-12-04 00:49:30 UTC (rev 9260)
@@ -313,6 +313,7 @@
</x-sysproperty>
<x-test>
<test todir="${test.reports}" name="org.jboss.portal.presentation.test.model.ModelTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.presentation.test.model.state.structural.MockModelTestCase"/>
</x-test>
<x-classpath>
<path refid="jboss.portal/modules/common.classpath"/>
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-03 23:38:42 UTC (rev 9259)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-04 00:49:30 UTC (rev 9260)
@@ -142,7 +142,9 @@
public StructuralObject loadParent(StructuralObject object)
{
- return getValidMockObject(object).getParent().takeSnapshot();
+ MockObject mockObject = getValidMockObject(object);
+ MockObject mockParent = mockObject.getParent();
+ return mockParent != null ? mockParent.takeSnapshot() : null;
}
private MockObject getValidMockObject(StructuralObject object)
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelTestCase.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelTestCase.java 2007-12-04 00:49:30 UTC (rev 9260)
@@ -0,0 +1,277 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.test.model.state.structural;
+
+import junit.framework.TestCase;
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.state.StaleStateException;
+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.StructuralStateChangeListener;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Test that the mock model we are using behaves in an expected manner
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class MockModelTestCase extends TestCase
+{
+
+ /** . */
+ private MockModel model;
+
+ /** . */
+ private StructuralStateContext ssc;
+
+ /** . */
+ private Map<String, StructuralObject> universe;
+
+ /** . */
+ private final StructuralStateChangeListener listener = new StructuralStateChangeListener()
+ {
+ public void update(StructuralObject object)
+ {
+ universe.put(object.getId(), object);
+ }
+ };
+
+ protected void setUp() throws Exception
+ {
+ model = new MockModel();
+ ssc = model.getStructuralStateContext();
+ universe = new HashMap<String, StructuralObject>();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ model = null;
+ ssc = null;
+ universe = null;
+ }
+
+ public void testRoot()
+ {
+ MockObject mockRoot = model.getRoot();
+ assertNotNull(mockRoot);
+ assertEquals(Collections.EMPTY_SET, mockRoot.getPropertyNames());
+ assertNull(mockRoot.getParent());
+ assertEquals(Collections.EMPTY_LIST, mockRoot.getChildren());
+ assertEquals(MockObject.Type.CONTEXT, mockRoot.getType());
+ assertEquals("", mockRoot.getName());
+ assertEquals(true, mockRoot.isValid());
+
+ //
+ String rootId = ssc.getRootId();
+ assertNotNull(rootId);
+ StructuralObject root = ssc.load(rootId);
+ assertNotNull(root);
+ assertEquals(rootId, root.getId());
+ StructuralState state = root.getState();
+ assertEquals(UIContext.class, state.getType());
+ assertEquals("", state.getName());
+ assertEquals(Collections.EMPTY_MAP, state.getProperties());
+ }
+
+ public void testSetProperty()
+ {
+ MockObject mockRoot = model.getRoot();
+ String rootId = mockRoot.getId();
+ int rootV0 = mockRoot.getVersion();
+
+ //
+ StructuralObject root0 = ssc.load(rootId);
+ StructuralState rootState0 = root0.getState();
+ assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
+
+ // Set
+ ssc.update(listener, root0, Collections.singletonMap("foo", "bar"));
+
+ //
+ int rootV1 = mockRoot.getVersion();
+ assertTrue(rootV1 > rootV0);
+ assertEquals(Collections.singleton("foo"), mockRoot.getPropertyNames());
+ assertEquals("bar", mockRoot.getPropertyValue("foo"));
+ assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
+ assertStale(root0);
+ StructuralObject root1_0 = universe.get(rootId);
+ assertNotNull(root1_0);
+ assertNotStale(root1_0);
+ StructuralState rootState1_0 = root1_0.getState();
+ assertEquals(Collections.singletonMap("foo", "bar"), rootState1_0.getProperties());
+ StructuralObject root1_1 = ssc.load(rootId);
+ assertNotNull(root1_1);
+ assertNotStale(root1_1);
+ StructuralState rootState1_1 = root1_1.getState();
+ assertEquals(Collections.singletonMap("foo", "bar"), rootState1_1.getProperties());
+ }
+
+ public void testUpdateProperty()
+ {
+ MockObject mockRoot = model.getRoot();
+ String rootId = mockRoot.getId();
+ int rootV0 = mockRoot.getVersion();
+
+ //
+ StructuralObject root0 = ssc.load(rootId);
+ StructuralState rootState0 = root0.getState();
+ assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
+
+ // Set
+ mockRoot.setPropertyValue("foo", "bar");
+
+ //
+ int rootV1 = mockRoot.getVersion();
+ assertTrue(rootV1 > rootV0);
+ assertEquals(Collections.singleton("foo"), mockRoot.getPropertyNames());
+ assertEquals("bar", mockRoot.getPropertyValue("foo"));
+ assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
+ assertStale(root0);
+ StructuralObject root1 = ssc.load(rootId);
+ assertNotNull(root1);
+ assertNotStale(root1);
+ StructuralState rootState1 = root1.getState();
+ assertEquals(Collections.singletonMap("foo", "bar"), rootState1.getProperties());
+
+ // Update
+ ssc.update(listener, root1, Collections.singletonMap("foo", "bar2"));
+
+ //
+ int rootV2 = mockRoot.getVersion();
+ assertTrue(rootV2 > rootV1);
+ assertEquals(Collections.singleton("foo"), mockRoot.getPropertyNames());
+ assertEquals("bar2", mockRoot.getPropertyValue("foo"));
+ assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
+ assertStale(root0);
+ assertStale(root1);
+
+ //
+ StructuralObject root2_0 = universe.get(rootId);
+ assertNotNull(root2_0);
+ assertNotStale(root2_0);
+ StructuralState rootState2_0 = root2_0.getState();
+ assertEquals(Collections.singletonMap("foo", "bar2"), rootState2_0.getProperties());
+ StructuralObject root2_1 = ssc.load(rootId);
+ assertNotNull(root2_1);
+ assertNotStale(root2_1);
+ StructuralState rootState2_1 = root2_1.getState();
+ assertEquals(Collections.singletonMap("foo", "bar2"), rootState2_1.getProperties());
+ }
+
+ private void assertStale(StructuralObject object)
+ {
+ try
+ {
+ ssc.loadParent(object);
+ fail();
+ }
+ catch (StaleStateException ignore)
+ {
+ }
+ try
+ {
+ ssc.loadChildren(object);
+ fail();
+ }
+ catch (StaleStateException ignore)
+ {
+ }
+ }
+
+ private void assertNotStale(StructuralObject object)
+ {
+ ssc.loadParent(object);
+ ssc.loadChildren(object);
+ }
+
+ public void testAddChild()
+ {
+ MockObject mockRoot = model.getRoot();
+ int rootV0 = mockRoot.getVersion();
+
+ //
+ String rootId = mockRoot.getId();
+ StructuralObject root = ssc.load(rootId);
+
+ //
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ assertNotNull(mockFoo);
+ String fooId = mockFoo.getId();
+
+ //
+ assertNotNull(fooId);
+ assertEquals("foo", mockFoo.getName());
+ assertEquals(MockObject.Type.PORTAL, mockFoo.getType());
+ assertSame(mockRoot, mockFoo.getParent());
+ assertEquals(Collections.singletonList(mockFoo), mockRoot.getChildren());
+ assertEquals(Collections.EMPTY_SET, mockFoo.getPropertyNames());
+ assertTrue(mockRoot.getVersion() > rootV0);
+
+ //
+ try
+ {
+ ssc.loadParent(root);
+ fail();
+ }
+ catch (StaleStateException ignore)
+ {
+ }
+ try
+ {
+ ssc.loadChildren(root);
+ fail();
+ }
+ catch (StaleStateException ignore)
+ {
+ }
+
+ //
+ root = ssc.load(rootId);
+ assertNotNull(root);
+ assertEquals(rootId, root.getId());
+
+ //
+ List<StructuralObject> children = ssc.loadChildren(root);
+ assertNotNull(children);
+ assertEquals(1, children.size());
+ StructuralObject foo = children.get(0);
+ assertNotNull(foo);
+ assertEquals(fooId, foo.getId());
+ StructuralState fooState = foo.getState();
+ assertNotNull(fooState);
+ assertEquals("foo", fooState.getName());
+ assertEquals(Collections.EMPTY_MAP, fooState.getProperties());
+ assertEquals(UIPortal.class, fooState.getType());
+ root = ssc.loadParent(foo);
+ assertNotNull(root);
+ assertEquals(rootId, root.getId());
+ }
+
+}
16 years, 5 months
JBoss Portal SVN: r9259 - docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2007-12-03 18:38:42 -0500 (Mon, 03 Dec 2007)
New Revision: 9259
Modified:
docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules/wsrp.xml
Log:
- Started updating documentation (synchronization commit).
Modified: docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules/wsrp.xml
===================================================================
--- docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules/wsrp.xml 2007-12-03 23:19:44 UTC (rev 9258)
+++ docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules/wsrp.xml 2007-12-03 23:38:42 UTC (rev 9259)
@@ -223,34 +223,6 @@
portlet.
</para>
- <sect3>
- <title>Using a WSRP Producer XML descriptor</title>
-
- <para>We will create a <emphasis>public-bea-wsrp.xml</emphasis> descriptor. Note that the actual name does not
- matter as long as it ends with <emphasis>-wsrp.xml</emphasis>.
- <programlisting><![CDATA[
-<?xml version='1.0' encoding='UTF-8' ?>
-<!DOCTYPE deployments PUBLIC "-//JBoss Portal//DTD WSRP Remote Producer Configuration 2.6//EN"
- "http://www.jboss.org/portal/dtd/jboss-wsrp-consumer_2_6.dtd">
-<deployments>
- <deployment>
- <wsrp-producer id="bea" expiration-cache="120">
- <endpoint-wsdl-url>http://wsrp.bea.com:7001/producer/producer?WSDL</endpoint-wsdl-url>
- <registration-data>
- <property>
- <name>registration/consumerRole</name>
- <lang>en</lang>
- <value>public</value>
- </property>
- </registration-data>
- </wsrp-producer>
- </deployment>
-</deployments>]]></programlisting>
- This producer descriptor gives access to BEA's public WSRP producer. We will look at the details of the
- different elements later. Note for now the <emphasis>producer-id</emphasis> element with a "bea" value. Put
- this file in the deploy directory and start the server (with JBoss Portal and its WSRP service deployed).
- </para></sect3>
-
<sect3 id="consumer_gui">
<title>Using the configuration portlet</title>
<para>
@@ -287,18 +259,17 @@
<imagedata fileref="images/wsrp/config_created.png" format="png" align="center" valign="middle"/>
</imageobject>
</mediaobject>
- Set the cache expiration value to 120 seconds and check the "Use WSDL?" checkbox. The form should now
- morph to:
+ Set the cache expiration value to 120 seconds and enter the WSDL URL for the producer in the text field
+ and press the "Save & Refresh" button:
<mediaobject>
<imageobject>
<imagedata fileref="images/wsrp/config_usewsdl.png" format="png" align="center" valign="middle"/>
</imageobject>
</mediaobject>
- Enter the WSDL URL for the producer in the text field and press the "Save & Refresh" button. This will retrieve
- the service description associated with the Producer which WSRP is described by the WSDL file found at
- the URL you just entered. In our case, querying the service description will allow us to learn that the
- Producer requires registration and that it expects a value for the registration property named
- "registration/consumerRole":
+ This will retrieve the service description associated with the Producer which WSRP is described by the
+ WSDL file found at the URL you just entered. In our case, querying the service description will allow us
+ to learn that the Producer requires registration and that it expects a value for the registration
+ property named "registration/consumerRole":
<mediaobject>
<imageobject>
<imagedata fileref="images/wsrp/config_refresh.png" format="png" align="center" valign="middle"/>
@@ -315,10 +286,48 @@
</mediaobject>
The Consumer for the "bea" Producer should now be available as a portlet provider and is ready to be used.
</para>
-
+ <para>
+ A producer is configured, by default, by retrieving the producer's information via a WSDL URL. There are
+ rare cases, however, where URLs need to be provided for each of the producer's end points. You can do
+ exactly that by unchecking the "Use WSDL?" checkbox, as is the case for the <literal>self</literal>
+ producer:
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/wsrp/config_self.png" format="png" align="center" valign="middle"/>
+ </imageobject>
+ </mediaobject>
+ </para>
</sect3>
<sect3>
+ <title>Using a WSRP Producer XML descriptor</title>
+
+ <para>We will create a <emphasis>public-bea-wsrp.xml</emphasis> descriptor. Note that the actual name does not
+ matter as long as it ends with <emphasis>-wsrp.xml</emphasis>.
+ <programlisting><![CDATA[
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE deployments PUBLIC "-//JBoss Portal//DTD WSRP Remote Producer Configuration 2.6//EN"
+ "http://www.jboss.org/portal/dtd/jboss-wsrp-consumer_2_6.dtd">
+<deployments>
+ <deployment>
+ <wsrp-producer id="bea" expiration-cache="120">
+ <endpoint-wsdl-url>http://wsrp.bea.com:7001/producer/producer?WSDL</endpoint-wsdl-url>
+ <registration-data>
+ <property>
+ <name>registration/consumerRole</name>
+ <lang>en</lang>
+ <value>public</value>
+ </property>
+ </registration-data>
+ </wsrp-producer>
+ </deployment>
+</deployments>]]></programlisting>
+ This producer descriptor gives access to BEA's public WSRP producer. We will look at the details of the
+ different elements later. Note for now the <emphasis>producer-id</emphasis> element with a "bea" value. Put
+ this file in the deploy directory and start the server (with JBoss Portal and its WSRP service deployed).
+ </para></sect3>
+
+ <sect3>
<title>Configuring access to a remote portlet</title>
<para>
Let's now look at the Admin page and the Management portlet. Click on the "Portlet definitions" tab at the
@@ -568,12 +577,17 @@
<sect2>
<title>Overview</title>
<para>
- You can configure the behavior of Portal's WSRP Producer by editing the <emphasis>conf/config.xml</emphasis>
+ You can configure the behavior of Portal's WSRP Producer by using the WSRP administration interface, which
+ is the preferred way, or by editing the <emphasis>conf/config.xml</emphasis>
file found in <emphasis>portal-wsrp.sar</emphasis>. Several aspects can be modified with respects to whether
registration is required for consumers to access the Producer's services.
</para>
</sect2>
<sect2>
+ <para>Using the configuration portlet</para>
+ <para>TODO: ADD CONTENT</para>
+ </sect2>
+ <sect2>
<title>Default configuration</title>
<para>
Let's look at the default configuration:
16 years, 5 months
JBoss Portal SVN: r9258 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: model/state/structural and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-03 18:19:44 -0500 (Mon, 03 Dec 2007)
New Revision: 9258
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.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/state/structural/MockModel.java
Log:
better implementation of model update
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-03 22:37:26 UTC (rev 9257)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-03 23:19:44 UTC (rev 9258)
@@ -32,6 +32,7 @@
import org.jboss.portal.presentation.model.UIWindow;
import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateChangeListener;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import java.util.ArrayList;
@@ -58,6 +59,18 @@
/** . */
protected final List<ModelListener> listeners;
+ protected final StructuralStateChangeListener listener = new StructuralStateChangeListener()
+ {
+ public void update(StructuralObject object)
+ {
+ // Get the corresping object
+ UIObjectImpl tmp = objects.get(object.getId());
+
+ // Update its structural view
+ tmp.structuralObject = object;
+ }
+ };
+
private static StructuralObject getRootState(StructuralStateContext loader)
{
return loader.load(loader.getRootId());
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-03 22:37:26 UTC (rev 9257)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-03 23:19:44 UTC (rev 9258)
@@ -55,7 +55,7 @@
private UIObjectImpl parent;
/** This is used to assist with data needed during lazy loading, other state related data etc... */
- private StructuralObject structuralObject;
+ StructuralObject structuralObject;
public UIObjectImpl(UIContextImpl context, StructuralObject object)
{
@@ -185,11 +185,8 @@
changes.put(propertyName, (String)propertyValue);
// Have context process change
- context.structuralStateContext.update(structuralObject, changes);
+ context.structuralStateContext.update(context.listener, structuralObject, changes);
- // Update state locally to reflect correct state
- structuralObject = context.structuralStateContext.load(structuralObject.getId());
-
// Broadcast event
StructuralStateModification mod = new StructuralStateModification.Update(changes);
StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(getId(), mod);
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java 2007-12-03 22:37:26 UTC (rev 9257)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java 2007-12-03 23:19:44 UTC (rev 9258)
@@ -27,7 +27,6 @@
import org.jboss.portal.presentation.model.UIObject;
import java.util.Map;
-import java.util.List;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -36,22 +35,22 @@
public abstract class AbstractStructuralStateContext implements StructuralStateContext
{
- public String create(StructuralObject parent, Class<? extends UIObject> type, String name, Map<String, String> properties) throws StateChangeVetoException, StateException, IllegalArgumentException
+ public String create(StructuralStateChangeListener listener, StructuralObject parent, Class<? extends UIObject> type, String name, Map<String, String> properties) throws StateChangeVetoException, StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public void destroy(StructuralObject object) throws StateChangeVetoException, StateException, IllegalArgumentException
+ public void destroy(StructuralStateChangeListener listener, StructuralObject object) throws StateChangeVetoException, StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public void move(StructuralObject object, StructuralObject parent) throws StateChangeVetoException, StateException, IllegalArgumentException
+ public void move(StructuralStateChangeListener listener, StructuralObject object, StructuralObject parent) throws StateChangeVetoException, StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public void update(StructuralObject object, Map<String, String> changes) throws StateChangeVetoException, StateException, IllegalArgumentException
+ public void update(StructuralStateChangeListener listener, StructuralObject object, Map<String, String> changes) throws StateChangeVetoException, StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java 2007-12-03 23:19:44 UTC (rev 9258)
@@ -0,0 +1,32 @@
+/******************************************************************************
+ * 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.model.state.structural;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface StructuralStateChangeListener
+{
+ void update(StructuralObject object);
+}
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-03 22:37:26 UTC (rev 9257)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-03 23:19:44 UTC (rev 9258)
@@ -62,51 +62,53 @@
/**
* Create an object.
*
+ * @param listener the listener
* @param parent the parent
* @param type the type of the child
* @param name the name of the child
- * @param properties the initial properties of the child
- * @return the id of the newly created structural state
+ * @param properties the initial properties of the child @return the id of the newly created structural state
+ * @return the state id
* @throws StateChangeVetoException if the creation is vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the parent id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- String create(StructuralObject parent, Class<? extends UIObject> type, String name, Map<String, String> properties) throws StateChangeVetoException, StateException, IllegalArgumentException;
+ String create(StructuralStateChangeListener listener, StructuralObject parent, Class<? extends UIObject> type, String name, Map<String, String> properties) throws StateChangeVetoException, StateException, IllegalArgumentException;
/**
* Destroy a specified object.
*
- * @param object the object to destroy
- * @throws StateChangeVetoException if the creation is vetoed
+ * @param listener the listener
+ * @param object the object to destroy @throws StateChangeVetoException if the creation is vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the object id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
+ * @throws StateChangeVetoException
*/
- void destroy(StructuralObject object) throws StateChangeVetoException, StateException, IllegalArgumentException;
+ void destroy(StructuralStateChangeListener listener, StructuralObject object) throws StateChangeVetoException, StateException, IllegalArgumentException;
/**
* Move an object to a new parent.
*
+ * @param listener the listener
* @param object the object to move
- * @param parent the new parent
- * @throws StateChangeVetoException if the creation is vetoed
+ * @param parent the new parent @throws StateChangeVetoException if the creation is vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the object id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- void move(StructuralObject object, StructuralObject parent) throws StateChangeVetoException, StateException, IllegalArgumentException;
+ void move(StructuralStateChangeListener listener, StructuralObject object, StructuralObject parent) throws StateChangeVetoException, StateException, IllegalArgumentException;
/**
* Update the state of a specified object.
*
+ * @param listener the listener
* @param object the object to udpate
- * @param changes the changes
- * @throws StateChangeVetoException if the creation is vetoed
+ * @param changes the changes @throws StateChangeVetoException if the creation is vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the object id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- void update(StructuralObject object, Map<String, String> changes) throws StateChangeVetoException, StateException, IllegalArgumentException;
+ void update(StructuralStateChangeListener listener, StructuralObject object, Map<String, String> changes) throws StateChangeVetoException, StateException, IllegalArgumentException;
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-03 22:37:26 UTC (rev 9257)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-03 23:19:44 UTC (rev 9258)
@@ -29,6 +29,7 @@
import org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateContext;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateChangeListener;
import java.util.ArrayList;
import java.util.HashMap;
@@ -93,7 +94,7 @@
return root.getId();
}
- public void update(StructuralObject object, Map<String, String> changes) throws StateChangeVetoException
+ public void update(StructuralStateChangeListener listener, StructuralObject object, Map<String, String> changes) throws StateChangeVetoException
{
MockObject mockObject = getValidMockObject(object);
@@ -118,6 +119,12 @@
mockObject.setPropertyValue(propertyName, entry.getValue());
}
}
+
+ //
+ if (listener != null)
+ {
+ listener.update(mockObject.takeSnapshot());
+ }
}
public List<StructuralObject> loadChildren(StructuralObject object)
16 years, 5 months
JBoss Portal SVN: r9257 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: test/model and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-03 17:37:26 -0500 (Mon, 03 Dec 2007)
New Revision: 9257
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StaleStateException.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
Log:
- implement a basic state versionning in the mock structural state context impl
- test case the model for stale state detection on property update for now
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StaleStateException.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StaleStateException.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StaleStateException.java 2007-12-03 22:37:26 UTC (rev 9257)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * 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.model.state;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class StaleStateException extends StateException
+{
+ public StaleStateException()
+ {
+ }
+
+ public StaleStateException(String s)
+ {
+ super(s);
+ }
+
+ public StaleStateException(String s, Throwable throwable)
+ {
+ super(s, throwable);
+ }
+
+ public StaleStateException(Throwable throwable)
+ {
+ super(throwable);
+ }
+}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-03 22:09:21 UTC (rev 9256)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-03 22:37:26 UTC (rev 9257)
@@ -33,7 +33,9 @@
import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.UIPortal;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
+import org.jboss.portal.presentation.model.state.StaleStateException;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.structural.StructuralStateModification;
import org.jboss.portal.presentation.test.model.state.structural.MockModel;
import org.jboss.portal.presentation.test.model.state.structural.MockObject;
@@ -464,4 +466,34 @@
foo.setProperty(StateScopeType.NAVIGATIONAL, "foo", 2);
fooAssert.assertNavigationalEquals("foo", 2, Integer.class);
}
+
+ public void testStructuralPropertyUpdateKeepModelStateConsistent()
+ {
+ UIContext context = createContext();
+
+ //
+ context.setProperty(StateScopeType.STRUCTURAL, "foo", "bar");
+ context.setProperty(StateScopeType.STRUCTURAL, "foo", "bar2");
+ }
+
+ public void testConcurrentStructuralPropertyDetection()
+ {
+ UIContext context = createContext();
+
+ //
+ context.setProperty(StateScopeType.STRUCTURAL, "foo", "bar");
+
+ // The concurrent update
+ model.getRoot().setPropertyValue("foo", "bar2");
+
+ //
+ try
+ {
+ context.setProperty(StateScopeType.STRUCTURAL, "foo", "bar3");
+ fail("Was expecting an stale state exception");
+ }
+ catch (StaleStateException ignore)
+ {
+ }
+ }
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-03 22:09:21 UTC (rev 9256)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-03 22:37:26 UTC (rev 9257)
@@ -23,6 +23,7 @@
package org.jboss.portal.presentation.test.model.state.structural;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
+import org.jboss.portal.presentation.model.state.StaleStateException;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateContext;
@@ -92,19 +93,15 @@
return root.getId();
}
- public void update(StructuralObject structuralObject, Map<String, String> changes) throws StateChangeVetoException
+ public void update(StructuralObject object, Map<String, String> changes) throws StateChangeVetoException
{
- MockObjectImpl object = universe.get(structuralObject.getId());
- if (object == null)
- {
- throw new NoSuchStateException();
- }
+ MockObject mockObject = getValidMockObject(object);
//
for (Map.Entry<String, String> entry : changes.entrySet())
{
String propertyName = entry.getKey();
- MockObject.UpdateBehavior behavior = object.getPropertyBehavior(propertyName);
+ MockObject.UpdateBehavior behavior = mockObject.getPropertyBehavior(propertyName);
if (behavior instanceof MockObject.Veto)
{
throw new StateChangeVetoException("Cannot modify non behavior property");
@@ -118,15 +115,16 @@
}
else
{
- object.setPropertyValue(propertyName, entry.getValue());
+ mockObject.setPropertyValue(propertyName, entry.getValue());
}
}
}
public List<StructuralObject> loadChildren(StructuralObject object)
{
- StructuralObjectImpl mockStructuralObject = (StructuralObjectImpl)object;
- MockObjectImpl mockObject = universe.get(mockStructuralObject.getId());
+ MockObject mockObject = getValidMockObject(object);
+
+ //
List<StructuralObject> tmp = new ArrayList<StructuralObject>();
for (MockObject mockChild : mockObject.getChildren())
{
@@ -137,9 +135,43 @@
public StructuralObject loadParent(StructuralObject object)
{
- StructuralObjectImpl mockStructuralObject = (StructuralObjectImpl)object;
- MockObjectImpl mockObject = universe.get(mockStructuralObject.getId());
- return mockObject.getParent().takeSnapshot();
+ return getValidMockObject(object).getParent().takeSnapshot();
}
+
+ private MockObject getValidMockObject(StructuralObject object)
+ {
+ if (object == null)
+ {
+ throw new IllegalArgumentException("No null object accepted");
+ }
+
+ //
+ StructuralObjectImpl structuralObject = (StructuralObjectImpl)object;
+
+ //
+ MockObjectImpl mockObject = universe.get(structuralObject.getId());
+
+ //
+ if (mockObject == null)
+ {
+ throw new NoSuchStateException();
+ }
+
+ //
+ if (!mockObject.isValid())
+ {
+ throw new StaleStateException();
+ }
+
+ //
+ if (mockObject.getVersion() != structuralObject.version)
+ {
+ throw new StaleStateException("Version has changed obtained=" + mockObject.getVersion() + " wanted=" + structuralObject.version);
+ }
+
+ //
+ return mockObject;
+ }
+
};
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java 2007-12-03 22:09:21 UTC (rev 9256)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java 2007-12-03 22:37:26 UTC (rev 9257)
@@ -99,6 +99,8 @@
String getId();
+ int getVersion();
+
String getPropertyValue(String propertyName);
void setPropertyBehavior(String propertyName, UpdateBehavior propertyBehavior);
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-03 22:09:21 UTC (rev 9256)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2007-12-03 22:37:26 UTC (rev 9257)
@@ -136,6 +136,7 @@
//
child.parent = this;
children.put(child.id, child);
+ version++;
//
return child;
@@ -186,6 +187,11 @@
this.version++;
}
+ public int getVersion()
+ {
+ return version;
+ }
+
public StructuralObject takeSnapshot()
{
return new StructuralObjectImpl(id, version, new StructuralStateImpl(type.clazz, name, new HashMap<String, String>(propertyValues)));
@@ -203,6 +209,7 @@
if (parent != null)
{
parent.children.remove(id);
+ parent.version++;
parent = null;
}
16 years, 5 months