portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r895664 - in /portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src: main/java/org/apache/jetspeed/services/rest/ test/assembly/ test/java/org/apache/jetspeed/services/rest/ test/resources/webapp/WEB-INF/pages/ test/testdata/pages/
Date Mon, 04 Jan 2010 15:29:20 GMT
Author: woonsan
Date: Mon Jan  4 15:29:20 2010
New Revision: 895664

URL: http://svn.apache.org/viewvc?rev=895664&view=rev
Log:
JS2-1084: Fixing PageLayoutService unit test.
- Testing fragment moving: row-column positioning, left/right/up/down moving
- Replacing custom fragment placement codes by the original PortletPlacementContext class,
which has been tested for long time with proper tests.
- Moving test pages to test resource folder because it doesn't seem desirable to have changes
during testing in the src/**/ folder.

Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/grid.psml
  (contents, props changed)
      - copied, changed from r895583, portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/grid.psml
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/page.security
  (contents, props changed)
      - copied, changed from r895583, portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/page.security
Removed:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/ignore.txt
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/
Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/jetspeed-restful-services.xml
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/page-manager.xml
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/services/rest/TestPageLayoutService.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java?rev=895664&r1=895663&r2=895664&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java
Mon Jan  4 15:29:20 2010
@@ -17,7 +17,6 @@
 package org.apache.jetspeed.services.rest;
 
 import java.util.Comparator;
-import java.util.Iterator;
 import java.util.List;
 import java.util.SortedSet;
 import java.util.TreeSet;
@@ -43,8 +42,13 @@
 import org.apache.jetspeed.JetspeedActions;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
 import org.apache.jetspeed.decoration.Decoration;
+import org.apache.jetspeed.layout.Coordinate;
 import org.apache.jetspeed.layout.PageLayoutComponent;
 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
+import org.apache.jetspeed.layout.PortletPlacementContext;
+import org.apache.jetspeed.layout.PortletPlacementException;
+import org.apache.jetspeed.layout.impl.CoordinateImpl;
+import org.apache.jetspeed.layout.impl.PortletPlacementContextImpl;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.ContentPage;
 import org.apache.jetspeed.om.portlet.InitParam;
@@ -67,19 +71,19 @@
     
     private static Logger log = LoggerFactory.getLogger(PageLayoutService.class);
     
-    @Context
-    private ServletConfig servletConfig;
+    protected PageLayoutComponent pageLayoutComponent;
     
-    @Context
-    private ServletContext servletContext;
+    protected PortletRegistry portletRegistry;
     
-    private PageLayoutComponent pageLayoutComponent;
+    protected PortletActionSecurityBehavior securityBehavior;
     
-    private PortletRegistry portletRegistry;
+    private ContentFragmentRowComparator contentFragmentRowComparator = new ContentFragmentRowComparator();
     
-    private PortletActionSecurityBehavior securityBehavior;
+    @Context
+    private ServletConfig servletConfig;
     
-    private ContentFragmentRowComparator contentFragmentRowComparator = new ContentFragmentRowComparator();
+    @Context
+    private ServletContext servletContext;
     
     public PageLayoutService(PageLayoutComponent pageLayoutComponent,
                              PortletRegistry portletRegistry,
@@ -89,14 +93,13 @@
         this.portletRegistry = portletRegistry;
         this.securityBehavior = securityBehavior;
     }
-
-    public PageLayoutService(PageLayoutComponent pageLayoutComponent)
+    
+    public PageLayoutService(PageLayoutComponent pageLayoutComponent,
+                             PortletRegistry portletRegistry)
     {
-        this.pageLayoutComponent = pageLayoutComponent;
-        this.portletRegistry = null;
-        this.securityBehavior = null;
+        this(pageLayoutComponent, portletRegistry, null);
     }
