portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r894945 - in /portals/jetspeed-2/portal/trunk: applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/ components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/ components/jetspeed-portal/src/test/assembly/ compon...
Date Thu, 31 Dec 2009 21:36:19 GMT
Author: taylor
Date: Thu Dec 31 21:36:18 2009
New Revision: 894945

URL: http://svn.apache.org/viewvc?rev=894945&view=rev
Log:
JS2-1084
its getting increasing harder to test jetui customizations without a set of unit tests on
the rest operations (we did have a test suite for ajax operations)



Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/jetspeed-restful-services.xml
  (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/services/
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/services/rest/
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/services/rest/TestPageLayoutService.java
  (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/testhelpers/AbstractTestPrincipal.java
  (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/grid.psml
  (with props)
Modified:
    portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
    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/page-manager.xml
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/layout/TestConstraintsAction.java

Modified: portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js?rev=894945&r1=894944&r2=894945&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
(original)
+++ portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
Thu Dec 31 21:36:18 2009
@@ -293,20 +293,20 @@
                 windowId = windowId.replace(/^jetspeed-detach-/, "");
             }
             var window = Y.one("[id='" + windowId + "']");
-            if (window) {
-                Y.log("data = " + window.data.get("name"));            	
-            }            
             var jetspeedZone = Y.one('#jetspeedZone');
             if (!Y.Lang.isNull(jetspeedZone)) {
         		var dragParent = window.get('parentNode');
             	var parentColumn = dragParent.data.get('column');
             	portal.reallocateColumn(parentColumn);
 
-            	window.data.set("x", 10);
-                window.data.set("y", 10);
+            	var pos = window.get('region');
+            	var x =  pos.top + 5;
+            	var y =  pos.left + 5;
+            	window.data.set("x", x);
+                window.data.set("y", y);
                 window.setStyle('position', 'absolute');
-                window.setStyle('top', '10px');
-                window.setStyle('left', '10px');
+                window.setStyle('top', x + 'px');
+                window.setStyle('left', y + 'px');
             	window.data.set('detached', true);
             	window.data.set("tool", false);
             	var drag = Y.DD.DDM.getDrag(window);
@@ -329,7 +329,17 @@
                         node: dragParent,
                         groups: ['grid']            
                     });
-    			}                
+    			}
+              var uri = portal.portalContextPath + "/services/pagelayout/fragment/" + windowId
+ "/pos/?_type=json";
+              uri += "&x=" + x + "&y=" + y + "&layout=detach";
+              var config = {
+                      on: { complete: portal.onMoveComplete },
+                      method: "PUT",
+                      headers: { "X-Portal-Path" : portal.portalPagePath },
+                      arguments: { complete: [ windowId ] }
+                  };
+              var request = Y.io(uri, config);
+    			
             }            
         },
         
