portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r344077 - in /portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout: ./ FragmentUtil.java LocalFragmentImpl.java Log4j.properties TestLayout.java TestPPM.java
Date Mon, 14 Nov 2005 08:26:18 GMT
Author: taylor
Date: Mon Nov 14 00:26:14 2005
New Revision: 344077

URL: http://svn.apache.org/viewcvs?rev=344077&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-387

Layout pipeline (AJAX), Portlet Placement Manager
base code checked in
still need to integrate into pipeline


Added:
    portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/
    portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/FragmentUtil.java
    portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/LocalFragmentImpl.java
    portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/Log4j.properties
    portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestLayout.java
    portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestPPM.java

Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/FragmentUtil.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/FragmentUtil.java?rev=344077&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/FragmentUtil.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/FragmentUtil.java
Mon Nov 14 00:26:14 2005
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.layout;
+
+import org.apache.jetspeed.om.page.ContentPage;
+import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.om.page.ContentPageImpl;
+import org.apache.jetspeed.om.page.psml.PageImpl;
+import org.apache.jetspeed.request.JetspeedRequestContext;
+import org.apache.jetspeed.request.RequestContext;
+
+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 for Fragment placement
+ * 
+ * @author <a>David Gurney </a>
+ * @version $Id: $
+ */
+public class FragmentUtil
+{
+
+    public static RequestContext buildFullRequestContext()
+    {
+        // Build a request object and populate it with fragments
+        RequestContext a_oRC = setupRequestContext("remove", "1234", "0", "0");
+
+        // Build some fragments and add them to the request context
+        // Prepare some fragments
+        Fragment a_oFrag1 = buildFragment("frag1", "1", "portlet", 0, 0);
+        Fragment a_oFrag2 = buildFragment("frag2", "2", "portlet", 0, 1);
+        Fragment a_oFrag3 = buildFragment("frag3", "3", "portlet", 1, 0);
+        Fragment a_oFrag4 = buildFragment("frag4", "4", "portlet", 1, 1);
+        Fragment a_oFrag5 = buildFragment("frag5", "5", "portlet", 1, 2);
+        Fragment a_oLayout = buildFragment("layout", "6", "layout", 0, 0);
+
+        LocalFragmentImpl a_oLocalLayout = (LocalFragmentImpl) a_oLayout;
+        a_oLocalLayout.addFragment(a_oFrag1);
+        a_oLocalLayout.addFragment(a_oFrag2);
+        a_oLocalLayout.addFragment(a_oFrag3);
+        a_oLocalLayout.addFragment(a_oFrag4);
+        a_oLocalLayout.addFragment(a_oFrag5);
+
+        Page a_oPage = new PageImpl();
+        a_oPage.setRootFragment(a_oLayout);
+        ContentPage a_oContentPage = new ContentPageImpl(a_oPage);
+        a_oRC.setPage(a_oContentPage);
+
+        return a_oRC;
+    }
+
+    // Helper method to find a string within the response
+    public static boolean findValue(RequestContext p_oRequestContext,
+            String p_sValue)
+    {
+        MockHttpServletResponse mr = (MockHttpServletResponse) p_oRequestContext
+                .getResponse();
+        String a_sContent = mr.getOutputStreamContent();
+        boolean a_bResults = a_sContent.indexOf(p_sValue) >= 0;
+        return a_bResults;
+    }
+
+    // Helper method
+    public static RequestContext setupRequestContext(String p_sAction,
+            String p_sPortletId, String p_sCol, String p_sRow)
+    {
+        MockServletConfig config = new MockServletConfig();
+        MockServletContext context = new MockServletContext();
+        MockHttpSession session = new MockHttpSession();
+        session.setupServletContext(context);
+        MockHttpServletRequest request = new MockHttpServletRequest();
+        request.setupAddParameter("action", p_sAction);
+        request.setupAddParameter("id", p_sPortletId);
+        if (p_sRow != null)
+        {
+            request.setupAddParameter("row", p_sRow);
+        }
+        if (p_sCol != null)
+        {
+            request.setupAddParameter("col", p_sCol);
+        }
+
+        request.setSession(session);
+        MockHttpServletResponse response = new MockHttpServletResponse();
+
+        RequestContext a_oRC = new JetspeedRequestContext(request, response,
+                config, null);
+
+        Page a_oPage = setupPage();
+        ContentPage a_oContentPage = new ContentPageImpl(a_oPage);
+
+        a_oRC.setPage(a_oContentPage);
+
+        return a_oRC;
+    }
+
+    // Helper method
+    public static Page setupPage()
+    {
+        // Prepare some fragments
+        Fragment a_oFrag1 = buildFragment("frag1", "1", "portlet", 0, 0);
+        Fragment a_oFrag2 = buildFragment("frag2", "2", "portlet", 0, 1);
+        Fragment a_oFrag3 = buildFragment("frag3", "3", "portlet", 1, 0);
+        Fragment a_oFrag4 = buildFragment("frag4", "4", "portlet", 1, 1);
+        Fragment a_oFrag5 = buildFragment("frag5", "5", "portlet", 1, 2);
+        Fragment a_oLayout = buildFragment("layout", "6", "layout", 0, 0);
+
+        LocalFragmentImpl a_oLocalLayout = (LocalFragmentImpl) a_oLayout;
+        a_oLocalLayout.addFragment(a_oFrag1);
+        a_oLocalLayout.addFragment(a_oFrag2);
+        a_oLocalLayout.addFragment(a_oFrag3);
+        a_oLocalLayout.addFragment(a_oFrag4);
+        a_oLocalLayout.addFragment(a_oFrag5);
+
+        Page a_oPage = new PageImpl();
+        a_oPage.setRootFragment(a_oLayout);
+
+        return a_oPage;
+    }
+
+    public static Fragment buildFragment(String p_sName, String p_sId,
+            String p_sType, int p_iCol, int p_iRow)
+    {
+        LocalFragmentImpl a_oFrag = new LocalFragmentImpl();
+        a_oFrag.setName(p_sName);
+        a_oFrag.setType(p_sType);
+        a_oFrag.setLayoutColumn(p_iCol);
+        a_oFrag.setLayoutRow(p_iRow);
+        a_oFrag.setId(p_sId);
+        return a_oFrag;
+    }
+
+}

Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/LocalFragmentImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/LocalFragmentImpl.java?rev=344077&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/LocalFragmentImpl.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/LocalFragmentImpl.java
Mon Nov 14 00:26:14 2005
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.layout;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.om.page.psml.FragmentImpl;
+import java.util.ArrayList;
+
+/**
+ * Test for Fragment placement
+ * 
+ * @author <a>David Gurney </a>
+ * @version $Id: $
+ */
+public class LocalFragmentImpl extends FragmentImpl
+{
+    private ArrayList m_oFragments = new ArrayList();
+
+    private String m_sName = null;
+
+    private String m_sType = null;
+
+    private String m_sID = null;
+
+    public LocalFragmentImpl()
+    {
+    }
+
+    public void addFragment(Fragment p_oFragment)
+    {
+        m_oFragments.add(p_oFragment);
+    }
+
+    public List getFragments()
+    {
+        return m_oFragments;
+    }
+
+    public String getId()
+    {
+        return m_sID;
+    }
+
+    public String getName()
+    {
+        return m_sName;
+    }
+
+    public String getType()
+    {
+        return m_sType;
+    }
+
+    public void setId(String p_sID)
+    {
+        m_sID = p_sID;
+    }
+
+    public void setName(String p_sName)
+    {
+        m_sName = p_sName;
+    }
+
+    public void setType(String p_sType)
+    {
+        m_sType = p_sType;
+    }
+}

Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/Log4j.properties
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/Log4j.properties?rev=344077&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/Log4j.properties
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/Log4j.properties
Mon Nov 14 00:26:14 2005
@@ -0,0 +1,42 @@
+#
+# If we don't know the logging facility, put it into the jetspeed.log
+# 
+#
+log4j.rootLogger = INFO, php
+
+#
+# Jetspeed goes into Jetspeed Log
+#
+log4j.category.com.fmr.portal.pipieline = DEBUG, jetspeed
+log4j.additivity.com.fmr.portal.pipeline = false
+
+########################################################################
+#
+# Logfile definitions
+#
+########################################################################
+
+
+#
+# php.log
+#
+log4j.appender.php = org.apache.log4j.FileAppender
+log4j.appender.php.file = ${applicationRoot}/logs/php.log
+log4j.appender.php.layout = org.apache.log4j.PatternLayout
+log4j.appender.php.layout.conversionPattern = %d [%t] %-5p %c - %m%n
+log4j.appender.php.append = false
+
+log4j.appender.digester = org.apache.log4j.FileAppender
+log4j.appender.digester.file = ${applicationRoot}/logs/digester.log
+log4j.appender.digester.layout = org.apache.log4j.PatternLayout
+log4j.appender.digester.layout.conversionPattern = %d [%t] %-5p %c - %m%n
+log4j.appender.digester.append = false
+
+#
+# Console
+#
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+
+# Pattern to output the caller's file name and line number.
+log4j.appender.console.layout.ConversionPattern=%5p: %m%n

Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestLayout.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestLayout.java?rev=344077&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestLayout.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestLayout.java
Mon Nov 14 00:26:14 2005
@@ -0,0 +1,397 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.layout;
+
+import org.apache.jetspeed.AbstractPortalContainerTestCase;
+import org.apache.jetspeed.components.ComponentManager;
+import org.apache.jetspeed.components.SpringComponentManager;
+import org.apache.jetspeed.layout.impl.LayoutValve;
+import org.apache.jetspeed.pipeline.PipelineException;
+import org.apache.jetspeed.request.RequestContext;
+
+/**
+ * Test for Fragment placement
+ * 
+ * @author <a>David Gurney </a>
+ * @version $Id: $
+ */
+public class TestLayout extends AbstractPortalContainerTestCase
+{
+
+    private ComponentManager m_oComponentManager;
+
+    private LayoutValve m_oLv;
+
+    public static void main(String[] args)
+    {
+        junit.swingui.TestRunner.run(TestLayout.class);
+    }
+
+    /**
+     * Setup the request context
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        // Load the Spring configs
+        String[] bootConfigs = null;
+        String[] appConfigs =
+        { "src/webapp/WEB-INF/assembly/layout-api.xml",
+                "src/test/resources/assembly/test-layout-api.xml"};
+        m_oComponentManager = new SpringComponentManager(bootConfigs,
+                appConfigs, null, ".");
+        m_oComponentManager.start();
+
+        // Get a valid LayoutValve from Spring
+        m_oLv = (LayoutValve) m_oComponentManager.getComponent("layoutValve");
+    }
+
+    protected void tearDown() throws Exception
+    {
+        m_oComponentManager.stop();
+    }
+
+    public void xtestNullRequestContext()
+    {
+        // Get the layout that has a null request context
+        LayoutValve lv = new LayoutValve(null);
+        try
+        {
+            lv.invoke(null, null);
+            TestLayout.fail("should have thrown an exception");
+        } catch (PipelineException e)
+        {
+            TestLayout.assertTrue("detected null request context", true);
+        }
+    }
+
+    public void xtestNullParameters()
+    {
+        try
+        {
+            // Test the success case
+            RequestContext rc = FragmentUtil
+                    .setupRequestContext(null, "1234", "0", "0");
+            m_oLv.invoke(rc, null);
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "failure"));
+        } catch (PipelineException e)
+        {
+            TestLayout.fail("unexpected exception");
+        }
+
+        try
+        {
+            // Test the success case
+            RequestContext rc = FragmentUtil.setupRequestContext("moveabs", null, "0",
+                    "0");
+            m_oLv.invoke(rc, null);
+
+            // Take a look at the response to verify a failiure
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "failure"));
+        } catch (PipelineException e)
+        {
+            TestLayout.fail("unexpected exception");
+        }
+
+        try
+        {
+            // Test the success case
+            RequestContext rc = FragmentUtil.setupRequestContext("moveabs", "1234",
+                    null, "0");
+            m_oLv.invoke(rc, null);
+
+            // Take a look at the response to verify a failiure
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "failure"));
+        } catch (PipelineException e)
+        {
+            TestLayout.fail("unexpected exception");
+        }
+
+        try
+        {
+            // Test the success case
+            RequestContext rc = FragmentUtil.setupRequestContext("moveabs", "1234",
+                    "0", null);
+            m_oLv.invoke(rc, null);
+
+            // Take a look at the response to verify a failiure
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "failure"));
+        } catch (PipelineException e)
+        {
+            TestLayout.fail("unexpected exception");
+        }
+    }
+
+    public void xtestMoveSuccess()
+    {
+        moveSuccess("moveabs", "1", "0", "0", "0", "0", "0", "0"); // Doesn't
+                                                                    // really
+                                                                    // move
+        moveSuccess("moveabs", "1", "0", "0", "0", "1", "0", "1"); // Move down
+        moveSuccess("moveabs", "2", "0", "1", "0", "0", "0", "0"); // Move up
+        moveSuccess("moveabs", "1", "0", "0", "1", "0", "1", "0"); // Move
+                                                                    // right
+        moveSuccess("moveabs", "3", "1", "0", "0", "0", "0", "0"); // Move left
+        moveSuccess("moveabs", "2", "0", "1", "1", "2", "1", "2"); // Move
+                                                                    // right &
+                                                                    // move down
+        moveSuccess("moveabs", "3", "1", "0", "0", "1", "0", "1"); // Move left
+                                                                    // & move
+                                                                    // down
+        moveSuccess("moveabs", "4", "1", "1", "0", "0", "0", "0"); // Move left
+                                                                    // & move up
+
+        moveSuccess("moveabs", "1", "0", "0", "0", "2", "0", "1"); // Move too
+                                                                    // far down,
+                                                                    // should be
+                                                                    // at end of
+                                                                    // row
+        moveSuccess("moveabs", "2", "0", "1", "0", "2", "0", "1"); // Move too
+                                                                    // far down,
+                                                                    // should be
+                                                                    // at end of
+                                                                    // row
+        moveSuccess("moveabs", "3", "1", "0", "1", "3", "1", "2"); // Move too
+                                                                    // far down,
+                                                                    // should be
+                                                                    // at end of
+                                                                    // row
+        moveSuccess("moveabs", "4", "1", "1", "1", "3", "1", "2"); // Move too
+                                                                    // far down,
+                                                                    // should be
+                                                                    // at end of
+                                                                    // row
+        moveSuccess("moveabs", "5", "1", "2", "1", "3", "1", "2"); // Move too
+                                                                    // far down,
+                                                                    // should be
+                                                                    // at end of
+                                                                    // row
+        moveSuccess("moveabs", "1", "0", "0", "1", "4", "1", "3"); // Move too
+                                                                    // far down,
+                                                                    // should be
+                                                                    // at end of
+                                                                    // row
+        moveSuccess("moveabs", "2", "0", "1", "1", "4", "1", "3"); // Move too
+                                                                    // far down,
+                                                                    // should be
+                                                                    // at end of
+                                                                    // row
+
+        moveSuccess("moveleft", "1", "0", "0", "0", "0", "0", "0"); // Shouldn't
+                                                                    // move
+        moveSuccess("moveleft", "2", "0", "1", "0", "1", "0", "1"); // Shouldn't
+                                                                    // move
+        moveSuccess("moveleft", "3", "1", "0", "0", "0", "0", "0"); // Straight
+                                                                    // across
+        moveSuccess("moveleft", "4", "1", "1", "0", "1", "0", "1"); // Straight
+                                                                    // across
+        moveSuccess("moveleft", "5", "1", "2", "0", "2", "0", "2"); // Straight
+                                                                    // across
+
+        moveSuccess("moveright", "1", "0", "0", "1", "0", "1", "0"); // Straight
+                                                                        // across
+        moveSuccess("moveright", "2", "0", "1", "1", "1", "1", "1"); // Straight
+                                                                        // across
+        moveSuccess("moveright", "3", "1", "0", "1", "0", "1", "0"); // Shouldn't
+                                                                        // move
+        moveSuccess("moveright", "4", "1", "1", "1", "1", "1", "1"); // Shouldn't
+                                                                        // move
+        moveSuccess("moveright", "5", "1", "2", "1", "2", "1", "2"); // Shouldn't
+                                                                        // move
+
+        moveSuccess("moveup", "2", "0", "1", "0", "0", "0", "0"); // Straight
+                                                                    // across
+        moveSuccess("moveup", "4", "1", "1", "1", "0", "1", "0"); // Straight
+                                                                    // across
+        moveSuccess("moveup", "5", "1", "2", "1", "1", "1", "1"); // Straight
+                                                                    // across
+
+        moveSuccess("movedown", "1", "0", "0", "0", "1", "0", "1"); // Straight
+                                                                    // across
+        moveSuccess("movedown", "2", "0", "1", "0", "1", "0", "1"); // Shouldn't
+                                                                    // move
+        moveSuccess("movedown", "3", "1", "0", "1", "1", "1", "1"); // Straight
+                                                                    // across
+        moveSuccess("movedown", "4", "1", "1", "1", "2", "1", "2"); // Straight
+                                                                    // across
+        moveSuccess("movedown", "5", "1", "2", "1", "2", "1", "2"); // Shouldn't
+                                                                    // move
+    }
+
+    public void xtestMoveFailure()
+    {
+        moveFailure("moveabs", "bogus", "0", "0", "0", "0"); // non integer
+                                                                // portlet id
+        moveFailure("moveleft", "0", "0", "0", "0", "0"); // portlet not found
+        moveFailure("moveabs", "1", "0", "0", "3", "0"); // non existent
+                                                            // column
+        moveFailure("bogus", "0", "0", "0", "0", "0"); // bogus action
+        moveFailure("moveabs", "1", "0", "0", "a", "0"); // non integer value
+        moveFailure("moveabs", "1", "0", "0", "0", "b"); // non integer value
+    }
+
+    public void moveSuccess(String a_sMoveType, String p_sPortletId,
+            String p_sOldCol, String p_sOldRow, String p_sNewCol,
+            String p_sNewRow, String p_sExpectedNewCol, String p_sExpectedNewRow)
+    {
+        try
+        {
+            // Test the success case
+            RequestContext rc = null;
+
+            if (a_sMoveType.equalsIgnoreCase("moveabs"))
+            {
+                rc = FragmentUtil.setupRequestContext(a_sMoveType, p_sPortletId,
+                        p_sNewCol, p_sNewRow);
+            } else
+            {
+                rc = FragmentUtil.setupRequestContext(a_sMoveType, p_sPortletId, null,
+                        null);
+            }
+
+            m_oLv.invoke(rc, null);
+
+            // Take a look at the response to verify a failiure
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "success"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<js>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<status>success</status>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<action>" + a_sMoveType + "</action>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<id>" + p_sPortletId + "</id>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<old_position><col>" + p_sOldCol + "</col><row>"
+                            + p_sOldRow + "</row></old_position>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<new_position><col>" + p_sExpectedNewCol + "</col><row>"
+                            + p_sExpectedNewRow + "</row></new_position>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "</js>"));
+        } catch (PipelineException e)
+        {
+            e.printStackTrace();
+            TestLayout.fail("layout valve failed");
+        }
+    }
+
+    public void moveFailure(String a_sMoveType, String p_sPortletId,
+            String p_sOldCol, String p_sOldRow, String p_sNewCol,
+            String p_sNewRow)
+    {
+        try
+        {
+            // Test failure case
+            RequestContext rc = null;
+
+            if (a_sMoveType.equalsIgnoreCase("moveabs"))
+            {
+                rc = FragmentUtil.setupRequestContext(a_sMoveType, p_sPortletId,
+                        p_sNewCol, p_sNewRow);
+            } else
+            {
+                rc = FragmentUtil.setupRequestContext(a_sMoveType, p_sPortletId, null,
+                        null);
+            }
+            m_oLv.invoke(rc, null);
+
+            // Take a look at the response to verify a failiure
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<status>failure</status>"));
+        } catch (PipelineException p)
+        {
+            TestLayout.fail("unexpected exception");
+        }
+
+        try
+        {
+            // Test failure case
+            RequestContext rc = null;
+
+            if (a_sMoveType.equalsIgnoreCase("moveabs"))
+            {
+                rc = FragmentUtil.setupRequestContext(a_sMoveType, "1234", "0", "foo");
+            } else
+            {
+                rc = FragmentUtil.setupRequestContext(a_sMoveType, null, null, null);
+            }
+
+            m_oLv.invoke(rc, null);
+
+            // Take a look at the response to verify a failiure
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<status>failure</status>"));
+        } catch (PipelineException p)
+        {
+            TestLayout.fail("unexpected exception");
+        }
+    }
+
+    public void xtestRemove()
+    {
+        remove("1");
+        remove("2");
+        remove("3");
+        remove("4");
+    }
+
+    private void remove(String p_sPortletId)
+    {
+        try
+        {
+            // Test the success case
+            RequestContext rc = null;
+
+            rc = FragmentUtil.setupRequestContext("remove", p_sPortletId, null, null);
+
+            m_oLv.invoke(rc, null);
+
+            // Take a look at the response to verify a failiure
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "success"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<js>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<status>success</status>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<action>" + "remove" + "</action>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<id>" + p_sPortletId + "</id>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<old_position>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<col>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "<row>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "</old_position>"));
+            TestLayout.assertTrue("couldn't find value", FragmentUtil.findValue(rc,
+                    "</js>"));
+        } catch (PipelineException e)
+        {
+            e.printStackTrace();
+            TestLayout.fail("layout valve failed");
+        }
+
+    }
+}

Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestPPM.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestPPM.java?rev=344077&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestPPM.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestPPM.java
Mon Nov 14 00:26:14 2005
@@ -0,0 +1,225 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.layout;
+
+import junit.framework.TestCase;
+
+import org.apache.jetspeed.layout.impl.CoordinateImpl;
+import org.apache.jetspeed.layout.impl.PortletPlacementManagerImpl;
+import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.request.RequestContext;
+
+/**
+ * Test for Fragment placement
+ * 
+ * @author <a>David Gurney </a>
+ * @version $Id: $
+ */
+public class TestPPM extends TestCase
+{
+
+    public void testGetFragmentAt()
+    {
+        // Build a request object and populate it with fragments
+        RequestContext a_oRC = FragmentUtil.buildFullRequestContext();
+
+        try
+        {
+            PortletPlacementManager ppm = new PortletPlacementManagerImpl(a_oRC);
+            int a_iNumCols = ppm.getNumCols();
+            assertEquals(a_iNumCols, 2);
+
+            int a_iNumRows = ppm.getNumRows(0);
+            assertEquals(a_iNumRows, 2);
+
+            a_iNumRows = ppm.getNumRows(1);
+            assertEquals(a_iNumRows, 3);
+
+            // Check the fragments
+            Fragment a_oFrag = ppm
+                    .getFragmentAtNewCoordinate(new CoordinateImpl(0, 0, 0, 0));
+            assertNotNull("null fragment found at 0,0", a_oFrag);
+            assertEquals(a_oFrag.getId(), "1");
+            assertEquals(a_oFrag.getName(), "frag1");
+
+            a_oFrag = ppm.getFragmentAtNewCoordinate(new CoordinateImpl(0, 0,
+                    0, 1));
+            assertNotNull("null fragment found at 0,0", a_oFrag);
+            assertEquals(a_oFrag.getId(), "2");
+            assertEquals(a_oFrag.getName(), "frag2");
+
+            a_oFrag = ppm.getFragmentAtNewCoordinate(new CoordinateImpl(0, 0,
+                    1, 0));
+            assertNotNull("null fragment found at 0,0", a_oFrag);
+            assertEquals(a_oFrag.getId(), "3");
+            assertEquals(a_oFrag.getName(), "frag3");
+
+            a_oFrag = ppm.getFragmentAtNewCoordinate(new CoordinateImpl(0, 0,
+                    1, 1));
+            assertNotNull("null fragment found at 0,0", a_oFrag);
+            assertEquals(a_oFrag.getId(), "4");
+            assertEquals(a_oFrag.getName(), "frag4");
+
+            a_oFrag = ppm.getFragmentAtNewCoordinate(new CoordinateImpl(0, 0,
+                    1, 2));
+            assertNotNull("null fragment found at 0,0", a_oFrag);
+            assertEquals(a_oFrag.getId(), "5");
+            assertEquals(a_oFrag.getName(), "frag5");
+
+        } catch (PortletPlacementException e)
+        {
+            fail("creating the PortletPlacementManager failed");
+        }
+    }
+
+    public void testGetFragmentById()
+    {
+        // Build a request object and populate it with fragments
+        RequestContext a_oRC = FragmentUtil.buildFullRequestContext();
+
+        try
+        {
+            PortletPlacementManager ppm = new PortletPlacementManagerImpl(a_oRC);
+
+            // Check the fragments
+            Fragment a_oFrag = ppm.getFragmentById("1");
+            assertNotNull("null fragment with id 1", a_oFrag);
+            assertEquals(a_oFrag.getId(), "1");
+            assertEquals(a_oFrag.getName(), "frag1");
+
+            a_oFrag = ppm.getFragmentById("2");
+            assertNotNull("null fragment with id 2", a_oFrag);
+            assertEquals(a_oFrag.getId(), "2");
+            assertEquals(a_oFrag.getName(), "frag2");
+
+            a_oFrag = ppm.getFragmentById("3");
+            assertNotNull("null fragment with id 3", a_oFrag);
+            assertEquals(a_oFrag.getId(), "3");
+            assertEquals(a_oFrag.getName(), "frag3");
+
+            a_oFrag = ppm.getFragmentById("4");
+            assertNotNull("null fragment with id 4", a_oFrag);
+            assertEquals(a_oFrag.getId(), "4");
+            assertEquals(a_oFrag.getName(), "frag4");
+
+            a_oFrag = ppm.getFragmentById("5");
+            assertNotNull("null fragment with id 5", a_oFrag);
+            assertEquals(a_oFrag.getId(), "5");
+            assertEquals(a_oFrag.getName(), "frag5");
+
+        } catch (PortletPlacementException e)
+        {
+            fail("creating the PortletPlacementManager failed");
+        }
+    }
+
+    public void testRemoveFragment()
+    {
+        RequestContext a_oRC = FragmentUtil.buildFullRequestContext();
+
+        try
+        {
+            PortletPlacementManager ppm = new PortletPlacementManagerImpl(a_oRC);
+
+            Fragment a_oFrag = ppm
+                    .getFragmentAtNewCoordinate(new CoordinateImpl(0, 0, 0, 0));
+
+            Coordinate a_oCoordinate = ppm.remove(a_oFrag);
+
+            assertEquals(a_oCoordinate.getOldCol(), 0);
+            assertEquals(a_oCoordinate.getOldRow(), 0);
+
+            // Should be the second fragment now that the first has been deleted
+            a_oFrag = ppm.getFragmentAtNewCoordinate(new CoordinateImpl(0, 0,
+                    0, 0));
+            assertEquals(a_oFrag.getId(), "2");
+            assertEquals(a_oFrag.getName(), "frag2");
+        } catch (PortletPlacementException e)
+        {
+            fail("creating the PortletPlacementManager failed");
+        }
+    }
+
+    public void footestFragmentMoveabs()
+    {
+        RequestContext a_oRC = FragmentUtil.buildFullRequestContext();
+
+        try
+        {
+            PortletPlacementManager ppm = new PortletPlacementManagerImpl(a_oRC);
+
+            Fragment a_oFrag = ppm
+                    .getFragmentAtNewCoordinate(new CoordinateImpl(0, 0, 0, 0));
+
+            Coordinate a_oCoordinate = ppm.moveAbs(a_oFrag, new CoordinateImpl(
+                    0, 0, 0, 1));
+
+            assertEquals(a_oCoordinate.getOldCol(), 0);
+            assertEquals(a_oCoordinate.getOldRow(), 0);
+            assertEquals(a_oCoordinate.getNewCol(), 0);
+            assertEquals(a_oCoordinate.getNewRow(), 1);
+
+            // Should be the second fragment now that the first has been moved
+            a_oFrag = ppm.getFragmentAtNewCoordinate(new CoordinateImpl(0, 0,
+                    0, 0));
+            assertEquals(a_oFrag.getId(), "2");
+            assertEquals(a_oFrag.getName(), "frag2");
+
+            a_oFrag = ppm.getFragmentAtNewCoordinate(new CoordinateImpl(0, 0,
+                    0, 1));
+            assertEquals(a_oFrag.getId(), "1");
+            assertEquals(a_oFrag.getName(), "frag1");
+        } catch (PortletPlacementException e)
+        {
+            fail("creating the PortletPlacementManager failed");
+        }
+    }
+
+    public void footestFragmentMoveUp()
+    {
+        RequestContext a_oRC = FragmentUtil.buildFullRequestContext();
+
+        try
+        {
+            PortletPlacementManager ppm = new PortletPlacementManagerImpl(a_oRC);
+
+            Fragment a_oFrag = ppm
+                    .getFragmentAtNewCoordinate(new CoordinateImpl(0, 0, 0, 1));
+
+            Coordinate a_oCoordinate = ppm.moveUp(a_oFrag);
+
+            assertEquals(a_oCoordinate.getOldCol(), 0);
+            assertEquals(a_oCoordinate.getOldRow(), 1);
+            assertEquals(a_oCoordinate.getNewCol(), 0);
+            assertEquals(a_oCoordinate.getNewRow(), 0);
+
+            // Should be the second fragment since it was moved up
+            a_oFrag = ppm.getFragmentAtNewCoordinate(new CoordinateImpl(0, 0,
+                    0, 0));
+            assertEquals(a_oFrag.getId(), "2");
+            assertEquals(a_oFrag.getName(), "frag2");
+
+            a_oFrag = ppm.getFragmentAtNewCoordinate(new CoordinateImpl(0, 0,
+                    0, 1));
+            assertEquals(a_oFrag.getId(), "1");
+            assertEquals(a_oFrag.getName(), "frag1");
+        } catch (PortletPlacementException e)
+        {
+            fail("creating the PortletPlacementManager failed");
+        }
+    }
+
+}



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