[gatein-commits] gatein SVN: r5366 - in portal/branches/branch-GTNPORTAL-1700/component: application-registry/src/test/java/org/exoplatform/application/gadget and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Nov 29 22:21:32 EST 2010


Author: tuyen.nguyenthe
Date: 2010-11-29 22:21:29 -0500 (Mon, 29 Nov 2010)
New Revision: 5366

Modified:
   portal/branches/branch-GTNPORTAL-1700/component/application-registry/src/test/java/org/exoplatform/application/AbstractApplicationRegistryTest.java
   portal/branches/branch-GTNPORTAL-1700/component/application-registry/src/test/java/org/exoplatform/application/gadget/TestSourceStorageService.java
   portal/branches/branch-GTNPORTAL-1700/component/application-registry/src/test/java/org/exoplatform/application/registry/TestApplicationRegistryService.java
   portal/branches/branch-GTNPORTAL-1700/component/identity/src/test/java/org/exoplatform/services/organization/TestOrganizationService.java
   portal/branches/branch-GTNPORTAL-1700/component/portal/src/test/java/org/exoplatform/portal/config/TestOrganization.java
Log:
GTNPORTAL-1704 Improve some testcase

Modified: portal/branches/branch-GTNPORTAL-1700/component/application-registry/src/test/java/org/exoplatform/application/AbstractApplicationRegistryTest.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1700/component/application-registry/src/test/java/org/exoplatform/application/AbstractApplicationRegistryTest.java	2010-11-30 03:15:59 UTC (rev 5365)
+++ portal/branches/branch-GTNPORTAL-1700/component/application-registry/src/test/java/org/exoplatform/application/AbstractApplicationRegistryTest.java	2010-11-30 03:21:29 UTC (rev 5366)
@@ -32,14 +32,4 @@
 })
 public abstract class AbstractApplicationRegistryTest extends AbstractKernelTest
 {
-
-/*
-   public void testFoo() throws Exception
-   {
-      PortalContainer container = PortalContainer.getInstance();
-      ApplicationRegistryService registry = (ApplicationRegistryService)container.getComponentInstanceOfType(ApplicationRegistryService.class);
-      registry.getAllApplications();
-   }
-*/
-
 }

