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

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Mon Nov 26 17:43:17 EST 2007


Author: julien at jboss.com
Date: 2007-11-26 17:43:17 -0500 (Mon, 26 Nov 2007)
New Revision: 9115

Added:
   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
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Removed:
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelLoaderImpl.java
Modified:
   branches/presentation/presentation/build.xml
   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
Log:
started to rewrite UIObject model test case

Modified: branches/presentation/presentation/build.xml
===================================================================
--- branches/presentation/presentation/build.xml	2007-11-26 19:44:19 UTC (rev 9114)
+++ branches/presentation/presentation/build.xml	2007-11-26 22:43:17 UTC (rev 9115)
@@ -205,10 +205,18 @@
 
       <!-- portal-presentation-lib.jar -->
       <jar jarfile="${build.lib}/portal-presentation-lib.jar">
-         <fileset dir="${build.classes}">            
+         <fileset dir="${build.classes}">
+            <exclude name="org/jboss/portal/presentation/test/**"/>
          </fileset>
       </jar> 
    	
+      <!-- portal-presentation-test-lib.jar -->
+      <jar jarfile="${build.lib}/portal-presentation-test-lib.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/portal/presentation/test/**"/>
+         </fileset>
+      </jar>
+
    	  <!-- presentation.war -->
 	  <!-- compile the GWT Java code into JavaScript/Web resources -->
    	  <!--
@@ -292,4 +300,30 @@
    <!-- ================================================================== -->
    <!-- Deployment                                                         -->
    <!-- ================================================================== -->    
+
+   <target name="test" depends="init">
+      <property name="build.testlog" value="${module.output}/log"/>
+      <execute-tests>
+         <x-sysproperty>
+            <sysproperty key="test.root" value="${build.lib}"/>
+            <!--
+            <jvmarg value="-Xdebug"/>
+            <jvmarg value="-Xrunjdwp:transport=dt_socket,address=7878,server=y,suspend=y"/>
+            -->
+         </x-sysproperty>
+         <x-test>
+            <test todir="${test.reports}" name="org.jboss.portal.presentation.test.model.ModelTestCase"/>
+         </x-test>
+         <x-classpath>
+            <path refid="jboss.portal/modules/common.classpath"/>
+            <path refid="apache.log4j.classpath"/>
+            <path refid="junit.junit.classpath"/>
+            <path refid="jboss.portal-server.classpath"/>
+            <path refid="jboss.portal-jems.classpath"/>
+            <path location="${build.lib}/portal-presentation-lib.jar"/>
+            <path location="${build.lib}/portal-presentation-test-lib.jar"/>
+         </x-classpath>
+      </execute-tests>
+   </target>
+
 </project>

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-26 19:44:19 UTC (rev 9114)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java	2007-11-26 22:43:17 UTC (rev 9115)
@@ -212,8 +212,8 @@
    /**
     * 
     */
-   public <T extends UIObject> List<T> getChildren(Class<T> type)
-   {
+//   public <T extends UIObject> List<T> getChildren(Class<T> type)
+//   {
 //      try
 //      {
 //         List<T> filteredList = new ArrayList<T>();
@@ -239,8 +239,8 @@
 //      {
 //         throw new RuntimeException(e);
 //      }
-      throw new UnsupportedOperationException("todo");
-   }   
+//      throw new UnsupportedOperationException("todo");
+//   }
 
    protected abstract <T extends UIObject> boolean isAllowedAsChild(Class<T> type);
 

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-26 19:44:19 UTC (rev 9114)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java	2007-11-26 22:43:17 UTC (rev 9115)
@@ -82,5 +82,5 @@
     * @param type
     * @return
     */
-   <T extends UIObject> List<T> getChildren(Class<T> type);    
+//   <T extends UIObject> List<T> getChildren(Class<T> type);
 }