-
+    
     @GET
     @Path("/page/")
     public ContentPageBean getContentPage(@Context HttpServletRequest servletRequest,
@@ -157,43 +160,28 @@
             ContentFragment contentFragment = pageLayoutComponent.addPortlet(contentPage,
fragmentType, fragmentName);
             String addedContentFragmentId = contentFragment.getId();
             
-            boolean needToAdjustPositions = false;
-            
             ContentFragment layoutFragment = null;
-            int columnCount = -1;
             
             if (col == -1 && minRowsColumn)
             {
                 layoutFragment = getParentFragment(pageLayoutComponent.getUnlockedRootFragment(contentPage),
addedContentFragmentId);
-                columnCount = getColumnCountOfLayoutFragment(layoutFragment);
-                col = getMinRowsColumnIndex(layoutFragment, columnCount);
+                col = getMinRowsColumnIndex(layoutFragment);
             }
             
             if (row != -1 || col != -1) 
             {
                 pageLayoutComponent.updateRowColumn(contentFragment, row, col);
-                needToAdjustPositions = true;
             } 
-            else 
-            {
-                needToAdjustPositions = (contentFragment.getLayoutColumn() == -1 || contentFragment.getLayoutRow()
== -1);
-            }
             
-            if (needToAdjustPositions)
+            if (layoutFragment == null)
             {
-                if (layoutFragment == null)
-                {
-                    layoutFragment = getParentFragment(pageLayoutComponent.getUnlockedRootFragment(contentPage),
addedContentFragmentId);
-                }
-                
-                if (columnCount == -1)
-                {
-                    columnCount = getColumnCountOfLayoutFragment(layoutFragment);
-                }
-                
-                adjustPositionsOfChildFragments(layoutFragment, columnCount);
+                layoutFragment = getParentFragment(pageLayoutComponent.getUnlockedRootFragment(contentPage),
addedContentFragmentId);
             }
             
+            PortletPlacementContext ppc = new PortletPlacementContextImpl(contentPage, portletRegistry,
layoutFragment);
+            // synchronize back to the page layout root fragment
+            contentPage = ppc.syncPageFragments();
+            
             return new ContentFragmentBean(contentFragment);
         }
         catch (Exception e)
@@ -233,15 +221,16 @@
         {
             pageLayoutComponent.removeFragment(contentPage, fragmentId);
             
-            int columnCount = getColumnCountOfLayoutFragment(layoutFragment);
-            adjustPositionsOfChildFragments(layoutFragment, columnCount);
-            
-            return new ContentFragmentBean(contentFragment);
+            PortletPlacementContext ppc = new PortletPlacementContextImpl(contentPage, portletRegistry,
layoutFragment);
+            // synchronize back to the page layout root fragment
+            contentPage = ppc.syncPageFragments();
         }
         catch (Exception e)
         {
             throw new WebApplicationException(e);
         }
+        
+        return new ContentFragmentBean(contentFragment);
     }
     
     @PUT
@@ -298,109 +287,46 @@
                 }
             }
             
-            int layoutColumnCount = getColumnCountOfLayoutFragment(layoutFragment);
+            PortletPlacementContext ppc = null;
             