Modified: portal/branches/branch-GTNPORTAL-1700/component/application-registry/src/test/java/org/exoplatform/application/gadget/TestSourceStorageService.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1700/component/application-registry/src/test/java/org/exoplatform/application/gadget/TestSourceStorageService.java	2010-11-30 03:15:59 UTC (rev 5365)
+++ portal/branches/branch-GTNPORTAL-1700/component/application-registry/src/test/java/org/exoplatform/application/gadget/TestSourceStorageService.java	2010-11-30 03:21:29 UTC (rev 5366)
@@ -1,155 +0,0 @@
-/**
- * Copyright (C) 2009 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.application.gadget;
-
-import org.exoplatform.component.test.AbstractGateInTest;
-
-/**
- * todo julien : fix or remove
- *
- * Thu, May 15, 2004 @   
- * @author: Tuan Nguyen
- * @version: $Id: TestResourceBundleService.java 5799 2006-05-28 17:55:42Z geaz $
- * @since: 0.0
- * @email: tuan08 at yahoo.com
- */
-public class TestSourceStorageService extends AbstractGateInTest
-{
-
-   private SourceStorage service_;
-
-   public void setUp() throws Exception
-   {
-      //    PortalContainer manager  = PortalContainer.getInstance();
-      //    service_ = (SourceStorage) manager.getComponentInstanceOfType(SourceStorage.class) ;
-   }
-
-   public void testSourceStorageAdd() throws Exception
-   {
-      //    //-------Insert Source Storeage 1--------
-      //    Source source1 = new Source("Calculator.xml", "application/xml", "UTF-8");
-      //    source1.setTextContent("Gadget's content");
-      //    source1.setLastModified(Calendar.getInstance());
-      //    service_.saveSource("source", source1) ; 
-      //    
-      //    //-------Check Source Storeage's content added--------
-      //    Source sourceGet = service_.getSource("source/Calculator.xml");
-      //    assertEquals("Gadget's content", sourceGet.getTextContent());
-      //    
-      //    //-------Insert Source Storeage 2 with path is null--------
-      //    Source source2 = new Source("Todo.xml", "application/xml", "UTF-8");
-      //    source2.setTextContent("Gadget's content");
-      //    source2.setLastModified(Calendar.getInstance());
-      //    service_.saveSource(null, source2) ; 
-      //    
-      //    //-------Check Source Storeage's content added--------
-      //    Source sourceGet2 = service_.getSource("Todo.xml");
-      //    assertEquals("Gadget's content", sourceGet2.getTextContent());
-      //    
-      //    //-------Insert Source Storeage 2 with text content is null--------
-      //    Source source3 = new Source("Todo.xml", "application/xml", "UTF-8");
-      //    source3.setTextContent(null);
-      //    source3.setLastModified(Calendar.getInstance());
-      //    service_.saveSource("source", source3) ; 
-      //    
-      //    Source sourceGet3 = service_.getSource("source/Todo.xml");
-      //    System.out.println("\n\n\n\n\n\n\n\n\naaa" + service_.getSourceURI("source/Todo.xml"));
-      //    assertTrue("Expect text content is empty", sourceGet3.getTextContent().equals(""));
-      //    
-   }
-   //  
-   //  public void testSourceStorageUpdate() throws Exception {    
-   //    //-------Insert Source Storeage 1--------
-   //    Source source = new Source("Calculator.xml", "application/xml", "UTF-8");
-   //    source.setTextContent("Gadget's content");
-   //    source.setLastModified(Calendar.getInstance());
-   //    service_.saveSource("source", source) ; 
-   //    
-   //    //-------Check Source Storeage's content added--------
-   //    Source sourceGet = service_.getSource("source/Calculator.xml");
-   //    assertEquals("Gadget's content", sourceGet.getTextContent());
-   //    
-   //    //-------Update Source Storeage's just added to database--------
-   //    source.setTextContent("Gadget's content update");
-   //    service_.saveSource("source", source);
-   //    
-   //    //-------Check Source Storeage's content just updated--------
-   //    sourceGet = service_.getSource("source/Calculator.xml");
-   //    assertEquals("Gadget's content update", sourceGet.getTextContent());
-   //    
-   //  }
-   //  
-   //  public void testSourceStorageRemove() throws Exception {    
-   //    //-------Insert Source Storeage 1--------
-   //    Source source = new Source("Calculator.xml", "application/xml", "UTF-8");
-   //    source.setTextContent("Gadget's content");
-   //    source.setLastModified(Calendar.getInstance());
-   //    service_.saveSource("source", source) ; 
-   //    
-   //    //-------Check Source Storeage's content added--------
-   //    Source sourceGet = service_.getSource("source/Calculator.xml");
-   //    assertEquals("Gadget's content", sourceGet.getTextContent());
-   //    
-   //    //System.out.println("\n\n\n\n\n\naaaa" + sourceGet.getName());
-   //    //-------Remove Source Storeage's content added--------
-   //    service_.removeSource("source/Calculator.xml");
-   //    sourceGet = service_.getSource("source/Calculator.xml");
-   //    //-------Check Source Storeage is really removed--------
-   //    assertTrue("Expect source is null", sourceGet==null);
-   //    
-   //  }
-   //  
-   //  public void testSourceStorageList() throws Exception {
-   //    //-------Check list of Source Storeage is empty--------
-   //    Source sourceGet = service_.getSource("source");
-   //    
-   //    assertTrue("First, none of source exist", sourceGet == null);
-   //    
-   //    //-------Insert Source Storeage1--------
-   //    Source source1 = new Source("Calculator.xml", "application/xml", "UTF-8");
-   //    source1.setTextContent("Gadget's content");
-   //    source1.setLastModified(Calendar.getInstance());
-   //    service_.saveSource("source", source1) ; 
-   //    
-   //    //-------Check Source Storeage1's content added--------
-   //    sourceGet = service_.getSource("source/Calculator.xml");
-   //    assertEquals("Gadget's content", sourceGet.getTextContent());
-   //    
-   //    //-------Insert Source Storeage2--------
-   //    Source source2 = new Source("Todo.xml", "application/xml", "UTF-8");
-   //    source2.setTextContent("Gadget's content");
-   //    source2.setLastModified(Calendar.getInstance());
-   //    service_.saveSource("source", source2) ; 
-   //    
-   //    //-------Check Source Storeage2's content added--------
-   //    Source sourceGet2 = service_.getSource("source/Todo.xml");
-   //    assertEquals("Gadget's content", sourceGet2.getTextContent());
-   //    
-   //  }
-   //  
-   //  protected String getDescription() {
-   //    return "Test Source Storage Service" ;
-   //  }
-   //  
-   //  public void tearDown() throws Exception {
-   //    // remove all data test
-   //    service_.removeSource("source");
-   //  }
-}