Added: 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	                        (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java	2007-11-26 22:43:17 UTC (rev 9115)
@@ -0,0 +1,180 @@
+/******************************************************************************
+ * 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.state.ModelLoader;
+import org.jboss.portal.presentation.model.state.ObjectState;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class MockModel implements ModelLoader
+{
+
+   /** . */
+   private int generator = 0;
+
+   /** . */
+   private final Map<String, MockObjectImpl> universe = new HashMap<String, MockObjectImpl>();
+
+   /** . */
+   private final MockObjectImpl context = new MockObjectImpl();
+
+   public MockObject getContext()
+   {
+      return context;
+   }
+
+   public ObjectState loadState(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 context.id;
+   }
+
+   private class MockObjectImpl implements MockObject
+   {
+
+      /** . */
+      private final MockObject.Type type;
+
+      /** . */
+      private final String name;
+
+      /** . */
+      private final String id = "" + generator++;
+
+      /** . */
+      private final Map<String, String> properties;
+
+      /** . */
+      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.properties = new HashMap<String, String>();
+
+         //
+         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.properties = new HashMap<String, String>();
+
+         //
+         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 ObjectState takeSnapshot()
+      {
+         ArrayList<String> childrenIds = new ArrayList<String>();
+         for (MockObjectImpl child : children.values())
+         {
+            childrenIds.add(child.id);
+         }
+         return new ObjectState(type.clazz, name, new HashMap<String, String>(properties), parent != null ? parent.id : null, childrenIds);
+      }
+
+      public String getProperty(String name)
+      {
+         return properties.get(name);
+      }
+
+      public MockObject addChild(String name, MockObject.Type type)
+      {
+         if (name == null)
+         {
+            throw new IllegalArgumentException();
+         }
+
+         //
+         return new MockObjectImpl(this, name, type);
+      }
+
+      public void setProperty(String name, String value)
+      {
+         if (name == null)
+         {
+            throw new IllegalArgumentException();
+         }
+         if (value != null)
+         {
+            properties.remove(name);
+         }
+         else
+         {
+            properties.put(name, value);
+         }
+      }
+   }
+}

Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelLoaderImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelLoaderImpl.java	2007-11-26 19:44:19 UTC (rev 9114)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelLoaderImpl.java	2007-11-26 22:43:17 UTC (rev 9115)
@@ -1,77 +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 java.util.List;
-import java.util.ArrayList;
-
-import org.jboss.portal.presentation.model.UIPortal;
-import org.jboss.portal.presentation.model.state.ModelLoader;
-import org.jboss.portal.presentation.model.state.ObjectState;
-
-/**
- * @author <a href="mailto:sshah at redhat.com">Sohil Shah</a>
- *
- */
-public class MockModelLoaderImpl implements ModelLoader
-{
-   /**
-    * 
-    */
-   public ObjectState loadState(String objectId) throws IllegalArgumentException
-   {      
-      ObjectState state = null;
-      
-      int lastIndex = objectId.lastIndexOf('/');
-      String name = objectId.substring(lastIndex+1);
-      String parentId = objectId.substring(0, lastIndex);
-      
-      //Just stub children
-      List<String> childrenIds = null;
-      if(name.contains("testingLazyLoading"))
-      {
-         childrenIds = new ArrayList<String>();
-         childrenIds.add(objectId+"/child1");
-         childrenIds.add(objectId+"/child2");
-         childrenIds.add(objectId+"/child3");
-      }
-      
-      
-      state = new ObjectState(UIPortal.class,
-      name, 
-      null, //properties
-      parentId, 
-      childrenIds //childrenIds
-      );
-      
-      return state;
-   }
-   
-   /**
-    * 
-    */
-   public String getRootId()
-   {
-      return null;
-   }
-}

