From do-not-reply at jboss.org Mon Jun 7 05:19:05 2010 Content-Type: multipart/mixed; boundary="===============1582617031816917928==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: gatein-commits at lists.jboss.org Subject: [gatein-commits] gatein SVN: r3236 - in portal/trunk/component/portal/src/test: resources/portal/portal/test and 1 other directory. Date: Mon, 07 Jun 2010 05:19:05 -0400 Message-ID: <201006070919.o579J5uE025744@svn01.web.mwc.hst.phx2.redhat.com> --===============1582617031816917928== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: hoang_to Date: 2010-06-07 05:19:05 -0400 (Mon, 07 Jun 2010) New Revision: 3236 Added: portal/trunk/component/portal/src/test/java/org/exoplatform/portal/confi= g/TestMovedPOM.java Modified: portal/trunk/component/portal/src/test/resources/portal/portal/test/page= s.xml Log: GTNPORTAL-1288: Add unit tests on moving child within page, site layout Added: portal/trunk/component/portal/src/test/java/org/exoplatform/portal/c= onfig/TestMovedPOM.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/trunk/component/portal/src/test/java/org/exoplatform/portal/conf= ig/TestMovedPOM.java (rev 0) +++ portal/trunk/component/portal/src/test/java/org/exoplatform/portal/conf= ig/TestMovedPOM.java 2010-06-07 09:19:05 UTC (rev 3236) @@ -0,0 +1,228 @@ +/* + * Copyright (C) 2010 eXo Platform SAS. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.exoplatform.portal.config; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.exoplatform.container.PortalContainer; +import org.exoplatform.portal.config.model.Container; +import org.exoplatform.portal.config.model.ModelObject; +import org.exoplatform.portal.config.model.Page; +import org.exoplatform.portal.config.model.PortalConfig; +import org.exoplatform.portal.pom.config.POMSession; +import org.exoplatform.portal.pom.config.POMSessionManager; + +/** + * @author Minh Hoang TO + * @version $Id$ + * + */ +public class TestMovedPOM extends AbstractPortalTest +{ + = + private DataStorage dataStorage; + = + private POMSessionManager sessionManager; + = + private POMSession session; + = + public TestMovedPOM(String name) + { + super(name); + } + = + private final static Map MOVE_CHILD_IN_PAGE_SCENARIOS; + = + private final static Map MOVE_CHILD_IN_PORTAL_SCENARIOS; + = + /** + * Moving child scenario 's parameters is a pair of source container an= d destination container + */ + static{ + MOVE_CHILD_IN_PAGE_SCENARIOS =3D new HashMap(); = + MOVE_CHILD_IN_PORTAL_SCENARIOS =3D new HashMap(); + } + = + @Override + protected void setUp() throws Exception + { + super.setUp(); + begin(); + PortalContainer container =3D getContainer(); + dataStorage =3D (DataStorage)container.getComponentInstanceOfType(Da= taStorage.class); + sessionManager =3D (POMSessionManager)container.getComponentInstance= OfType(POMSessionManager.class); + session =3D sessionManager.openSession(); + } + = + @Override + protected void tearDown() throws Exception + { + session.close(); + end(); + super.tearDown(); + } + = + public void testMoveChildInPage() throws Exception + { + Page page =3D dataStorage.getPage("portal::test::testMoveChild"); + assertNotNull(page); + = + String testApplication =3D "application_test"; + String testContainer =3D "container_test"; + int scenarioIndex =3D0; + = + for(String srcContainer : MOVE_CHILD_IN_PAGE_SCENARIOS.keySet()) + { + String dstContainer =3D MOVE_CHILD_IN_PAGE_SCENARIOS.get(srcConta= iner); + String scenarioName =3D "Test on page, scenario_" + scenarioIndex; + = + executeMoveChildInPageScenario(scenarioName, page, srcContainer, = dstContainer, testApplication); + executeMoveChildInPageScenario(scenarioName, page, srcContainer, = dstContainer, testContainer); + = + scenarioIndex++; + } + } + = + public void testMoveChildInPortal() throws Exception + { + PortalConfig portalConfig =3D dataStorage.getPortalConfig("test"); + assertNotNull(portalConfig); + = + String testApplication =3D "site_layout_application_test"; + String testContainer =3D "site_layout_container_test"; + = + int scenarioIndex =3D 0; + = + for(String srcContainer : MOVE_CHILD_IN_PORTAL_SCENARIOS.keySet()) + { + String dstContainer =3D MOVE_CHILD_IN_PORTAL_SCENARIOS.get(srcCon= tainer); + String scenarioName =3D "Test on site layout, scenario_" + scenar= ioIndex; + = + executeMoveChildInSiteLayoutScenario(scenarioName, portalConfig, = srcContainer, dstContainer, testApplication); + executeMoveChildInSiteLayoutScenario(scenarioName, portalConfig, = srcContainer, dstContainer, testContainer); + = + scenarioIndex++; + } + } + = + public void executeMoveChildInSiteLayoutScenario(String scenarioName, P= ortalConfig portalConfig, String srcContainerName, String dstContainerName,= String movedObjectName) throws Exception + { + = + } + = + private void executeMoveChildInPageScenario(String scenarioName, Page p= age, String srcContainerName, String dstContainerName, String movedObjectNa= me) throws Exception + { + Container srcContainer =3D findDescendant(page, Container.class, src= ContainerName); + Container dstContainer =3D findDescendant(page, Container.class, dst= ContainerName); + ModelObject movedObject =3D findDescendant(page, ModelObject.class, = movedObjectName); + + assertNotNull("Source container is null in " + scenarioName, srcCont= ainer); + assertNotNull("Destination container is null in " + scenarioName, ds= tContainer); + assertNotNull("Moved object is null in " + scenarioName, movedObject= ); + = + moveChild(srcContainer, dstContainer, movedObject); + dataStorage.save(page); + page =3D dataStorage.getPage(page.getStorageId()); + = + Container updatedSrcContainer =3D findDescendant(page, Container.cla= ss, srcContainerName); + Container updatedDstContainer =3D findDescendant(page, Container.cla= ss, dstContainerName); + ModelObject updatedMovedObject =3D findDescendant(page, ModelObject.= class, movedObjectName); + = + assertFalse("Source container still contains moved child in " + scen= arioName, checkChildExistence(updatedSrcContainer, movedObjectName)); + assertTrue("Destination container does not contain moved child in " = + scenarioName, checkChildExistence(updatedDstContainer, movedObjectName)); + = + //Backup the moving changes, needed to run consecutive and pairwise = independent scenariosc + moveChild(updatedDstContainer, updatedSrcContainer, updatedMovedObje= ct); + dataStorage.save(page); + page =3D dataStorage.getPage(page.getStorageId()); + = + } + = + private void moveChild(Container srcContainer, Container dstContainer, = ModelObject modelObject) throws Exception + { + List children =3D srcContainer.getChildren(); + boolean found =3D false; + = + //Clone children list to avoid fail-fast iterator exception + for(ModelObject child : new ArrayList(children)) + { + if(modelObject.getStorageName().equals(modelObject.getStorageName= ())) + { + found =3D true; + children.remove(child); + break; + } + } + = + if(found) + { + dstContainer.getChildren().add(modelObject); + } + } + = + private boolean checkChildExistence(Container srcContainer, String chil= dName) + { + for(ModelObject child : srcContainer.getChildren()) + { + if(childName.equals(child.getStorageName())) + { + return true; + } + } + return false; + } + = + /** + * Find descendant by name and type + * = + * @param + * @param rootContainer + * @param clazz + * @param name + * @return + */ + private T findDescendant(Container rootContainer, Class clazz, S= tring name) + { + if(rootContainer.getStorageName().equals(name)) + { + return (T)rootContainer; + } + = + for(ModelObject child : rootContainer.getChildren()) + { + if(child.getStorageName().equals(name) && (clazz.isAssignableFrom= (child.getClass()))) + { + return (T)child; + } + else if(child instanceof Container) + { + T re =3D findDescendant((Container)child, clazz, name); + if(re !=3D null) + { + return re; + } + } + } + = + return null; + } +} Modified: portal/trunk/component/portal/src/test/resources/portal/portal/te= st/pages.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/trunk/component/portal/src/test/resources/portal/portal/test/pag= es.xml 2010-06-07 07:44:53 UTC (rev 3235) +++ portal/trunk/component/portal/src/test/resources/portal/portal/test/pag= es.xml 2010-06-07 09:19:05 UTC (rev 3236) @@ -95,4 +95,36 @@ = + + portal::test::testMoveChild + portal + test + testMoveChild + testMoveChildTitle + test_factory_id + test_access_permissions + test_edit_permission + + container_1 + container_1_title + container_1_icon + container_1_description + + = + + portal#testMoveChild:/web/BannerPortlet/banner + application_1_type + application_1_title + application_1_access_permissions + application_1_description + + = + + container_2 + container_2_title + container_2_icon + container_2_description + + = + --===============1582617031816917928==--