[portal-commits] JBoss Portal SVN: r9119 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: model and 1 other directories.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Mon Nov 26 20:39:35 EST 2007


Author: julien at jboss.com
Date: 2007-11-26 20:39:35 -0500 (Mon, 26 Nov 2007)
New Revision: 9119

Modified:
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
basic test of get/set property on model

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-11-27 01:26:52 UTC (rev 9118)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java	2007-11-27 01:39:35 UTC (rev 9119)
@@ -147,6 +147,11 @@
       return safeCast(map.get(propertyName), propertyType);
    }
 
+   public Object getProperty(StateScopeType scopeType, String propertyName)
+   {
+      return getProperty(scopeType, propertyName, Object.class);
+   }
+
    public <T> void setProperty(StateScopeType scopeType, String propertyName, T propertyValue)
    {
       Map map;

Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java	2007-11-27 01:26:52 UTC (rev 9118)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java	2007-11-27 01:39:35 UTC (rev 9119)
@@ -52,6 +52,16 @@
 
    <T> T getProperty(StateScopeType scopeType, String propertyName, Class<T> propertyType);
 
+   /**
+    * Equivalent to call <code>getProperty(StateScopeType,String,Class)</code> with the <code>Object.class</code>
+    * literal.
+    *
+    * @param scopeType
+    * @param propertyName
+    * @return
+    */
+   Object getProperty(StateScopeType scopeType, String propertyName);
+
    <T> void setProperty(StateScopeType scopeType, String propertyName, T propertyValue);
 
    /**

Modified: 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-11-27 01:26:52 UTC (rev 9118)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java	2007-11-27 01:39:35 UTC (rev 9119)
@@ -169,11 +169,11 @@
          }
          if (value != null)
          {
-            properties.remove(name);
+            properties.put(name, value);
          }
          else
          {
-            properties.put(name, value);
+            properties.remove(name);
          }
       }
    }

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-11-27 01:26:52 UTC (rev 9118)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java	2007-11-27 01:39:35 UTC (rev 9119)
@@ -25,6 +25,7 @@
 import junit.framework.TestCase;
 import org.apache.log4j.Logger;
 import org.jboss.portal.presentation.impl.model.UIContextImpl;
+import org.jboss.portal.presentation.model.StateScopeType;
 import org.jboss.portal.presentation.model.UIContext;
 import org.jboss.portal.presentation.model.UIObject;
 import org.jboss.portal.presentation.model.UIPage;
@@ -184,4 +185,55 @@
       assertEquals(defaultPortal.getName(), "defaultPortal");
       assertEquals(mockDefaultPortal.getId(), defaultPortal.getId());
    }
+
+   public void testProperty()
+   {
+      MockObject mockFoo = model.getContext().addChild("foo", MockObject.Type.PORTAL);
+      mockFoo.setProperty("foo_name", "foo_value");
+      UIContext context = new UIContextImpl(model);
+
+      //
+      UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
+      assertEquals("foo_value", foo.getProperty(StateScopeType.PERSISTENT, "foo_name", String.class));
+      assertEquals("foo_value", foo.getProperty(StateScopeType.PERSISTENT, "foo_name", Object.class));
+      assertEquals("foo_value", foo.getProperty(StateScopeType.PERSISTENT, "foo_name"));
+      assertEquals(null, foo.getProperty(StateScopeType.PERSISTENT, "foo_name", Float.class));
+      assertEquals(null, foo.getProperty(StateScopeType.NAVIGATIONAL, "foo_name", Object.class));
+      assertEquals(null, foo.getProperty(StateScopeType.NAVIGATIONAL, "foo_name"));
+      assertEquals(null, foo.getProperty(StateScopeType.NAVIGATIONAL, "foo_name", Float.class));
+      assertEquals(null, foo.getProperty(StateScopeType.TRANSIENT, "foo_name", Object.class));
+      assertEquals(null, foo.getProperty(StateScopeType.TRANSIENT, "foo_name"));
+      assertEquals(null, foo.getProperty(StateScopeType.TRANSIENT, "foo_name", Float.class));
+
+      //
+      foo.setProperty(StateScopeType.NAVIGATIONAL, "foo_name", 0);
+      assertEquals("foo_value", foo.getProperty(StateScopeType.PERSISTENT, "foo_name", String.class));
+      assertEquals("foo_value", foo.getProperty(StateScopeType.PERSISTENT, "foo_name", Object.class));
+      assertEquals("foo_value", foo.getProperty(StateScopeType.PERSISTENT, "foo_name"));
+      assertEquals(null, foo.getProperty(StateScopeType.PERSISTENT, "foo_name", Float.class));
+      assertEquals(0, foo.getProperty(StateScopeType.NAVIGATIONAL, "foo_name", Object.class));
+      assertEquals(new Integer(0), foo.getProperty(StateScopeType.NAVIGATIONAL, "foo_name", Integer.class));
+      assertEquals(0, foo.getProperty(StateScopeType.NAVIGATIONAL, "foo_name"));
+      assertEquals(null, foo.getProperty(StateScopeType.NAVIGATIONAL, "foo_name", Float.class));
+      assertEquals(null, foo.getProperty(StateScopeType.TRANSIENT, "foo_name", Object.class));
+      assertEquals(null, foo.getProperty(StateScopeType.TRANSIENT, "foo_name"));
+      assertEquals(null, foo.getProperty(StateScopeType.TRANSIENT, "foo_name", Float.class));
+
+      //
+      foo.setProperty(StateScopeType.TRANSIENT, "foo_name", true);
+      assertEquals("foo_value", foo.getProperty(StateScopeType.PERSISTENT, "foo_name", String.class));
+      assertEquals("foo_value", foo.getProperty(StateScopeType.PERSISTENT, "foo_name", Object.class));
+      assertEquals("foo_value", foo.getProperty(StateScopeType.PERSISTENT, "foo_name"));
+      assertEquals(null, foo.getProperty(StateScopeType.PERSISTENT, "foo_name", Float.class));
+      assertEquals(0, foo.getProperty(StateScopeType.NAVIGATIONAL, "foo_name", Object.class));
+      assertEquals(new Integer(0), foo.getProperty(StateScopeType.NAVIGATIONAL, "foo_name", Integer.class));
+      assertEquals(0, foo.getProperty(StateScopeType.NAVIGATIONAL, "foo_name"));
+      assertEquals(null, foo.getProperty(StateScopeType.NAVIGATIONAL, "foo_name", Float.class));
+      assertEquals(true, foo.getProperty(StateScopeType.TRANSIENT, "foo_name", Object.class));
+      assertEquals(true, foo.getProperty(StateScopeType.TRANSIENT, "foo_name"));
+      assertEquals(Boolean.TRUE, foo.getProperty(StateScopeType.TRANSIENT, "foo_name", Boolean.class));
+      assertEquals(null, foo.getProperty(StateScopeType.TRANSIENT, "foo_name", Float.class));
+
+      //
+   }
 }




More information about the portal-commits mailing list