Modified: portal/branches/branch-GTNPORTAL-1700/component/application-registry/src/test/java/org/exoplatform/application/registry/TestApplicationRegistryService.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1700/component/application-registry/src/test/java/org/exoplatform/application/registry/TestApplicationRegistryService.java	2010-11-30 03:15:59 UTC (rev 5365)
+++ portal/branches/branch-GTNPORTAL-1700/component/application-registry/src/test/java/org/exoplatform/application/registry/TestApplicationRegistryService.java	2010-11-30 03:21:29 UTC (rev 5366)
@@ -64,12 +64,6 @@
 
    protected OrganizationService orgService;
 
-/*
-   protected int initialCats;
-
-   protected int initialApps;
-*/
-
    protected ChromatticManager chromatticManager;
 
    @Override
@@ -151,160 +145,12 @@
       chessApp.setAccessPermissions(pers);
       service_.save(gameCategory, chessApp);
 
-      List<ApplicationCategory> returnCategorys = service_.getApplicationCategories(username1);
-      for (ApplicationCategory cate : returnCategorys)
-      {
-         System.out.println("\n\n\ncateName: " + cate.getName());
-         List<Application> apps = service_.getApplications(cate);
-         for (Application app : apps)
-         {
-            System.out.println("\nappName: " + app.getApplicationName() + "---" + app.getAccessPermissions());
-         }
-      }
-      assertEquals(2, returnCategorys.size());
+      List<ApplicationCategory> returnCategories = service_.getApplicationCategories(username1);
+      assertEquals(2, returnCategories.size());
+      assertEquals(2, returnCategories.get(0).getApplications().size());
+      assertEquals(2, returnCategories.get(1).getApplications().size());
    }