-            if ("left".equals(direction))
+            try
             {
-                int oldColumn = contentFragment.getLayoutColumn();
+                ppc = new PortletPlacementContextImpl(contentPage, portletRegistry, layoutFragment);
                 
-                if (oldColumn < 0 || oldColumn >= layoutColumnCount)
+                if ("left".equals(direction))
                 {
-                    oldColumn = layoutColumnCount - 1;
+                    ppc.moveLeft(contentFragment);
                 }
-                
-                int newColumn = (oldColumn <= 0 ? 0 : oldColumn - 1);
-                
-                if (newColumn != oldColumn)
+                else if ("right".equals(direction))
                 {
-                    pageLayoutComponent.updateRowColumn(contentFragment, contentFragment.getLayoutRow(),
newColumn, PageLayoutComponent.USER_PROPERTY_SCOPE, null);
-                    adjustPositionsOfChildFragments(layoutFragment, layoutColumnCount);
+                    ppc.moveRight(contentFragment);
                 }
-            }
-            else if ("right".equals(direction))
-            {
-                int oldColumn = contentFragment.getLayoutColumn();
-                
-                if (oldColumn < 0 || oldColumn >= layoutColumnCount)
+                else if ("up".equals(direction))
                 {
-                    oldColumn = layoutColumnCount - 1;
+                    ppc.moveUp(contentFragment);
                 }
-                
-                int newColumn = (oldColumn < layoutColumnCount - 1 ? oldColumn + 1 : layoutColumnCount
- 1);
-                
-                if (newColumn != oldColumn)
+                else if ("down".equals(direction))
                 {
-                    pageLayoutComponent.updateRowColumn(contentFragment, contentFragment.getLayoutRow(),
newColumn, PageLayoutComponent.USER_PROPERTY_SCOPE, null);
-                    adjustPositionsOfChildFragments(layoutFragment, layoutColumnCount);
+                    ppc.moveDown(contentFragment);
                 }
-            }
-            else if ("up".equals(direction))
-            {
-                adjustPositionsOfChildFragments(layoutFragment, layoutColumnCount);
-                SortedSet<ContentFragment> [] fragmentSetArray = getSortedChildFragmentSetArray(layoutFragment,
layoutColumnCount);
-                for (SortedSet<ContentFragment> set : fragmentSetArray)
-                {
-                    if (set.contains(contentFragment))
-                    {
-                        SortedSet<ContentFragment> headSet = set.headSet(contentFragment);
-                        
-                        if (!headSet.isEmpty())
-                        {
-                            ContentFragment destFragment = headSet.last();
-                            int row = contentFragment.getLayoutRow();
-                            int column = contentFragment.getLayoutColumn();
-                            int destRow = destFragment.getLayoutRow();
-                            int destColumn = destFragment.getLayoutColumn();
-                            pageLayoutComponent.updateRowColumn(contentFragment, destRow,
destColumn, PageLayoutComponent.USER_PROPERTY_SCOPE, null);
-                            pageLayoutComponent.updateRowColumn(destFragment, row, column,
PageLayoutComponent.USER_PROPERTY_SCOPE, null);
-                        }
-                        
-                        break;
-                    }
-                }
-            }
-            else if ("down".equals(direction))
-            {
-                adjustPositionsOfChildFragments(layoutFragment, layoutColumnCount);
-                SortedSet<ContentFragment> [] fragmentSetArray = getSortedChildFragmentSetArray(layoutFragment,
layoutColumnCount);
-                for (SortedSet<ContentFragment> set : fragmentSetArray)
+                else
                 {
-                    if (set.contains(contentFragment))
-                    {
-                        SortedSet<ContentFragment> tailSet = set.tailSet(contentFragment);
-                        
-                        if (tailSet.size() > 1)
-                        {
-                            Iterator<ContentFragment> it = tailSet.iterator();
-                            ContentFragment tempFragment = it.next();
-                            
-                            if (!tempFragment.getId().equals(contentFragment.getId()))
-                            {
-                                throw new IllegalStateException("Tail set of the column fragment
set must start with the content fragment itself.");
-                            }
-                            
-                            ContentFragment destFragment = it.next();
-                            int row = contentFragment.getLayoutRow();
-                            int column = contentFragment.getLayoutColumn();
-                            int destRow = destFragment.getLayoutRow();
-                            int destColumn = destFragment.getLayoutColumn();
-                            pageLayoutComponent.updateRowColumn(contentFragment, destRow,
destColumn);
-                            pageLayoutComponent.updateRowColumn(destFragment, row, column,
PageLayoutComponent.USER_PROPERTY_SCOPE, null);
-                        }
-                        
-                        break;
-                    }
+                    throw new WebApplicationException(new IllegalArgumentException("Invalid
direction: " + direction));
                 }
+                
+                // synchronize back to the page layout root fragment
+                contentPage = ppc.syncPageFragments();
             }
-            else
+            catch (PortletPlacementException e)
             {
-                throw new WebApplicationException(new IllegalArgumentException("Invalid direction:
" + direction));
+                throw new WebApplicationException(e);
             }
         }
         else if (!StringUtils.isBlank(rowParam) && !StringUtils.isBlank(colParam))
         {
             int row = NumberUtils.toInt(rowParam, -1);
             int col = NumberUtils.toInt(colParam, -1);
+            float posHeight = NumberUtils.toFloat(posHeightParam, -1.0f);
             
             if (row != -1 && col != -1 && (contentFragment.getLayoutRow()
!= row || contentFragment.getLayoutColumn() != col))
             {
@@ -427,35 +353,17 @@
                         }
                     }
                     
-                    int layoutColumnCount = getColumnCountOfLayoutFragment(layoutFragment);
+                    PortletPlacementContext ppc = new PortletPlacementContextImpl(contentPage,
portletRegistry, layoutFragment);
+                    Coordinate coordinate = new CoordinateImpl(0, 0, col, row);
+                    ppc.moveAbsolute(contentFragment, coordinate);
                     
-                    SortedSet<ContentFragment> [] fragmentSetArray = getSortedChildFragmentSetArray(layoutFragment,
layoutColumnCount);
-                    
-                    if (fragmentSetArray.length > col)
+                    if (posHeight != -1.0f)
                     {
-                        SortedSet<ContentFragment> set = fragmentSetArray[col];
-                        
-                        if (row >= set.size())
-                        {
-                            row = set.size();
-                        }
-  
-                        int prevRow = contentFragment.getLayoutRow();
-                        boolean movingDown = (prevRow < row);
-                        pageLayoutComponent.updateRowColumn(contentFragment, row, col, PageLayoutComponent.USER_PROPERTY_SCOPE,
null);
-                        SortedSet<ContentFragment> sscf = this.getSortedChildFragmentSet(set,
movingDown, contentFragment);
-                        int rowCount = 0;
-                        for (ContentFragment f : sscf)
-                        {
-                            if (f != contentFragment)
-                            {
-                                if (rowCount != f.getLayoutRow())
-                                    pageLayoutComponent.updateRowColumn(f, rowCount, col,
PageLayoutComponent.USER_PROPERTY_SCOPE, null);                                    
-                            }
-                            rowCount++;
-                            
-                        }                        
+                        pageLayoutComponent.updatePosition(contentFragment, -1.0f, -1.0f,
-1.0f, -1.0f, posHeight, PageLayoutComponent.USER_PROPERTY_SCOPE, null);
                     }
+                    
+                    // synchronize back to the page layout root fragment
+                    contentPage = ppc.syncPageFragments();
                 }
                 catch (Exception e)
                 {
@@ -477,6 +385,7 @@
                 {
                     // first time detach, need to reorder
                 }
+                
                 pageLayoutComponent.updatePosition(contentFragment, posX, posY, posZ, posWidth,
posHeight, PageLayoutComponent.USER_PROPERTY_SCOPE, null);
                 pageLayoutComponent.updateStateMode(contentFragment, JetspeedActions.DETACH,
null, PageLayoutComponent.USER_PROPERTY_SCOPE, null);
             }
@@ -504,15 +413,18 @@
         
         RequestContext requestContext = (RequestContext) servletRequest.getAttribute(RequestContext.REQUEST_PORTALENV);
         ContentPage contentPage = getContentPage(requestContext, JetspeedActions.EDIT);
-        ContentFragment contentFragment = contentPage.getFragmentById(fragmentId);      
 
+        ContentFragment contentFragment = contentPage.getFragmentById(fragmentId);
+        
         if (contentFragment == null)
         {
             throw new WebApplicationException(new IllegalArgumentException("Fragment not
found with the specified id: " + fragmentId));
         }
+        
         if (!StringUtils.isBlank(state) || !StringUtils.isBlank(state))
         {
             pageLayoutComponent.updateStateMode(contentFragment, state, mode, PageLayoutComponent.USER_PROPERTY_SCOPE,
null);            
-        }        
+        }
+        
         return new ContentFragmentBean(contentFragment);
     }
     
@@ -558,12 +470,9 @@
     {
         try
         {
-            if (securityBehavior != null)
+            if (securityBehavior != null && !securityBehavior.checkAccess(requestContext,
action))
             {
-                if (!securityBehavior.checkAccess(requestContext, action))
-                {
-                    throw new SecurityException("Insufficient access to view page");
-                }
+                throw new SecurityException("Insufficient access to view page");
             }
             
             return requestContext.getPage();
@@ -680,34 +589,9 @@
         return fragmentSetArray;
     }
     
-    /**
-     * Adjusts the rows and cols of each content fragment contained in the layout fragment.
-     * @param layoutFragment
-     * @param columnCount the column count of the layout fragment.
-     * @see #getColumnCountOfLayoutFragment(ContentFragment)
-     */
-    private void adjustPositionsOfChildFragments(ContentFragment layoutFragment, int columnCount)
-    {
-        SortedSet<ContentFragment> [] fragmentSetArray = getSortedChildFragmentSetArray(layoutFragment,
columnCount);
-
-        for (int column = 0; column < columnCount; column++)
-        {
-            int row = 0;
-            
-            for (ContentFragment child : fragmentSetArray[column])
-            {
-                if (row != child.getLayoutRow() || -1 == child.getLayoutColumn())
-                {
-                    pageLayoutComponent.updateRowColumn(child, row, column, PageLayoutComponent.USER_PROPERTY_SCOPE,
null);
-                }
-                
-                ++row;
-            }
-        }
-    }
-    
-    private int getMinRowsColumnIndex(ContentFragment layoutFragment, int columnCount)
+    private int getMinRowsColumnIndex(ContentFragment layoutFragment)
     {
+        int columnCount = getColumnCountOfLayoutFragment(layoutFragment);
         SortedSet<ContentFragment> [] fragmentSetArray = getSortedChildFragmentSetArray(layoutFragment,
columnCount);
         int col = fragmentSetArray.length - 1;
         
@@ -739,6 +623,7 @@
             int r2 = f2.getLayoutRow();            
             String s1 = f1.getState(); 
             String s2 = f2.getState();
+            
             if (!StringUtils.isEmpty(s1) && s1.equals(JetspeedActions.DETACH))
             {
                 if (StringUtils.isEmpty(s2) || !s2.equals(JetspeedActions.DETACH))
@@ -749,6 +634,7 @@
                 if (StringUtils.isEmpty(s1) || !s1.equals(JetspeedActions.DETACH))
                     return 1;                                
             }
+            
             if (r1 == r2)
             {
                 return 0;
@@ -771,11 +657,11 @@
             }
         }
     }
-
+    
     private class ExtendedContentFragmentRowComparator implements Comparator<ContentFragment>
     {
         private boolean movingDown;
-        private ContentFragment movingFragment;        
+        private ContentFragment movingFragment;
         public ExtendedContentFragmentRowComparator(boolean movingDown, ContentFragment movingFragment)
         {
             this.movingDown = movingDown;
@@ -827,20 +713,5 @@
             }
         }
     }
-
-    /**
-     * Returns child content fragment set array ordered by the column index from the layout
content fragment.
-     * @param layoutFragment
-     * @param columnCount
-     * @return
-     */
-    private SortedSet<ContentFragment> getSortedChildFragmentSet(SortedSet<ContentFragment>
layoutFragments, boolean movingDown, ContentFragment movedFragment)
-    {
-        SortedSet<ContentFragment> set = new TreeSet<ContentFragment>(new ExtendedContentFragmentRowComparator(movingDown,
movedFragment));
-        for (ContentFragment child : layoutFragments)
-        {
-            set.add(child);
-        }        
-        return set;
-    }
+    
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/jetspeed-restful-services.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/jetspeed-restful-services.xml?rev=895664&r1=895663&r2=895664&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/jetspeed-restful-services.xml
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/jetspeed-restful-services.xml
Mon Jan  4 15:29:20 2010
@@ -147,8 +147,7 @@
   <bean id="jaxrsPageLayoutService" class="org.apache.jetspeed.services.rest.PageLayoutService">
     <meta key="j2:cat" value="default" />
     <constructor-arg ref="org.apache.jetspeed.layout.PageLayoutComponent" />
-    <!--  <constructor-arg ref="org.apache.jetspeed.components.portletregistry.PortletRegistry"
/>  -->
-    <!--  <constructor-arg ref="PortletActionSecurityBehavior" />  -->
+    <constructor-arg><null/></constructor-arg>
   </bean>
   
 </beans>

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/page-manager.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/page-manager.xml?rev=895664&r1=895663&r2=895664&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/page-manager.xml
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/page-manager.xml
Mon Jan  4 15:29:20 2010
@@ -26,7 +26,7 @@
        <constructor-arg index="1"><value>/JETSPEED-INF/castor/page-mapping.xml</value></constructor-arg>
        <constructor-arg index="2"><value>.psml</value></constructor-arg>
        <constructor-arg index="3" ><value>org.apache.jetspeed.om.page.psml.PageImpl</value></constructor-arg>
      
-       <constructor-arg index="4" ><value>${applicationRoot}/src/test/testdata/pages/pages</value></constructor-arg>
+       <constructor-arg index="4" ><value>${applicationRoot}/target/test-classes/webapp/WEB-INF/pages</value></constructor-arg>
        <constructor-arg index="5" ><ref bean="PageFileCache"/></constructor-arg>
   </bean>
   
@@ -36,7 +36,7 @@
        <constructor-arg index="1"><value>/JETSPEED-INF/castor/page-mapping.xml</value></constructor-arg>
        <constructor-arg index="2"><value>.tpsml</value></constructor-arg>
        <constructor-arg index="3" ><value>org.apache.jetspeed.om.page.psml.PageTemplateImpl</value></constructor-arg>
      
-       <constructor-arg index="4" ><value>${applicationRoot}/src/test/testdata/pages/pages</value></constructor-arg>
+       <constructor-arg index="4" ><value>${applicationRoot}/target/test-classes/webapp/WEB-INF/pages</value></constructor-arg>
        <constructor-arg index="5" ><ref bean="PageFileCache"/></constructor-arg>
   </bean>
   
@@ -46,7 +46,7 @@
        <constructor-arg index="1"><value>/JETSPEED-INF/castor/page-mapping.xml</value></constructor-arg>
        <constructor-arg index="2"><value>.dpsml</value></constructor-arg>
        <constructor-arg index="3" ><value>org.apache.jetspeed.om.page.psml.DynamicPageImpl</value></constructor-arg>
      
-       <constructor-arg index="4" ><value>${applicationRoot}/src/test/testdata/pages/pages</value></constructor-arg>
+       <constructor-arg index="4" ><value>${applicationRoot}/target/test-classes/webapp/WEB-INF/pages</value></constructor-arg>
        <constructor-arg index="5" ><ref bean="PageFileCache"/></constructor-arg>
   </bean>
   
@@ -56,7 +56,7 @@
        <constructor-arg index="1"><value>/JETSPEED-INF/castor/page-mapping.xml</value></constructor-arg>
        <constructor-arg index="2"><value>.fpsml</value></constructor-arg>
        <constructor-arg index="3" ><value>org.apache.jetspeed.om.page.psml.FragmentDefinitionImpl</value></constructor-arg>
      
-       <constructor-arg index="4" ><value>${applicationRoot}/src/test/testdata/pages/pages</value></constructor-arg>
+       <constructor-arg index="4" ><value>${applicationRoot}/target/test-classes/webapp/WEB-INF/pages</value></constructor-arg>
        <constructor-arg index="5" ><ref bean="PageFileCache"/></constructor-arg>
   </bean>
   
@@ -66,7 +66,7 @@
        <constructor-arg index="1"><value>/JETSPEED-INF/castor/page-mapping.xml</value></constructor-arg>
        <constructor-arg index="2"><value>.link</value></constructor-arg>
        <constructor-arg index="3" ><value>org.apache.jetspeed.om.page.psml.LinkImpl</value></constructor-arg>
      
-       <constructor-arg index="4" ><value>${applicationRoot}/src/test/testdata/pages/pages</value></constructor-arg>
+       <constructor-arg index="4" ><value>${applicationRoot}/target/test-classes/webapp/WEB-INF/pages</value></constructor-arg>
        <constructor-arg index="5" ><ref bean="PageFileCache"/></constructor-arg>
   </bean>
   
@@ -76,7 +76,7 @@
        <constructor-arg index="1"><value>/JETSPEED-INF/castor/page-mapping.xml</value></constructor-arg>
        <constructor-arg index="2"><value>folder.metadata</value></constructor-arg>
        <constructor-arg index="3" ><value>org.apache.jetspeed.om.folder.psml.FolderMetaDataImpl</value></constructor-arg>
      
-       <constructor-arg index="4" ><value>${applicationRoot}/src/test/testdata/pages/pages</value></constructor-arg>
+       <constructor-arg index="4" ><value>${applicationRoot}/target/test-classes/webapp/WEB-INF/pages</value></constructor-arg>
        <constructor-arg index="5" ><ref bean="PageFileCache"/></constructor-arg>
   </bean>
   
@@ -86,7 +86,7 @@
        <constructor-arg index="1"><value>/JETSPEED-INF/castor/page-mapping.xml</value></constructor-arg>
        <constructor-arg index="2"><value>page.security</value></constructor-arg>
        <constructor-arg index="3" ><value>org.apache.jetspeed.om.page.psml.PageSecurityImpl</value></constructor-arg>
      
-       <constructor-arg index="4" ><value>${applicationRoot}/src/test/testdata/pages/pages</value></constructor-arg>
+       <constructor-arg index="4" ><value>${applicationRoot}/target/test-classes/webapp/WEB-INF/pages</value></constructor-arg>
        <constructor-arg index="5" ><ref bean="PageFileCache"/></constructor-arg>
   </bean>
   
@@ -122,7 +122,7 @@
   <bean id="FolderHandler"         
        class="org.apache.jetspeed.page.document.psml.FileSystemFolderHandler" >      
  
        <constructor-arg index="0"><ref bean="IdGenerator"/></constructor-arg>
-       <constructor-arg index="1"><value>${applicationRoot}/src/test/testdata/pages/pages</value></constructor-arg>
+       <constructor-arg index="1"><value>${applicationRoot}/target/test-classes/webapp/WEB-INF/pages</value></constructor-arg>
        <constructor-arg index="2"><ref bean="DocumentHandlerFactory"/></constructor-arg>
        <constructor-arg index="3"><ref bean="PageFileCache"/></constructor-arg>
       
   </bean>

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/services/rest/TestPageLayoutService.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/services/rest/TestPageLayoutService.java?rev=895664&r1=895663&r2=895664&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/services/rest/TestPageLayoutService.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/services/rest/TestPageLayoutService.java
Mon Jan  4 15:29:20 2010
@@ -27,11 +27,14 @@
 import org.apache.jetspeed.components.ComponentManager;
 import org.apache.jetspeed.components.SpringComponentManager;
 import org.apache.jetspeed.components.factorybeans.ServletConfigFactoryBean;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
 import org.apache.jetspeed.layout.PageLayoutComponent;
 import org.apache.jetspeed.layout.impl.LayoutValve;
 import org.apache.jetspeed.mocks.ResourceLocatingServletContext;
 import org.apache.jetspeed.om.page.ContentPage;
 import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.om.portlet.InitParam;
+import org.apache.jetspeed.om.portlet.PortletDefinition;
 import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.request.JetspeedRequestContext;
 import org.apache.jetspeed.request.RequestContext;
@@ -44,6 +47,12 @@
 import org.apache.jetspeed.test.JetspeedTestCase;
 import org.apache.jetspeed.testhelpers.AbstractTestPrincipal;
 import org.jmock.Mock;
+import org.jmock.core.Constraint;
+import org.jmock.core.InvocationMatcher;
+import org.jmock.core.constraint.IsEqual;
+import org.jmock.core.constraint.IsInstanceOf;
+import org.jmock.core.matcher.InvokeAtLeastOnceMatcher;
+import org.jmock.core.stub.ReturnStub;
 
 import com.mockrunner.mock.web.MockHttpServletRequest;
 import com.mockrunner.mock.web.MockHttpServletResponse;
@@ -67,6 +76,7 @@
     private PageManager pageManager;
     private PageLayoutComponent layoutManager;
     private PageLayoutService pageLayoutService;
+    private PortletRegistry portletRegistry;
 
     public static void main(String[] args)
     {
@@ -79,7 +89,7 @@
     protected void setUp() throws Exception
     {
         super.setUp();
-
+        
         MockServletConfig servletConfig = new MockServletConfig();        
         ResourceLocatingServletContext servletContent = new ResourceLocatingServletContext(new
File(getBaseDir()));        
         servletConfig.setServletContext(servletContent);
@@ -103,8 +113,11 @@
         assertNotNull(pageManager);
         layoutManager = (PageLayoutComponent)cm.getComponent("org.apache.jetspeed.layout.PageLayoutComponent");
         assertNotNull(layoutManager);
-        pageLayoutService = (PageLayoutService)cm.getComponent("jaxrsPageLayoutService");
-        assertNotNull(pageLayoutService);        
+
+        portletRegistry = createMockPortletRegistry();
+        assertNotNull(portletRegistry);
+
+        pageLayoutService = new PageLayoutService(layoutManager, portletRegistry);
     }
 
     protected void tearDown() throws Exception
@@ -116,9 +129,6 @@
     public void testRunner()
     throws Exception
     {
-        if (0 == 0)
-            return; // UNDER DEVELOPMENT, let it pass for now....
-        
         RequestContextComponent rcc = (RequestContextComponent) new Mock(RequestContextComponent.class).proxy();
       
         MockServletConfig config = new MockServletConfig();
         MockServletContext context = new MockServletContext();
@@ -132,12 +142,13 @@
         principals.add(new TestUser("admin"));
         principals.add(new TestRole("user"));
         principals.add(new TestRole("admin"));
-        Subject subject = new Subject(true, principals, new HashSet(), new HashSet());  
     
-        JSSubject.doAsPrivileged(subject, new PrivilegedAction()
+        Subject subject = new Subject(true, principals, new HashSet(), new HashSet());
+        
+        Object ret = JSSubject.doAsPrivileged(subject, new PrivilegedAction()
                 {
                     public Object run() 
                     {
-                         try
+                        try
                         {
                             executeGridMoves(request, rc);                 
                             return null;
@@ -147,22 +158,85 @@
                             return e;
                         }                    
                     }
-                }, null);        
+                }, null);
+        
+        assertFalse("Exception occurrred: " + ret, ret instanceof Throwable);
     }
     
-    public void executeGridMoves(HttpServletRequest request, RequestContext rc) throws Exception
+    private void executeGridMoves(HttpServletRequest request, RequestContext rc) throws Exception
     {
         Page grid = pageManager.getPage("grid.psml");
         assertNotNull("default page not found", grid);
+        
         ContentPage page = layoutManager.newContentPage(grid, null, null);
         rc.setPage(page);
-        ContentFragmentBean cfb = this.pageLayoutService.moveContentFragment(request, null,
"dp-1.dp-3", null, null, "1", "0", null, null, null, null, null);
-        assertEquals(cfb.getId(), "dp-1.dp-3");
+        
+        ContentFragmentBean cfb = pageLayoutService.moveContentFragment(request, null, "dp-0.dp-00",
null, null, "1", "0", null, null, null, null, null);
+        assertEquals(cfb.getId(), "dp-0.dp-00");
+        assertEquals(cfb.getProperties().get("column"), "0");
         assertEquals(cfb.getProperties().get("row"), "1");
-        assertEquals(cfb.getProperties().get("column"), "0");        
-    }    
         
-    static class TestUser extends AbstractTestPrincipal implements User
+        cfb = pageLayoutService.moveContentFragment(request, null, "dp-0.dp-02", null, "right",
null, null, null, null, null, null, null);
+        assertEquals(cfb.getId(), "dp-0.dp-02");
+        assertEquals(cfb.getProperties().get("column"), "1");
+        assertEquals(cfb.getProperties().get("row"), "2");
+
+        cfb = pageLayoutService.moveContentFragment(request, null, "dp-0.dp-02", null, "down",
null, null, null, null, null, null, null);
+        assertEquals(cfb.getId(), "dp-0.dp-02");
+        assertEquals(cfb.getProperties().get("column"), "1");
+        assertEquals(cfb.getProperties().get("row"), "3");
+        
+        cfb = pageLayoutService.moveContentFragment(request, null, "dp-0.dp-02", null, "up",
null, null, null, null, null, null, null);
+        assertEquals(cfb.getId(), "dp-0.dp-02");
+        assertEquals(cfb.getProperties().get("column"), "1");
+        assertEquals(cfb.getProperties().get("row"), "2");
+        
+        cfb = pageLayoutService.moveContentFragment(request, null, "dp-0.dp-02", null, "left",
null, null, null, null, null, null, null);
+        assertEquals(cfb.getId(), "dp-0.dp-02");
+        assertEquals(cfb.getProperties().get("column"), "0");
+        assertEquals(cfb.getProperties().get("row"), "2");
+    }
+    
+    private PortletRegistry createMockPortletRegistry()
+    {
+        Mock portletRegistryMock;
+        PortletRegistry portletRegistry;
+        Mock portletDefMock;
+        PortletDefinition portletDef;
+
+        Mock portletSizesParamMock;
+        InitParam portletSizesParam;
+        
+        portletRegistryMock = new Mock(PortletRegistry.class);
+        portletRegistry = (PortletRegistry) portletRegistryMock.proxy();
+        
+        portletDefMock = new Mock(PortletDefinition.class);
+        portletDef = (PortletDefinition) portletDefMock.proxy();
+
+        portletSizesParamMock = new Mock(InitParam.class);
+        portletSizesParam = (InitParam) portletSizesParamMock.proxy();
+
+        expectAndReturn(new InvokeAtLeastOnceMatcher(), portletSizesParamMock, "getParamValue",
"33%,66%");
+        expectAndReturn(new InvokeAtLeastOnceMatcher(), portletRegistryMock, "getPortletDefinitionByUniqueName",
portletDef);
+        expectAndReturn(new InvokeAtLeastOnceMatcher(), portletDefMock, "getInitParam", new
Constraint[] {new IsEqual("sizes")}, portletSizesParam);
+        
+        return portletRegistry;
+    }
+
+    private void expectAndReturn(InvocationMatcher matcher, Mock mock, String methodName,
Constraint[] constraints, Object returnValue)
+    {
+        mock.expects(matcher).method(methodName)
+                            .with(constraints)
+                            .will(new ReturnStub(returnValue));
+    }
+    
+    private void expectAndReturn(InvocationMatcher matcher, Mock mock, String methodName,
Object returnValue)
+    {
+        mock.expects(matcher).method(methodName)
+                            .will(new ReturnStub(returnValue));
+    }
+    
+    private static class TestUser extends AbstractTestPrincipal implements User
     {
         private static final long serialVersionUID = 1L;
 
@@ -172,7 +246,7 @@
         }
     }
 
