[exo-jcr-commits] exo-jcr SVN: r4996 - in core/trunk: exo.core.component.organization.tests and 8 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Sep 28 07:50:26 EDT 2011
Author: dkuleshov
Date: 2011-09-28 07:50:25 -0400 (Wed, 28 Sep 2011)
New Revision: 4996
Added:
core/trunk/exo.core.component.organization.tests/
core/trunk/exo.core.component.organization.tests/pom.xml
core/trunk/exo.core.component.organization.tests/src/
core/trunk/exo.core.component.organization.tests/src/main/
core/trunk/exo.core.component.organization.tests/src/main/java/
core/trunk/exo.core.component.organization.tests/src/main/java/org/
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/AbstractOrganizationServiceTest.java
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestGroupHandler.java
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestMembershipHandler.java
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestMembershipTypeHandler.java
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestUserHandler.java
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestUserProfileHandler.java
Modified:
core/trunk/pom.xml
Log:
EXOJCR-953: added org service tck tests module
Added: core/trunk/exo.core.component.organization.tests/pom.xml
===================================================================
--- core/trunk/exo.core.component.organization.tests/pom.xml (rev 0)
+++ core/trunk/exo.core.component.organization.tests/pom.xml 2011-09-28 11:50:25 UTC (rev 4996)
@@ -0,0 +1,70 @@
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.exoplatform.core</groupId>
+ <artifactId>core-parent</artifactId>
+ <version>2.4.2-GA-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>exo.core.component.organization.tests</artifactId>
+
+ <name>eXo Core :: Component :: Organization Service Tests</name>
+ <description>Create an Organisation Service TCK package</description>
+
+ <build>
+ <plugins>
+ <!--
+ To avoid test sources compilation we simply exclude them
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/*.*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <!--
+ Configure maven-source-plugin to add sources packed
+ in jar files to maven artifact
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>2.1.2</version>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>jar-no-fork</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/AbstractOrganizationServiceTest.java
===================================================================
--- core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/AbstractOrganizationServiceTest.java (rev 0)
+++ core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/AbstractOrganizationServiceTest.java 2011-09-28 11:50:25 UTC (rev 4996)
@@ -0,0 +1,239 @@
+/*
+ * Copyright (C) 2003-2011 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.tck.organization;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.container.StandaloneContainer;
+import org.exoplatform.services.organization.Group;
+import org.exoplatform.services.organization.GroupHandler;
+import org.exoplatform.services.organization.MembershipHandler;
+import org.exoplatform.services.organization.MembershipType;
+import org.exoplatform.services.organization.MembershipTypeHandler;
+import org.exoplatform.services.organization.OrganizationService;
+import org.exoplatform.services.organization.User;
+import org.exoplatform.services.organization.UserHandler;
+import org.exoplatform.services.organization.UserProfile;
+import org.exoplatform.services.organization.UserProfileHandler;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2011
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id: AbstractOrganizationServiceTest.java 111 2011-11-11 11:11:11Z rainf0x $
+ */
+public class AbstractOrganizationServiceTest extends TestCase
+{
+
+ protected GroupHandler gHandler;
+
+ protected MembershipHandler mHandler;
+
+ protected UserHandler uHandler;
+
+ protected MembershipTypeHandler mtHandler;
+
+ protected UserProfileHandler upHandler;
+
+ protected String membershipType = "type";
+
+ protected String userName = "user";
+
+ protected String newUserName = "newUser";
+
+ protected String groupName1 = "group1";
+
+ protected String groupName2 = "group2";
+
+ protected StandaloneContainer container;
+
+ /**
+ * The list of users which have been created during test.
+ * Will be removed in tearDown() method.
+ */
+ private List<String> users = new ArrayList<String>();
+
+ /**
+ * The list of membership types which have been created during test.
+ * Will be removed in tearDown() method.
+ */
+ private List<String> types = new ArrayList<String>();
+
+ /**
+ * The list of group which have been created during test.
+ * Will be removed in tearDown() method.
+ */
+ private List<String> groups = new ArrayList<String>();
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ String containerConf = getClass().getResource("/conf/standalone/test-configuration.xml").toString();
+
+ StandaloneContainer.addConfigurationURL(containerConf);
+ container = StandaloneContainer.getInstance();
+
+ OrganizationService organizationService =
+ (OrganizationService)container.getComponentInstanceOfType(OrganizationService.class);
+
+ gHandler = organizationService.getGroupHandler();
+ uHandler = organizationService.getUserHandler();
+ mHandler = organizationService.getMembershipHandler();
+ mtHandler = organizationService.getMembershipTypeHandler();
+ upHandler = organizationService.getUserProfileHandler();
+
+ users.add(userName);
+ users.add(newUserName);
+
+ groups.add("/" + groupName1);
+ groups.add("/" + groupName1 + "/" + groupName2);
+
+ types.add(membershipType);
+ }
+
+ /**
+ * Create new user for test purpose only.
+ */
+ protected void createUser(String userName) throws Exception
+ {
+ User u = uHandler.createUserInstance(userName);
+ u.setEmail("email at test");
+ u.setFirstName("first");
+ u.setLastLoginTime(Calendar.getInstance().getTime());
+ u.setCreatedDate(Calendar.getInstance().getTime());
+ u.setLastName("last");
+ u.setPassword("pwd");
+
+ uHandler.createUser(u, true);
+
+ users.add(userName);
+ }
+
+ /**
+ * Create user with profile.
+ */
+ protected void createUserProfile(String userName) throws Exception
+ {
+ UserProfile up = upHandler.createUserProfileInstance(userName);
+ up.setAttribute("key1", "value1");
+ up.setAttribute("key2", "value2");
+ upHandler.saveUserProfile(up, true);
+ }
+
+ /**
+ * Create membership type.
+ */
+ protected void createMembershipType(String type, String desc) throws Exception
+ {
+ MembershipType mt = mtHandler.createMembershipTypeInstance();
+ mt.setName(type);
+ mt.setDescription(desc);
+ mtHandler.createMembershipType(mt, true);
+
+ types.add(type);
+ }
+
+ /**
+ * Create new group.
+ */
+ protected void createGroup(String parentId, String name, String label, String desc) throws Exception
+ {
+ Group parent = gHandler.findGroupById(parentId);
+
+ Group child = gHandler.createGroupInstance();
+ child.setGroupName(name);
+ child.setLabel(label);
+ child.setDescription(desc);
+ gHandler.addChild(parent, child, true);
+
+ groups.add((parent == null ? "" : parentId) + "/" + name);
+ }
+
+ /**
+ * Create membership.
+ */
+ protected void createMembership(String userName, String groupName, String type) throws Exception
+ {
+ createUser(userName);
+ createGroup(null, groupName, "lable", "desc");
+ createMembershipType(type, "desc");
+
+ // link membership
+ mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName), mtHandler
+ .findMembershipType(type), true);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void tearDown() throws Exception
+ {
+ // remove all users
+ Iterator<String> iter = users.iterator();
+ while (iter.hasNext())
+ {
+ String userName = iter.next();
+
+ if (uHandler.findUserByName(userName) != null)
+ {
+ uHandler.removeUser(userName, true);
+ }
+ iter.remove();
+ }
+
+ // remove all membership types
+ iter = types.iterator();
+ while (iter.hasNext())
+ {
+ String type = iter.next();
+
+ if (mtHandler.findMembershipType(type) != null)
+ {
+ mtHandler.removeMembershipType(type, true);
+ }
+ iter.remove();
+ }
+
+ // remove all groups
+ iter = groups.iterator();
+ while (iter.hasNext())
+ {
+ String groupId = iter.next();
+
+ Group group = gHandler.findGroupById(groupId);
+ if (group != null)
+ {
+ gHandler.removeGroup(group, true);
+ }
+
+ iter.remove();
+ }
+
+ super.tearDown();
+ }
+}
Added: core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestGroupHandler.java
===================================================================
--- core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestGroupHandler.java (rev 0)
+++ core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestGroupHandler.java 2011-09-28 11:50:25 UTC (rev 4996)
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.tck.organization;
+
+import org.exoplatform.services.organization.Group;
+import org.exoplatform.services.organization.GroupEventListener;
+import org.exoplatform.services.organization.GroupEventListenerHandler;
+
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
+ * @version $Id: TestOrganizationService.java 111 2008-11-11 11:11:11Z $
+ */
+public class TestGroupHandler extends AbstractOrganizationServiceTest
+{
+
+ /**
+ * Find group by id.
+ */
+ public void testFindGroupById() throws Exception
+ {
+ Group g = gHandler.findGroupById("/platform/administrators");
+ assertNotNull(g);
+ assertEquals(g.getDescription(), "the /platform/administrators group");
+ assertEquals(g.getGroupName(), "administrators");
+ assertEquals(g.getId(), "/platform/administrators");
+ assertEquals(g.getLabel(), "Administrators");
+ assertEquals(g.getParentId(), "/platform");
+
+ // try to find not existed group. We are supposed to get "null" instead of Exception
+ try
+ {
+ assertNull(gHandler.findGroupById("/not-existed-group"));
+ }
+ catch (Exception e)
+ {
+ fail("Exception should be thrown");
+ }
+ }
+
+ /**
+ * Find groups by user.
+ */
+ public void testFindGroupsByUser() throws Exception
+ {
+ assertEquals(gHandler.findGroupsOfUser("john").size(), 3);
+ }
+
+ /**
+ * Find groups.
+ */
+ public void testFindGroups() throws Exception
+ {
+ assertEquals(gHandler.findGroups(null).size(), 4);
+ assertEquals(gHandler.findGroups(gHandler.findGroupById("/organization/operations")).size(), 2);
+ assertEquals(gHandler.findGroups(gHandler.findGroupById("/organization/management/executive-board")).size(), 0);
+ }
+
+ /**
+ * Get all groups.
+ */
+ public void testGetAllGroups() throws Exception
+ {
+ assertEquals(gHandler.getAllGroups().size(), 16);
+ }
+
+ /**
+ * Remove group.
+ */
+ public void testRemoveGroup() throws Exception
+ {
+ createGroup("/organization", groupName1, "label", "desc");
+ createGroup("/organization/" + groupName1, groupName1, "label", "desc");
+
+ Group group = gHandler.removeGroup(gHandler.findGroupById("/organization/group1"), true);
+ assertNull(gHandler.findGroupById("/organization/group1"));
+ assertNull(gHandler.findGroupById("/organization/group1/group2"));
+
+ // try to remove not exited group. Exception should be thrown
+ try
+ {
+ gHandler.removeGroup(group, true);
+ fail("Exception should be thrown");
+ }
+ catch (Exception e)
+ {
+ }
+
+ // create in root
+ createGroup(null, groupName1, "label", "desc");
+ createGroup("/" + groupName1, groupName2, "label", "desc");
+
+ gHandler.removeGroup(gHandler.findGroupById("/" + groupName1), true);
+ assertNull(gHandler.findGroupById("/" + groupName1));
+ assertNull(gHandler.findGroupById("/" + groupName1 + "/" + groupName2));
+ }
+
+ /**
+ * Add child.
+ */
+ public void testAddChild() throws Exception
+ {
+ Group parent = gHandler.createGroupInstance();
+ parent.setGroupName(groupName1);
+
+ Group child = gHandler.createGroupInstance();
+ child.setGroupName(groupName2);
+
+ // try to add child to not existed parent group
+ try
+ {
+ gHandler.addChild(parent, child, false);
+ fail("Exception should be thrown.");
+ }
+ catch (Exception e)
+ {
+ }
+
+ // add parent group
+ gHandler.addChild(null, parent, false);
+ assertNotNull(gHandler.findGroupById("/" + groupName1));
+
+ // add child group
+ gHandler.addChild(parent, child, false);
+ assertNotNull(gHandler.findGroupById("/" + groupName1 + "/" + groupName2));
+ }
+
+ /**
+ * Create group.
+ */
+ public void testCreateGroup() throws Exception
+ {
+ Group group = gHandler.createGroupInstance();
+ group.setGroupName(groupName1);
+ gHandler.createGroup(group, true);
+
+ assertNotNull(gHandler.findGroupById("/" + groupName1));
+ }
+
+ /**
+ * Save group.
+ */
+ public void testSaveGroup() throws Exception
+ {
+ createGroup(null, groupName1, "label", "desc");
+
+ // set new description
+ Group g = gHandler.findGroupById("/" + groupName1);
+ g.setDescription("newDesc");
+ gHandler.saveGroup(g, true);
+
+ // check if group has new description
+ g = gHandler.findGroupById("/" + groupName1);
+ assertEquals(g.getDescription(), "newDesc");
+ }
+
+ /**
+ * Test get listeners.
+ */
+ public void testGetListeners() throws Exception
+ {
+ if (gHandler instanceof GroupEventListenerHandler)
+ {
+ List<GroupEventListener> list = ((GroupEventListenerHandler) gHandler).getGroupListeners();
+ try
+ {
+ list.clear();
+ fail("We are not supposed to be able to change list of listeners.");
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ }
+}
Added: core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestMembershipHandler.java
===================================================================
--- core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestMembershipHandler.java (rev 0)
+++ core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestMembershipHandler.java 2011-09-28 11:50:25 UTC (rev 4996)
@@ -0,0 +1,486 @@
+/*
+ * Copyright (C) 2003-2008 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.tck.organization;
+
+import org.exoplatform.commons.utils.ListAccess;
+import org.exoplatform.services.organization.Group;
+import org.exoplatform.services.organization.Membership;
+import org.exoplatform.services.organization.MembershipEventListener;
+import org.exoplatform.services.organization.MembershipEventListenerHandler;
+import org.exoplatform.services.organization.MembershipType;
+import org.exoplatform.services.organization.User;
+
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
+ * @version $Id: TestMembershipImpl.java 111 2008-11-11 11:11:11Z $
+ */
+public class TestMembershipHandler extends AbstractOrganizationServiceTest
+{
+ /**
+ * Find membership.
+ */
+ public void testFindMembership() throws Exception
+ {
+ createMembership(userName, groupName1, membershipType);
+
+ Membership m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType);
+ assertNotNull(mHandler.findMembership(m.getId()));
+
+ // try to find not existed membership. We are supposed to get null instead of Exception
+ try
+ {
+ assertNull(mHandler.findMembership("not-existed-id"));
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Find membership by user and group.
+ */
+ public void testFindMembershipByUserGroupAndType() throws Exception
+ {
+ Membership m = mHandler.findMembershipByUserGroupAndType("marry", "/platform/users", "member");
+
+ assertNotNull(m);
+ assertEquals(m.getGroupId(), "/platform/users");
+ assertEquals(m.getMembershipType(), "member");
+ assertEquals(m.getUserName(), "marry");
+
+ // try to find not existed membership. We are supposed to get null instead of Exception
+ try
+ {
+ assertNull(mHandler.findMembershipByUserGroupAndType(userName, "/platform/users", "member"));
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+
+ try
+ {
+ assertNull(mHandler.findMembershipByUserGroupAndType("marry", "/" + groupName1, "member"));
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+
+ try
+ {
+ assertNull(mHandler.findMembershipByUserGroupAndType("marry", "/platform/users", membershipType));
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Find membership by group.
+ */
+ public void testFindMembershipsByGroup() throws Exception
+ {
+ Group g = gHandler.findGroupById("/platform/users");
+ assertEquals(mHandler.findMembershipsByGroup(g).size(), 4);
+
+ g = gHandler.createGroupInstance();
+ g.setGroupName(groupName1);
+ assertEquals(mHandler.findMembershipsByGroup(g).size(), 0);
+
+ }
+
+ /**
+ * Find membership by group.
+ */
+ public void testFindAllMembershipsByGroup() throws Exception
+ {
+ Group g = gHandler.findGroupById("/platform/users");
+ ListAccess<Membership> memberships = mHandler.findAllMembershipsByGroup(g);
+ assertEquals(memberships.getSize(), 4);
+
+ try
+ {
+ Membership[] m = memberships.load(0, 4);
+ assertEquals(4, m.length);
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+
+ try
+ {
+ Membership[] m = memberships.load(1, 2);
+ assertEquals(2, m.length);
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+
+ try
+ {
+ Membership[] m = memberships.load(1, 4);
+ fail("Exception should be thrown");
+ }
+ catch (Exception e)
+ {
+ }
+
+ g = gHandler.createGroupInstance();
+ g.setGroupName(groupName1);
+ assertEquals(mHandler.findMembershipsByGroup(g).size(), 0);
+
+ }
+
+ /**
+ * Find all memberships by user.
+ */
+ public void testFindMembershipsByUser() throws Exception
+ {
+ assertEquals(mHandler.findMembershipsByUser("john").size(), 3);
+ assertEquals(mHandler.findMembershipsByUser("not-existed-user").size(), 0);
+ }
+
+ /**
+ * Find all membership by user and group.
+ */
+ public void testFindMembershipsByUserAndGroup() throws Exception
+ {
+ assertEquals(mHandler.findMembershipsByUserAndGroup("john", "/platform/users").size(), 1);
+
+ // try to find not existed membership. We are supposed to get null instead of Exception
+ try
+ {
+ assertEquals(mHandler.findMembershipsByUserAndGroup("non-existed-john", "/platform/users").size(), 0);
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+
+ try
+ {
+ assertEquals(mHandler.findMembershipsByUserAndGroup("john", "/non-existed-group").size(), 0);
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Link membership.
+ */
+ public void testLinkMembership() throws Exception
+ {
+ createUser(userName);
+ createGroup(null, groupName1, "lable", "desc");
+ createMembershipType(membershipType, "desc");
+
+ // link membership
+ mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName1), mtHandler
+ .findMembershipType(membershipType), true);
+
+ Membership m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType);
+ assertNotNull(m);
+
+ // try to create already existed membership. Exception should not be thrown
+ try
+ {
+ mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName1),
+ mtHandler.findMembershipType(membershipType), true);
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+
+ // we expect only 1 membership record
+ assertEquals(1, mHandler.findMembershipsByUser(userName).size());
+
+ // test deprecated memthod create membership
+ mHandler.removeMembership(m.getId(), true);
+ mHandler.createMembership(m, true);
+ m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType);
+ assertNotNull(m);
+
+ // try to link membership with not existed entries. We are supposed to get Exception
+ Group group = gHandler.createGroupInstance();
+ group.setGroupName("not-existed-group");
+ try
+ {
+ mHandler.linkMembership(uHandler.findUserByName(userName), group,
+ mtHandler.findMembershipType(membershipType), true);
+ fail("Exception should be thrown");
+ }
+ catch (Exception e)
+ {
+ }
+
+ User user = uHandler.createUserInstance("not-existed-user");
+ try
+ {
+ mHandler.linkMembership(user, gHandler.findGroupById("/" + groupName1), mtHandler
+ .findMembershipType(membershipType), true);
+ fail("Exception should be thrown");
+ }
+ catch (Exception e)
+ {
+ }
+
+ MembershipType mt = mtHandler.createMembershipTypeInstance();
+ mt.setName("not-existed-mt");
+ try
+ {
+ mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName1), mt, true);
+ fail("Exception should be thrown");
+ }
+ catch (Exception e)
+ {
+ }
+
+ try
+ {
+ mHandler.linkMembership(uHandler.findUserByName(userName), null, mtHandler.findMembershipType(membershipType),
+ true);
+ fail("Exception should be thrown");
+ }
+ catch (Exception e)
+ {
+ }
+
+ try
+ {
+ mHandler.linkMembership(null, gHandler.findGroupById("/" + groupName1), mtHandler
+ .findMembershipType(membershipType), true);
+ fail("Exception should be thrown");
+ }
+ catch (Exception e)
+ {
+ }
+
+ try
+ {
+ mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName1), null,
+ true);
+ fail("Exception should be thrown");
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ /**
+ * Remove membership
+ */
+ public void testRemoveMembership() throws Exception
+ {
+
+ createMembership(userName, groupName1, membershipType);
+ Membership m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType);
+
+ assertNotNull(m);
+
+ m = mHandler.removeMembership(m.getId(), true);
+ assertEquals(m.getGroupId(), "/" + groupName1);
+ assertEquals(m.getMembershipType(), membershipType);
+ assertEquals(m.getUserName(), userName);
+
+ assertNull(mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType));
+
+
+ // try to remove not existed membership. We are supposed to get "null" instead of Exception
+ try
+ {
+ assertNull(mHandler.removeMembership("not-existed-id", true));
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Remove membership by user.
+ */
+ public void testRemoveMembershipByUser() throws Exception
+ {
+ createMembership(userName, groupName1, membershipType);
+
+ assertEquals(mHandler.removeMembershipByUser("user", true).size(), 1);
+ assertNull(mHandler.findMembershipByUserGroupAndType("user", "/group", "type"));
+
+ // try to remove memberships by not existed users. We are supposed to get empty list instead of Exception
+ try
+ {
+ assertEquals(mHandler.removeMembershipByUser("not-existed-user", true).size(), 0);
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Find group by membership.
+ */
+ public void testFindGroupByMembership() throws Exception
+ {
+ assertEquals(gHandler.findGroupByMembership("john", "manager").size(), 1);
+
+ // try to find groups by not existed entries. We supposed to get empty list instead of Exception
+ try
+ {
+ assertEquals(gHandler.findGroupByMembership("not-existed-john", "manager").size(), 0);
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+
+
+ }
+
+ /**
+ * Find groups of user.
+ */
+ public void testFindGroupsOfUser() throws Exception
+ {
+ assertEquals(gHandler.findGroupsOfUser("john").size(), 3);
+
+ // try to find groups by not existed entries. We supposed to get empty list instead of Exception
+ try
+ {
+ assertEquals(gHandler.findGroupsOfUser("not-existed-james").size(), 0);
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Find users by group.
+ */
+ public void testFindUsersByGroupId() throws Exception
+ {
+ assertEquals(uHandler.findUsersByGroupId("/platform/users").getSize(), 4);
+
+ // try to find users by not existed entries. We supposed to get empty list instead of Exception
+ try
+ {
+ assertEquals(uHandler.findUsersByGroupId("/not-existed-group").getSize(), 0);
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Find users by group.
+ */
+ public void testFindUsersByGroup() throws Exception
+ {
+ assertEquals(uHandler.findUsersByGroup("/platform/users").getAll().size(), 4);
+
+ // try to find users by not existed entries. We supposed to get empty list instead of Exception
+ try
+ {
+ assertEquals(uHandler.findUsersByGroup("/not-existed-group").getAll().size(), 0);
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Remove membership type.
+ */
+ public void testRemoveMembershipType() throws Exception
+ {
+ createMembership(userName, groupName1, membershipType);
+
+ mtHandler.removeMembershipType("type", true);
+ assertNull(mtHandler.findMembershipType("type"));
+ assertNull(mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType));
+ }
+
+ /**
+ * Remove group.
+ */
+ public void testRemoveGroup() throws Exception
+ {
+ createMembership(userName, groupName1, membershipType);
+
+ gHandler.removeGroup(gHandler.findGroupById("/" + groupName1), true);
+
+ assertNull(gHandler.findGroupById("/" + groupName1));
+ assertNull(mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType));
+
+
+ // try to remove not existed groups. We are supposed to get Exception
+ try
+ {
+ Group g = gHandler.createGroupInstance();
+ g.setGroupName("not-existed-group");
+ gHandler.removeGroup(g, true);
+
+ fail("Exception should be thrown");
+ }
+ catch (Exception e)
+ {
+ }
+
+ try
+ {
+ gHandler.removeGroup(null, true);
+ fail("Exception should be thrown");
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ /**
+ * Test get listeners.
+ */
+ public void testGetListeners() throws Exception
+ {
+ if (mHandler instanceof MembershipEventListenerHandler)
+ {
+ List<MembershipEventListener> list = ((MembershipEventListenerHandler) mHandler).getMembershipListeners();
+ try
+ {
+ list.clear();
+ fail("We are not supposed to change list of listners");
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ }
+}
Added: core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestMembershipTypeHandler.java
===================================================================
--- core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestMembershipTypeHandler.java (rev 0)
+++ core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestMembershipTypeHandler.java 2011-09-28 11:50:25 UTC (rev 4996)
@@ -0,0 +1,223 @@
+/**
+ *
+ */
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.tck.organization;
+
+import org.exoplatform.services.organization.MembershipType;
+import org.exoplatform.services.organization.MembershipTypeEventListener;
+import org.exoplatform.services.organization.MembershipTypeEventListenerHandler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
+ * @version $Id: TestMembershipTypeHandlerImpl.java 111 2008-11-11 11:11:11Z $
+ */
+public class TestMembershipTypeHandler extends AbstractOrganizationServiceTest
+{
+
+ /**
+ * Find membership type.
+ */
+ public void testFindMembershipType() throws Exception
+ {
+ MembershipType mt = mtHandler.findMembershipType("manager");
+ assertNotNull(mt);
+ assertEquals(mt.getName(), "manager");
+ assertEquals(mt.getDescription(), "manager membership type");
+
+ // try to find not existed membership type
+ assertNull(mtHandler.findMembershipType("manager_"));
+ }
+
+ /**
+ * Find membership types.
+ */
+ public void testFindMembershipTypes() throws Exception
+ {
+ assertEquals(mtHandler.findMembershipTypes().size(), 3);
+ }
+
+ /**
+ * Remove membership type.
+ */
+ public void testRemoveMembershipType() throws Exception
+ {
+ createMembershipType(membershipType, "desc");
+
+ MembershipType mt = mtHandler.removeMembershipType("type", true);
+ assertEquals(mt.getName(), membershipType);
+ assertNull(mtHandler.findMembershipType("type"));
+
+ // try to remove not existed membership type. We are supposed to get "null" instead of Exception
+ try
+ {
+ assertNull(mtHandler.removeMembershipType("not-existed-mt", true));
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Save membership type.
+ */
+ public void testSaveMembershipType() throws Exception
+ {
+ createMembershipType(membershipType, "desc");
+ MembershipType mt = mtHandler.findMembershipType(membershipType);
+
+ // change description
+ mt.setDescription("newDesc");
+ mtHandler.saveMembershipType(mt, true);
+
+ mt = mtHandler.findMembershipType(membershipType);
+ assertEquals(mt.getDescription(), "newDesc");
+ }
+
+ /**
+ * Test get listeners.
+ */
+ public void testGetListeners() throws Exception
+ {
+ if (mtHandler instanceof MembershipTypeEventListenerHandler)
+ {
+ List<MembershipTypeEventListener> list =
+ ((MembershipTypeEventListenerHandler)mtHandler).getMembershipTypeListeners();
+
+ assertEquals(1, list.size());
+ try
+ {
+ list.clear();
+ fail("We are not supposed to change list of listeners");
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ }
+
+ /**
+ * Test events.
+ */
+ public void testMembershipTypeEventListener() throws Exception
+ {
+ TesterMembershipTypeEventListener testListener = new TesterMembershipTypeEventListener();
+ mtHandler.addMembershipTypeEventListener(testListener);
+
+ if (mtHandler instanceof MembershipTypeEventListenerHandler)
+ {
+ List<MembershipTypeEventListener> list =
+ ((MembershipTypeEventListenerHandler)mtHandler).getMembershipTypeListeners();
+
+ assertEquals(2, list.size());
+ }
+
+ // Create new membership type. In preSave event there is not recored in db.
+ createMembershipType(membershipType, "desc");
+
+ assertEquals(2, testListener.mtInEvent.size());
+ assertEquals(2, testListener.mtInStorage.size());
+
+ // preSave Event
+ assertEquals(membershipType, testListener.mtInEvent.get(0).getName());
+ assertNull(testListener.mtInStorage.get(0));
+
+ // postSave Event
+ assertEquals(membershipType, testListener.mtInEvent.get(1).getName());
+ assertNotNull(testListener.mtInStorage.get(1));
+ assertEquals(membershipType, testListener.mtInStorage.get(1).getName());
+
+ testListener.mtInEvent.clear();
+ testListener.mtInStorage.clear();
+
+ // Modify membership type. In preSave event there is old record in storage.
+ MembershipType mt = mtHandler.findMembershipType(membershipType);
+ mt.setDescription("newDesc");
+
+ mtHandler.saveMembershipType(mt, true);
+
+ // preSave Event
+ assertEquals(2, testListener.mtInEvent.size());
+ assertEquals(2, testListener.mtInStorage.size());
+
+ assertEquals("newDesc", testListener.mtInEvent.get(0).getDescription());
+ assertEquals("desc", testListener.mtInStorage.get(0).getDescription());
+
+ // postSave Event
+ assertEquals("newDesc", testListener.mtInEvent.get(1).getDescription());
+ assertEquals("newDesc", testListener.mtInStorage.get(1).getDescription());
+
+ testListener.mtInEvent.clear();
+ testListener.mtInStorage.clear();
+
+ // Remove membership type. In preDelete Event there is still record in storage
+ mtHandler.removeMembershipType(membershipType, true);
+
+ assertEquals(2, testListener.mtInEvent.size());
+ assertEquals(2, testListener.mtInStorage.size());
+
+ // preDelete Event
+ assertEquals(membershipType, testListener.mtInEvent.get(0).getName());
+ assertNotNull(testListener.mtInStorage.get(0));
+
+ // postDelete Event
+ assertEquals(membershipType, testListener.mtInEvent.get(1).getName());
+ assertNull(testListener.mtInStorage.get(1));
+
+ testListener.mtInEvent.clear();
+ testListener.mtInStorage.clear();
+
+ }
+
+ private class TesterMembershipTypeEventListener extends MembershipTypeEventListener
+ {
+ List<MembershipType> mtInEvent = new ArrayList<MembershipType>();
+
+ List<MembershipType> mtInStorage = new ArrayList<MembershipType>();
+
+ public void preSave(MembershipType type, boolean isNew) throws Exception
+ {
+ mtInEvent.add(type);
+ mtInStorage.add(mtHandler.findMembershipType(type.getName()));
+ }
+
+ public void postSave(MembershipType type, boolean isNew) throws Exception
+ {
+ mtInEvent.add(type);
+ mtInStorage.add(mtHandler.findMembershipType(type.getName()));
+ }
+
+ public void preDelete(MembershipType type) throws Exception
+ {
+ mtInEvent.add(type);
+ mtInStorage.add(mtHandler.findMembershipType(type.getName()));
+ }
+
+ public void postDelete(MembershipType type) throws Exception
+ {
+ mtInEvent.add(type);
+ mtInStorage.add(mtHandler.findMembershipType(type.getName()));
+ }
+ }
+}
Added: core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestUserHandler.java
===================================================================
--- core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestUserHandler.java (rev 0)
+++ core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestUserHandler.java 2011-09-28 11:50:25 UTC (rev 4996)
@@ -0,0 +1,331 @@
+/*
+ * Copyright (C) 2003-2008 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.tck.organization;
+
+import org.exoplatform.services.organization.Query;
+import org.exoplatform.services.organization.User;
+import org.exoplatform.services.organization.UserEventListener;
+import org.exoplatform.services.organization.UserEventListenerHandler;
+
+import java.util.Calendar;
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
+ * @version $Id: TestOrganizationService.java 111 2008-11-11 11:11:11Z $
+ */
+public class TestUserHandler extends AbstractOrganizationServiceTest
+{
+
+ /**
+ * User authentication.
+ */
+ public void testAuthenticate() throws Exception
+ {
+ // authentication with existed user and correct password
+ assertTrue(uHandler.authenticate("demo", "exo"));
+
+ // unknown user authentication
+ assertFalse(uHandler.authenticate("demo_", "exo"));
+
+ // authentication with wrong password
+ assertFalse(uHandler.authenticate("demo", "exo_"));
+ }
+
+ /**
+ * Find user by name.
+ */
+ public void testFindUserByName() throws Exception
+ {
+ // try to find existed user
+ User u = uHandler.findUserByName("demo");
+
+ assertNotNull(u);
+ assertEquals("demo at localhost", u.getEmail());
+ assertEquals("Demo", u.getFirstName());
+ assertEquals("exo", u.getLastName());
+ assertEquals("exo", u.getPassword());
+ assertEquals("demo", u.getUserName());
+
+ // try to find not existed user. We are supposed to get "null" instead of Exception.
+ try
+ {
+ assertNull(uHandler.findUserByName("not-existed-user"));
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Find users by query.
+ */
+ public void testFindUsersByQuery() throws Exception
+ {
+ createUser("tolik");
+
+ Query query = new Query();
+ query.setEmail("email at test");
+
+ // try to find user by email
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by name with mask
+ query = new Query();
+ query.setUserName("*tolik*");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by name with mask
+ query = new Query();
+ query.setUserName("tol*");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by name with mask
+ query = new Query();
+ query.setUserName("*lik");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by name explicitly
+ query = new Query();
+ query.setUserName("tolik");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by name explicitly, case sensitive search
+ query = new Query();
+ query.setUserName("Tolik");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by part of name without mask
+ query = new Query();
+ query.setUserName("tol");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by fist and last names, case sensitive search
+ query = new Query();
+ query.setFirstName("fiRst");
+ query.setLastName("lasT");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by login date
+ Calendar calc = Calendar.getInstance();
+ calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) - 1);
+
+ query = new Query();
+ query.setFromLoginDate(calc.getTime());
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ calc = Calendar.getInstance();
+ calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) + 1);
+
+ query = new Query();
+ query.setFromLoginDate(calc.getTime());
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 0);
+
+ calc = Calendar.getInstance();
+ calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) - 1);
+
+ query = new Query();
+ query.setToLoginDate(calc.getTime());
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 0);
+
+ calc = Calendar.getInstance();
+ calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) + 1);
+
+ query = new Query();
+ query.setToLoginDate(calc.getTime());
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+ }
+
+ /**
+ * Find users.
+ */
+ public void testFindUsers() throws Exception
+ {
+ createUser("tolik");
+
+ Query query = new Query();
+ query.setEmail("email at test");
+
+ // try to find user by email
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by name with mask
+ query = new Query();
+ query.setUserName("*tolik*");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by name with mask
+ query = new Query();
+ query.setUserName("tol*");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by name with mask
+ query = new Query();
+ query.setUserName("*lik");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by name explicitly
+ query = new Query();
+ query.setUserName("tolik");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by name explicitly, case sensitive search
+ query = new Query();
+ query.setUserName("Tolik");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by part of name without mask
+ query = new Query();
+ query.setUserName("tol");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by fist and last names, case sensitive search
+ query = new Query();
+ query.setFirstName("fiRst");
+ query.setLastName("lasT");
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ // try to find user by login date
+ Calendar calc = Calendar.getInstance();
+ calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) - 1);
+
+ query = new Query();
+ query.setFromLoginDate(calc.getTime());
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+
+ calc = Calendar.getInstance();
+ calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) + 1);
+
+ query = new Query();
+ query.setFromLoginDate(calc.getTime());
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 0);
+
+ calc = Calendar.getInstance();
+ calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) - 1);
+
+ query = new Query();
+ query.setToLoginDate(calc.getTime());
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 0);
+
+ calc = Calendar.getInstance();
+ calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) + 1);
+
+ query = new Query();
+ query.setToLoginDate(calc.getTime());
+ assertEquals(uHandler.findUsersByQuery(query).getSize(), 1);
+ }
+
+ /**
+ * Get users page list.
+ */
+ public void testGetUserPageList() throws Exception
+ {
+ assertEquals(uHandler.getUserPageList(10).getAll().size(), 4);
+ }
+
+ /**
+ * Find all users.
+ */
+ public void testFindAllUsers() throws Exception
+ {
+ assertEquals(uHandler.findAllUsers().getSize(), 4);
+ }
+
+ /**
+ * Remove user.
+ */
+ public void testRemoveUser() throws Exception
+ {
+ createUser(userName);
+ assertNotNull(uHandler.removeUser(userName, true));
+
+ // try to find user after remove. We are supposed to get "null" instead of exception
+ try
+ {
+ assertNull(uHandler.findUserByName(userName + "_"));
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Save user.
+ */
+ public void testSaveUser() throws Exception
+ {
+ createUser(userName);
+
+ String newEmail = "new at Email";
+
+ // change email and check
+ User u = uHandler.findUserByName(userName);
+ u.setEmail(newEmail);
+
+ uHandler.saveUser(u, true);
+ assertEquals(newEmail, uHandler.findUserByName(userName).getEmail());
+
+ // change name
+ u = uHandler.findUserByName(userName);
+ u.setUserName(newUserName);
+ uHandler.saveUser(u, true);
+
+ // we should to find user with new name but not with old one
+ assertNotNull(uHandler.findUserByName(newUserName));
+ assertNull(uHandler.findUserByName(userName));
+ }
+
+ /**
+ * Create user.
+ */
+ public void testCreateUser() throws Exception
+ {
+ User u = uHandler.createUserInstance(userName);
+ u.setEmail("email at test");
+ u.setFirstName("first");
+ u.setLastName("last");
+ u.setPassword("pwd");
+ uHandler.createUser(u, true);
+
+ // check if user exists
+ assertNotNull(uHandler.findUserByName(userName));
+ }
+
+ /**
+ * Test get listeners.
+ */
+ public void testGetListeners() throws Exception
+ {
+ if (uHandler instanceof UserEventListenerHandler)
+ {
+ List<UserEventListener> list = ((UserEventListenerHandler) uHandler).getUserListeners();
+ try
+ {
+ // check if we able to modify the list of listeners
+ list.clear();
+ fail("Exception should not be thrown");
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ }
+}
Added: core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestUserProfileHandler.java
===================================================================
--- core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestUserProfileHandler.java (rev 0)
+++ core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestUserProfileHandler.java 2011-09-28 11:50:25 UTC (rev 4996)
@@ -0,0 +1,158 @@
+/**
+ *
+ */
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.tck.organization;
+
+import org.exoplatform.services.organization.UserProfile;
+import org.exoplatform.services.organization.UserProfileEventListener;
+import org.exoplatform.services.organization.UserProfileEventListenerHandler;
+
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
+ * @version $Id: TestUserProfileHandlerImpl.java 111 2008-11-11 11:11:11Z $
+ */
+public class TestUserProfileHandler extends AbstractOrganizationServiceTest
+{
+ /**
+ * Find user profile by name.
+ */
+ public void testFindUserProfileByName() throws Exception
+ {
+ createUser(userName);
+ createUserProfile(userName);
+
+ UserProfile up = upHandler.findUserProfileByName(userName);
+ assertNotNull(up);
+ assertEquals(userName, up.getUserName());
+ assertEquals("value1", up.getAttribute("key1"));
+ assertEquals("value2", up.getAttribute("key2"));
+
+ // try to find profile for not existed user. We are supposed to get "null" instead of Exception
+ try
+ {
+ assertNull(upHandler.findUserProfileByName(newUserName));
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+
+ // try to find not existed profile. We are supposed to get "null" instead of Exception
+ createUser(newUserName);
+ try
+ {
+ assertNull(upHandler.findUserProfileByName(newUserName));
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Find user profiles.
+ */
+ public void testFindUserProfiles() throws Exception
+ {
+ createUser(userName);
+ createUserProfile(userName);
+
+ createUser(newUserName);
+ createUserProfile(newUserName);
+
+ assertEquals(upHandler.findUserProfiles().size(), 2);
+ }
+
+ /**
+ * Remove user profile.
+ */
+ public void testRemoveUserProfile() throws Exception
+ {
+ createUser(userName);
+ createUserProfile(userName);
+
+ UserProfile up = upHandler.removeUserProfile(userName, true);
+ assertNotNull(up);
+ assertEquals(up.getAttribute("key1"), "value1");
+ assertEquals(up.getAttribute("key2"), "value2");
+ assertNull(upHandler.findUserProfileByName("userP1"));
+
+ // remove not existed profile. We are supposed to get "null" instead of Exception
+ try
+ {
+ assertNull(upHandler.removeUserProfile(newUserName, true));
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Save user profile.
+ */
+ public void testSaveUserProfile() throws Exception
+ {
+ createUser(userName);
+ createUserProfile(userName);
+
+ UserProfile up = upHandler.findUserProfileByName(userName);
+ up.setAttribute("key1", "value11");
+ up.setAttribute("key2", null);
+ upHandler.saveUserProfile(up, true);
+
+ up = upHandler.findUserProfileByName(userName);
+ assertEquals(up.getAttribute("key1"), "value11");
+ assertNull(up.getAttribute("key2"));
+
+ // try to save user profile for not existed user
+ try
+ {
+ up = upHandler.createUserProfileInstance(newUserName);
+ upHandler.saveUserProfile(up, true);
+ }
+ catch (Exception e)
+ {
+ fail("Exception should not be thrown");
+ }
+ }
+
+ /**
+ * Test get listeners.
+ */
+ public void testGetListeners() throws Exception
+ {
+ if (upHandler instanceof UserProfileEventListenerHandler)
+ {
+ List<UserProfileEventListener> list = ((UserProfileEventListenerHandler) upHandler).getUserProfileListeners();
+ try
+ {
+ list.clear();
+ fail("We should not able to modife list of listeners");
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ }
+}
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2011-09-28 10:27:01 UTC (rev 4995)
+++ core/trunk/pom.xml 2011-09-28 11:50:25 UTC (rev 4996)
@@ -56,6 +56,7 @@
<module>exo.core.component.organization.api</module>
<module>exo.core.component.organization.jdbc</module>
<module>exo.core.component.organization.ldap</module>
+ <module>exo.core.component.organization.tests</module>
<module>exo.core.component.xml-processing</module>
<module>exo.core.component.script.groovy</module>
<module>exo.core.component.web.css</module>
@@ -128,6 +129,14 @@
<dependency>
<groupId>org.exoplatform.core</groupId>
+ <artifactId>exo.core.component.organization.tests</artifactId>
+ <version>${project.version}</version>
+ <classifier>sources</classifier>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.core</groupId>
<artifactId>exo.core.component.security.core</artifactId>
<version>${project.version}</version>
</dependency>
More information about the exo-jcr-commits
mailing list