@@ -375,7 +385,7 @@
             else
             {
                 var uri = portal.portalContextPath + "/services/pagelayout/fragment/" + windowId
+ "/pos/?_type=json";
-                uri += "&x=" + e.target.region.top + "&y=" + e.target.region.left
+ "&detached=true";
+                uri += "&x=" + e.target.region.top + "&y=" + e.target.region.left;
                 var config = {
                         on: { complete: portal.onMoveComplete },
                         method: "PUT",

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=894945&r1=894944&r2=894945&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
Thu Dec 31 21:36:18 2009
@@ -89,7 +89,14 @@
         this.portletRegistry = portletRegistry;
         this.securityBehavior = securityBehavior;
     }
-    
+
+    public PageLayoutService(PageLayoutComponent pageLayoutComponent)
+    {
+        this.pageLayoutComponent = pageLayoutComponent;
+        this.portletRegistry = null;
+        this.securityBehavior = null;
+    }
+
     @GET
     @Path("/page/")
     public ContentPageBean getContentPage(@Context HttpServletRequest servletRequest,
@@ -466,6 +473,10 @@
             
             try
             {
+                if (layoutFragmentId != null && layoutFragmentId.equals("detach"))
+                {
+                    // 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);
             }
@@ -604,20 +615,23 @@
         
         if (StringUtils.isBlank(sizes))
         {
-            PortletDefinition layoutPortletDef = portletRegistry.getPortletDefinitionByUniqueName(layoutFragment.getName(),
true);
-            InitParam initParam = layoutPortletDef.getInitParam("sizes");
-            
-            if (initParam != null)
-            {
-                sizes = initParam.getParamValue();
-            }
-            else
+            if (portletRegistry != null)
             {
-                initParam = layoutPortletDef.getInitParam("columns");
+                PortletDefinition layoutPortletDef = portletRegistry.getPortletDefinitionByUniqueName(layoutFragment.getName(),
true);
+                InitParam initParam = layoutPortletDef.getInitParam("sizes");
                 
                 if (initParam != null)
                 {
-                    return Integer.parseInt(initParam.getParamValue());
+                    sizes = initParam.getParamValue();
+                }
+                else
+                {
+                    initParam = layoutPortletDef.getInitParam("columns");
+                    
+                    if (initParam != null)
+                    {
+                        return Integer.parseInt(initParam.getParamValue());
+                    }
                 }
             }
         }
@@ -722,8 +736,19 @@
         public int compare(ContentFragment f1, ContentFragment f2)
         {
             int r1 = f1.getLayoutRow();
-            int r2 = f2.getLayoutRow();
-            
+            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))
+                    return -1;                
+            }
+            else if (!StringUtils.isEmpty(s2) && s2.equals(JetspeedActions.DETACH))
+            {
+                if (StringUtils.isEmpty(s1) || !s1.equals(JetspeedActions.DETACH))
+                    return 1;                                
+            }
             if (r1 == r2)
             {
                 return 0;
@@ -760,7 +785,18 @@
         {
             int r1 = f1.getLayoutRow();
             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))
+                    return -1;                
+            }
+            else if (!StringUtils.isEmpty(s2) && s2.equals(JetspeedActions.DETACH))
+            {
+                if (StringUtils.isEmpty(s1) || !s1.equals(JetspeedActions.DETACH))
+                    return 1;                                
+            }            
             if (r1 == r2)
             {
                 if (f1 == movingFragment)

Added: 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=894945&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/jetspeed-restful-services.xml
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/jetspeed-restful-services.xml
Thu Dec 31 21:36:18 2009
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" 
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+  
+  <!-- To enable log4j logging instead of the default java logging of cxf. -->
+  <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+    <meta key="j2:cat" value="default" />
+    <property name="targetClass" value="java.lang.System"/>
+    <property name="targetMethod" value="setProperty"/>
+    <property name="arguments">
+      <list>
+        <value>org.apache.cxf.Logger</value>
+        <value>org.apache.cxf.common.logging.Log4jLogger</value>
+      </list>
+    </property>
+  </bean>
+  
+  <bean id="jacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper">
+    <meta key="j2:cat" value="default" />
+  </bean>
+  
+  <bean id="jacksonJaxbIntrospector" class="org.codehaus.jackson.xc.JaxbAnnotationIntrospector">
+    <meta key="j2:cat" value="default" />
+  </bean>
+  
+  <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+    <meta key="j2:cat" value="default" />
+    <property name="targetObject">
+      <bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
+        <meta key="j2:cat" value="default" />
+        <property name="targetObject" ref="jacksonObjectMapper" />
+        <property name="propertyPath" value="serializationConfig"/>
+      </bean>
+    </property>
+    <property name="targetMethod" value="setAnnotationIntrospector"/>
+    <property name="arguments">
+      <list>
+        <ref bean="jacksonJaxbIntrospector" />
+      </list>
+    </property>
+  </bean>
+  
+  <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+    <meta key="j2:cat" value="default" />
+    <property name="targetObject">
+      <bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
+        <meta key="j2:cat" value="default" />
+        <property name="targetObject" ref="jacksonObjectMapper" />
+        <property name="propertyPath" value="deserializationConfig"/>
+      </bean>
+    </property>
+    <property name="targetMethod" value="setAnnotationIntrospector"/>
+    <property name="arguments">
+      <list>
+        <ref bean="jacksonJaxbIntrospector" />
+      </list>
+    </property>
+  </bean>
+  
+  <bean id="jaxrsJsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider">
+    <meta key="j2:cat" value="default" />
+    <property name="mapper" ref="jacksonObjectMapper" />
+  </bean>
+  
+  <bean id="cxfJaxrsBus" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+    <meta key="j2:cat" value="default" />
+    <property name="targetClass" value="org.apache.cxf.BusFactory"/>
+    <property name="targetMethod" value="getThreadDefaultBus"/>
+    <property name="arguments">
+      <list>
+        <value>true</value>
+      </list>
+    </property>
+  </bean>
+  
+  <bean id="cxfDestinationFactory" class="org.apache.cxf.transport.servlet.ServletTransportFactory">
+    <meta key="j2:cat" value="default" />
+    <constructor-arg ref="cxfJaxrsBus" />
+  </bean>
+  
+  <bean id="cxfJaxrsServletController" class="org.apache.cxf.transport.servlet.ServletController">
+    <meta key="j2:cat" value="default" />
+    <constructor-arg ref="cxfDestinationFactory" />
+    <constructor-arg ref="javax.servlet.ServletConfig" />
+    <constructor-arg>
+      <bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
+        <meta key="j2:cat" value="default" />
+        <property name="targetObject" ref="javax.servlet.ServletConfig" />
+        <property name="propertyPath" value="servletContext"/>
+      </bean>
+    </constructor-arg>
+    <constructor-arg ref="cxfJaxrsBus" />
+  </bean>
+  
+  <bean id="cxfJaxrsServerFactoryBean" class="org.apache.cxf.jaxrs.JAXRSServerFactoryBean">
+    <meta key="j2:cat" value="default" />
+    <property name="address" value="/" />
+    <property name="destinationFactory" ref="cxfDestinationFactory" />
+    <property name="providers">
+      <list>
+        <ref bean="jaxrsJsonProvider" />
+      </list>
+    </property>
+    <property name="resourceProviders">
+      <list>
+<!-- 
+        <bean class="org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider">
+          <meta key="j2:cat" value="default" />
+          <constructor-arg ref="jaxrsPortletRegistryService" />
+        </bean>
+ -->        
+        <bean class="org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider">
+          <meta key="j2:cat" value="default" />
+          <constructor-arg ref="jaxrsPageLayoutService" />
+        </bean>
+      </list>
+    </property>
+  </bean>
+  <!-- Portlet Registry JAX-RS Service -->
+  <!-- 
+  <bean id="jaxrsPortletRegistryService" class="org.apache.jetspeed.services.rest.PortletRegistryService">
+    <meta key="j2:cat" value="default" />
+    <constructor-arg ref="org.apache.jetspeed.security.SecurityAccessController" />
+    <constructor-arg ref="org.apache.jetspeed.components.portletregistry.PortletRegistry"
/>
+    <constructor-arg ref="org.apache.jetspeed.search.SearchEngine" />
+  </bean>
+  -->
+  
+  <!-- Portal Page Management JAX-RS Service -->
+  <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" />  -->
+  </bean>
+  
+</beans>

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/jetspeed-restful-services.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/assembly/jetspeed-restful-services.xml
------------------------------------------------------------------------------
    svn:keywords = Id

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=894945&r1=894944&r2=894945&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
Thu Dec 31 21:36:18 2009
@@ -174,5 +174,14 @@
             <value></value>
         </constructor-arg>
     </bean>
+
+  <!-- PageLayoutComponent -->
+  <bean id="org.apache.jetspeed.layout.PageLayoutComponent"
+    class="org.apache.jetspeed.layout.impl.PageLayoutComponentImpl">
+    <meta key="j2:cat" value="default" />
+    <constructor-arg index="0">
+      <ref bean="org.apache.jetspeed.page.PageManager" />
+    </constructor-arg>
+  </bean>
     
 </beans>

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/layout/TestConstraintsAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/layout/TestConstraintsAction.java?rev=894945&r1=894944&r2=894945&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/layout/TestConstraintsAction.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/layout/TestConstraintsAction.java
Thu Dec 31 21:36:18 2009
@@ -18,10 +18,8 @@
 
 import java.io.File;
 import java.security.PrivilegedAction;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import javax.security.auth.Subject;
@@ -40,14 +38,11 @@
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.request.RequestContextComponent;
 import org.apache.jetspeed.security.JSSubject;
-import org.apache.jetspeed.security.JetspeedPrincipal;
 import org.apache.jetspeed.security.JetspeedPrincipalType;
 import org.apache.jetspeed.security.Role;
-import org.apache.jetspeed.security.SecurityAttributeType;
-import org.apache.jetspeed.security.SecurityAttributeTypes;
 import org.apache.jetspeed.security.User;
-import org.apache.jetspeed.security.impl.TransientJetspeedPrincipal;
 import org.apache.jetspeed.test.JetspeedTestCase;
+import org.apache.jetspeed.testhelpers.AbstractTestPrincipal;
 import org.jmock.Mock;
 
 import com.mockrunner.mock.web.MockHttpServletRequest;
@@ -271,6 +266,7 @@
         Set principals = new HashSet();
         principals.add(new TestUser("admin"));
         principals.add(new TestRole("admin"));
+        principals.add(new TestRole("user"));        
         Subject subject = new Subject(true, principals, new HashSet(), new HashSet());
         
         JSSubject.doAsPrivileged(subject, new PrivilegedAction()
@@ -291,72 +287,7 @@
      
         
     }
-    
-    static class AbstractTestPrincipal extends TransientJetspeedPrincipal
-    {
-        private static final SecurityAttributeTypes attributeTypes = new SecurityAttributeTypes()
-        {
-
-            public Map<String, SecurityAttributeType> getAttributeTypeMap()
-            {
-                return Collections.emptyMap();
-            }
-
-            public Map<String, SecurityAttributeType> getAttributeTypeMap(String category)
-            {
-                return Collections.emptyMap();
-            }
-
-            public boolean isExtendable()
-            {
-                return false;
-            }
-
-            public boolean isReadOnly()
-            {
-                return true;
-            }
-        };
-        
-        private JetspeedPrincipalType type;
         
-        private static final long serialVersionUID = 1L;
-        
-
-        public AbstractTestPrincipal(final String type, String name)
-        {
-            super(type, name);
-            this.type = new JetspeedPrincipalType()
-            {               
-                public SecurityAttributeTypes getAttributeTypes()
-                {
-                    return attributeTypes;
-                }
-
-                public String getClassName()
-                {
-                    return null;
-                }
-
-                public String getName()
-                {
-                    return type;
-                }
-
-                public Class<JetspeedPrincipal> getPrincipalClass()
-                {
-                    return null;
-                }
-            };
-        }
-
-        @Override
-        public synchronized JetspeedPrincipalType getType()
-        {
-            return type;
-        }
-    }
-    
     static class TestUser extends AbstractTestPrincipal implements User
     {
         private static final long serialVersionUID = 1L;

Added: 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=894945&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/services/rest/TestPageLayoutService.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/services/rest/TestPageLayoutService.java
Thu Dec 31 21:36:18 2009
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.services.rest;
+
+import java.io.File;
+import java.security.PrivilegedAction;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.security.auth.Subject;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.jetspeed.components.ComponentManager;
+import org.apache.jetspeed.components.SpringComponentManager;
+import org.apache.jetspeed.components.factorybeans.ServletConfigFactoryBean;
+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.page.PageManager;
+import org.apache.jetspeed.request.JetspeedRequestContext;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.request.RequestContextComponent;
+import org.apache.jetspeed.security.JSSubject;
+import org.apache.jetspeed.security.JetspeedPrincipalType;
+import org.apache.jetspeed.security.Role;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.services.beans.ContentFragmentBean;
+import org.apache.jetspeed.test.JetspeedTestCase;
+import org.apache.jetspeed.testhelpers.AbstractTestPrincipal;
+import org.jmock.Mock;
+
+import com.mockrunner.mock.web.MockHttpServletRequest;
+import com.mockrunner.mock.web.MockHttpServletResponse;
+import com.mockrunner.mock.web.MockHttpSession;
+import com.mockrunner.mock.web.MockServletConfig;
+import com.mockrunner.mock.web.MockServletContext;
+
+/**
+ * Test Page Layout REST Service
+ *  
+ * @author <a>David Sean Taylor </a>
+ * @version $Id$
+ */
+public class TestPageLayoutService extends JetspeedTestCase
+{
+
+    private ComponentManager cm;
+
+    private LayoutValve valve;
+    
+    private PageManager pageManager;
+    private PageLayoutComponent layoutManager;
+    private PageLayoutService pageLayoutService;
+
+    public static void main(String[] args)
+    {
+        junit.swingui.TestRunner.run(TestPageLayoutService.class);
+    }
+
+    /**
+     * Setup the request context
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        MockServletConfig servletConfig = new MockServletConfig();        
+        ResourceLocatingServletContext servletContent = new ResourceLocatingServletContext(new
File(getBaseDir()));        
+        servletConfig.setServletContext(servletContent);
+        ServletConfigFactoryBean.setServletConfig(servletConfig);
+        
+        // Load the Spring configs
+        String[] bootConfigs = null;
+        String[] appConfigs =
+        { //"src/webapp/WEB-INF/assembly/layout-api.xml",
+                "src/test/assembly/test-layout-constraints-api.xml",
+                "src/test/assembly/page-manager.xml",
+                "src/test/assembly/jetspeed-restful-services.xml",
+                "src/test/assembly/cache-test.xml"};
+        
+                
+        cm = new SpringComponentManager(null, bootConfigs, appConfigs, servletContent, getBaseDir());
+        cm.addComponent("javax.servlet.ServletConfig", servletConfig);
+        cm.start();
+        valve = (LayoutValve) cm.getComponent("layoutValve");
+        pageManager = (PageManager) cm.getComponent("pageManager");
+        assertNotNull(pageManager);
+        layoutManager = (PageLayoutComponent)cm.getComponent("org.apache.jetspeed.layout.PageLayoutComponent");
+        assertNotNull(layoutManager);
+        pageLayoutService = (PageLayoutService)cm.getComponent("jaxrsPageLayoutService");
+        assertNotNull(pageLayoutService);        
+    }
+
+    protected void tearDown() throws Exception
+    {
+        cm.stop();
+        super.tearDown();
+    }
+
+    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();
+        MockHttpSession session = new MockHttpSession();
+        session.setupServletContext(context);
+        final MockHttpServletRequest request = new MockHttpServletRequest();
+        request.setSession(session);
+        MockHttpServletResponse response = new MockHttpServletResponse();
+        final RequestContext rc = new JetspeedRequestContext(rcc, request, response, config,
null);        
+        Set principals = new HashSet();
+        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()
+                {
+                    public Object run() 
+                    {
+                         try
+                        {
+                            executeGridMoves(request, rc);                 
+                            return null;
+                        }
+                        catch (Exception e)
+                        {
+                            return e;
+                        }                    
+                    }
+                }, null);        
+    }
+    
+    public 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");
+        assertEquals(cfb.getProperties().get("row"), "1");
+        assertEquals(cfb.getProperties().get("column"), "0");        
+    }    
+        
+    static class TestUser extends AbstractTestPrincipal implements User
+    {
+        private static final long serialVersionUID = 1L;
+
+        public TestUser(String name)
+        {
+            super(JetspeedPrincipalType.USER, name);
+        }
+    }
+
+    static class TestRole extends AbstractTestPrincipal implements Role
+    {
+        private static final long serialVersionUID = 1L;
+
+        public TestRole(String name)
+        {
+            super(JetspeedPrincipalType.ROLE, name);
+        }
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/services/rest/TestPageLayoutService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/services/rest/TestPageLayoutService.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/testhelpers/AbstractTestPrincipal.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/testhelpers/AbstractTestPrincipal.java?rev=894945&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/testhelpers/AbstractTestPrincipal.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/testhelpers/AbstractTestPrincipal.java
Thu Dec 31 21:36:18 2009
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.testhelpers;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.jetspeed.security.JetspeedPrincipal;
+import org.apache.jetspeed.security.JetspeedPrincipalType;
+import org.apache.jetspeed.security.SecurityAttributeType;
+import org.apache.jetspeed.security.SecurityAttributeTypes;
+import org.apache.jetspeed.security.impl.TransientJetspeedPrincipal;
+
+public class AbstractTestPrincipal extends TransientJetspeedPrincipal
+{
+    private static final SecurityAttributeTypes attributeTypes = new SecurityAttributeTypes()
+    {
+
+        public Map<String, SecurityAttributeType> getAttributeTypeMap()
+        {
+            return Collections.emptyMap();
+        }
+
+        public Map<String, SecurityAttributeType> getAttributeTypeMap(String category)
+        {
+            return Collections.emptyMap();
+        }
+
+        public boolean isExtendable()
+        {
+            return false;
+        }
+
+        public boolean isReadOnly()
+        {
+            return true;
+        }
+    };
+    
+    private JetspeedPrincipalType type;
+    
+    private static final long serialVersionUID = 1L;
+    
+
+    public AbstractTestPrincipal(final String type, String name)
+    {
+        super(type, name);
+        this.type = new JetspeedPrincipalType()
+        {               
+            public SecurityAttributeTypes getAttributeTypes()
+            {
+                return attributeTypes;
+            }
+
+            public String getClassName()
+            {
+                return null;
+            }
+
+            public String getName()
+            {
+                return type;
+            }
+
+            public Class<JetspeedPrincipal> getPrincipalClass()
+            {
+                return null;
+            }
+        };
+    }
+
+    @Override
+    public synchronized JetspeedPrincipalType getType()
+    {
+        return type;
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/testhelpers/AbstractTestPrincipal.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/testhelpers/AbstractTestPrincipal.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 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/testdata/pages/pages/grid.psml?rev=894945&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/grid.psml
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/grid.psml
Thu Dec 31 21:36:18 2009
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<page id="grid.psml"
+    xmlns="http://portals.apache.org/jetspeed"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+    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">
+            <property name="column" value="0"></property>
+            <property name="row" value="0"></property>
+        </fragment>
+        <fragment id="dp-12" 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">
+            <property name="column" value="0"></property>
+            <property name="row" value="2"></property>
+        </fragment>
+        <fragment id="dp-7" 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">
+            <property name="column" value="1"></property>
+            <property name="row" value="1"></property>
+        </fragment>
+        <fragment id="dp-17" 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">
+            <property name="column" value="1"></property>
+            <property name="row" value="3"></property>
+        </fragment>
+    </fragment>
+    <security-constraints>
+        <security-constraints-ref>public-view</security-constraints-ref>
+    </security-constraints>
+</page>
\ No newline at end of file

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

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



---------------------------------------------------------------------
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