You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by ca...@apache.org on 2011/09/16 18:30:03 UTC

svn commit: r1171649 [2/2] - in /incubator/rave/trunk/rave-portal/src: main/java/org/apache/rave/portal/model/ main/java/org/apache/rave/portal/service/ main/java/org/apache/rave/portal/service/impl/ main/java/org/apache/rave/portal/web/api/rpc/ main/j...

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_layout.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_layout.js?rev=1171649&r1=1171648&r2=1171649&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_layout.js (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_layout.js Fri Sep 16 16:30:03 2011
@@ -1,211 +1,248 @@
-/*
- * 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.
- */
-
-var rave = rave || {};
-rave.layout = rave.layout || (function() {
-    var MOVE_PAGE_DEFAULT_POSITION_IDX = -1;
-    
-    var $tab_title_input = $("#tab_title"),
-        $page_layout_input = $("#pageLayout");
-        
-    // modal dialog init: custom buttons and a "close" callback reseting the form inside
-    var $dialog = $( "#dialog" ).dialog({
-            autoOpen: false,
-            modal: true,
-            buttons: {
-                    Add: function() {
-                            addPage();                            
-                    },
-                    Cancel: function() {
-                            $( this ).dialog( "close" );
-                    }
-            },
-            open: function() {
-                    $tab_title_input.focus();
-            },
-            close: function() {
-                    $form[ 0 ].reset();
-                    $("#pageFormErrors").html("");
-            }
-    });        
-   
-    // the modal dialog for moving a page
-    var $movePageDialog = $("#movePageDialog").dialog({
-            autoOpen: false,
-            modal: true,
-            buttons: {
-                    Move: function() {
-                            movePage();                            
-                    },
-                    Cancel: function() {
-                            $( this ).dialog( "close" );
-                    }
-            },
-            open: function() {
-                    $("#moveAfterPageId").focus();
-            },
-            close: function() {
-                    $("#movePageForm")[0].reset();                    
-            }
-    });        
-   
-    // define the form object    
-    var $form = $("#pageForm", $dialog);  
-    
-    // page menu related functions
-    var pageMenu = (function() {
-        var $button = $("#pageMenuButton");
-        var $menu = $("#pageMenu");
-        var $menuItemEdit = $("#pageMenuEdit");
-        var $menuItemDelete = $("#pageMenuDelete");
-        var $menuItemMove = $("#pageMenuMove");
-                        
-        function hideMenu() {
-            $menu.hide();
-        }
-        
-        function showMenu() {
-            $menu.show();
-        }
-        
-        /**
-         * Initializes the private pageMenu closure
-         * - binds click event handler to menu button
-         * - binds menu item click event handlers
-         * - binds body click event handler to close the menu
-         */
-        function init() {
-            // initialize the page menu and button
-            $button.bind('click', function(event) {  
-                $menu.toggle();
-                // prevent the menu button click event from bubbling up to parent 
-                // DOM object event handlers such as the page tab click event
-                event.stopPropagation();
-            });         
-
-            // setup the edit page menu item
-            $menuItemEdit.bind('click', function(event) {
-                alert("Edit not yet implemented!");
-                pageMenu.hide();
-                // prevent the menu button click event from bubbling up to parent 
-                // DOM object event handlers such as the page tab click event
-                event.stopPropagation();
-            });
-
-            // setup the delete page menu item if it is not disabled
-            if (!$menuItemDelete.hasClass("page-menu-item-disabled")) {                            
-                $menuItemDelete.bind('click', function(event) {
-                    // send the rpc request to delete the page
-                    rave.api.rest.deletePage({pageId: getCurrentPageId(), successCallback: rave.viewPage});  
-                    pageMenu.hide();
-                    // prevent the menu button click event from bubbling up to parent 
-                    // DOM object event handlers such as the page tab click event
-                    event.stopPropagation();
-                });
-            }
-
-            // setup the edit page menu item if it is not disabled
-            if (!$menuItemDelete.hasClass("page-menu-item-disabled")) {
-                $menuItemMove.bind('click', function(event) {
-                    pageMenu.hide();                 
-                    $movePageDialog.dialog("open");                                             
-                    // prevent the menu button click event from bubbling up to parent 
-                    // DOM object event handlers such as the page tab click event
-                    event.stopPropagation();
-                });      
-            }
-
-            // close the page menu if the user clicks outside of it           
-            $("html").click(pageMenu.hide);
-        }
-        
-        return {
-            init: init,
-            hide: hideMenu,
-            show: showMenu
-        }
-    })();
-
-    /**
-     * Submits the RPC call to add a new page if form validation passes
-     */        
-    function addPage() {
-        // if the form has passed validation submit the request
-        if ($("#pageForm").valid()) {        
-            var newPageTitle = $tab_title_input.val();
-            var newPageLayoutCode = $page_layout_input.val();
-
-            // send the rpc request to create the new page
-            rave.api.rpc.addPage({pageName: newPageTitle, 
-                                  pageLayoutCode: newPageLayoutCode,
-                                  successCallback: function(result) {                                      
-                                      rave.viewPage(result.result.id); 
-                                  } 
-            });      
-        }
-    }      
-    
-    /**
-     * Submits the RPC call to move the page to a new render sequence
-     */        
-    function movePage() {
-        var moveAfterPageId = $("#moveAfterPageId").val();        
-        var args = { pageId: $("#currentPageId").val(),
-                     successCallback: function(result) { rave.viewPage(result.result.id); }
-                   };
-       
-        if (moveAfterPageId != MOVE_PAGE_DEFAULT_POSITION_IDX) {
-            args["moveAfterPageId"] = moveAfterPageId;
-        }
-                          
-        // send the rpc request to move the new page
-        rave.api.rpc.movePage(args);              
-    }          
-    
-    /**
-     * Returns the pageId of the currently viewed page
-     */
-    function getCurrentPageId() {
-        return $("#currentPageId").val();
-    }
-       
-   /***
-    * initializes the rave.layout namespace code
-    */
-    function init() {
-        // add_page button to open the dialog for creating a new page
-        $( "#add_page" )
-                .button({ 
-                    text: false,
-                    icons: {primary:'ui-icon-plusthick'} 
-                })
-                .click(function() {
-                    $dialog.dialog( "open" );
-                })
-                .show();
-
-        pageMenu.init();
-    }
-   
-    // public rave.layout API
-    return {
-        init: init,
-        getCurrentPageId: getCurrentPageId
-    };    
-})();
\ No newline at end of file
+/*
+ * 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.
+ */
+
+var rave = rave || {};
+rave.layout = rave.layout || (function() {
+    var MOVE_PAGE_DEFAULT_POSITION_IDX = -1;
+    
+    var $tab_title_input = $("#tab_title"),
+        $tab_id = $("#tab_id"),
+        $page_layout_input = $("#pageLayout");
+        
+    // modal dialog init: custom buttons and a "close" callback reseting the form inside
+    var $dialog = $( "#dialog" ).dialog({
+            autoOpen: false,
+            modal: true,
+            buttons: {
+                    Add: function() {
+                            addPage();                            
+                    },
+
+                    Update: function() {
+                            updatePage();
+                    },
+
+                    Cancel: function() {
+                            $( this ).dialog( "close" );
+                    }
+            },
+            open: function(event, ui) {
+                    if ($tab_id.val() == '') {
+                        $("#"+this.id).dialog("option", "title", "Add a New Page");
+                        $(":button:contains('Update')").hide();
+                        $(":button:contains('Add')").show();
+                    }
+                    else {
+                        $("#"+this.id).dialog("option", "title", "Update Page");
+                        $(":button:contains('Update')").show();
+                        $(":button:contains('Add')").hide();
+                    }
+                    $tab_title_input.focus();
+            },
+            close: function() {
+                    $form[ 0 ].reset();
+                    $tab_id.val('');
+                    $("#pageFormErrors").html("");
+            }
+    });
+
+    // the modal dialog for moving a page
+    var $movePageDialog = $("#movePageDialog").dialog({
+            autoOpen: false,
+            modal: true,
+            buttons: {
+                    Move: function() {
+                            movePage();                            
+                    },
+                    Cancel: function() {
+                            $( this ).dialog( "close" );
+                    }
+            },
+            open: function() {
+                    $("#moveAfterPageId").focus();
+            },
+            close: function() {
+                    $("#movePageForm")[0].reset();                    
+            }
+    });        
+   
+    // define the form object    
+    var $form = $("#pageForm", $dialog);  
+    
+    // page menu related functions
+    var pageMenu = (function() {
+        var $button = $("#pageMenuButton");
+        var $menu = $("#pageMenu");
+        var $menuItemEdit = $("#pageMenuEdit");
+        var $menuItemDelete = $("#pageMenuDelete");
+        var $menuItemMove = $("#pageMenuMove");
+                        
+        function hideMenu() {
+            $menu.hide();
+        }
+        
+        function showMenu() {
+            $menu.show();
+        }
+        
+        /**
+         * Initializes the private pageMenu closure
+         * - binds click event handler to menu button
+         * - binds menu item click event handlers
+         * - binds body click event handler to close the menu
+         */
+        function init() {
+            // initialize the page menu and button
+            $button.bind('click', function(event) {  
+                $menu.toggle();
+                // prevent the menu button click event from bubbling up to parent 
+                // DOM object event handlers such as the page tab click event
+                event.stopPropagation();
+            });         
+
+            // setup the edit page menu item
+            $menuItemEdit.bind('click', function(event) {
+                 rave.api.rpc.getPagePrefs({pageId: getCurrentPageId(),
+                                        successCallback: function(result) {
+                                            $tab_title_input.val(result.result.name);
+                                            $tab_id.val(result.result.entityId);
+                                            $page_layout_input.val(result.result.pageLayout.code);
+                                            $dialog.dialog( "open" );
+                                        }
+                });
+
+                pageMenu.hide();
+                // prevent the menu button click event from bubbling up to parent 
+                // DOM object event handlers such as the page tab click event
+                event.stopPropagation();
+            });
+
+            // setup the delete page menu item if it is not disabled
+            if (!$menuItemDelete.hasClass("page-menu-item-disabled")) {                            
+                $menuItemDelete.bind('click', function(event) {
+                    // send the rpc request to delete the page
+                    rave.api.rest.deletePage({pageId: getCurrentPageId(), successCallback: rave.viewPage});  
+                    pageMenu.hide();
+                    // prevent the menu button click event from bubbling up to parent 
+                    // DOM object event handlers such as the page tab click event
+                    event.stopPropagation();
+                });
+            }
+
+            // setup the edit page menu item if it is not disabled
+            if (!$menuItemDelete.hasClass("page-menu-item-disabled")) {
+                $menuItemMove.bind('click', function(event) {
+                    pageMenu.hide();                 
+                    $movePageDialog.dialog("open");                                             
+                    // prevent the menu button click event from bubbling up to parent 
+                    // DOM object event handlers such as the page tab click event
+                    event.stopPropagation();
+                });      
+            }
+
+            // close the page menu if the user clicks outside of it           
+            $("html").click(pageMenu.hide);
+        }
+        
+        return {
+            init: init,
+            hide: hideMenu,
+            show: showMenu
+        }
+    })();
+
+    /**
+     * Submits the RPC call to add a new page if form validation passes
+     */        
+    function addPage() {
+        // if the form has passed validation submit the request
+        if ($("#pageForm").valid()) {        
+            var newPageTitle = $tab_title_input.val();
+            var newPageLayoutCode = $page_layout_input.val();
+
+            // send the rpc request to create the new page
+            rave.api.rpc.addPage({pageName: newPageTitle, 
+                                  pageLayoutCode: newPageLayoutCode,
+                                  successCallback: function(result) {                                      
+                                      rave.viewPage(result.result.entityId); 
+                                  } 
+            });      
+        }
+    }      
+
+    /**
+     * Submits the RPC call to move the page to a new render sequence
+     */        
+    function movePage() {
+        var moveAfterPageId = $("#moveAfterPageId").val();        
+        var args = { pageId: $("#currentPageId").val(),
+                     successCallback: function(result) { rave.viewPage(result.result.entityId); }
+                   };
+       
+        if (moveAfterPageId != MOVE_PAGE_DEFAULT_POSITION_IDX) {
+            args["moveAfterPageId"] = moveAfterPageId;
+        }
+                          
+        // send the rpc request to move the new page
+        rave.api.rpc.movePage(args);              
+    }
+
+    function updatePage() {
+        if ($("#pageForm").valid()) {
+            // send the rpc request to update the page
+            rave.api.rpc.updatePagePrefs({pageId: $tab_id.val(),
+                                            title: $tab_title_input.val(),
+                                            layout: $page_layout_input.val(),
+                                            successCallback: function(result) {
+                                                rave.viewPage(result.result.entityId);
+                                            }});
+        }
+    }
+    
+    /**
+     * Returns the pageId of the currently viewed page
+     */
+    function getCurrentPageId() {
+        return $("#currentPageId").val();
+    }
+       
+   /***
+    * initializes the rave.layout namespace code
+    */
+    function init() {
+        // add_page button to open the dialog for creating a new page
+        $( "#add_page" )
+                .button({ 
+                    text: false,
+                    icons: {primary:'ui-icon-plusthick'} 
+                })
+                .click(function() {
+                    $dialog.dialog( "open" );
+                })
+                .show();
+
+        pageMenu.init();
+    }
+   
+    // public rave.layout API
+    return {
+        init: init,
+        getCurrentPageId: getCurrentPageId
+    };    
+})();

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java?rev=1171649&r1=1171648&r2=1171649&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java (original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java Fri Sep 16 16:30:03 2011
@@ -38,15 +38,8 @@ import org.junit.Test;
 import java.util.ArrayList;
 import java.util.List;
 
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.easymock.EasyMock.*;
+import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.assertThat;
 
 public class PageServiceTest {
@@ -515,8 +508,267 @@ public class PageServiceTest {
       
         verify(userService);        
         verify(pageRepository);
-    }       
+    }
     
+    @Test
+    public void updatePage_nameUpdate() {
+        String newName = "new page name";
+        String layoutName = "layout name";
+        
+        PageLayout layout = createStrictMock(PageLayout.class);
+        expect(layout.getNumberOfRegions()).andReturn(new Long(2)).anyTimes();
+//        expect(layout.equals(layout)).andReturn((boolean) true);
+        replay(layout);
+        
+        //create a strict mock that ensures that the appropriate setters are
+        //called, rather than checking the return value from the function
+        Page curPage = createStrictMock(Page.class);
+        expect(curPage.getPageLayout()).andReturn(layout);
+        curPage.setName(newName);
+        curPage.setPageLayout(layout);
+        replay(curPage);
+        
+        expect(pageRepository.get(PAGE_ID)).andReturn(curPage);
+        expect(pageRepository.save(curPage)).andReturn(curPage);
+        replay(pageRepository);
+        
+        
+        expect(pageLayoutRepository.getByPageLayoutCode(layoutName)).andReturn(layout);
+        replay(pageLayoutRepository);
+        
+        pageService.updatePage(PAGE_ID, newName, layoutName);
+        
+        verify(curPage);
+    }
+    
+    
+    @Test
+    public void updatePage_addRegion() {
+        String newName = "new page name";
+        String layoutName = "layout name";
+        
+        List<Region> regions = new ArrayList<Region>();
+        Region region = createStrictMock(Region.class);
+        expect(region.getRenderOrder()).andReturn(1);
+        replay(region);
+        regions.add(new Region());
+        regions.add(region);
+        
+        PageLayout prevLayout = createStrictMock(PageLayout.class);
+        expect(prevLayout.getNumberOfRegions()).andReturn(new Long(2)).anyTimes();
+        replay(prevLayout);
+        
+        PageLayout layout = createStrictMock(PageLayout.class);
+        expect(layout.getNumberOfRegions()).andReturn(new Long(3)).anyTimes();
+//        expect(layout.equals(layout)).andReturn((boolean) true);
+        replay(layout);
+        
+        //create a strict mock that ensures that the appropriate setters are
+        //called, rather than checking the return value from the function
+        Page curPage = createStrictMock(Page.class);
+        expect(curPage.getPageLayout()).andReturn(prevLayout);
+        expect(curPage.getRegions()).andReturn(regions);
+        curPage.setName(newName);
+        curPage.setPageLayout(layout);
+        replay(curPage);
+        
+        expect(pageRepository.get(PAGE_ID)).andReturn(curPage);
+        expect(pageRepository.save(curPage)).andReturn(curPage);
+        replay(pageRepository);
+        
+        expect(pageLayoutRepository.getByPageLayoutCode(layoutName)).andReturn(layout);
+        replay(pageLayoutRepository);
+        
+        pageService.updatePage(PAGE_ID, newName, layoutName);
+        assertThat(regions.size(), is(3));
+        assertThat(regions.get(regions.size()-1).getPage(), is(curPage));
+        
+        verify(curPage);
+    }
+    
+    
+    @Test
+    public void updatePage_removeRegion_noWidgets() {
+        String newName = "new page name";
+        String layoutName = "layout name";
+        
+        List<Region> regions = new ArrayList<Region>();
+        Region region = createStrictMock(Region.class);
+        expect(region.getRegionWidgets()).andReturn(new ArrayList<RegionWidget>());
+        expect(region.getRenderOrder()).andReturn(1);
+        replay(region);
+        regions.add(region);
+        
+        Region deletedRegion = createStrictMock(Region.class);
+        expect(deletedRegion.getRegionWidgets()).andReturn(new ArrayList<RegionWidget>());
+        replay(deletedRegion);
+        regions.add(deletedRegion);
+        
+        PageLayout prevLayout = createStrictMock(PageLayout.class);
+        expect(prevLayout.getNumberOfRegions()).andReturn(new Long(2)).anyTimes();
+        replay(prevLayout);
+        
+        PageLayout layout = createStrictMock(PageLayout.class);
+        expect(layout.getNumberOfRegions()).andReturn(new Long(1)).anyTimes();
+        replay(layout);
+        
+        regionRepository.delete(deletedRegion);
+        expect(regionRepository.save(region)).andReturn(region);
+        replay(regionRepository);
+        
+        //create a strict mock that ensures that the appropriate setters are
+        //called, rather than checking the return value from the function
+        Page curPage = createStrictMock(Page.class);
+        expect(curPage.getPageLayout()).andReturn(prevLayout);
+        expect(curPage.getRegions()).andReturn(regions);
+        curPage.setName(newName);
+        curPage.setPageLayout(layout);
+        replay(curPage);
+        
+        expect(pageRepository.get(PAGE_ID)).andReturn(curPage);
+        expect(pageRepository.save(curPage)).andReturn(curPage);
+        replay(pageRepository);
+        
+        expect(pageLayoutRepository.getByPageLayoutCode(layoutName)).andReturn(layout);
+        replay(pageLayoutRepository);
+        
+        pageService.updatePage(PAGE_ID, newName, layoutName);
+        
+        verify(curPage);
+    }
+    
+    
+    @Test
+    public void updatePage_removeRegion_moveWidgetToEmptyColumn() {
+        String newName = "new page name";
+        String layoutName = "layout name";
+        
+        
+        List<RegionWidget> newLastWidgetColumn = new ArrayList<RegionWidget>();
+        
+        List<Region> regions = new ArrayList<Region>();
+        Region region = createStrictMock(Region.class);
+        expect(region.getRegionWidgets()).andReturn(newLastWidgetColumn).times(2);
+        expect(region.getRenderOrder()).andReturn(1);
+        replay(region);
+        regions.add(region);
+        
+        
+        RegionWidget widget = createStrictMock(RegionWidget.class);
+        widget.setRegion(region);
+        widget.setRenderOrder(1);
+        replay(widget);
+        List<RegionWidget> movedWidgets = new ArrayList<RegionWidget>();
+        movedWidgets.add(widget);
+        
+        Region deletedRegion = createStrictMock(Region.class);
+        expect(deletedRegion.getRegionWidgets()).andReturn(movedWidgets);
+        replay(deletedRegion);
+        regions.add(deletedRegion);
+        
+        PageLayout prevLayout = createStrictMock(PageLayout.class);
+        expect(prevLayout.getNumberOfRegions()).andReturn(new Long(2)).anyTimes();
+        replay(prevLayout);
+        
+        PageLayout layout = createStrictMock(PageLayout.class);
+        expect(layout.getNumberOfRegions()).andReturn(new Long(1)).anyTimes();
+        replay(layout);
+        
+        regionRepository.delete(deletedRegion);
+        expect(regionRepository.save(region)).andReturn(region);
+        replay(regionRepository);
+        
+        //create a strict mock that ensures that the appropriate setters are
+        //called, rather than checking the return value from the function
+        Page curPage = createStrictMock(Page.class);
+        expect(curPage.getPageLayout()).andReturn(prevLayout);
+        expect(curPage.getRegions()).andReturn(regions);
+        curPage.setName(newName);
+        curPage.setPageLayout(layout);
+        replay(curPage);
+        
+        expect(pageRepository.get(PAGE_ID)).andReturn(curPage);
+        expect(pageRepository.save(curPage)).andReturn(curPage);
+        replay(pageRepository);
+        
+        expect(pageLayoutRepository.getByPageLayoutCode(layoutName)).andReturn(layout);
+        replay(pageLayoutRepository);
+        
+        pageService.updatePage(PAGE_ID, newName, layoutName);
+        assertThat(newLastWidgetColumn.size(), is (1));
+        
+        verify(curPage);
+    }
+    
+    
+    @Test
+    public void updatePage_removeRegion_moveWidgetToNonEmptyColumn() {
+        String newName = "new page name";
+        String layoutName = "layout name";
+        
+        
+        RegionWidget widget = createStrictMock(RegionWidget.class);
+        expect(widget.getRenderOrder()).andReturn(0).anyTimes();
+        replay(widget);
+        List<RegionWidget> newLastWidgetColumn = new ArrayList<RegionWidget>();
+        newLastWidgetColumn.add(widget);
+        
+        List<Region> regions = new ArrayList<Region>();
+        Region region = createStrictMock(Region.class);
+        expect(region.getRegionWidgets()).andReturn(newLastWidgetColumn).times(2);
+        expect(region.getRenderOrder()).andReturn(1);
+        replay(region);
+        regions.add(region);
+        
+        
+        widget = createStrictMock(RegionWidget.class);
+        widget.setRegion(region);
+        widget.setRenderOrder(1);
+        expect(widget.getRenderOrder()).andReturn(1).anyTimes();
+        replay(widget);
+        List<RegionWidget> movedWidgets = new ArrayList<RegionWidget>();
+        movedWidgets.add(widget);
+        
+        Region deletedRegion = createStrictMock(Region.class);
+        expect(deletedRegion.getRegionWidgets()).andReturn(movedWidgets);
+        replay(deletedRegion);
+        regions.add(deletedRegion);
+        
+        PageLayout prevLayout = createStrictMock(PageLayout.class);
+        expect(prevLayout.getNumberOfRegions()).andReturn(new Long(2)).anyTimes();
+        replay(prevLayout);
+        
+        PageLayout layout = createStrictMock(PageLayout.class);
+        expect(layout.getNumberOfRegions()).andReturn(new Long(1)).anyTimes();
+        replay(layout);
+        
+        regionRepository.delete(deletedRegion);
+        expect(regionRepository.save(region)).andReturn(region);
+        replay(regionRepository);
+        
+        //create a strict mock that ensures that the appropriate setters are
+        //called, rather than checking the return value from the function
+        Page curPage = createStrictMock(Page.class);
+        expect(curPage.getPageLayout()).andReturn(prevLayout);
+        expect(curPage.getRegions()).andReturn(regions);
+        curPage.setName(newName);
+        curPage.setPageLayout(layout);
+        replay(curPage);
+        
+        expect(pageRepository.get(PAGE_ID)).andReturn(curPage);
+        expect(pageRepository.save(curPage)).andReturn(curPage);
+        replay(pageRepository);
+        
+        expect(pageLayoutRepository.getByPageLayoutCode(layoutName)).andReturn(layout);
+        replay(pageLayoutRepository);
+        
+        pageService.updatePage(PAGE_ID, newName, layoutName);
+        assertThat(newLastWidgetColumn.size(), is (2));
+        assertThat(newLastWidgetColumn.get(0).getRenderOrder(), is (0));
+        assertThat(newLastWidgetColumn.get(1).getRenderOrder(), is (1));
+        
+        verify(curPage);
+    }
     // private methods    
     private void verifyPositions(int newPosition, RegionWidget widget, boolean sameRegion) {
         assertThat(widget.getRenderOrder(), is(equalTo(newPosition)));        
@@ -557,4 +809,4 @@ public class PageServiceTest {
         }
         return regions;
     }
-}
\ No newline at end of file
+}

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java?rev=1171649&r1=1171648&r2=1171649&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java (original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java Fri Sep 16 16:30:03 2011
@@ -1,277 +1,308 @@
-/*
- * 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.rave.portal.web.api.rpc;
-
-import org.apache.rave.portal.model.Page;
-import org.apache.rave.portal.model.Region;
-import org.apache.rave.portal.model.RegionWidget;
-import org.apache.rave.portal.service.PageService;
-import org.apache.rave.portal.web.api.rpc.model.RpcResult;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.easymock.EasyMock.*;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.assertThat;
-
-/** */
-public class PageApiTest {
-
-    private final String PARAM_ERROR_MESSAGE = "Target Region does not exist";
-    private final String INTERNAL_ERROR_MESSAGE = "Internal Error";
-    private PageApi pageApi;
-    private PageService pageService;
-    private final long REGION_WIDGET_ID = 35;
-    private final int NEW_POSITION = 3;
-    private final long PAGE_ID = 20L;
-    private final long PAGE_2_ID = 38L;
-    
-    private Page page, page2;
-
-
-    @Before
-    public void setup() {
-        pageService = createMock(PageService.class);
-        pageApi = new PageApi(pageService);
-        
-        page = new Page(PAGE_ID);
-        page2 = new Page(PAGE_2_ID);
-    }
-
-    @Test
-    public void moveWidget_validParams() {
-        final long TO_REGION = 1;
-        final long FROM_REGION = 2;
-
-        expect(pageService.moveRegionWidget(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION)).andReturn(new RegionWidget());
-        replay(pageService);
-        RpcResult<RegionWidget> result = pageApi.moveWidgetOnPage(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION);
-        verify(pageService);
-        assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(notNullValue()));
-        assertThat(result.isError(), is(false));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.NO_ERROR));
-        assertThat(result.getErrorMessage(), is(nullValue()));
-    }
-
-    @Test
-    public void moveWidget_invalidParams() {
-        final long TO_REGION = -1;
-        final long FROM_REGION = 2;
-
-        expect(pageService.moveRegionWidget(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION)).andThrow(new IllegalArgumentException(PARAM_ERROR_MESSAGE));
-        replay(pageService);
-
-        RpcResult<RegionWidget> result = pageApi.moveWidgetOnPage(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION);
-        verify(pageService);
-        assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(nullValue()));
-        assertThat(result.isError(), is(true));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INVALID_PARAMS));
-        assertThat(result.getErrorMessage(), is(equalTo(PARAM_ERROR_MESSAGE)));
-    }
-
-    @Test
-    public void moveWidget_internalError() {
-        final long TO_REGION = 1;
-        final long FROM_REGION = 2;
-
-        expect(pageService.moveRegionWidget(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION)).andThrow(new RuntimeException(INTERNAL_ERROR_MESSAGE));
-        replay(pageService);
-
-        RpcResult<RegionWidget> result = pageApi.moveWidgetOnPage(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION);
-        verify(pageService);
-        assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(nullValue()));
-        assertThat(result.isError(), is(true));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INTERNAL_ERROR));
-        assertThat(result.getErrorMessage(), is(equalTo(INTERNAL_ERROR_MESSAGE)));
-    }    
-    
-    @Test
-    public void addWidget_validParams() {
-        final int PAGE_ID = 1;
-        final long WIDGET_ID = 2;
-
-        expect(pageService.addWidgetToPage(PAGE_ID, WIDGET_ID)).andReturn(new RegionWidget());
-        replay(pageService);
-        RpcResult result = pageApi.addWidgetToPage(PAGE_ID, WIDGET_ID);
-        verify(pageService);
-        assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(notNullValue()));
-        assertThat(result.isError(), is(false));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.NO_ERROR));
-        assertThat(result.getErrorMessage(), is(nullValue()));
-    }
-
-    @Test
-    public void addWidget_invalidParams() {
-        final int PAGE_ID = 1;
-        final long WIDGET_ID = 2;
-
-        expect(pageService.addWidgetToPage(PAGE_ID, WIDGET_ID)).andThrow(new IllegalArgumentException(PARAM_ERROR_MESSAGE));
-        replay(pageService);
-        RpcResult result = pageApi.addWidgetToPage(PAGE_ID, WIDGET_ID);
-        verify(pageService);
-        assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(nullValue()));
-        assertThat(result.isError(), is(true));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INVALID_PARAMS));
-        assertThat(result.getErrorMessage(), is(equalTo(PARAM_ERROR_MESSAGE)));
-    }
-
-    @Test
-    public void addWidget_internalError() {
-        final int PAGE_ID = 1;
-        final long WIDGET_ID = 2;
-
-        expect(pageService.addWidgetToPage(PAGE_ID, WIDGET_ID)).andThrow(new RuntimeException(INTERNAL_ERROR_MESSAGE));
-        replay(pageService);
-        RpcResult result = pageApi.addWidgetToPage(PAGE_ID, WIDGET_ID);
-        verify(pageService);
-        assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(nullValue()));
-        assertThat(result.isError(), is(true));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INTERNAL_ERROR));
-        assertThat(result.getErrorMessage(), is(equalTo(INTERNAL_ERROR_MESSAGE)));
-    }
-
-    @Test
-    public void deleteWidget_validParams() {
-        final long WIDGET_ID = 3;
-        expect(pageService.removeWidgetFromPage(WIDGET_ID)).andReturn(new Region());
-        replay(pageService);
-
-        RpcResult<Region> result = pageApi.removeWidgetFromPage(WIDGET_ID);
-        verify(pageService);
-        assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(notNullValue()));
-        assertThat(result.isError(), is(false));
-
-    }
-
-   @Test
-    public void deleteWidget_invalidParams() {
-        final long WIDGET_ID = 2;
-
-        expect(pageService.removeWidgetFromPage(WIDGET_ID)).andThrow(new IllegalArgumentException(PARAM_ERROR_MESSAGE));
-        replay(pageService);
-        RpcResult result = pageApi.removeWidgetFromPage(WIDGET_ID);
-        verify(pageService);
-        assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(nullValue()));
-        assertThat(result.isError(), is(true));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INVALID_PARAMS));
-        assertThat(result.getErrorMessage(), is(equalTo(PARAM_ERROR_MESSAGE)));
-    }
-
-    @Test
-    public void deleteWidget_internalError() {
-        final long WIDGET_ID = 2;
-
-        expect(pageService.removeWidgetFromPage(WIDGET_ID)).andThrow(new RuntimeException(INTERNAL_ERROR_MESSAGE));
-        replay(pageService);
-        RpcResult result = pageApi.removeWidgetFromPage(WIDGET_ID);
-        verify(pageService);
-        assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(nullValue()));
-        assertThat(result.isError(), is(true));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INTERNAL_ERROR));
-        assertThat(result.getErrorMessage(), is(equalTo(INTERNAL_ERROR_MESSAGE)));
-    }
-    
-    @Test
-    public void addPage_validParams() {
-        final String PAGE_NAME = "My New Page";
-        final String PAGE_LAYOUT_CODE = "layout1";
-
-        expect(pageService.addNewPage(PAGE_NAME, PAGE_LAYOUT_CODE)).andReturn(new Page());
-        replay(pageService);
-        RpcResult result = pageApi.addPage(PAGE_NAME, PAGE_LAYOUT_CODE);
-        verify(pageService);
-        assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(notNullValue()));
-        assertThat(result.isError(), is(false));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.NO_ERROR));
-        assertThat(result.getErrorMessage(), is(nullValue()));
-    }
-    
-    @Test
-    public void addPage_invalidParams() {
-        final String PAGE_NAME = "My New Page";
-        final String PAGE_LAYOUT_CODE = "layout1";
-
-        expect(pageService.addNewPage(PAGE_NAME, PAGE_LAYOUT_CODE)).andThrow(new IllegalArgumentException(PARAM_ERROR_MESSAGE));
-        replay(pageService);
-        RpcResult result = pageApi.addPage(PAGE_NAME, PAGE_LAYOUT_CODE);
-        verify(pageService);
-        assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(nullValue()));
-        assertThat(result.isError(), is(true));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INVALID_PARAMS));
-        assertThat(result.getErrorMessage(), is(equalTo(PARAM_ERROR_MESSAGE)));
-    }
-    
-    @Test
-    public void addPage_internalError() {
-        final String PAGE_NAME = "My New Page";
-        final String PAGE_LAYOUT_CODE = "layout1";
-
-        expect(pageService.addNewPage(PAGE_NAME, PAGE_LAYOUT_CODE)).andThrow(new RuntimeException(INTERNAL_ERROR_MESSAGE));
-        replay(pageService);
-        RpcResult result = pageApi.addPage(PAGE_NAME, PAGE_LAYOUT_CODE);
-        verify(pageService);
-        assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(nullValue()));
-        assertThat(result.isError(), is(true));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INTERNAL_ERROR));
-        assertThat(result.getErrorMessage(), is(equalTo(INTERNAL_ERROR_MESSAGE)));
-    }
-    
-    @Test
-    public void movePage_nonNullMoveAfterPageId() {
-        expect(pageService.movePage(PAGE_ID, PAGE_2_ID)).andReturn(page);
-        replay(pageService);
-                
-        RpcResult result = pageApi.movePage(PAGE_ID, PAGE_2_ID);                
-        
-        verify(pageService);        
-        assertThat(result, is(notNullValue()));
-        assertThat((Page)result.getResult(), is(page));
-        assertThat(result.isError(), is(false));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.NO_ERROR));
-        assertThat(result.getErrorMessage(), is(nullValue()));
-    }    
-    
-    @Test
-    public void movePage_nullMoveAfterPageId() {
-        expect(pageService.movePageToDefault(PAGE_2_ID)).andReturn(page2);
-        replay(pageService);
-                
-        RpcResult result = pageApi.movePage(PAGE_2_ID, null);                
-        
-        verify(pageService);        
-        assertThat(result, is(notNullValue()));
-        assertThat((Page)result.getResult(), is(page2));
-        assertThat(result.isError(), is(false));
-        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.NO_ERROR));
-        assertThat(result.getErrorMessage(), is(nullValue()));
-    }      
-}
+/*
+ * 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.rave.portal.web.api.rpc;
+
+import org.apache.rave.portal.model.Page;
+import org.apache.rave.portal.model.Region;
+import org.apache.rave.portal.model.RegionWidget;
+import org.apache.rave.portal.service.PageService;
+import org.apache.rave.portal.web.api.rpc.model.RpcResult;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.*;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+
+/** */
+public class PageApiTest {
+
+    private final String PARAM_ERROR_MESSAGE = "Target Region does not exist";
+    private final String INTERNAL_ERROR_MESSAGE = "Internal Error";
+    private PageApi pageApi;
+    private PageService pageService;
+    private final long REGION_WIDGET_ID = 35;
+    private final int NEW_POSITION = 3;
+    private final long PAGE_ID = 20L;
+    private final long PAGE_2_ID = 38L;
+    
+    private Page page, page2;
+
+
+    @Before
+    public void setup() {
+        pageService = createMock(PageService.class);
+        pageApi = new PageApi(pageService);
+        
+        page = new Page(PAGE_ID);
+        page2 = new Page(PAGE_2_ID);
+    }
+
+    @Test
+    public void moveWidget_validParams() {
+        final long TO_REGION = 1;
+        final long FROM_REGION = 2;
+
+        expect(pageService.moveRegionWidget(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION)).andReturn(new RegionWidget());
+        replay(pageService);
+        RpcResult<RegionWidget> result = pageApi.moveWidgetOnPage(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION);
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.getResult(), is(notNullValue()));
+        assertThat(result.isError(), is(false));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.NO_ERROR));
+        assertThat(result.getErrorMessage(), is(nullValue()));
+    }
+
+    @Test
+    public void moveWidget_invalidParams() {
+        final long TO_REGION = -1;
+        final long FROM_REGION = 2;
+
+        expect(pageService.moveRegionWidget(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION)).andThrow(new IllegalArgumentException(PARAM_ERROR_MESSAGE));
+        replay(pageService);
+
+        RpcResult<RegionWidget> result = pageApi.moveWidgetOnPage(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION);
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.getResult(), is(nullValue()));
+        assertThat(result.isError(), is(true));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INVALID_PARAMS));
+        assertThat(result.getErrorMessage(), is(equalTo(PARAM_ERROR_MESSAGE)));
+    }
+
+    @Test
+    public void moveWidget_internalError() {
+        final long TO_REGION = 1;
+        final long FROM_REGION = 2;
+
+        expect(pageService.moveRegionWidget(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION)).andThrow(new RuntimeException(INTERNAL_ERROR_MESSAGE));
+        replay(pageService);
+
+        RpcResult<RegionWidget> result = pageApi.moveWidgetOnPage(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION);
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.getResult(), is(nullValue()));
+        assertThat(result.isError(), is(true));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INTERNAL_ERROR));
+        assertThat(result.getErrorMessage(), is(equalTo(INTERNAL_ERROR_MESSAGE)));
+    }    
+    
+    @Test
+    public void addWidget_validParams() {
+        final int PAGE_ID = 1;
+        final long WIDGET_ID = 2;
+
+        expect(pageService.addWidgetToPage(PAGE_ID, WIDGET_ID)).andReturn(new RegionWidget());
+        replay(pageService);
+        RpcResult result = pageApi.addWidgetToPage(PAGE_ID, WIDGET_ID);
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.getResult(), is(notNullValue()));
+        assertThat(result.isError(), is(false));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.NO_ERROR));
+        assertThat(result.getErrorMessage(), is(nullValue()));
+    }
+
+    @Test
+    public void addWidget_invalidParams() {
+        final int PAGE_ID = 1;
+        final long WIDGET_ID = 2;
+
+        expect(pageService.addWidgetToPage(PAGE_ID, WIDGET_ID)).andThrow(new IllegalArgumentException(PARAM_ERROR_MESSAGE));
+        replay(pageService);
+        RpcResult result = pageApi.addWidgetToPage(PAGE_ID, WIDGET_ID);
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.getResult(), is(nullValue()));
+        assertThat(result.isError(), is(true));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INVALID_PARAMS));
+        assertThat(result.getErrorMessage(), is(equalTo(PARAM_ERROR_MESSAGE)));
+    }
+
+    @Test
+    public void addWidget_internalError() {
+        final int PAGE_ID = 1;
+        final long WIDGET_ID = 2;
+
+        expect(pageService.addWidgetToPage(PAGE_ID, WIDGET_ID)).andThrow(new RuntimeException(INTERNAL_ERROR_MESSAGE));
+        replay(pageService);
+        RpcResult result = pageApi.addWidgetToPage(PAGE_ID, WIDGET_ID);
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.getResult(), is(nullValue()));
+        assertThat(result.isError(), is(true));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INTERNAL_ERROR));
+        assertThat(result.getErrorMessage(), is(equalTo(INTERNAL_ERROR_MESSAGE)));
+    }
+
+    @Test
+    public void deleteWidget_validParams() {
+        final long WIDGET_ID = 3;
+        expect(pageService.removeWidgetFromPage(WIDGET_ID)).andReturn(new Region());
+        replay(pageService);
+
+        RpcResult<Region> result = pageApi.removeWidgetFromPage(WIDGET_ID);
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.getResult(), is(notNullValue()));
+        assertThat(result.isError(), is(false));
+
+    }
+
+   @Test
+    public void deleteWidget_invalidParams() {
+        final long WIDGET_ID = 2;
+
+        expect(pageService.removeWidgetFromPage(WIDGET_ID)).andThrow(new IllegalArgumentException(PARAM_ERROR_MESSAGE));
+        replay(pageService);
+        RpcResult result = pageApi.removeWidgetFromPage(WIDGET_ID);
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.getResult(), is(nullValue()));
+        assertThat(result.isError(), is(true));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INVALID_PARAMS));
+        assertThat(result.getErrorMessage(), is(equalTo(PARAM_ERROR_MESSAGE)));
+    }
+
+    @Test
+    public void deleteWidget_internalError() {
+        final long WIDGET_ID = 2;
+
+        expect(pageService.removeWidgetFromPage(WIDGET_ID)).andThrow(new RuntimeException(INTERNAL_ERROR_MESSAGE));
+        replay(pageService);
+        RpcResult result = pageApi.removeWidgetFromPage(WIDGET_ID);
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.getResult(), is(nullValue()));
+        assertThat(result.isError(), is(true));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INTERNAL_ERROR));
+        assertThat(result.getErrorMessage(), is(equalTo(INTERNAL_ERROR_MESSAGE)));
+    }
+    
+    @Test
+    public void addPage_validParams() {
+        final String PAGE_NAME = "My New Page";
+        final String PAGE_LAYOUT_CODE = "layout1";
+
+        expect(pageService.addNewPage(PAGE_NAME, PAGE_LAYOUT_CODE)).andReturn(new Page());
+        replay(pageService);
+        RpcResult result = pageApi.addPage(PAGE_NAME, PAGE_LAYOUT_CODE);
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.getResult(), is(notNullValue()));
+        assertThat(result.isError(), is(false));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.NO_ERROR));
+        assertThat(result.getErrorMessage(), is(nullValue()));
+    }
+    
+    @Test
+    public void addPage_invalidParams() {
+        final String PAGE_NAME = "My New Page";
+        final String PAGE_LAYOUT_CODE = "layout1";
+
+        expect(pageService.addNewPage(PAGE_NAME, PAGE_LAYOUT_CODE)).andThrow(new IllegalArgumentException(PARAM_ERROR_MESSAGE));
+        replay(pageService);
+        RpcResult result = pageApi.addPage(PAGE_NAME, PAGE_LAYOUT_CODE);
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.getResult(), is(nullValue()));
+        assertThat(result.isError(), is(true));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INVALID_PARAMS));
+        assertThat(result.getErrorMessage(), is(equalTo(PARAM_ERROR_MESSAGE)));
+    }
+    
+    @Test
+    public void addPage_internalError() {
+        final String PAGE_NAME = "My New Page";
+        final String PAGE_LAYOUT_CODE = "layout1";
+
+        expect(pageService.addNewPage(PAGE_NAME, PAGE_LAYOUT_CODE)).andThrow(new RuntimeException(INTERNAL_ERROR_MESSAGE));
+        replay(pageService);
+        RpcResult result = pageApi.addPage(PAGE_NAME, PAGE_LAYOUT_CODE);
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat(result.getResult(), is(nullValue()));
+        assertThat(result.isError(), is(true));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INTERNAL_ERROR));
+        assertThat(result.getErrorMessage(), is(equalTo(INTERNAL_ERROR_MESSAGE)));
+    }
+    
+    @Test
+    public void getPage() {
+        expect(pageService.getPage(PAGE_ID)).andReturn(page);
+        replay(pageService);
+        
+        RpcResult result = pageApi.getPage(PAGE_ID);
+        
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat((Page)result.getResult(), is (page));
+        assertThat(result.isError(), is(false));
+        assertThat(result.getErrorCode(), is (RpcResult.ErrorCode.NO_ERROR));
+        assertThat(result.getErrorMessage(), is(nullValue()));
+    }
+    @Test
+    public void updatePage() {
+        String pageName = "name";
+        String layoutName = "layout";
+        expect(pageService.updatePage(PAGE_ID, pageName, layoutName)).andReturn(page);
+        replay(pageService);
+        
+        RpcResult result = pageApi.updatePageProperties(PAGE_ID, pageName, layoutName);
+        
+        verify(pageService);
+        assertThat(result, is(notNullValue()));
+        assertThat((Page)result.getResult(), is (page));
+        assertThat(result.isError(), is(false));
+        assertThat(result.getErrorCode(), is (RpcResult.ErrorCode.NO_ERROR));
+        assertThat(result.getErrorMessage(), is(nullValue()));
+    }
+    
+    @Test
+    public void movePage_nonNullMoveAfterPageId() {
+        expect(pageService.movePage(PAGE_ID, PAGE_2_ID)).andReturn(page);
+        replay(pageService);
+                
+        RpcResult result = pageApi.movePage(PAGE_ID, PAGE_2_ID);                
+        
+        verify(pageService);        
+        assertThat(result, is(notNullValue()));
+        assertThat((Page)result.getResult(), is(page));
+        assertThat(result.isError(), is(false));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.NO_ERROR));
+        assertThat(result.getErrorMessage(), is(nullValue()));
+    }    
+    
+    @Test
+    public void movePage_nullMoveAfterPageId() {
+        expect(pageService.movePageToDefault(PAGE_2_ID)).andReturn(page2);
+        replay(pageService);
+                
+        RpcResult result = pageApi.movePage(PAGE_2_ID, null);                
+        
+        verify(pageService);        
+        assertThat(result, is(notNullValue()));
+        assertThat((Page)result.getResult(), is(page2));
+        assertThat(result.isError(), is(false));
+        assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.NO_ERROR));
+        assertThat(result.getErrorMessage(), is(nullValue()));
+    }      
+}

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java?rev=1171649&r1=1171648&r2=1171649&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java (original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java Fri Sep 16 16:30:03 2011
@@ -1,120 +1,120 @@
-/*
- * 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.rave.portal.web.renderer;
-
-
-import org.apache.rave.portal.model.Page;
-import org.apache.rave.portal.model.Region;
-import org.apache.rave.portal.model.RegionWidget;
-import org.apache.rave.portal.model.User;
-import org.apache.rave.portal.model.Widget;
-import org.apache.rave.provider.opensocial.repository.impl.ShindigGadgetMetadataRepository;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.authentication.AbstractAuthenticationToken;
-import org.springframework.security.core.context.SecurityContext;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.core.context.SecurityContextImpl;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.test.util.ReflectionTestUtils;
-import org.springframework.web.client.RestOperations;
-
-import java.util.Arrays;
-
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assert.assertThat;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = {"classpath:portal-test-dataContext.xml", "classpath:portal-test-applicationContext.xml"})
-//@ContextConfiguration(locations = {"file:src/main/webapp/WEB-INF/dataContext.xml", "file:src/main/webapp/WEB-INF/applicationContext.xml"})
-public class RenderServiceIntegrationTest {
-
-    @Autowired
-    private RenderService service;
-
-    @Autowired
-    private ShindigGadgetMetadataRepository metadataRepository;
-
-    private RestOperations restOperations;
-
-    private static final String VALID_METADATA = "[{\"id\":\"gadgets.metadata\",\"result\"" +
-            ":{\"http://www.example.com/gadget.xml\":{\"data-snipped\":\"here-for-brevity\"}}}]";
-
-    private static final Long VALID_USER_ID = 1234L;
-    private static final String VALID_USER_NAME = "jdoe";
-
-    @Before
-    public void setup() {
-        restOperations = createNiceMock(RestOperations.class);
-        expect(restOperations.postForObject(anyObject(String.class), anyObject(String.class), anyObject(Class.class)))
-                .andReturn(VALID_METADATA);
-        replay(restOperations);
-
-        //Replace the real restOperations instance with a mock -- otherwise the call for gadget metadata would fail since
-        //we don't have a shindig server available to hit.
-        ReflectionTestUtils.setField(metadataRepository, "restOperations", restOperations);
-
-        //Setup a mock authenticated user
-        final User authUser = new User(VALID_USER_ID, VALID_USER_NAME);
-        AbstractAuthenticationToken auth = createNiceMock(AbstractAuthenticationToken.class);
-        expect(auth.getPrincipal()).andReturn(authUser).anyTimes();
-        replay(auth);
-
-        SecurityContext context = new SecurityContextImpl();
-        context.setAuthentication(auth);
-        SecurityContextHolder.setContext(context);
-    }
-
-    @Test
-    public void supportedWidgets() {
-        assertThat(service.getSupportedWidgetTypes().size(), is(equalTo(2)));
-        assertThat(service.getSupportedWidgetTypes().contains("OpenSocial"), is(true));
-        assertThat(service.getSupportedWidgetTypes().contains("W3C"), is(true));
-    }
-
-    @Test
-    public void renderOpenSocial() {
-        Page page = new Page(1L, new User(VALID_USER_ID, VALID_USER_NAME));
-        Region region = new Region(1L, page);
-        page.setRegions(Arrays.asList(region));
-
-        Widget w = new Widget();
-        w.setType("OpenSocial");
-        w.setEntityId(1L);
-        w.setTitle("Gadget Title");
-        w.setUrl("http://www.example.com/gadget.xml");
-
-        RegionWidget rw = new RegionWidget(1L, w, region);
-        region.setRegionWidgets(Arrays.asList(rw));
-
-        String rendered = service.render(rw);
-        assertThat(rendered, is(notNullValue()));
-        assertThat(rendered.contains("widgets.push({"), is(true));
-    }
-}
+/*
+ * 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.rave.portal.web.renderer;
+
+
+import org.apache.rave.portal.model.Page;
+import org.apache.rave.portal.model.Region;
+import org.apache.rave.portal.model.RegionWidget;
+import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.model.Widget;
+import org.apache.rave.provider.opensocial.repository.impl.ShindigGadgetMetadataRepository;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.authentication.AbstractAuthenticationToken;
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.context.SecurityContextImpl;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.util.ReflectionTestUtils;
+import org.springframework.web.client.RestOperations;
+
+import java.util.Arrays;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:portal-test-dataContext.xml", "classpath:portal-test-applicationContext.xml"})
+//@ContextConfiguration(locations = {"file:src/main/webapp/WEB-INF/dataContext.xml", "file:src/main/webapp/WEB-INF/applicationContext.xml"})
+public class RenderServiceIntegrationTest {
+
+    @Autowired
+    private RenderService service;
+
+    @Autowired
+    private ShindigGadgetMetadataRepository metadataRepository;
+
+    private RestOperations restOperations;
+
+    private static final String VALID_METADATA = "[{\"id\":\"gadgets.metadata\",\"result\"" +
+            ":{\"http://www.example.com/gadget.xml\":{\"data-snipped\":\"here-for-brevity\"}}}]";
+
+    private static final Long VALID_USER_ID = 1234L;
+    private static final String VALID_USER_NAME = "jdoe";
+
+    @Before
+    public void setup() {
+        restOperations = createNiceMock(RestOperations.class);
+        expect(restOperations.postForObject(anyObject(String.class), anyObject(String.class), anyObject(Class.class)))
+                .andReturn(VALID_METADATA);
+        replay(restOperations);
+
+        //Replace the real restOperations instance with a mock -- otherwise the call for gadget metadata would fail since
+        //we don't have a shindig server available to hit.
+        ReflectionTestUtils.setField(metadataRepository, "restOperations", restOperations);
+
+        //Setup a mock authenticated user
+        final User authUser = new User(VALID_USER_ID, VALID_USER_NAME);
+        AbstractAuthenticationToken auth = createNiceMock(AbstractAuthenticationToken.class);
+        expect(auth.getPrincipal()).andReturn(authUser).anyTimes();
+        replay(auth);
+
+        SecurityContext context = new SecurityContextImpl();
+        context.setAuthentication(auth);
+        SecurityContextHolder.setContext(context);
+    }
+
+    @Test
+    public void supportedWidgets() {
+        assertThat(service.getSupportedWidgetTypes().size(), is(equalTo(2)));
+        assertThat(service.getSupportedWidgetTypes().contains("OpenSocial"), is(true));
+        assertThat(service.getSupportedWidgetTypes().contains("W3C"), is(true));
+    }
+
+    @Test
+    public void renderOpenSocial() {
+        Page page = new Page(1L, new User(VALID_USER_ID, VALID_USER_NAME));
+        Region region = new Region(1L, page, 1);
+        page.setRegions(Arrays.asList(region));
+
+        Widget w = new Widget();
+        w.setType("OpenSocial");
+        w.setEntityId(1L);
+        w.setTitle("Gadget Title");
+        w.setUrl("http://www.example.com/gadget.xml");
+
+        RegionWidget rw = new RegionWidget(1L, w, region);
+        region.setRegionWidgets(Arrays.asList(rw));
+
+        String rendered = service.render(rw);
+        assertThat(rendered, is(notNullValue()));
+        assertThat(rendered.contains("widgets.push({"), is(true));
+    }
+}

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/service/SecurityTokenServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/service/SecurityTokenServiceTest.java?rev=1171649&r1=1171648&r2=1171649&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/service/SecurityTokenServiceTest.java (original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/service/SecurityTokenServiceTest.java Fri Sep 16 16:30:03 2011
@@ -83,7 +83,7 @@ public class SecurityTokenServiceTest {
         validPerson = new User(VALID_USER_ID, VALID_USER_NAME);
 
         validPage = new Page(1L, validPerson);
-        validRegion = new Region(1L, validPage);
+        validRegion = new Region(1L, validPage, 1);
         validPage.setRegions(Arrays.asList(validRegion));
 
         validWidget = new Widget(1L, VALID_URL);
@@ -161,4 +161,4 @@ public class SecurityTokenServiceTest {
         assertEquals(VALID_USER_ID, Long.valueOf(securityToken.getViewerId()));
         assertEquals(VALID_URL, securityToken.getAppUrl());
     }
-}
\ No newline at end of file
+}

Modified: incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js?rev=1171649&r1=1171648&r2=1171649&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js (original)
+++ incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js Fri Sep 16 16:30:03 2011
@@ -231,6 +231,53 @@ describe("Rave API", function() {
                 rave.api.rpc.movePage({pageId: pageId, moveAfterPageId: moveAfterPageId});
             });
         });        
+        
+        describe("getPagePrefs", function() {
+            it("gets the correct metadata for a page", function() {
+                var callbackCalled = false;
+                var pageId = 73;
+                $.get = function(url, data, callback) {
+                    expect(url).toEqual("api/rpc/page/get?pageId=" + pageId);                                       
+                    expect(typeof(callback)).toEqual("function");
+                    callback({error:false});
+                    return {
+                        error: function(a, b, c) {
+                        }
+                    }
+                };
+                var callback = function() {
+                    callbackCalled = true;
+                };
+                rave.api.rpc.getPagePrefs({pageId: pageId, successCallback: callback});
+                expect(callbackCalled).toBeTruthy();
+            });
+        });        
+        
+        describe("updatePagePrefs", function() {
+            it("posts the correct values to RPC service for updating page metadata", function() {
+                var pageId = 7;                
+                var newTitle = "New Title";
+                var newLayout = "1_column";
+                var callbackCalled = false;
+
+                $.post = function(url, data, callback) {
+                    expect(url).toEqual("api/rpc/page/" + pageId + "/update");                   
+                    expect(data.name).toEqual(newTitle);
+                    expect(data.layout).toEqual(newLayout);
+                    expect(typeof(callback)).toEqual("function");
+                    callback({error:false});
+                    return {
+                        error: function(a, b, c) {
+                        }
+                    }
+                };
+                var callback = function() {
+                    callbackCalled = true;
+                };
+                rave.api.rpc.updatePagePrefs({pageId: pageId, title: newTitle, layout: newLayout, successCallback: callback});
+                expect(callbackCalled).toBeTruthy();
+            });
+        });                
 
         describe("Error handling", function() {
             it("displays the appropriate alert when invalid parameters are passed", function() {