-/*
-
-   void assertApplicationOperation(ApplicationRegistryService service) throws Exception
-   {
-      assertApplicationSave(service);
-      assertApplicationUpdate(service);
-      assertApplicationRemove(service);
-   }
-
-   void assertApplicationSave(ApplicationRegistryService service) throws Exception
-   {
-      String categoryName = "Office";
-      String appType = "TypeOne";
-      String appGroup = "GroupOne";
-      String[] appNames = {"OpenOffice_org", "MS_Office"};
-
-      ApplicationCategory appCategory = createAppCategory(categoryName, "None");
-      service.save(appCategory);
-
-      for (String appName : appNames)
-      {
-         Application app = createApplication(appName, appType, appGroup);
-         app.setCategoryName(categoryName);
-         service.save(appCategory, app);
-      }
-
-      List<Application> apps = service.getApplications(appCategory);
-      assertEquals(2, apps.size());
-
-      for (String appName : appNames)
-      {
-         String appId = categoryName + "/" + appName;
-
-         Application app = service.getApplication(appId);
-         assertEquals(appName, app.getApplicationName());
-      }
-      //    service.clearAllRegistries() ;
-   }
-
-   void assertApplicationUpdate(ApplicationRegistryService service) throws Exception
-   {
-      String categoryName = "Office";
-      String appType = "TypeOne";
-      String appGroup = "GroupOne";
-      String[] appNames = {"OpenOffice_org", "MS_Office"};
-
-      ApplicationCategory appCategory = createAppCategory(categoryName, "None");
-      service.save(appCategory);
-
-      // Save apps with description
-      for (String appName : appNames)
-      {
-         String oldDesciption = "This is: " + appName;
-         Application app = createApplication(appName, appType, appGroup);
-         app.setCategoryName(categoryName);
-         app.setDescription(oldDesciption);
-         service.save(appCategory, app);
-      }
-
-      for (String appName : appNames)
-      {
-         String appId = categoryName + "/" + appName;
-         String oldDesciption = "This is: " + appName;
-
-         Application app = service.getApplication(appId);
-         assertEquals(oldDesciption, app.getDescription());
-      }
-
-      // Update apps with new description: use save() method
-      List<Application> apps = service.getApplications(appCategory);
-      for (Application app : apps)
-      {
-         String newDesciption = "This is: " + app.getApplicationName() + " suite.";
-         app.setDescription(newDesciption);
-         service.save(appCategory, app);
-
-      }
-
-      for (String appName : appNames)
-      {
-         String appId = categoryName + "/" + appName;
-
-         Application app = service.getApplication(appId);
-         String newDesciption = "This is: " + app.getApplicationName() + " suite.";
-         assertEquals(newDesciption, app.getDescription());
-      }
-
-      // Update apps with new description: use update() method
-      for (String appName : appNames)
-      {
-         String appId = categoryName + "/" + appName;
-         String newDesciption = "This is new : " + appName + " suite.";
-
-         Application app = service.getApplication(appId);
-         app.setDescription(newDesciption);
-         service.update(app);
-      }
-
-      for (String appName : appNames)
-      {
-         String appId = categoryName + "/" + appName;
-         String newDesciption = "This is new : " + appName + " suite.";
-         Application app = service.getApplication(appId);
-         assertEquals(newDesciption, app.getDescription());
-      }
-
-      List<Application> apps2 = service.getApplications(appCategory);
-      assertEquals(2, apps2.size());
-
-      //    service.clearAllRegistries() ;
-   }
-
-   void assertApplicationRemove(ApplicationRegistryService service) throws Exception
-   {
-      String categoryName = "Office";
-      String appType = "TestType";
-      String appGroup = "TestGroup";
-      String[] appNames = {"OpenOffice_org", "MS_Office"};
-
-      ApplicationCategory appCategory = createAppCategory(categoryName, "None");
-      service.save(appCategory);
-
-      for (String appName : appNames)
-      {
-         Application app = createApplication(appName, appType, appGroup);
-         app.setCategoryName(categoryName);
-         service.save(appCategory, app);
-      }
-
-      List<Application> apps = service.getApplications(appCategory);
-      assertEquals(2, apps.size());
-
-      for (Application app : apps)
-      {
-         service.remove(app);
-      }
-
-      List<Application> apps2 = service.getApplications(appCategory);
-      assertEquals(0, apps2.size());
-      //    service.clearAllRegistries() ;
-   }
-*/
+   
    private ApplicationCategory createAppCategory(String categoryName, String categoryDes)
    {
       ApplicationCategory category = new ApplicationCategory();
@@ -313,6 +159,7 @@
       category.setDescription(categoryDes);
       return category;
    }
+   
    private Application createApplication(String appName, String appGroup)
    {
       Application app = new Application();
@@ -322,90 +169,4 @@
       app.setType(ApplicationType.PORTLET);
       return app;
    }
