Loading...

jetspeed-dev@portals.apache.org

[Prev] Thread [Next]  |  [Prev] Date [Next]

broken test TestPortletPlacement Dennis Dam Tue Dec 18 06:00:48 2007

Hi,

I was looking at the broken testcase TestPortletPlacement, which tests the recently (heavily) refactored PortletPlacementContextImpl. The constructor of PortletPlacementContextImpl was changed, so I added some JMock objects to account for this, see the attached patch.

*however*, the tests are still broken, and this is something I don't know how to fix, because I don't know the specs are. The problem: the mock test data has 1-based column numbering, but the PortletPlacementContextImpl seems to need a 0-based column count ( see the method getColumnFromFragment() ). The result is that the column with column nr. = column-count is reset to column-count - 1, which results in all fragments from both column 1 and 2 ending up in the same column.

What should the behaviour be, columns must be 0-based ? In that case all the column nrs in FragmentUtil and TestPortletPlacemen must decreased by 1.

regards,
Dennis

Index: 
components/portal/src/test/org/apache/jetspeed/layout/TestPortletPlacement.java
===================================================================
--- 
components/portal/src/test/org/apache/jetspeed/layout/TestPortletPlacement.java 
    (revision 597664)
+++ 
components/portal/src/test/org/apache/jetspeed/layout/TestPortletPlacement.java 
    (working copy)
@@ -16,12 +16,18 @@
  */
 package org.apache.jetspeed.layout;
 
-import junit.framework.TestCase;
-
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
 import org.apache.jetspeed.layout.impl.CoordinateImpl;
 import org.apache.jetspeed.layout.impl.PortletPlacementContextImpl;
+import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.request.RequestContext;
+import org.apache.pluto.om.common.Parameter;
+import org.apache.pluto.om.common.ParameterSet;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+import org.jmock.core.Constraint;
+import org.jmock.core.InvocationMatcher;
 
 /**
  * Test for Fragment placement
@@ -29,17 +35,59 @@
  * @author <a>David Gurney </a>
  * @version $Id: $
  */
-public class TestPortletPlacement extends TestCase
+public class TestPortletPlacement extends MockObjectTestCase
 {
+    private Mock portletRegistryMock;
+    private PortletRegistry portletRegistry;
+    private Mock portletDefMock;
+    private PortletDefinitionComposite portletDef;
+    private Mock portletDefInitParamsMock;
+    private ParameterSet portletDefInitParams;
 
+    private Mock portletSizesParamMock;
+    private Parameter portletSizesParam;
+
+    public void setUp(){
+        portletRegistryMock = new Mock(PortletRegistry.class);
+        portletRegistry = (PortletRegistry) portletRegistryMock.proxy();
+        
+        portletDefMock = new Mock(PortletDefinitionComposite.class);
+        portletDef = (PortletDefinitionComposite) portletDefMock.proxy();
+
+        portletDefInitParamsMock = new Mock(ParameterSet.class);
+        portletDefInitParams = (ParameterSet) portletDefInitParamsMock.proxy();
+
+        portletSizesParamMock = new Mock(Parameter.class);
+        portletSizesParam = (Parameter) portletSizesParamMock.proxy();
+
+        expectAndReturn(atLeastOnce(), portletSizesParamMock, "getValue", 
"33%,66%");
+        expectAndReturn(atLeastOnce(), portletDefInitParamsMock, "get",new 
Constraint[] {eq("sizes")}, portletSizesParam);
+        expectAndReturn(atLeastOnce(), portletDefMock, "getInitParameterSet", 
portletDefInitParams);
+        expectAndReturn(atLeastOnce(), portletRegistryMock, 
"getPortletDefinitionByUniqueName",new Constraint[] {eq("layout")}, portletDef);
+    }
+    
+    protected void expectAndReturn(InvocationMatcher matcher, Mock mock, 
String methodName, Constraint[] constraints, Object returnValue)
+    {
+        mock.expects(matcher).method(methodName)
+                            .with(constraints)
+                            .will(returnValue(returnValue));
+    }
+    
+    protected void expectAndReturn(InvocationMatcher matcher, Mock mock, 
String methodName, Object returnValue)
+    {
+        mock.expects(matcher).method(methodName)
+                            .withNoArguments()
+                            .will(returnValue(returnValue));
+    }
+    
     public void testGetFragmentAt()
     {
         // Build a request object and populate it with fragments
         RequestContext requestContext = FragmentUtil.buildFullRequestContext();
-
+        
         try
         {
-            PortletPlacementContext ppc = new 
PortletPlacementContextImpl(requestContext);
+            PortletPlacementContext ppc = new 
PortletPlacementContextImpl(requestContext.getPage(),portletRegistry);
             int a_iNumCols = ppc.getNumberColumns();
             assertEquals(a_iNumCols, 2);
 
@@ -93,7 +141,7 @@
 
         try
         {
-            PortletPlacementContext ppc = new 
PortletPlacementContextImpl(requestContext);
+            PortletPlacementContext ppc = new 
PortletPlacementContextImpl(requestContext.getPage(),portletRegistry);
 
             // Check the fragments
             Fragment a_oFrag = ppc.getFragmentById("1");
@@ -133,7 +181,7 @@
 
         try
         {
-            PortletPlacementContext ppc = new 
PortletPlacementContextImpl(requestContext);
+            PortletPlacementContext ppc = new 
PortletPlacementContextImpl(requestContext.getPage(),portletRegistry);
 
             Fragment a_oFrag = ppc
                     .getFragmentAtNewCoordinate(new CoordinateImpl(1, 0, 1, 
0));
@@ -160,7 +208,7 @@
 
         try
         {
-            PortletPlacementContext ppc = new 
PortletPlacementContextImpl(requestContext);
+            PortletPlacementContext ppc = new 
PortletPlacementContextImpl(requestContext.getPage(),portletRegistry);
 
             Fragment a_oFrag = ppc
                     .getFragmentAtNewCoordinate(new CoordinateImpl(0, 0, 0, 
0));
@@ -195,7 +243,7 @@
 
         try
         {
-            PortletPlacementContext ppc = new 
PortletPlacementContextImpl(requestContext);
+            PortletPlacementContext ppc = new 
PortletPlacementContextImpl(requestContext.getPage(),portletRegistry);
 
             Fragment a_oFrag = ppc
                     .getFragmentAtNewCoordinate(new CoordinateImpl(0, 0, 0, 
1));

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]