-    static class TestRole extends AbstractTestPrincipal implements Role
+    private static class TestRole extends AbstractTestPrincipal implements Role
     {
         private static final long serialVersionUID = 1L;
 

Copied: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/grid.psml
(from r895583, portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/grid.psml)
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/grid.psml?p2=portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/grid.psml&p1=portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/grid.psml&r1=895583&r2=895664&rev=895664&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/grid.psml
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/grid.psml
Mon Jan  4 15:29:20 2010
@@ -21,32 +21,32 @@
     xsi:schemaLocation="http://portals.apache.org/jetspeed http://portals.apache.org/jetspeed-2/2.1/schemas/psml.xsd">

     <title>Welcome to Jetspeed 2</title>
     <short-title>Welcome to Jetspeed 2</short-title>
-    <fragment id="dp-1" type="layout" name="jetspeed-layouts::VelocityTwoColumns">
-        <fragment id="dp-3" type="portlet" name="j2-admin::LocaleSelector">
+    <fragment id="dp-0" type="layout" name="jetspeed-layouts::VelocityTwoColumns">
+        <fragment id="dp-00" type="portlet" name="j2-admin::LocaleSelector">
             <property name="column" value="0"></property>
             <property name="row" value="0"></property>
         </fragment>
-        <fragment id="dp-12" type="portlet" name="j2-admin::LoginPortlet">
+        <fragment id="dp-01" type="portlet" name="j2-admin::LoginPortlet">
             <property name="column" value="0"></property>
             <property name="row" value="1"></property>
         </fragment>
-        <fragment id="dp-22" type="portlet" name="j2-admin::ForgottenPasswordPortlet">
+        <fragment id="dp-02" type="portlet" name="j2-admin::ForgottenPasswordPortlet">
             <property name="column" value="0"></property>
             <property name="row" value="2"></property>
         </fragment>
-        <fragment id="dp-7" type="portlet" name="demo::PickANumberPortlet">
+        <fragment id="dp-10" type="portlet" name="demo::PickANumberPortlet">
             <property name="column" value="1"></property>
             <property name="row" value="0"></property>
         </fragment>
-        <fragment id="dp-16" type="portlet" name="demo::RoleSecurityTest">
+        <fragment id="dp-11" type="portlet" name="demo::RoleSecurityTest">
             <property name="column" value="1"></property>
             <property name="row" value="1"></property>
         </fragment>
-        <fragment id="dp-17" type="portlet" name="demo::UserInfoTest">
+        <fragment id="dp-12" type="portlet" name="demo::UserInfoTest">
             <property name="column" value="1"></property>
             <property name="row" value="2"></property>
         </fragment>
-        <fragment id="dp-18" type="portlet" name="demo::BookmarkPortlet">
+        <fragment id="dp-13" type="portlet" name="demo::BookmarkPortlet">
             <property name="column" value="1"></property>
             <property name="row" value="3"></property>
         </fragment>

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/grid.psml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/grid.psml
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/page.security
(from r895583, portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/page.security)
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/page.security?p2=portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/page.security&p1=portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/page.security&r1=895583&r2=895664&rev=895664&view=diff
==============================================================================
    (empty)

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/resources/webapp/WEB-INF/pages/page.security
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message