Added: 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	                        (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java	2007-11-26 22:43:17 UTC (rev 9115)
@@ -0,0 +1,74 @@
+/******************************************************************************
+ * 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.ObjectState;
+
+/**
+ * @author <a href="mailto:julien at 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;
+      }
+   }
+
+   Type getType();
+
+   String getName();
+
+   String getId();
+
+   String getProperty(String name);
+
+   void setProperty(String name, String value);
+
+   MockObject addChild(String name, Type type);
+
+   /**
+    * Creates and returns a snapshot of the state.
+    *
+    * @return the state snapshot
+    */
+   ObjectState takeSnapshot();
+}

Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java (from rev 9052, branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java	                        (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java	2007-11-26 22:43:17 UTC (rev 9115)
@@ -0,0 +1,165 @@
+/******************************************************************************
+ * 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.apache.log4j.Logger;
+import org.jboss.portal.presentation.impl.model.UIContextImpl;
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.UIPortal;
+
+/**
+ * @author <a href="mailto:sshah at redhat.com">Sohil Shah</a>
+ *
+ */
+public class ModelTestCase extends TestCase
+{
+
+   /** . */
+   private Logger logger = Logger.getLogger(this.getClass());
+
+   /** . */
+   private MockModel model;
+
+   public ModelTestCase()
+   {
+   }
+
+   public ModelTestCase(String testName)
+   {
+      super(testName);
+   }
+
+   /**
+    * 
+    */
+   protected void setUp() throws Exception
+   {
+      this.model = new MockModel();
+   }
+
+   /**
+    * 
+    */
+   protected void tearDown() throws Exception
+   {
+      this.model = null;
+   }
+   
+   /**
+    * 
+    * @throws Exception
+    */
+   /*public void testCreateChild() throws Exception
+   {
+      //Adding a UIContext...this should result in an IllegalArgumentException
+      try
+      {
+         this.uiContext.createChild("duplicateRoot", UIContext.class);
+      }
+      catch(Exception e)
+      {
+         this.assertEquals(e.getClass(), IllegalArgumentException.class);
+      }
+      
+      //Assert the state of UIPortal added to the UIObject tree
+      UIPortal portal = this.uiContext.createChild("defaultPortal", UIPortal.class);
+      assertEquals(portal.getName(), "defaultPortal");
+      assertEquals(portal.getId(), "/defaultPortal");
+      assertTrue(portal.getParent() instanceof UIContext);
+      
+      //Add a UIPage to the UIPortal
+      UIPage page = portal.createChild("defaultPage", UIPage.class);      
+      assertEquals(page.getName(), "defaultPage");
+      assertEquals(page.getId(), "/defaultPortal/defaultPage");
+      assertTrue(page.getParent() instanceof UIPortal);
+      
+      //Add a UIPage to the UIContainer
+      UIContainer container = page.createChild("defaultContainer", UIContainer.class);      
+      assertEquals(container.getName(), "defaultContainer");
+      assertEquals(container.getId(), "/defaultPortal/defaultPage/defaultContainer");
+      assertTrue(container.getParent() instanceof UIPage);
+      
+      //Add a UIWindow to UIPage
+      UIWindow window = container.createChild("defaultWindow", UIWindow.class);      
+      assertEquals(window.getName(), "defaultWindow");
+      assertEquals(window.getId(), "/defaultPortal/defaultPage/defaultContainer/defaultWindow");
+      assertTrue(window.getParent() instanceof UIContainer);
+   }*/
+   
+   /**
+    * 
+    * @throws Exception
+    */
+   /*public void testDestroyChild() throws Exception
+   {      
+      //Assert the state of UIPortal added to the UIObject tree
+      UIPortal portal = this.uiContext.createChild("defaultPortal", UIPortal.class);      
+      
+      //Add a UIPage to the UIPortal
+      UIPage page = portal.createChild("defaultPage", UIPage.class);      
+      
+      //Add a UIPage to the UIContainer
+      UIContainer container = page.createChild("defaultContainer", UIContainer.class);      
+            
+      //Add a UIWindow to UIPage
+      UIWindow window = container.createChild("defaultWindow", UIWindow.class);       
+      
+      //Destroy the container. When this is done, both container and window must be destroyed from the UIObject tree
+      page.destroyChild(container.getName());
+      List<UIObject> pageChildren = page.getChildren();
+      assertTrue(pageChildren == null || pageChildren.size() == 0);
+   }*/
+   
+   public void testModelLoading() throws Exception
+   {
+      MockObject mockDefaultPortal = model.getContext().addChild("defaultPortal", MockObject.Type.PORTAL);
+      MockObject mockSomeOtherPortal = model.getContext().addChild("someOtherPortal", MockObject.Type.PORTAL);
+
+      UIContext context = new UIContextImpl(model);
+      
+      UIPortal defaultPortal = (UIPortal)context.getChildren().get(0);
+      UIPortal someOtherPortal = (UIPortal)context.getChildren().get(1);
+      
+      assertEquals(defaultPortal.getName(), "defaultPortal");
+      assertEquals(defaultPortal.getId(), mockDefaultPortal.getId());
+      assertEquals(someOtherPortal.getName(), "someOtherPortal");
+      assertEquals(someOtherPortal.getId(), mockSomeOtherPortal.getId());
+   }
+   
+   public void testParentLoading() throws Exception
+   {
+      //Setup rootChildrenInfo
+      MockObject mockDefaultPortal = model.getContext().addChild("defaultPortal", MockObject.Type.PORTAL);
+      MockObject mockDefaultPage = mockDefaultPortal.addChild("defaultPage", MockObject.Type.PORTAL);
+
+      UIContext context = new UIContextImpl(model);
+
+      UIPortal portal = (UIPortal)context.getObject(mockDefaultPage.getId());
+      UIObject parent = portal.getParent();
+      
+      assertEquals(parent.getName(), "defaultPortal");
+      assertEquals(parent.getId(), mockDefaultPortal.getId());
+   }
+}




More information about the portal-commits mailing list