-
-/*
-   private void prepareOrganizationData() throws Exception
-   {
-      groupDefault = orgService.getGroupHandler().findGroupById("/platform/users");
-      if (group1 == null)
-      {
-         group1 = createGroup(orgService, Group1);
-      }
-      if (group2 == null)
-      {
-         group2 = createGroup(orgService, Group2);
-      }
-
-      mTypeDefault = orgService.getMembershipTypeHandler().findMembershipType("member");
-      if (mType1 == null)
-      {
-         mType1 = createMembershipType(orgService, memtype1);
-      }
-      if (mType2 == null)
-      {
-         mType2 = createMembershipType(orgService, memtype2);
-      }
-
-      if (user1 == null)
-      {
-         user1 = createUser(orgService, username1);
-         createDataUser(orgService, user1);
-      }
-      if (user2 == null)
-      {
-         user2 = createUser(orgService, username2);
-         createDataUser(orgService, user2);
-      }
-
-      userDefault = orgService.getUserHandler().findUserByName(demo);
-   }
-
-   private Group createGroup(OrganizationService orgService, String groupName) throws Exception
-   {
-      Group savedGroup = orgService.getGroupHandler().findGroupById("/" + groupName);
-      if (savedGroup != null)
-         return savedGroup;
-      Group groupParent = orgService.getGroupHandler().createGroupInstance();
-      groupParent.setGroupName(groupName);
-      groupParent.setDescription("This is description");
-      orgService.getGroupHandler().addChild(null, groupParent, true);
-      return groupParent;
-   }
-
-   private MembershipType createMembershipType(OrganizationService orgService, String name) throws Exception
-   {
-      MembershipType savedMt = orgService.getMembershipTypeHandler().findMembershipType(name);
-      if (savedMt != null)
-         return savedMt;
-      MembershipType mt = orgService.getMembershipTypeHandler().createMembershipTypeInstance();
-      mt.setName(name);
-      mt.setDescription("This is a test");
-      mt.setOwner("exo");
-      orgService.getMembershipTypeHandler().createMembershipType(mt, true);
-      return mt;
-   }
-
-   @SuppressWarnings("deprecation")
-   private User createUser(OrganizationService orgService, String userName) throws Exception
-   {
-      User savedUser = orgService.getUserHandler().findUserByName(userName);
-      if (savedUser != null)
-         return savedUser;
-      User user = orgService.getUserHandler().createUserInstance(userName);
-      user.setPassword("default");
-      user.setFirstName("default");
-      user.setLastName("default");
-      user.setEmail("exo at exoportal.org");
-      orgService.getUserHandler().createUser(user, true);
-      return user;
-   }
-
-   private User createDataUser(OrganizationService orgService, User u) throws Exception
-   {
-      UserProfile up = orgService.getUserProfileHandler().findUserProfileByName(u.getUserName());
-      up.getUserInfoMap().put("user.gender", "male");
-      orgService.getUserProfileHandler().saveUserProfile(up, true);
-      return u;
-   }
-*/
 }

Modified: portal/branches/branch-GTNPORTAL-1700/component/identity/src/test/java/org/exoplatform/services/organization/TestOrganizationService.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1700/component/identity/src/test/java/org/exoplatform/services/organization/TestOrganizationService.java	2010-11-30 03:15:59 UTC (rev 5365)
+++ portal/branches/branch-GTNPORTAL-1700/component/identity/src/test/java/org/exoplatform/services/organization/TestOrganizationService.java	2010-11-30 03:21:29 UTC (rev 5366)
@@ -117,12 +117,6 @@
       RequestLifeCycle.end();
    }
 
-   public void testSimle() throws Exception
-   {
-      assertTrue(true);
-
-   }
-
    public void testUserPageSize() throws Exception
    {
       for (String name : USERS)

Modified: portal/branches/branch-GTNPORTAL-1700/component/portal/src/test/java/org/exoplatform/portal/config/TestOrganization.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1700/component/portal/src/test/java/org/exoplatform/portal/config/TestOrganization.java	2010-11-30 03:15:59 UTC (rev 5365)
+++ portal/branches/branch-GTNPORTAL-1700/component/portal/src/test/java/org/exoplatform/portal/config/TestOrganization.java	2010-11-30 03:21:29 UTC (rev 5366)
@@ -19,16 +19,15 @@
 
 package org.exoplatform.portal.config;
 
+import java.util.Collection;
 import org.exoplatform.commons.utils.PageList;
 import org.exoplatform.container.PortalContainer;
+import org.exoplatform.services.organization.Group;
 import org.exoplatform.services.organization.GroupHandler;
 import org.exoplatform.services.organization.OrganizationService;
 import org.exoplatform.services.organization.User;
 import org.exoplatform.services.organization.UserHandler;
 
-import java.util.Collection;
-import java.util.List;
-
 /**
  * Created by The eXo Platform SARL Author : Tung Pham thanhtungty at gmail.com Nov
  * 13, 2007
@@ -36,6 +35,16 @@
 public class TestOrganization extends AbstractPortalTest
 {
 
+	private static final String GROUP_1 = "testOrganization_group1";
+	private static final String GROUP_2 = "testOrganization_group2";
+	private static final String GROUP_3 = "testOrganization_group3";
+	
+	private static final String USER_1 = "testOrganization_user1";
+	private static final String USER_2 = "testOrganization_user2";
+	private static final String USER_3 = "testOrganization_user3";
+	private static final String DEFAULT_PASSWORD = "defaultpassword";
+	private static final String DESCRIPTION = " Description";
+	
    private OrganizationService organizationService;
 
    @Override
@@ -45,59 +54,148 @@
       begin();
       PortalContainer container = getContainer();
       organizationService = (OrganizationService)container.getComponentInstance(OrganizationService.class);
+      
+      createGroup(null, GROUP_1);
+      createGroup(GROUP_1, GROUP_2);
+      createGroup(GROUP_1, GROUP_3);
+      
+      createUser(USER_1, GROUP_1);
+      createUser(USER_2, GROUP_2);
+      createUser(USER_3, GROUP_1);
    }
 
    @Override
    protected void tearDown() throws Exception
    {
-      end();
+	  deleteGroup(GROUP_1);
+	  deleteGroup(GROUP_2);
+	  deleteGroup(GROUP_3);
+	  
+	  deleteUser(USER_1);
+	  deleteUser(USER_2);
+	  deleteUser(USER_3);
+	  
+      end(false);
       super.tearDown();
    }
 
-   public void testFindGroups() throws Exception
+   public void testFindGroupNotFound() throws Exception {
+	   GroupHandler groupHander = organizationService.getGroupHandler();
+	   Group group = groupHander.findGroupById(GROUP_1 + "NOTFOUND");
+	   assertNull(group);
+   }
+   
+   public void testFindGroupFromRoot() throws Exception
    {
       GroupHandler handler = organizationService.getGroupHandler();
-      Collection allGroups = handler.findGroups(null);
+      Collection<Group> allGroups = handler.findGroups(null);
+      assertNotNull(allGroups);
       assertTrue(allGroups.size() > 0);
    }
 
    public void testFindGroupById() throws Exception
    {
-      GroupHandler uHandler = organizationService.getGroupHandler();
-      Collection group = uHandler.findGroupsOfUser("root");
+      GroupHandler groupHandler = organizationService.getGroupHandler();
+      Group group = groupHandler.findGroupById(GROUP_1);
+      assertNotNull(group);
+      assertEquals(GROUP_1, group.getGroupName());
+      assertEquals(GROUP_1 + DESCRIPTION, group.getDescription());
+      
+      group = groupHandler.findGroupById(GROUP_3);
+      assertNotNull(group);
+      assertEquals(GROUP_3, group.getGroupName());
    }
+   
+   public void testFindGroupOfUser() {
+	   GroupHandler groupHandler = organizationService.getGroupHandler();
+	   try {
+		Collection<Group> groups = groupHandler.findGroupsOfUser(USER_1);
+		assertNotNull(groups);
+		assertTrue(groups.size() >= 1);
+	} catch (Exception e) {
+		fail();
+	}
+   }
 
    public void testFindUserByGroup() throws Exception
    {
+	  GroupHandler groupHandler = organizationService.getGroupHandler();
+	  Group group = groupHandler.findGroupById(GROUP_1);
       UserHandler uHandler = organizationService.getUserHandler();
-      PageList users = uHandler.findUsersByGroup("/platform/administrators");
-      assertTrue(users.getAvailable() > 0);
-
-      List iterator = users.getAll();
-      for (Object test : iterator)
-      {
-         User a = (User)test;
-         System.out.println(a.getUserName());
-      }
+      PageList<User> users = uHandler.findUsersByGroup(group.getId());
+      assertNotNull(users);
+      assertTrue(users.getPageSize() > 0);
    }
 
    public void testChangePassword() throws Exception
    {
       UserHandler uHandler = organizationService.getUserHandler();
-      User user = uHandler.findUserByName("root");
+      User user = uHandler.findUserByName(USER_1);
       assertNotNull(user);
-      assertTrue(uHandler.authenticate("root", "gtn"));
+      assertTrue(uHandler.authenticate(USER_1, DEFAULT_PASSWORD));
       
       // Test changing password
       user.setPassword("newPassword");
       uHandler.saveUser(user, false);
-      user = uHandler.findUserByName("root");
+      user = uHandler.findUserByName(USER_1);
       assertNotNull(user);
-      assertTrue(uHandler.authenticate("root", "newPassword"));    
-
-      // Reset to default password
-      user.setPassword("gtn");
-      uHandler.saveUser(user, false);
-
+      assertTrue(uHandler.authenticate(USER_1, "newPassword"));
    }
+   
+   
+   private void createGroup(String parent, String name) {
+	   GroupHandler groupHandler = organizationService.getGroupHandler();
+	   try {
+		   Group parentGroup = null;
+		   if(parent != null) {
+			   parentGroup = groupHandler.findGroupById(parent);
+		   }
+		   Group newGroup = groupHandler.createGroupInstance();
+		   newGroup.setGroupName(name);
+		   newGroup.setDescription(name + DESCRIPTION);
+		   newGroup.setLabel(name);
+		   if(parentGroup != null) {
+			   groupHandler.addChild(parentGroup, newGroup, true);
+		   }
+		   groupHandler.saveGroup(newGroup, true);
+		   
+	   } catch (Exception e) {
+			e.printStackTrace();
+			fail("Error on create group [" + name + "] " + e.getMessage());
+	   }
+	   
+   }
+   
+   private void deleteGroup(String name) {
+	   GroupHandler groupHandler = organizationService.getGroupHandler();
+	   try {
+		Group group = groupHandler.findGroupById(name);
+		groupHandler.removeGroup(group, true);
+	} catch (Exception e) {
+		
+	}
+   }
+   
+   private void createUser(String username, String... groups) {
+	   UserHandler userHandler = organizationService.getUserHandler();
+	   User user = userHandler.createUserInstance(username);
+	   user.setPassword(DEFAULT_PASSWORD);
+	   user.setFirstName("default");
+	   user.setLastName("default");
+	   user.setEmail("exo at exoportal.org");
+	   user.setOrganizationId(groups[0]);
+	   try {
+		userHandler.createUser(user, true);
+	   } catch (Exception e) {
+		   e.printStackTrace();
+		   fail("Error on create user: " + e.getMessage());
+	   }
+   }
+   private void deleteUser(String username) {
+	   UserHandler userHandler = organizationService.getUserHandler();
+	   try {
+		   userHandler.removeUser(username, true);
+	   } catch (Exception e) {
+	   }	   
+   }
 }



More information about the gatein-commits mailing list