diff --git a/exo.core.component.database/pom.xml b/exo.core.component.database/pom.xml
index 44a52b322..cb5481595 100644
--- a/exo.core.component.database/pom.xml
+++ b/exo.core.component.database/pom.xml
@@ -81,7 +81,7 @@
jboss-logging
- org.hibernate
+ org.hibernate.orm
hibernate-core
diff --git a/exo.core.component.database/src/main/java/org/exoplatform/services/database/DBObjectPageList.java b/exo.core.component.database/src/main/java/org/exoplatform/services/database/DBObjectPageList.java
index 70324fcd3..90ed43c57 100644
--- a/exo.core.component.database/src/main/java/org/exoplatform/services/database/DBObjectPageList.java
+++ b/exo.core.component.database/src/main/java/org/exoplatform/services/database/DBObjectPageList.java
@@ -18,15 +18,16 @@
*/
package org.exoplatform.services.database;
-import org.exoplatform.commons.utils.PageList;
-import org.hibernate.Query;
-import org.hibernate.Session;
-
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.hibernate.Session;
+import org.hibernate.query.Query;
+
+import org.exoplatform.commons.utils.PageList;
+
/**
* @author Tuan Nguyen (tuan08@users.sourceforge.net)
* @since Oct 21, 2004
diff --git a/exo.core.component.database/src/main/java/org/exoplatform/services/database/impl/HibernateServiceImpl.java b/exo.core.component.database/src/main/java/org/exoplatform/services/database/impl/HibernateServiceImpl.java
index dc5034931..4d8239c7a 100644
--- a/exo.core.component.database/src/main/java/org/exoplatform/services/database/impl/HibernateServiceImpl.java
+++ b/exo.core.component.database/src/main/java/org/exoplatform/services/database/impl/HibernateServiceImpl.java
@@ -150,7 +150,7 @@ final public void closeSession() {
}
public Object findExactOne(Session session, String query, String id) throws Exception {
- Object res = session.createQuery(query).setString("id", id).uniqueResult();
+ Object res = session.createQuery(query).setParameter("id", id).uniqueResult();
if (res == null) {
throw new ObjectNotFoundException("Cannot find the object with id: " + id);
}
@@ -158,7 +158,7 @@ public Object findExactOne(Session session, String query, String id) throws Exce
}
public Object findOne(Session session, String query, String id) throws Exception {
- List> l = session.createQuery(query).setString("id", id).list();
+ List> l = session.createQuery(query).setParameter("id", id).list();
if (l.size() == 0) {
return null;
} else if (l.size() > 1) {
diff --git a/exo.core.component.organization.api/pom.xml b/exo.core.component.organization.api/pom.xml
index 1cd4e74ea..a8ccba93c 100644
--- a/exo.core.component.organization.api/pom.xml
+++ b/exo.core.component.organization.api/pom.xml
@@ -48,7 +48,11 @@
exo.core.component.security.core
- org.hibernate
+ org.apache.commons
+ commons-lang3
+
+
+ org.hibernate.orm
hibernate-core
diff --git a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/externalstore/IDMExternalStoreImportService.java b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/externalstore/IDMExternalStoreImportService.java
index e14d8b65f..44976c061 100644
--- a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/externalstore/IDMExternalStoreImportService.java
+++ b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/externalstore/IDMExternalStoreImportService.java
@@ -4,7 +4,7 @@
import java.util.*;
import java.util.function.Consumer;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.services.organization.impl.UserImpl;
import org.picocontainer.Startable;
diff --git a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/externalstore/model/IDMQueueEntry.java b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/externalstore/model/IDMQueueEntry.java
index f46406a37..2268d67c8 100644
--- a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/externalstore/model/IDMQueueEntry.java
+++ b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/externalstore/model/IDMQueueEntry.java
@@ -3,7 +3,7 @@
import java.util.Calendar;
import java.util.Objects;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
/**
* IDM Queue entry DTO
diff --git a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/GroupImpl.java b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/GroupImpl.java
index 8b0d87b29..56505fa64 100644
--- a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/GroupImpl.java
+++ b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/GroupImpl.java
@@ -26,12 +26,17 @@
import java.util.Objects;
-import javax.persistence.*;
-
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
-import org.exoplatform.services.organization.*;
+import org.exoplatform.services.organization.ExtendedCloneable;
+import org.exoplatform.services.organization.Group;
+import org.exoplatform.services.organization.OrganizationService;
+
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+import jakarta.persistence.Table;
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
diff --git a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipImpl.java b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipImpl.java
index b361137fb..cd74dc262 100644
--- a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipImpl.java
+++ b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipImpl.java
@@ -18,16 +18,18 @@
*/
package org.exoplatform.services.organization.impl;
-import org.exoplatform.services.organization.ExtendedCloneable;
-import org.exoplatform.services.organization.Membership;
+import java.util.Objects;
+
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import java.util.Objects;
+import org.exoplatform.services.organization.ExtendedCloneable;
+import org.exoplatform.services.organization.Membership;
+
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+import jakarta.persistence.Table;
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
diff --git a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipTypeImpl.java b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipTypeImpl.java
index 803e1fdfb..c63e20d80 100644
--- a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipTypeImpl.java
+++ b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/MembershipTypeImpl.java
@@ -18,17 +18,19 @@
*/
package org.exoplatform.services.organization.impl;
-import org.exoplatform.services.organization.ExtendedCloneable;
-import org.exoplatform.services.organization.MembershipType;
+import java.util.Date;
+import java.util.Objects;
+
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import java.util.Date;
-import java.util.Objects;
+import org.exoplatform.services.organization.ExtendedCloneable;
+import org.exoplatform.services.organization.MembershipType;
+
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+import jakarta.persistence.Table;
/**
* Created by The eXo Platform SAS .
diff --git a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/UserImpl.java b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/UserImpl.java
index 88a53a770..7f662a667 100644
--- a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/UserImpl.java
+++ b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/impl/UserImpl.java
@@ -18,17 +18,20 @@
*/
package org.exoplatform.services.organization.impl;
+import java.util.Date;
+import java.util.Objects;
+
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
-import org.exoplatform.services.organization.*;
+import org.exoplatform.services.organization.ExtendedCloneable;
+import org.exoplatform.services.organization.OrganizationService;
+import org.exoplatform.services.organization.User;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import java.util.Date;
-import java.util.Objects;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+import jakarta.persistence.Table;
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
diff --git a/exo.core.component.organization.tests/pom.xml b/exo.core.component.organization.tests/pom.xml
deleted file mode 100644
index 912ce8ce5..000000000
--- a/exo.core.component.organization.tests/pom.xml
+++ /dev/null
@@ -1,74 +0,0 @@
-
-
-
-
-
- 4.0.0
-
-
- org.exoplatform.core
- core-parent
- 6.6.x-SNAPSHOT
-
-
- exo.core.component.organization.tests
-
- eXo PLF Core :: Component :: Organization Service Tests
- Organisation Service TCK tests of Exoplatform SAS 'eXo Core' project.
-
-
-
- true
-
-
-
- junit
- junit
- provided
-
-
- org.exoplatform.core
- exo.core.component.organization.api
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
-
-
- attach-sources
- generate-sources
-
- test-jar-no-fork
-
-
-
-
-
-
-
diff --git a/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/AbstractOrganizationServiceTest.java b/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/AbstractOrganizationServiceTest.java
deleted file mode 100644
index 08679e0f7..000000000
--- a/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/AbstractOrganizationServiceTest.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * 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.
- */
-package org.exoplatform.services.tck.organization;
-
-import junit.framework.TestCase;
-
-import org.exoplatform.commons.utils.ListAccess;
-import org.exoplatform.container.StandaloneContainer;
-import org.exoplatform.container.component.RequestLifeCycle;
-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 org.exoplatform.services.organization.UserStatus;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Created by The eXo Platform SAS.
- *
- *
Date: 2011
- *
- * @author Alex Reshetnyak
- * @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 users = new ArrayList();
-
- /**
- * The list of membership types which have been created during test.
- * Will be removed in tearDown() method.
- */
- private List types = new ArrayList();
-
- /**
- * The list of group which have been created during test.
- * Will be removed in tearDown() method.
- */
- private List groups = new ArrayList();
-
- /**
- * {@inheritDoc}
- */
- public void setUp() throws Exception
- {
- super.setUp();
-
-
- String configPath = System.getProperty("orgservice.test.configuration.file");
- if (configPath == null)
- {
- configPath = "/conf/standalone/test-configuration.xml";
- }
-
- String containerConf = getClass().getResource(configPath).toString();
-
- StandaloneContainer.addConfigurationURL(containerConf);
- container = StandaloneContainer.getInstance();
-
- 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);
-
- RequestLifeCycle.begin(container);
- }
-
- /**
- * Create new user for test purpose only.
- */
- protected void createUser(String userName) throws Exception
- {
- User u = uHandler.createUserInstance(userName);
- u.setEmail("email@test");
- u.setFirstName("first");
- u.setLastLoginTime(Calendar.getInstance().getTime());
- u.setCreatedDate(Calendar.getInstance().getTime());
- u.setLastName("last");
- u.setPassword("pwdADDSomeSaltToBeCompliantWithSomeIS00");
-
- uHandler.createUser(u, true);
-
- users.add(userName);
- }
-
- /**
- * Create user with profile.
- */
- protected void createUserProfile(String userName) throws Exception
- {
- UserProfile up = upHandler.createUserProfileInstance(userName);
- Map attributes = up.getUserInfoMap();
- attributes.put("key1", "value1");
- attributes.put("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 = parentId == null ? null : 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, "label", "desc");
- createMembershipType(type, "desc");
-
- // link membership
- mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName), mtHandler
- .findMembershipType(type), true);
- }
-
- /**
- * Create new group instance.
- */
- protected Group createGroupInstance(String name) throws Exception
- {
- createGroup(null, name, "label", "desc");
- return gHandler.removeGroup(gHandler.findGroupById("/" + name), true);
- }
-
- /**
- * {@inheritDoc}
- */
- public void tearDown() throws Exception
- {
-
- RequestLifeCycle.end();
- RequestLifeCycle.begin(container);
-
- // remove all users
- Iterator 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();
-
- removeGroups(groupId);
- iter.remove();
- }
-
- RequestLifeCycle.end();
- super.tearDown();
- }
-
- private void removeGroups(String parentId) throws Exception
- {
- Group group = gHandler.findGroupById(parentId);
- if (group != null)
- {
-
- Collection childs = gHandler.findGroups(group);
- for (Group child : childs)
- {
- removeGroups(child.getId());
- }
-
- gHandler.removeGroup(group, true);
- }
- }
-
- protected void assertSizeEquals(int expectedSize, ListAccess> list) throws Exception
- {
- int size;
- assertEquals(expectedSize, size = list.getSize());
- Object[] values = list.load(0, size);
- size = 0;
- for (int i = 0; i < values.length; i++)
- {
- if (values[i] != null)
- {
- size++;
- }
- }
- assertEquals(expectedSize, size);
- }
-
- protected void assertSizeEquals(int expectedSize, Collection> list) throws Exception
- {
- int size;
- assertEquals(expectedSize, list.size());
- size = 0;
- for (Object value : list)
- {
- if (value != null)
- {
- size++;
- }
- }
- assertEquals(expectedSize, size);
- }
-
- protected void assertSizeEquals(int expectedSize, ListAccess list, UserStatus status) throws Exception
- {
- int size;
- assertEquals(expectedSize, size = list.getSize());
- User[] values = list.load(0, size);
- size = 0;
- for (int i = 0; i < values.length; i++)
- {
- User usr = values[i];
- if (usr != null && status.matches(usr.isEnabled()))
- {
- size++;
- }
- }
- assertEquals(expectedSize, size);
- }
-}
diff --git a/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestGroupHandler.java b/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestGroupHandler.java
deleted file mode 100644
index 347583d95..000000000
--- a/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestGroupHandler.java
+++ /dev/null
@@ -1,480 +0,0 @@
-/*
- * 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.
- */
-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 org.exoplatform.services.organization.MembershipTypeHandler;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * @author Anatoliy Bazko
- * @version $Id: TestOrganizationService.java 111 2008-11-11 11:11:11Z $
- */
-public class TestGroupHandler extends AbstractOrganizationServiceTest
-{
-
- private MyGroupEventListener listener;
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- listener = new MyGroupEventListener();
- gHandler.addGroupEventListener(listener);
- }
-
- @Override
- public void tearDown() throws Exception
- {
- gHandler.removeGroupEventListener(listener);
- super.tearDown();
- }
-
- /**
- * 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");
- }
-
- // Check the listener's counters
- assertEquals(0, listener.preSaveNew);
- assertEquals(0, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * Find groups by user.
- */
- public void testFindGroupsByUser() throws Exception
- {
- assertSizeEquals(3, gHandler.findGroupsOfUser("john"));
- assertSizeEquals(0, gHandler.findGroupsOfUser("fake-user"));
-
- createMembership(userName, groupName1, membershipType);
- createGroup(null, groupName2, "label", "desc");
- mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName2),
- mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE), true);
-
- Collection groups;
- assertSizeEquals(2, groups = gHandler.findGroupsOfUser(userName));
- Set groupNames = new HashSet();
- for (Group g : groups)
- {
- groupNames.add(g.getGroupName());
- }
- assertTrue(groupNames.contains(groupName1));
- assertTrue(groupNames.contains(groupName2));
-
- Iterator it = groups.iterator();
- gHandler.removeGroup(it.next(), true);
-
- assertSizeEquals(1, gHandler.findGroupsOfUser(userName));
-
- gHandler.removeGroup(it.next(), true);
-
- assertSizeEquals(0, gHandler.findGroupsOfUser(userName));
-
- createMembership(userName + "2", groupName2, membershipType + "2");
-
- assertSizeEquals(1, gHandler.findGroupsOfUser(userName + "2"));
-
- mHandler.removeMembershipByUser(userName + "2", false);
-
- assertSizeEquals(0, gHandler.findGroupsOfUser(userName + "2"));
-
- createMembership(userName + "3", groupName2 + "3", membershipType + "3");
-
- assertSizeEquals(1, gHandler.findGroupsOfUser(userName + "3"));
-
- uHandler.removeUser(userName + "3", false);
-
- assertSizeEquals(0, gHandler.findGroupsOfUser(userName + "3"));
-
- // Check the listener's counters
- assertEquals(4, listener.preSaveNew);
- assertEquals(4, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(2, listener.preDelete);
- assertEquals(2, listener.postDelete);
- }
-
- /**
- * Find groups.
- */
- public void testFindGroups() throws Exception
- {
- assertSizeEquals(4, gHandler.findGroups(null));
- assertSizeEquals(2, gHandler.findGroups(gHandler.findGroupById("/organization/operations")));
- assertSizeEquals(0, gHandler.findGroups(gHandler.findGroupById("/organization/management/executive-board")));
-
- // Check the listener's counters
- assertEquals(0, listener.preSaveNew);
- assertEquals(0, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * Get all groups.
- */
- public void testGetAllGroups() throws Exception
- {
- assertSizeEquals(16, gHandler.getAllGroups());
-
- // Check the listener's counters
- assertEquals(0, listener.preSaveNew);
- assertEquals(0, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * Get groups by keyword.
- */
- public void testGetGroupsByKeyword() throws Exception
- {
- try {
- assertSizeEquals(2, gHandler.findGroupsByKeyword("us")); // customers and users
- assertSizeEquals(1, gHandler.findGroupsByKeyword("ad")); // administrators
-
- // Check the listener's counters
- assertEquals(0, listener.preSaveNew);
- assertEquals(0, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- } catch (UnsupportedOperationException e) {
- // Catch unsupported implementations for ldap and hibernate
- }
- }
-
- /**
- * Remove group.
- */
- public void testRemoveGroup() throws Exception
- {
- createUser(userName);
- createGroup("/organization", groupName1, "label", "desc");
- createGroup("/organization/" + groupName1, groupName2, "label", "desc");
-
- createMembership(newUserName, groupName2, membershipType);
- assertEquals("We expect to find single membership for user " + newUserName, 1,
- mHandler.findMembershipsByUser(newUserName).size());
-
- // can not remove group till children exist
- try
- {
- gHandler.removeGroup(gHandler.findGroupById("/organization/group1"), true);
- fail("");
- }
- catch (Exception e)
- {
- }
-
- gHandler.removeGroup(gHandler.findGroupById("/organization/group1/group2"), true);
- Group group = gHandler.removeGroup(gHandler.findGroupById("/organization/group1"), true);
-
- assertNull(gHandler.findGroupById("/organization/group1"));
- assertNull(gHandler.findGroupById("/organization/group1/group2"));
-
- gHandler.removeGroup(gHandler.findGroupById("/" + groupName2), true);
- assertEquals("We expect to find no membership for user " + newUserName, 0,
- mHandler.findMembershipsByUser(newUserName).size());
-
- // 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 + "/" + groupName2), true);
- gHandler.removeGroup(gHandler.findGroupById("/" + groupName1), true);
- assertNull(gHandler.findGroupById("/" + groupName1));
- assertNull(gHandler.findGroupById("/" + groupName1 + "/" + groupName2));
-
- // Check the listener's counters
- assertEquals(5, listener.preSaveNew);
- assertEquals(5, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(5, listener.preDelete);
- assertEquals(5, listener.postDelete);
- }
-
- /**
- * Add child.
- */
- public void testAddChild() throws Exception
- {
- Group parent = createGroupInstance(groupName1);
- Group child = createGroupInstance(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));
-
- // Check the listener's counters
- assertEquals(2, listener.preSaveNew);
- assertEquals(2, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(2, listener.preDelete);
- assertEquals(2, listener.postDelete);
- }
-
- /**
- * Test add new group same name with existing one
- * @throws Exception
- */
- public void testAddDuplicateChild() throws Exception {
- // Create parent group
- String parentName = "testAddDuplicateChild_GroupParent";
- Group groupParent = gHandler.createGroupInstance();
- groupParent.setGroupName(parentName);
- groupParent.setLabel("GroupParent Label");
- groupParent.setDescription("This is description");
- gHandler.addChild(null, groupParent, true);
- assertEquals(gHandler.findGroupById(groupParent.getId()).getLabel(), "GroupParent Label");
-
- /* Create a child group with name: Group1 */
- Group groupChild1 = gHandler.createGroupInstance();
- groupChild1.setGroupName("testAddDuplicateChild");
- groupChild1.setLabel("Group1 Label");
- gHandler.addChild(groupParent, groupChild1, true);
- assertEquals(gHandler.findGroupById(groupChild1.getId()).getLabel(), "Group1 Label");
-
- try {
- // Add new child same name with existing one
- Group groupChild2 = gHandler.createGroupInstance();
- groupChild2.setGroupName("testAddDuplicateChild");
- groupChild2.setLabel("Group2 Label");
- gHandler.addChild(groupParent, groupChild2, true);
-
- fail("Exception should be thrown because group child is existing");
- } catch (Exception ex) {
-
- }
- // Label of the existing group is not updated
- assertEquals(gHandler.findGroupById(groupChild1.getId()).getLabel(), "Group1 Label");
-
- // remove child group
- gHandler.removeGroup(gHandler.findGroupById(groupChild1.getId()),true);
- // remove parent group
- gHandler.removeGroup(gHandler.findGroupById(groupParent.getId()),true);
- }
-
- /**
- * Create group.
- */
- @SuppressWarnings("deprecation")
- public void testCreateGroup() throws Exception
- {
- Group group = gHandler.createGroupInstance();
- group.setGroupName(groupName1);
- group.setLabel("label");
- 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");
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(1, listener.preSave);
- assertEquals(1, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * Test get listeners.
- */
- public void testGetListeners() throws Exception
- {
- if (gHandler instanceof GroupEventListenerHandler)
- {
- List list = ((GroupEventListenerHandler) gHandler).getGroupListeners();
- try
- {
- list.clear();
- fail("We are not supposed to be able to change list of listeners.");
- }
- catch (Exception e)
- {
- }
- }
- }
-
- private static class MyGroupEventListener extends GroupEventListener
- {
- public int preSaveNew, postSaveNew;
- public int preSave, postSave;
- public int preDelete, postDelete;
-
- @Override
- public void preSave(Group group, boolean isNew) throws Exception
- {
- if (group == null)
- return;
- if (isNew)
- preSaveNew++;
- else
- preSave++;
- }
-
- @Override
- public void postSave(Group group, boolean isNew) throws Exception
- {
- if (group == null)
- return;
- if (isNew)
- postSaveNew++;
- else
- postSave++;
- }
-
- @Override
- public void preDelete(Group group) throws Exception
- {
- if (group == null)
- return;
- preDelete++;
- }
-
- @Override
- public void postDelete(Group group) throws Exception
- {
- if (group == null)
- return;
- postDelete++;
- }
- }
-
- public void testFindGroupByMembership() throws Exception
- {
- createMembership(userName, groupName1, membershipType);
- createGroup(null, groupName2, "label", "desc");
- mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE);
- mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName2),
- mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE), false);
- Collection groups = gHandler.findGroupByMembership(userName, membershipType);
- assertNotNull(groups);
- assertEquals(1, groups.size());
- assertEquals(groupName1, groups.iterator().next().getGroupName());
-
- groups = gHandler.findGroupByMembership(userName, MembershipTypeHandler.ANY_MEMBERSHIP_TYPE);
- assertNotNull(groups);
- assertEquals(1, groups.size());
- assertEquals(groupName2, groups.iterator().next().getGroupName());
- }
-
- public void testResolveGroupByMembership() throws Exception
- {
- createMembership(userName, groupName1, membershipType);
- createGroup(null, groupName2, "label", "desc");
- mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName2),
- mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE), false);
- Collection groups = gHandler.resolveGroupByMembership(userName, membershipType);
- assertNotNull(groups);
- assertEquals(2, groups.size());
- Set groupNames = new HashSet();
- for (Group g : groups)
- {
- groupNames.add(g.getGroupName());
- }
- assertTrue(groupNames.contains(groupName1));
- assertTrue(groupNames.contains(groupName2));
-
- groups = gHandler.resolveGroupByMembership(userName, MembershipTypeHandler.ANY_MEMBERSHIP_TYPE);
- assertNotNull(groups);
- assertEquals(1, groups.size());
- assertEquals(groupName2, groups.iterator().next().getGroupName());
- }
-}
diff --git a/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestMembershipHandler.java b/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestMembershipHandler.java
deleted file mode 100644
index e6e77ce3c..000000000
--- a/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestMembershipHandler.java
+++ /dev/null
@@ -1,1119 +0,0 @@
-/*
- * 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.
- */
-package org.exoplatform.services.tck.organization;
-
-import org.exoplatform.commons.utils.ListAccess;
-import org.exoplatform.commons.utils.PageList;
-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.MembershipTypeHandler;
-import org.exoplatform.services.organization.User;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * @author Anatoliy Bazko
- * @version $Id: TestMembershipImpl.java 111 2008-11-11 11:11:11Z $
- */
-public class TestMembershipHandler extends AbstractOrganizationServiceTest
-{
- private MyMembershipEventListener listener;
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- listener = new MyMembershipEventListener();
- mHandler.addMembershipEventListener(listener);
- }
-
- @Override
- public void tearDown() throws Exception
- {
- mHandler.removeMembershipEventListener(listener);
- super.tearDown();
- }
-
- /**
- * Find membership.
- */
- public void testFindMembership() throws Exception
- {
- createMembership(userName, groupName1, membershipType);
-
- Membership m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType);
- assertNotNull(m);
- assertEquals(membershipType, m.getMembershipType());
- assertNotNull(m = mHandler.findMembership(m.getId()));
- assertEquals(membershipType, m.getMembershipType());
-
- // try to find not existed membership. We are supposed to get Exception
- try
- {
- assertNull(mHandler.findMembership("not-existed-id"));
- fail("Exception should be thrown");
- }
- catch (Exception e)
- {
-
- }
-
- mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName1),
- mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE), true);
-
- m =
- mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1,
- MembershipTypeHandler.ANY_MEMBERSHIP_TYPE);
- assertNotNull(m);
- assertEquals(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE, m.getMembershipType());
- assertNotNull(m = mHandler.findMembership(m.getId()));
- assertEquals(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE, m.getMembershipType());
-
- // Check the listener's counters
- assertEquals(2, listener.preSaveNew);
- assertEquals(2, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * 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");
- }
-
- createMembership(userName, groupName1, membershipType);
-
- assertNotNull(m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType));
-
- mHandler.removeMembership(m.getId(), true);
-
- assertNull(mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType));
-
- createMembership(userName + "2", groupName2, membershipType + "2");
-
- assertNotNull(mHandler.findMembershipByUserGroupAndType(userName + "2", "/" + groupName2, membershipType + "2"));
-
- mHandler.removeMembershipByUser(userName + "2", true);
-
- assertNull(mHandler.findMembershipByUserGroupAndType(userName + "2", "/" + groupName2, membershipType + "2"));
-
- createMembership(userName + "3", groupName2 + "3", membershipType + "3");
-
- assertNotNull(mHandler.findMembershipByUserGroupAndType(userName + "3", "/" + groupName2 + "3", membershipType
- + "3"));
-
- uHandler.removeUser(userName + "3", false);
-
- assertNull(mHandler
- .findMembershipByUserGroupAndType(userName + "3", "/" + groupName2 + "3", membershipType + "3"));
-
- createMembership(userName + "4", groupName2 + "4", membershipType + "4");
-
- assertNotNull(mHandler.findMembershipByUserGroupAndType(userName + "4", "/" + groupName2 + "4", membershipType
- + "4"));
-
- gHandler.removeGroup(gHandler.findGroupById("/" + groupName2 + "4"), false);
-
- assertNull(mHandler
- .findMembershipByUserGroupAndType(userName + "4", "/" + groupName2 + "4", membershipType + "4"));
-
- // Check the listener's counters
- assertEquals(4, listener.preSaveNew);
- assertEquals(4, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(2, listener.preDelete);
- assertEquals(2, listener.postDelete);
- }
-
- /**
- * Test find all membershipTypes linked to this group
- * @throws Exception
- */
- public void testFindMembershipTypesByGroup() throws Exception {
-
- Group users, testGroup = null;
- try {
- createUser(userName);
- assertEquals(1, mHandler.findMembershipTypesByGroup("/platform/users").size());
-
- testGroup = gHandler.createGroupInstance();
- testGroup.setGroupName("testGroup");
- testGroup.setLabel("Testing Group");
- gHandler.addChild(null, testGroup, false);
-
- assertEquals(0, mHandler.findMembershipTypesByGroup("/testGroup").size());
-
- mHandler.linkMembership(uHandler.findUserByName(userName), testGroup,
- mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE), true);
-
- assertEquals(1, mHandler.findMembershipTypesByGroup("/testGroup").size());
-
- // Add another user
- String ali = "ali";
- createUser(ali);
-
- mHandler.linkMembership(uHandler.findUserByName(ali), testGroup,
- mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE), true);
-
- assertEquals(1, mHandler.findMembershipTypesByGroup("/testGroup").size());
-
- createMembershipType(membershipType, "desc");
- mHandler.linkMembership(uHandler.findUserByName(ali), testGroup,
- mtHandler.findMembershipType(membershipType), true);
-
- assertEquals(2, mHandler.findMembershipTypesByGroup("/testGroup").size());
-
-
- Membership membership = mHandler.findMembershipByUserGroupAndType(userName,"/testGroup", MembershipTypeHandler.ANY_MEMBERSHIP_TYPE);
- mHandler.removeMembership(membership.getId(), true);
-
- assertEquals(2, mHandler.findMembershipTypesByGroup("/testGroup").size());
-
- // remove all memberships of ali
- membership = mHandler.findMembershipByUserGroupAndType(ali,"/testGroup", membershipType);
- mHandler.removeMembership(membership.getId(), true);
-
- // we have 2 membership types * and type
- assertEquals(1, mHandler.findMembershipTypesByGroup("/testGroup").size());
- } catch (UnsupportedOperationException unsupportedOperationException) {
- //Expected if this function was not implemented
- }
- }
-
-
- /**
- * Find membership by group.
- */
- public void testFindMembershipsByGroup() throws Exception
- {
- Group g = gHandler.findGroupById("/platform/users");
- assertSizeEquals(4, mHandler.findMembershipsByGroup(g));
-
- // try to find for non-existing group
- g = gHandler.createGroupInstance();
- g.setGroupName(groupName1);
- g.setLabel("label");
- gHandler.addChild(null, g, false);
- assertEquals(g.getId(), gHandler.findGroupById("/" + groupName1).getId());
- g = gHandler.removeGroup(g, false);
- assertSizeEquals(0, mHandler.findMembershipsByGroup(g));
-
- // Check the listener's counters
- assertEquals(0, listener.preSaveNew);
- assertEquals(0, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * Find membership by group.
- */
- public void testFindAllMembershipsByGroup() throws Exception
- {
- Group g = gHandler.findGroupById("/platform/users");
- ListAccess memberships = mHandler.findAllMembershipsByGroup(g);
- assertSizeEquals(4, memberships);
-
- 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");
- }
- // test case removed from tck organization PLF-7379
- // no need to improve ldap and jdbc implementation : it will be removed on 5.0
-
- /* try
- {
- memberships.load(1, 4);
- fail("Exception should be thrown");
- }
- catch (Exception e)
- {
-
- }*/
-
- // try to find for non-existing group
- g = gHandler.createGroupInstance();
- g.setGroupName(groupName1);
- g.setLabel("label");
- gHandler.addChild(null, g, false);
- assertEquals(g.getId(), gHandler.findGroupById("/" + groupName1).getId());
- g = gHandler.removeGroup(g, true);
- assertSizeEquals(0, mHandler.findMembershipsByGroup(g));
-
- createMembership(userName, groupName1, membershipType);
-
- g = gHandler.findGroupById("/" + groupName1);
-
- assertSizeEquals(1, mHandler.findAllMembershipsByGroup(g));
-
- Membership m;
- assertNotNull(m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType));
-
- mHandler.linkMembership(uHandler.findUserByName(userName), g,
- mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE), true);
-
- assertSizeEquals(2, mHandler.findAllMembershipsByGroup(g));
-
- Set membershipTypes = new HashSet();
- for (Membership mem : mHandler.findAllMembershipsByGroup(g).load(0, 2))
- {
- membershipTypes.add(mem.getMembershipType());
- }
- assertTrue(membershipTypes.contains(membershipType));
- assertTrue(membershipTypes.contains(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- mHandler.removeMembership(m.getId(), true);
-
- assertSizeEquals(1, mHandler.findAllMembershipsByGroup(g));
-
- assertNotNull(m =
- mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1,
- MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- mHandler.removeMembership(m.getId(), true);
-
- assertSizeEquals(0, mHandler.findAllMembershipsByGroup(g));
-
- createMembership(userName + "2", groupName2, membershipType + "2");
-
- g = gHandler.findGroupById("/" + groupName2);
-
- assertSizeEquals(1, mHandler.findAllMembershipsByGroup(g));
-
- mHandler.removeMembershipByUser(userName + "2", true);
-
- assertSizeEquals(0, mHandler.findAllMembershipsByGroup(g));
-
- createMembership(userName + "3", groupName2 + "3", membershipType + "3");
-
- g = gHandler.findGroupById("/" + groupName2 + "3");
-
- assertSizeEquals(1, mHandler.findAllMembershipsByGroup(g));
-
- uHandler.removeUser(userName + "3", false);
-
- assertSizeEquals(0, mHandler.findAllMembershipsByGroup(g));
-
- createMembership(userName + "4", groupName2 + "4", membershipType + "4");
-
- g = gHandler.findGroupById("/" + groupName2 + "4");
-
- assertSizeEquals(1, mHandler.findAllMembershipsByGroup(g));
-
- gHandler.removeGroup(gHandler.findGroupById("/" + groupName2 + "4"), false);
-
- assertSizeEquals(0, mHandler.findAllMembershipsByGroup(g));
-
- // Check the listener's counters
- assertEquals(5, listener.preSaveNew);
- assertEquals(5, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(3, listener.preDelete);
- assertEquals(3, listener.postDelete);
- }
-
- /**
- * Find all memberships by user.
- */
- public void testFindMembershipsByUser() throws Exception
- {
- assertSizeEquals(3, mHandler.findMembershipsByUser("john"));
- assertSizeEquals(0, mHandler.findMembershipsByUser("not-existed-user"));
-
- createMembership(userName, groupName1, membershipType);
-
- assertSizeEquals(1, mHandler.findMembershipsByUser(userName));
-
- Membership m;
- assertNotNull(m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType));
-
- mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName1),
- mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE), true);
-
- assertSizeEquals(2, mHandler.findMembershipsByUser(userName));
-
- Set membershipTypes = new HashSet();
- for (Membership mem : mHandler.findMembershipsByUser(userName))
- {
- membershipTypes.add(mem.getMembershipType());
- }
- assertTrue(membershipTypes.contains(membershipType));
- assertTrue(membershipTypes.contains(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- mHandler.removeMembership(m.getId(), true);
-
- assertSizeEquals(1, mHandler.findMembershipsByUser(userName));
-
- assertNotNull(m =
- mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1,
- MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- mHandler.removeMembership(m.getId(), true);
-
- assertSizeEquals(0, mHandler.findMembershipsByUser(userName));
-
- createMembership(userName + "2", groupName2, membershipType + "2");
-
- assertSizeEquals(1, mHandler.findMembershipsByUser(userName + "2"));
-
- mHandler.removeMembershipByUser(userName + "2", true);
-
- assertSizeEquals(0, mHandler.findMembershipsByUser(userName + "2"));
-
- createMembership(userName + "3", groupName2 + "3", membershipType + "3");
-
- assertSizeEquals(1, mHandler.findMembershipsByUser(userName + "3"));
-
- uHandler.removeUser(userName + "3", false);
-
- assertSizeEquals(0, mHandler.findMembershipsByUser(userName + "3"));
-
- createMembership(userName + "4", groupName2 + "4", membershipType + "4");
-
- assertSizeEquals(1, mHandler.findMembershipsByUser(userName + "4"));
-
- gHandler.removeGroup(gHandler.findGroupById("/" + groupName2 + "4"), false);
-
- assertSizeEquals(0, mHandler.findMembershipsByUser(userName + "4"));
-
- // Check the listener's counters
- assertEquals(5, listener.preSaveNew);
- assertEquals(5, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(3, listener.preDelete);
- assertEquals(3, listener.postDelete);
- }
-
- /**
- * Find all membership by user and group.
- */
- public void testFindMembershipsByUserAndGroup() throws Exception
- {
- assertSizeEquals(1, mHandler.findMembershipsByUserAndGroup("john", "/platform/users"));
-
- // try to find not existed membership. We are supposed to get null instead of Exception
- try
- {
- assertSizeEquals(0, mHandler.findMembershipsByUserAndGroup("non-existed-john", "/platform/users"));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- try
- {
- assertSizeEquals(0, mHandler.findMembershipsByUserAndGroup("john", "/non-existed-group"));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- createMembership(userName, groupName1, membershipType);
-
- assertSizeEquals(1, mHandler.findMembershipsByUserAndGroup(userName, "/" + groupName1));
-
- Membership m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType);
- assertNotNull(m);
- assertEquals(membershipType, m.getMembershipType());
-
- mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName1),
- mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE), true);
-
- assertSizeEquals(2, mHandler.findMembershipsByUserAndGroup(userName, "/" + groupName1));
-
- Set membershipTypes = new HashSet();
- for (Membership mem : mHandler.findMembershipsByUserAndGroup(userName, "/" + groupName1))
- {
- membershipTypes.add(mem.getMembershipType());
- }
- assertTrue(membershipTypes.contains(membershipType));
- assertTrue(membershipTypes.contains(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- m = mHandler.removeMembership(m.getId(), true);
- assertNotNull(m);
- assertEquals(membershipType, m.getMembershipType());
-
- assertSizeEquals(1, mHandler.findMembershipsByUserAndGroup(userName, "/" + groupName1));
-
- m =
- mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1,
- MembershipTypeHandler.ANY_MEMBERSHIP_TYPE);
- assertNotNull(m);
- assertEquals(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE, m.getMembershipType());
-
- m = mHandler.removeMembership(m.getId(), true);
-
- assertNotNull(m);
- assertEquals(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE, m.getMembershipType());
-
- assertSizeEquals(0, mHandler.findMembershipsByUserAndGroup(userName, "/" + groupName1));
-
- createMembership(userName + "2", groupName2, membershipType + "2");
-
- assertSizeEquals(1, mHandler.findMembershipsByUserAndGroup(userName + "2", "/" + groupName2));
-
- mHandler.removeMembershipByUser(userName + "2", true);
-
- assertSizeEquals(0, mHandler.findMembershipsByUserAndGroup(userName + "2", "/" + groupName2));
-
- createMembership(userName + "3", groupName2 + "3", membershipType + "3");
-
- assertSizeEquals(1, mHandler.findMembershipsByUserAndGroup(userName + "3", "/" + groupName2 + "3"));
-
- uHandler.removeUser(userName + "3", false);
-
- assertSizeEquals(0, mHandler.findMembershipsByUserAndGroup(userName + "3", "/" + groupName2 + "3"));
-
- createMembership(userName + "4", groupName2 + "4", membershipType + "4");
-
- assertSizeEquals(1, mHandler.findMembershipsByUserAndGroup(userName + "4", "/" + groupName2 + "4"));
-
- gHandler.removeGroup(gHandler.findGroupById("/" + groupName2 + "4"), false);
-
- assertSizeEquals(0, mHandler.findMembershipsByUserAndGroup(userName + "4", "/" + groupName2 + "4"));
-
- // Check the listener's counters
- assertEquals(5, listener.preSaveNew);
- assertEquals(5, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(3, listener.preDelete);
- assertEquals(3, listener.postDelete);
- }
-
- /**
- * Link membership.
- */
- public void testLinkMembership() throws Exception
- {
- createUser(userName);
- createGroup(null, groupName1, "label", "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 = createGroupInstance("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)
- {
- }
-
- mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName1),
- mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE), true);
- m =
- mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1,
- MembershipTypeHandler.ANY_MEMBERSHIP_TYPE);
- assertNotNull(m);
-
- // Check the listener's counters
- assertEquals(3, listener.preSaveNew);
- assertEquals(3, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * 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");
- }
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * Remove membership by user.
- */
- public void testRemoveMembershipByUser() throws Exception
- {
- createMembership(userName, groupName1, membershipType);
- assertNotNull(mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType));
-
- mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName1),
- mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE), true);
-
- assertNotNull(mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1,
- MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- Collection memberships;
- assertSizeEquals(2, memberships = mHandler.removeMembershipByUser(userName, true));
- Set membershipNames = new HashSet();
- for (Membership m : memberships)
- {
- membershipNames.add(m.getMembershipType());
- }
- assertTrue(membershipNames.contains(membershipType));
- assertTrue(membershipNames.contains(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- assertNull(mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType));
- assertNull(mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1,
- MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- assertSizeEquals(0, mHandler.findMembershipsByUserAndGroup(userName, "/" + groupName1));
- assertSizeEquals(0, mHandler.findMembershipsByUser(userName));
-
- assertNull(mHandler.findMembershipByUserGroupAndType(userName, "/group", membershipType));
-
- // try to remove memberships by not existed users. We are supposed to get empty list instead of Exception
- try
- {
- assertSizeEquals(0, mHandler.removeMembershipByUser("not-existed-user", true));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- // Check the listener's counters
- assertEquals(2, listener.preSaveNew);
- assertEquals(2, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(2, listener.preDelete);
- assertEquals(2, listener.postDelete);
- }
-
- /**
- * Find group by membership.
- */
- public void testFindGroupByMembership() throws Exception
- {
- createMembership(userName, groupName1, membershipType);
- assertSizeEquals(1, gHandler.findGroupByMembership(userName, membershipType));
-
- // try to find groups by not existed entries. We supposed to get empty list instead of Exception
- try
- {
- assertSizeEquals(0, gHandler.findGroupByMembership("not-existed-john", membershipType));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- mHandler.removeMembershipByUser(userName, true);
- try
- {
- assertSizeEquals(0, gHandler.findGroupByMembership(userName, membershipType));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- createMembership(userName + "2", groupName2, "foo");
-
- assertSizeEquals(1, gHandler.findGroupByMembership(userName + "2", "foo"));
-
- uHandler.removeUser(userName + "2", false);
-
- try
- {
- assertSizeEquals(0, gHandler.findGroupByMembership(userName + "2", "foo"));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- // Check the listener's counters
- assertEquals(2, listener.preSaveNew);
- assertEquals(2, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * Find groups of user.
- */
- public void testFindGroupsOfUser() throws Exception
- {
- assertSizeEquals(3, gHandler.findGroupsOfUser("john"));
-
- // try to find groups by not existed entries. We supposed to get empty list instead of Exception
- try
- {
- assertSizeEquals(0, gHandler.findGroupsOfUser("not-existed-james"));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- // Check the listener's counters
- assertEquals(0, listener.preSaveNew);
- assertEquals(0, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * Find users by group.
- */
- public void testFindUsersByGroupId() throws Exception
- {
- ListAccess users = uHandler.findUsersByGroupId("/platform/users");
-
- assertSizeEquals(4, users);
-
- for (User u : users.load(0, users.getSize()))
- {
- User currentUrer = uHandler.findUserByName(u.getUserName());
- assertNotNull(currentUrer);
-
- assertEquals(currentUrer.getUserName(), u.getUserName());
- assertEquals(currentUrer.getFirstName(), u.getFirstName());
- assertEquals(currentUrer.getLastName(), u.getLastName());
- assertEquals(currentUrer.getEmail(), u.getEmail());
- assertEquals(currentUrer.getOrganizationId(), u.getOrganizationId());
- }
-
- // try to find users by not existed entries. We supposed to get empty list instead of Exception
- try
- {
- assertSizeEquals(0, uHandler.findUsersByGroupId("/not-existed-group"));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- User[] allPage = users.load(0, 4);
- User[] page1 = users.load(0, 2);
- User[] page2 = users.load(2, 2);
-
- assertEquals(allPage[0].getUserName(), page1[0].getUserName());
- assertEquals(allPage[1].getUserName(), page1[1].getUserName());
- assertEquals(allPage[2].getUserName(), page2[0].getUserName());
- assertEquals(allPage[3].getUserName(), page2[1].getUserName());
-
- try
- {
- users.load(0, 0);
- }
- catch (Exception e)
- {
- fail("Exception is not expected");
- }
-
- // try to load more than exist
- try
- {
- users.load(0, 5);
- fail("Exception is expected");
- }
- catch (Exception e)
- {
- }
-
- // try to load more than exist
- try
- {
- users.load(1, 4);
- fail("Exception is expected");
- }
- catch (Exception e)
- {
- }
-
- // Check the listener's counters
- assertEquals(0, listener.preSaveNew);
- assertEquals(0, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * Find users by group.
- */
- public void testFindUsersByGroup() throws Exception
- {
- PageList usersList = uHandler.findUsersByGroup("/platform/users");
-
- assertSizeEquals(4, usersList.getAll());
-
- for (User u : usersList.getAll())
- {
- User currentUrer = uHandler.findUserByName(u.getUserName());
- assertNotNull(currentUrer);
-
- assertEquals(currentUrer.getUserName(), u.getUserName());
- assertEquals(currentUrer.getFirstName(), u.getFirstName());
- assertEquals(currentUrer.getLastName(), u.getLastName());
- assertEquals(currentUrer.getEmail(), u.getEmail());
- assertEquals(currentUrer.getOrganizationId(), u.getOrganizationId());
- }
-
- // try to find users by not existed entries. We supposed to get empty list instead of Exception
- try
- {
- assertSizeEquals(0, uHandler.findUsersByGroup("/not-existed-group").getAll());
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- // Check the listener's counters
- assertEquals(0, listener.preSaveNew);
- assertEquals(0, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * 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));
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * 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 group = createGroupInstance("not-existed-group");
-
- gHandler.removeGroup(group, true);
-
- fail("Exception should be thrown");
- }
- catch (Exception e)
- {
- }
-
- try
- {
- gHandler.removeGroup(null, true);
- fail("Exception should be thrown");
- }
- catch (Exception e)
- {
- }
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * Remove user.
- */
- public void testRemoveUser() throws Exception
- {
- String userName = "testRemoveUser";
- createMembership(userName, groupName1, membershipType);
-
- uHandler.removeUser(userName, true);
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * Test get listeners.
- */
- public void testGetListeners() throws Exception
- {
- if (mHandler instanceof MembershipEventListenerHandler)
- {
- List list = ((MembershipEventListenerHandler)mHandler).getMembershipListeners();
- try
- {
- list.clear();
- fail("We are not supposed to change list of listners");
- }
- catch (Exception e)
- {
- }
- }
- }
-
- private static class MyMembershipEventListener extends MembershipEventListener
- {
- public int preSaveNew, postSaveNew;
-
- public int preSave, postSave;
-
- public int preDelete, postDelete;
-
- @Override
- public void preSave(Membership m, boolean isNew) throws Exception
- {
- if (m == null)
- return;
- if (!m.getMembershipType().startsWith("type") && !m.getMembershipType().equals("foo")
- && !m.getMembershipType().equals(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE))
- {
- throw new Exception("Unexpected membership type, it should be 'type' or '"
- + MembershipTypeHandler.ANY_MEMBERSHIP_TYPE + "' but was " + m.getMembershipType());
- }
- if (isNew)
- preSaveNew++;
- else
- preSave++;
- }
-
- @Override
- public void postSave(Membership m, boolean isNew) throws Exception
- {
- if (m == null)
- return;
- if (isNew)
- postSaveNew++;
- else
- postSave++;
- }
-
- @Override
- public void preDelete(Membership m) throws Exception
- {
- if (m == null)
- return;
- preDelete++;
- }
-
- @Override
- public void postDelete(Membership m) throws Exception
- {
- if (m == null)
- return;
- postDelete++;
- }
- }
-}
diff --git a/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestMembershipTypeHandler.java b/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestMembershipTypeHandler.java
deleted file mode 100644
index eee4da15b..000000000
--- a/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestMembershipTypeHandler.java
+++ /dev/null
@@ -1,417 +0,0 @@
-/**
- *
- */
-/*
- * 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.
- */
-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 org.exoplatform.services.organization.MembershipTypeHandler;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * @author Anatoliy Bazko
- * @version $Id: TestMembershipTypeHandlerImpl.java 111 2008-11-11 11:11:11Z $
- */
-public class TestMembershipTypeHandler extends AbstractOrganizationServiceTest
-{
- private MyMembershipTypeEventListener listener;
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- listener = new MyMembershipTypeEventListener();
- mtHandler.addMembershipTypeEventListener(listener);
- }
-
- @Override
- public void tearDown() throws Exception
- {
- mtHandler.removeMembershipTypeEventListener(listener);
- super.tearDown();
- }
-
- /**
- * 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_"));
-
- // Check the listener's counters
- assertEquals(0, listener.preSaveNew);
- assertEquals(0, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * Find membership types.
- */
- public void testFindMembershipTypes() throws Exception
- {
- int initSize = 4;
- assertEquals(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE, mtHandler.findMembershipTypes().iterator()
- .next().getName());
-
- assertSizeEquals(initSize, mtHandler.findMembershipTypes());
-
- createMembershipType("type2", "membership type2");
- assertSizeEquals(initSize + 1, mtHandler.findMembershipTypes());
-
- mtHandler.removeMembershipType("type2", true);
- assertSizeEquals(initSize, mtHandler.findMembershipTypes());
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * Remove membership type.
- */
- public void testRemoveMembershipType() throws Exception
- {
- createMembership(userName, groupName1, membershipType);
- assertEquals("We expect to find single membership for user " + userName, 1,
- mHandler.findMembershipsByUser(userName).size());
-
- MembershipType mt = mtHandler.removeMembershipType("type", true);
- assertEquals(mt.getName(), membershipType);
- assertNull(mtHandler.findMembershipType("type"));
- assertEquals("We expect to find no membership for user " + userName, 0, mHandler.findMembershipsByUser(userName)
- .size());
-
- // try to remove not existed membership type. We are supposed to get "null" instead of Exception
- try
- {
- assertNull(mtHandler.removeMembershipType("not-existed-mt", true));
- fail("Exception should be thrown");
- }
- catch (Exception e)
- {
- }
-
- assertNotNull(mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- try
- {
- mtHandler.removeMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE, true);
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
- assertNull(mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
- try
- {
- assertNull(mtHandler.removeMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE, true));
- fail("Exception should be thrown");
- }
- catch (Exception e)
- {
- }
- assertNull(mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- MembershipType anyMT = mtHandler.createMembershipTypeInstance();
- anyMT.setName(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE);
- anyMT.setDescription("desc");
- mtHandler.createMembershipType(anyMT, true);
-
- assertNotNull(mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- // Check the listener's counters
- assertEquals(2, listener.preSaveNew);
- assertEquals(2, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(2, listener.preDelete);
- assertEquals(2, listener.postDelete);
- }
-
- /**
- * 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");
-
- MembershipType anyMT = mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE);
- assertNotNull(anyMT);
-
- try
- {
- mtHandler.saveMembershipType(anyMT, true);
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(2, listener.preSave);
- assertEquals(2, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- public void testCreateMembershipType() throws Exception
- {
- createMembershipType(membershipType, "desc");
- MembershipType mt = mtHandler.findMembershipType(membershipType);
- assertNotNull(mt);
-
- try
- {
- mtHandler.removeMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE, true);
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- assertNull(mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- MembershipType anyMT = mtHandler.createMembershipTypeInstance();
- anyMT.setName(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE);
- anyMT.setDescription("desc");
- try
- {
- mtHandler.createMembershipType(anyMT, true);
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- assertNotNull(mtHandler.findMembershipType(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE));
-
- // Check the listener's counters
- assertEquals(2, listener.preSaveNew);
- assertEquals(2, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * Test get listeners.
- */
- public void testGetListeners() throws Exception
- {
- if (mtHandler instanceof MembershipTypeEventListenerHandler)
- {
- List list =
- ((MembershipTypeEventListenerHandler)mtHandler).getMembershipTypeListeners();
-
- 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();
- int currentSize = 1;
- if (mtHandler instanceof MembershipTypeEventListenerHandler)
- {
- List list =
- ((MembershipTypeEventListenerHandler)mtHandler).getMembershipTypeListeners();
-
- currentSize = list.size();
- }
- mtHandler.addMembershipTypeEventListener(testListener);
-
- if (mtHandler instanceof MembershipTypeEventListenerHandler)
- {
- List list =
- ((MembershipTypeEventListenerHandler)mtHandler).getMembershipTypeListeners();
-
- assertEquals(currentSize + 1, 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());
-
- // 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 mtInEvent = new ArrayList();
-
- List mtInStorage = new ArrayList();
-
- 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()));
- }
- }
-
- private static class MyMembershipTypeEventListener extends MembershipTypeEventListener
- {
- public int preSaveNew, postSaveNew;
- public int preSave, postSave;
- public int preDelete, postDelete;
-
- @Override
- public void preSave(MembershipType type, boolean isNew) throws Exception
- {
- if (type == null)
- return;
- if (isNew)
- preSaveNew++;
- else
- preSave++;
- }
-
- @Override
- public void postSave(MembershipType type, boolean isNew) throws Exception
- {
- if (type == null)
- return;
- if (isNew)
- postSaveNew++;
- else
- postSave++;
- }
-
- @Override
- public void preDelete(MembershipType type) throws Exception
- {
- if (type == null)
- return;
- preDelete++;
- }
-
- @Override
- public void postDelete(MembershipType type) throws Exception
- {
- if (type == null)
- return;
- postDelete++;
- }
- }
-}
diff --git a/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestUserHandler.java b/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestUserHandler.java
deleted file mode 100644
index 64896254d..000000000
--- a/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestUserHandler.java
+++ /dev/null
@@ -1,1222 +0,0 @@
-/*
- * 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.
- */
-package org.exoplatform.services.tck.organization;
-
-import org.exoplatform.commons.utils.ListAccess;
-import org.exoplatform.container.xml.InitParams;
-import org.exoplatform.container.xml.ObjectParameter;
-import org.exoplatform.services.organization.DisabledUserException;
-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 org.exoplatform.services.organization.UserProfile;
-import org.exoplatform.services.organization.UserStatus;
-import org.exoplatform.services.organization.impl.NewUserConfig;
-import org.exoplatform.services.organization.impl.NewUserEventListener;
-
-import java.util.Calendar;
-import java.util.List;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * @author Anatoliy Bazko
- * @version $Id: TestOrganizationService.java 111 2008-11-11 11:11:11Z $
- */
-public class TestUserHandler extends AbstractOrganizationServiceTest
-{
- private MyUserEventListener listener;
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- listener = new MyUserEventListener();
- uHandler.addUserEventListener(listener);
- }
-
- @Override
- public void tearDown() throws Exception
- {
- uHandler.removeUserEventListener(listener);
- super.tearDown();
- }
-
- /**
- * User authentication.
- */
- public void testAuthenticate() throws Exception
- {
- createUser("testAuthenticate");
-
- // authentication with existing user and correct password
- assertTrue(uHandler.authenticate("testAuthenticate", "pwdADDSomeSaltToBeCompliantWithSomeIS00"));
-
- // unknown user authentication
- assertFalse(uHandler.authenticate("testAuthenticate_", "pwdADDSomeSaltToBeCompliantWithSomeIS00"));
-
- // authentication with wrong password
- assertFalse(uHandler.authenticate("testAuthenticate", "pwdADDSomeSaltToBeCompliantWithSomeIS00_"));
-
- boolean unsupportedOperation = false;
- try
- {
- // Disable the user testAuthenticate
- uHandler.setEnabled("testAuthenticate", false, true);
-
- try
- {
- uHandler.authenticate("testAuthenticate", "pwdADDSomeSaltToBeCompliantWithSomeIS00");
- fail("A DisabledUserException was expected");
- }
- catch (DisabledUserException e)
- {
- // expected exception
- }
-
- // Enable the user testAuthenticate
- uHandler.setEnabled("testAuthenticate", true, true);
- assertTrue(uHandler.authenticate("testAuthenticate", "pwdADDSomeSaltToBeCompliantWithSomeIS00"));
- }
- catch (UnsupportedOperationException e)
- {
- // This operation can be unsupported
- unsupportedOperation = true;
- }
-
- // Remove the user testAuthenticate
- uHandler.removeUser("testAuthenticate", true);
-
- // The user testAuthenticate doesn't exist anymore thus the authentication should fail
- assertFalse(uHandler.authenticate("testAuthenticate", "pwdADDSomeSaltToBeCompliantWithSomeIS00"));
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(unsupportedOperation ? 0 : 2, listener.preSetEnabled);
- assertEquals(unsupportedOperation ? 0 : 2, listener.postSetEnabled);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * Find user by name.
- */
- public void testFindUserByName() throws Exception
- {
- createUser("testFindUserByName");
-
- // try to find existed user
- User u = uHandler.findUserByName("demo");
-
- assertNotNull(u);
- assertEquals("demo@localhost", u.getEmail());
- assertEquals("Demo", u.getFirstName());
- assertEquals("exo", u.getLastName());
- assertEquals("demo", u.getUserName());
- assertTrue(u.isEnabled());
-
- // try to find a non existing 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");
- }
- try
- {
- assertNull(uHandler.findUserByName("not-existed-user", UserStatus.ENABLED));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
- try
- {
- assertNull(uHandler.findUserByName("not-existed-user", UserStatus.DISABLED));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
- try
- {
- assertNull(uHandler.findUserByName("not-existed-user", UserStatus.ANY));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- assertNotNull(uHandler.findUserByName("testFindUserByName"));
- assertTrue(uHandler.findUserByName("testFindUserByName").isEnabled());
- assertNotNull(uHandler.findUserByName("testFindUserByName", UserStatus.ENABLED));
- assertTrue(uHandler.findUserByName("testFindUserByName", UserStatus.ENABLED).isEnabled());
- assertNotNull(uHandler.findUserByName("testFindUserByName", UserStatus.ANY));
- assertTrue(uHandler.findUserByName("testFindUserByName", UserStatus.ANY).isEnabled());
-
- boolean unsupportedOperation = false;
- try
- {
- // Disable the user testFindUserByName
- uHandler.setEnabled("testFindUserByName", false, true);
-
- // We should not find the user testFindUserByName anymore from the normal method
- assertNull(uHandler.findUserByName("testFindUserByName"));
- assertNull(uHandler.findUserByName("testFindUserByName", UserStatus.ENABLED));
- // We should find it using the method that includes the disabled user account
- assertNotNull(uHandler.findUserByName("testFindUserByName", UserStatus.ANY));
- assertFalse(uHandler.findUserByName("testFindUserByName", UserStatus.ANY).isEnabled());
- // We should find it using the method that queries only the disabled user account
- assertNotNull(uHandler.findUserByName("testFindUserByName", UserStatus.DISABLED));
- assertFalse(uHandler.findUserByName("testFindUserByName", UserStatus.DISABLED).isEnabled());
-
- // Enable the user testFindUserByName
- uHandler.setEnabled("testFindUserByName", true, true);
-
- // We should find it again whatever the value of the parameter status
- assertNotNull(uHandler.findUserByName("testFindUserByName"));
- assertTrue(uHandler.findUserByName("testFindUserByName").isEnabled());
- assertNotNull(uHandler.findUserByName("testFindUserByName", UserStatus.ENABLED));
- assertTrue(uHandler.findUserByName("testFindUserByName", UserStatus.ENABLED).isEnabled());
- assertNotNull(uHandler.findUserByName("testFindUserByName", UserStatus.ANY));
- assertTrue(uHandler.findUserByName("testFindUserByName", UserStatus.ANY).isEnabled());
- // We should not find the user using the method that queries only the disabled user account
- assertNull(uHandler.findUserByName("testFindUserByName", UserStatus.DISABLED));
- }
- catch (UnsupportedOperationException e)
- {
- // This operation can be unsupported
- unsupportedOperation = true;
- }
-
- // Remove the user testFindUserByName
- uHandler.removeUser("testFindUserByName", true);
-
- // try to find a user that doesn't exist anymore. We are supposed to get "null" instead of Exception.
- try
- {
- assertNull(uHandler.findUserByName("testFindUserByName"));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
- try
- {
- assertNull(uHandler.findUserByName("testFindUserByName", UserStatus.ENABLED));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
- try
- {
- assertNull(uHandler.findUserByName("testFindUserByName", UserStatus.DISABLED));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
- try
- {
- assertNull(uHandler.findUserByName("testFindUserByName", UserStatus.ANY));
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown");
- }
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(unsupportedOperation ? 0 : 2, listener.preSetEnabled);
- assertEquals(unsupportedOperation ? 0 : 2, listener.postSetEnabled);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * Find users by query.
- */
- public void testFindUsersByQuery() throws Exception
- {
- createUser("tolik");
- uHandler.authenticate("tolik", "pwdADDSomeSaltToBeCompliantWithSomeIS00");
-
- Query query = new Query();
- query.setEmail("email@test");
-
- // try to find user by email
- assertSizeEquals(1, uHandler.findUsersByQuery(query), UserStatus.ENABLED);
- assertSizeEquals(1, uHandler.findUsersByQuery(query, UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(1, uHandler.findUsersByQuery(query, UserStatus.ANY), UserStatus.ANY);
-
- // try to find user by name with mask
- query = new Query();
- query.setUserName("*tolik*");
- assertSizeEquals(1, uHandler.findUsersByQuery(query));
-
- // try to find user by name with mask
- query = new Query();
- query.setUserName("tol*");
- assertSizeEquals(1, uHandler.findUsersByQuery(query));
-
- // try to find user by name with mask
- query = new Query();
- query.setUserName("*lik");
- assertSizeEquals(1, uHandler.findUsersByQuery(query));
-
- // try to find user by name explicitly
- query = new Query();
- query.setUserName("tolik");
- assertSizeEquals(1, uHandler.findUsersByQuery(query));
-
- // try to find user by part of name without mask
- query = new Query();
- query.setUserName("tol");
- assertSizeEquals(1, uHandler.findUsersByQuery(query));
-
- // try to find user by fist and last names
- query = new Query();
- query.setFirstName("first");
- query.setLastName("last");
- assertSizeEquals(1, uHandler.findUsersByQuery(query));
-
- String skipCISearchTests = System.getProperty("orgservice.test.configuration.skipCISearchTests");
- if (!"true".equals(skipCISearchTests))
- {
- // try to find user by name explicitly, case insensitive search
- query = new Query();
- query.setUserName("Tolik");
- assertSizeEquals(1, uHandler.findUsersByQuery(query));
-
- // try to find user by fist and last names, case insensitive search
- query = new Query();
- query.setFirstName("fiRst");
- query.setLastName("lasT");
- assertSizeEquals(1, uHandler.findUsersByQuery(query));
- }
-
- String skipDateTests = System.getProperty("orgservice.test.configuration.skipDateTests");
- if (!"true".equals(skipDateTests))
- {
- // 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());
- query.setUserName("tolik");
- assertSizeEquals(1, uHandler.findUsersByQuery(query));
-
- calc = Calendar.getInstance();
- calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) + 1);
-
- query = new Query();
- query.setFromLoginDate(calc.getTime());
- assertSizeEquals(0, uHandler.findUsersByQuery(query));
-
- calc = Calendar.getInstance();
- calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) - 1);
-
- query = new Query();
- query.setToLoginDate(calc.getTime());
- assertSizeEquals(0, uHandler.findUsersByQuery(query));
-
- calc = Calendar.getInstance();
- calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) + 1);
-
- query = new Query();
- query.setToLoginDate(calc.getTime());
- query.setUserName("tolik");
- assertSizeEquals(1, uHandler.findUsersByQuery(query));
- }
-
- createUser("rolik");
- createUser("bolik");
- createUser("volik");
-
- query = new Query();
- query.setUserName("olik");
-
- ListAccess users = uHandler.findUsersByQuery(query);
-
- assertSizeEquals(4, users, UserStatus.ENABLED);
- assertSizeEquals(4, uHandler.findUsersByQuery(query, UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(4, uHandler.findUsersByQuery(query, UserStatus.ANY), UserStatus.ANY);
-
- User[] allPage = users.load(0, 4);
- User[] page1 = users.load(0, 2);
- User[] page2 = users.load(2, 2);
-
- assertEquals(allPage[0].getUserName(), page1[0].getUserName());
- assertEquals(allPage[1].getUserName(), page1[1].getUserName());
- assertEquals(allPage[2].getUserName(), page2[0].getUserName());
- assertEquals(allPage[3].getUserName(), page2[1].getUserName());
-
- try
- {
- users.load(0, 0);
- }
- catch (Exception e)
- {
- fail("Exception is not expected");
- }
-
- // try to load more than exist
- try
- {
- users.load(0, 5);
- fail("Exception is expected");
- }
- catch (Exception e)
- {
- }
-
- // try to load more than exist
- try
- {
- users.load(1, 4);
- fail("Exception is expected");
- }
- catch (Exception e)
- {
- }
-
- boolean unsupportedOperation = false;
- try
- {
- // Disable the user tolik
- uHandler.setEnabled("tolik", false, true);
-
- assertSizeEquals(3, uHandler.findUsersByQuery(query), UserStatus.ENABLED);
- assertSizeEquals(3, uHandler.findUsersByQuery(query, UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(1, uHandler.findUsersByQuery(query, UserStatus.DISABLED), UserStatus.DISABLED);
- assertSizeEquals(4, uHandler.findUsersByQuery(query, UserStatus.ANY), UserStatus.ANY);
-
- // Enable the user tolik
- uHandler.setEnabled("tolik", true, true);
-
- assertSizeEquals(4, uHandler.findUsersByQuery(query), UserStatus.ENABLED);
- assertSizeEquals(4, uHandler.findUsersByQuery(query, UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(0, uHandler.findUsersByQuery(query, UserStatus.DISABLED), UserStatus.DISABLED);
- assertSizeEquals(4, uHandler.findUsersByQuery(query, UserStatus.ANY), UserStatus.ANY);
- }
- catch (UnsupportedOperationException e)
- {
- // This operation can be unsupported
- unsupportedOperation = true;
- }
-
- // Remove the user tolik
- uHandler.removeUser("tolik", true);
-
- assertSizeEquals(3, uHandler.findUsersByQuery(query), UserStatus.ENABLED);
- assertSizeEquals(3, uHandler.findUsersByQuery(query, UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(3, uHandler.findUsersByQuery(query, UserStatus.ANY), UserStatus.ANY);
-
-
- // Check the listener's counters
- assertEquals(4, listener.preSaveNew);
- assertEquals(4, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(unsupportedOperation ? 0 : 2, listener.preSetEnabled);
- assertEquals(unsupportedOperation ? 0 : 2, listener.postSetEnabled);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * Find users.
- */
- public void testFindUsers() throws Exception
- {
- createUser("tolik");
- uHandler.authenticate("tolik", "pwdADDSomeSaltToBeCompliantWithSomeIS00");
-
- Query query = new Query();
- query.setEmail("email@test");
-
- // try to find user by email
- assertSizeEquals(1, uHandler.findUsers(query).getAll());
-
- // try to find user by name with mask
- query = new Query();
- query.setUserName("*tolik*");
- assertSizeEquals(1, uHandler.findUsers(query).getAll());
-
- // try to find user by name with mask
- query = new Query();
- query.setUserName("tol*");
- assertSizeEquals(1, uHandler.findUsers(query).getAll());
-
- // try to find user by name with mask
- query = new Query();
- query.setUserName("*lik");
- assertSizeEquals(1, uHandler.findUsers(query).getAll());
-
- // try to find user by name explicitly
- query = new Query();
- query.setUserName("tolik");
- assertSizeEquals(1, uHandler.findUsers(query).getAll());
-
- // try to find user by part of name without mask
- query = new Query();
- query.setUserName("tol");
- assertSizeEquals(1, uHandler.findUsers(query).getAll());
-
- // try to find user by fist and last names
- query = new Query();
- query.setFirstName("first");
- query.setLastName("last");
- assertSizeEquals(1, uHandler.findUsers(query).getAll());
-
- String skipCISearchTests = System.getProperty("orgservice.test.configuration.skipCISearchTests");
- if (!"true".equals(skipCISearchTests))
- {
- // try to find user by name explicitly, case insensitive search
- query = new Query();
- query.setUserName("Tolik");
- assertSizeEquals(1, uHandler.findUsers(query).getAll());
-
- // try to find user by fist and last names, case insensitive search
- query = new Query();
- query.setFirstName("fiRst");
- query.setLastName("lasT");
- assertSizeEquals(1, uHandler.findUsers(query).getAll());
- }
-
- String skipDateTests = System.getProperty("orgservice.test.configuration.skipDateTests");
- if (!"true".equals(skipDateTests))
- {
- // 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());
- query.setUserName("tolik");
- assertSizeEquals(1, uHandler.findUsers(query).getAll());
-
- calc = Calendar.getInstance();
- calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) + 1);
-
- query = new Query();
- query.setFromLoginDate(calc.getTime());
- assertSizeEquals(0, uHandler.findUsers(query).getAll());
-
- calc = Calendar.getInstance();
- calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) - 1);
-
- query = new Query();
- query.setToLoginDate(calc.getTime());
- assertSizeEquals(0, uHandler.findUsers(query).getAll());
-
- calc = Calendar.getInstance();
- calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) + 1);
-
- query = new Query();
- query.setToLoginDate(calc.getTime());
- query.setUserName("tolik");
- assertSizeEquals(1, uHandler.findUsers(query).getAll());
- }
- }
-
- /**
- * Get users page list.
- */
- public void testGetUserPageList() throws Exception
- {
- assertSizeEquals(4, uHandler.getUserPageList(10).getAll());
- }
-
- /**
- * Find all users.
- */
- public void testFindAllUsers() throws Exception
- {
- createUser("testFindAllUsers");
-
- assertSizeEquals(5, uHandler.findAllUsers(), UserStatus.ENABLED);
- assertSizeEquals(5, uHandler.findAllUsers(UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(5, uHandler.findAllUsers(UserStatus.ANY), UserStatus.ANY);
-
- ListAccess users = uHandler.findAllUsers();
- User[] allPage = users.load(0, 4);
- User[] page1 = users.load(0, 2);
- User[] page2 = users.load(2, 2);
-
- assertEquals(allPage[0].getUserName(), page1[0].getUserName());
- assertEquals(allPage[1].getUserName(), page1[1].getUserName());
- assertEquals(allPage[2].getUserName(), page2[0].getUserName());
- assertEquals(allPage[3].getUserName(), page2[1].getUserName());
-
- try
- {
- users.load(0, 0);
- }
- catch (Exception e)
- {
- fail("Exception is not expected");
- }
-
- // try to load more than exist
- try
- {
- users.load(0, 6);
- fail("Exception is expected");
- }
- catch (Exception e)
- {
- }
-
- // try to load more than exist
- try
- {
- users.load(1, 5);
- fail("Exception is expected");
- }
- catch (Exception e)
- {
- }
-
- String userName = "testFindAllUsers";
-
- boolean unsupportedOperation = false;
- try
- {
- // Disable the user
- uHandler.setEnabled(userName, false, true);
-
- assertSizeEquals(4, uHandler.findAllUsers(), UserStatus.ENABLED);
- assertSizeEquals(4, uHandler.findAllUsers(UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(1, uHandler.findAllUsers(UserStatus.DISABLED), UserStatus.DISABLED);
- assertSizeEquals(5, uHandler.findAllUsers(UserStatus.ANY), UserStatus.ANY);
-
- // Enable the user
- uHandler.setEnabled(userName, true, true);
-
- assertSizeEquals(5, uHandler.findAllUsers(), UserStatus.ENABLED);
- assertSizeEquals(5, uHandler.findAllUsers(UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(0, uHandler.findAllUsers(UserStatus.DISABLED), UserStatus.DISABLED);
- assertSizeEquals(5, uHandler.findAllUsers(UserStatus.ANY), UserStatus.ANY);
- }
- catch (UnsupportedOperationException e)
- {
- // This operation can be unsupported
- unsupportedOperation = true;
- }
-
- // Remove the user
- uHandler.removeUser(userName, true);
-
- assertSizeEquals(4, uHandler.findAllUsers(), UserStatus.ENABLED);
- assertSizeEquals(4, uHandler.findAllUsers(UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(4, uHandler.findAllUsers(UserStatus.ANY), UserStatus.ANY);
-
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(unsupportedOperation ? 0 : 2, listener.preSetEnabled);
- assertEquals(unsupportedOperation ? 0 : 2, listener.postSetEnabled);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * Remove user.
- */
- public void testRemoveUser() throws Exception
- {
- createMembership(userName, groupName2, membershipType);
-
- assertEquals("We expect to find single membership for user " + userName, 1,
- mHandler.findMembershipsByUser(userName).size());
-
- assertNotNull(uHandler.removeUser(userName, true));
-
- assertNull(upHandler.findUserProfileByName(userName));
- assertEquals("We expect to find no membership for user " + userName, 0, mHandler.findMembershipsByUser(userName)
- .size());
-
- // 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
- {
- String userName = "testSaveUser";
- createUser(userName);
-
- String newEmail = "new@Email";
- String displayName = "name";
-
- // change email and check
- User u = uHandler.findUserByName(userName);
- u.setEmail(newEmail);
-
- uHandler.saveUser(u, true);
-
- u = uHandler.findUserByName(userName);
- assertEquals(newEmail, u.getEmail());
- assertEquals(u.getDisplayName(), u.getFirstName() + " " + u.getLastName());
-
- u.setDisplayName(displayName);
- uHandler.saveUser(u, true);
-
- u = uHandler.findUserByName(userName);
- assertEquals(displayName, u.getDisplayName());
-
- boolean unsupportedOperation = false;
- try
- {
- // Disable the user
- u = uHandler.setEnabled(userName, false, true);
- u.setDisplayName(displayName + "new-value");
- try
- {
- uHandler.saveUser(u, true);
- fail("A DisabledUserException was expected");
- }
- catch (DisabledUserException e)
- {
- // expected issue
- }
-
- // Enable the user
- u = uHandler.setEnabled(userName, true, true);
- u.setDisplayName(displayName + "new-value");
- uHandler.saveUser(u, true);
-
- u = uHandler.findUserByName(userName);
- assertEquals(displayName + "new-value", u.getDisplayName());
- }
- catch (UnsupportedOperationException e)
- {
- // This operation can be unsupported
- unsupportedOperation = true;
- }
-
- // Remove the user
- uHandler.removeUser(userName, true);
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(unsupportedOperation ? 2 : 3, listener.preSave);
- assertEquals(unsupportedOperation ? 2 : 3, listener.postSave);
- assertEquals(unsupportedOperation ? 0 : 2, listener.preSetEnabled);
- assertEquals(unsupportedOperation ? 0 : 2, listener.postSetEnabled);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * Change password.
- */
- public void testChangePassword() throws Exception
- {
- createUser("testChangePassword");
-
- // authentication with existing user and correct password
- assertTrue(uHandler.authenticate("testChangePassword", "pwdADDSomeSaltToBeCompliantWithSomeIS00"));
-
- // authentication with wrong password
- assertFalse(uHandler.authenticate("testChangePassword", "pwdADDSomeSaltToBeCompliantWithSomeIS00_"));
-
- User u = uHandler.findUserByName("testChangePassword");
- u.setPassword("pwdADDSomeSaltToBeCompliantWithSomeIS00_");
- uHandler.saveUser(u, true);
-
- // authentication with existing user and correct password
- assertTrue(uHandler.authenticate("testChangePassword", "pwdADDSomeSaltToBeCompliantWithSomeIS00_"));
-
- // authentication with wrong password
- assertFalse(uHandler.authenticate("testChangePassword", "pwdADDSomeSaltToBeCompliantWithSomeIS00"));
-
- boolean unsupportedOperation = false;
- try
- {
- // Disable the user
- u = uHandler.setEnabled("testChangePassword", false, true);
- u.setPassword("pwdADDSomeSaltToBeCompliantWithSomeIS00");
-
- try
- {
- uHandler.saveUser(u, true);
- fail("A DisabledUserException was expected");
- }
- catch (DisabledUserException e)
- {
- // expected issue
- }
-
- try
- {
- // authentication with existing user and correct password
- uHandler.authenticate("testChangePassword", "pwdADDSomeSaltToBeCompliantWithSomeIS00_");
- fail("A DisabledUserException was expected");
- }
- catch (DisabledUserException e)
- {
- // expected issue
- }
-
- try
- {
- // authentication with wrong password
- uHandler.authenticate("testChangePassword", "pwdADDSomeSaltToBeCompliantWithSomeIS00");
- fail("A DisabledUserException was expected");
- }
- catch (DisabledUserException e)
- {
- // expected issue
- }
-
- // Disable the user
- u = uHandler.setEnabled("testChangePassword", true, true);
- u.setPassword("pwdADDSomeSaltToBeCompliantWithSomeIS00");
- uHandler.saveUser(u, true);
-
- // authentication with existing user and correct password
- assertTrue(uHandler.authenticate("testChangePassword", "pwdADDSomeSaltToBeCompliantWithSomeIS00"));
-
- // authentication with wrong password
- assertFalse(uHandler.authenticate("testChangePassword", "pwdADDSomeSaltToBeCompliantWithSomeIS00_"));
- }
- catch (UnsupportedOperationException e)
- {
- // This operation can be unsupported
- unsupportedOperation = true;
- }
-
- // Remove the user
- uHandler.removeUser("testChangePassword", true);
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(unsupportedOperation ? 1 : 2, listener.preSave);
- assertEquals(unsupportedOperation ? 1 : 2, listener.postSave);
- assertEquals(unsupportedOperation ? 0 : 2, listener.preSetEnabled);
- assertEquals(unsupportedOperation ? 0 : 2, listener.postSetEnabled);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * Create user.
- */
- public void testCreateUser() throws Exception
- {
- User u = uHandler.createUserInstance(userName);
- u.setEmail("email@test");
- u.setFirstName("first");
- u.setLastName("last");
- u.setPassword("pwdADDSomeSaltToBeCompliantWithSomeIS00");
- uHandler.createUser(u, true);
-
- // check if user exists
- assertNotNull(uHandler.findUserByName(userName));
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(0, listener.preSetEnabled);
- assertEquals(0, listener.postSetEnabled);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- public void testFindUsersByGroupId() throws Exception
- {
- createMembership(userName, groupName2, membershipType);
-
- String groupId = "/" + groupName2;
- assertSizeEquals(1, uHandler.findUsersByGroupId(groupId), UserStatus.ENABLED);
- assertSizeEquals(1, uHandler.findUsersByGroupId(groupId, UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(1, uHandler.findUsersByGroupId(groupId, UserStatus.ANY), UserStatus.ANY);
-
- boolean unsupportedOperation = false;
- try
- {
- // Disable the user
- uHandler.setEnabled(userName, false, true);
-
- assertSizeEquals(0, uHandler.findUsersByGroupId(groupId), UserStatus.ENABLED);
- assertSizeEquals(0, uHandler.findUsersByGroupId(groupId, UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(1, uHandler.findUsersByGroupId(groupId, UserStatus.DISABLED), UserStatus.DISABLED);
- assertSizeEquals(1, uHandler.findUsersByGroupId(groupId, UserStatus.ANY), UserStatus.ANY);
-
- // Enable the user
- uHandler.setEnabled(userName, true, true);
-
- assertSizeEquals(1, uHandler.findUsersByGroupId(groupId), UserStatus.ENABLED);
- assertSizeEquals(1, uHandler.findUsersByGroupId(groupId, UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(0, uHandler.findUsersByGroupId(groupId, UserStatus.DISABLED), UserStatus.DISABLED);
- assertSizeEquals(1, uHandler.findUsersByGroupId(groupId, UserStatus.ANY), UserStatus.ANY);
- }
- catch (UnsupportedOperationException e)
- {
- // This operation can be unsupported
- unsupportedOperation = true;
- }
-
- // Remove the user
- uHandler.removeUser(userName, true);
-
- assertSizeEquals(0, uHandler.findUsersByGroupId(groupId), UserStatus.ENABLED);
- assertSizeEquals(0, uHandler.findUsersByGroupId(groupId, UserStatus.ENABLED), UserStatus.ENABLED);
- assertSizeEquals(0, uHandler.findUsersByGroupId(groupId, UserStatus.ANY), UserStatus.ANY);
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(unsupportedOperation ? 0 : 2, listener.preSetEnabled);
- assertEquals(unsupportedOperation ? 0 : 2, listener.postSetEnabled);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * Test get listeners.
- */
- public void testGetListeners() throws Exception
- {
- if (uHandler instanceof UserEventListenerHandler)
- {
- List 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)
- {
- }
- }
- }
-
- public void testSetEnabled() throws Exception
- {
- try
- {
- // Trying to disable a non existing user should not throw any exception
- assertNull(uHandler.setEnabled("foo", false, true));
- }
- catch (UnsupportedOperationException e)
- {
- // This operation can be unsupported, the unit test will be ignored
- return;
- }
- createUser("testSetEnabled");
-
- // Trying to disable an existing user should return the corresponding user
- User user = uHandler.setEnabled("testSetEnabled", false, true);
-
- assertNotNull(user);
- assertEquals("testSetEnabled", user.getUserName());
- assertFalse(user.isEnabled());
-
- // Trying to disable an user already disabled
- user = uHandler.setEnabled("testSetEnabled", false, true);
-
- assertNotNull(user);
- assertEquals("testSetEnabled", user.getUserName());
- assertFalse(user.isEnabled());
-
- // Trying to enable the user
- user = uHandler.setEnabled("testSetEnabled", true, true);
-
- assertNotNull(user);
- assertEquals("testSetEnabled", user.getUserName());
- assertTrue(user.isEnabled());
-
- // Trying to enable an user already enabled
- user = uHandler.setEnabled("testSetEnabled", true, true);
-
- assertNotNull(user);
- assertEquals("testSetEnabled", user.getUserName());
- assertTrue(user.isEnabled());
-
- // Remove the user testSetEnabled
- uHandler.removeUser("testSetEnabled", true);
- assertNull(uHandler.setEnabled("testSetEnabled", false, true));
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(2, listener.preSetEnabled);
- assertEquals(2, listener.postSetEnabled);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- public void testPreDeleteUserEventListenerPreventRemoveUser() throws Exception
- {
- createMembership(userName, groupName2, membershipType);
- createUserProfile(userName);
-
- assertEquals("Only one membership is expected for the user " + userName, 1,
- mHandler.findMembershipsByUser(userName).size());
-
- // We ensure that the UserProfile has been created properly
- UserProfile up = upHandler.findUserProfileByName(userName);
- assertNotNull(up);
- assertEquals(userName, up.getUserName());
- assertEquals("value1", up.getAttribute("key1"));
- assertEquals("value2", up.getAttribute("key2"));
-
- //Try to remove user
- PreventDeleteUserListener preventDeleteUserListener = new PreventDeleteUserListener();
- uHandler.addUserEventListener(preventDeleteUserListener);
- try
- {
- uHandler.removeUser(userName, true);
- fail("Exception should be thrown");
- }
- catch (Exception ex)
- {
- //Expect exception will be thrown
- }
- finally
- {
- uHandler.removeUserEventListener(preventDeleteUserListener);
- }
-
- // Make sure that the user has not been removed
- assertNotNull(uHandler.findUserByName(userName));
-
- // Make sure that the membership has not been removed
- assertEquals("Only one membership is expected for the user " + userName, 1,
- mHandler.findMembershipsByUser(userName).size());
-
- // Make sure that the UserProfile has not been removed
- up = upHandler.findUserProfileByName(userName);
- assertNotNull(up);
- assertEquals(userName, up.getUserName());
- assertEquals("value1", up.getAttribute("key1"));
- assertEquals("value2", up.getAttribute("key2"));
- }
-
- public void testPreDeleteNewUserEventListener() throws Exception
- {
- createMembership(userName, groupName2, membershipType);
- createUserProfile(userName);
-
- assertEquals("Only one membership is expected for the user " + userName, 1,
- mHandler.findMembershipsByUser(userName).size());
-
- // We ensure that the UserProfile has been created properly
- UserProfile up = upHandler.findUserProfileByName(userName);
- assertNotNull(up);
- assertEquals(userName, up.getUserName());
- assertEquals("value1", up.getAttribute("key1"));
- assertEquals("value2", up.getAttribute("key2"));
-
- //Try to remove user
- ObjectParameter param = new ObjectParameter();
- param.setObject(new NewUserConfig());
- InitParams params = new InitParams();
- params.addParam(param);
- NewUserEventListener newUserEventListener = new NewUserEventListener(params);
- uHandler.addUserEventListener(newUserEventListener);
- try
- {
- uHandler.removeUser(userName, true);
- }
- catch (Exception ex)
- {
- fail("Exception should not be thrown");
- }
- finally
- {
- uHandler.removeUserEventListener(newUserEventListener);
- }
-
- // Make sure that the user has been removed
- assertNull(uHandler.findUserByName(userName));
-
- // Make sure that the membership has been removed
- assertEquals("the membership should be removed for the user " + userName, 0,
- mHandler.findMembershipsByUser(userName).size());
-
- // Make sure that the UserProfile has been removed
- up = upHandler.findUserProfileByName(userName);
- assertNull(up);
- }
-
- public void testPreventRemoveUser() throws Exception
- {
- createMembership(userName, groupName2, membershipType);
- createUserProfile(userName);
-
- assertEquals("Only one membership is expected for the user " + userName, 1,
- mHandler.findMembershipsByUser(userName).size());
-
- // We ensure that the UserProfile has been created properly
- UserProfile up = upHandler.findUserProfileByName(userName);
- assertNotNull(up);
- assertEquals(userName, up.getUserName());
- assertEquals("value1", up.getAttribute("key1"));
- assertEquals("value2", up.getAttribute("key2"));
-
- //Try to remove user
- ObjectParameter param = new ObjectParameter();
- param.setObject(new NewUserConfig());
- InitParams params = new InitParams();
- params.addParam(param);
- NewUserEventListener newUserEventListener = new NewUserEventListener(params);
- PreventDeleteUserListener preventDeleteUserListener = new PreventDeleteUserListener();
- uHandler.addUserEventListener(newUserEventListener);
- uHandler.addUserEventListener(preventDeleteUserListener);
- try
- {
- uHandler.removeUser(userName, true);
- fail("Exception should be thrown");
- }
- catch (Exception ex)
- {
- //Expect exception will be thrown
- }
- finally
- {
- uHandler.removeUserEventListener(preventDeleteUserListener);
- uHandler.removeUserEventListener(newUserEventListener);
- }
-
- // Make sure that the user has not been removed
- assertNotNull(uHandler.findUserByName(userName));
-
- // Make sure that the membership has not been removed
- assertEquals("Only one membership is expected for the user " + userName, 1,
- mHandler.findMembershipsByUser(userName).size());
-
- // Make sure that the UserProfile has not been removed
- up = upHandler.findUserProfileByName(userName);
- assertNotNull(up);
- assertEquals(userName, up.getUserName());
- assertEquals("value1", up.getAttribute("key1"));
- assertEquals("value2", up.getAttribute("key2"));
- }
-
- private static class PreventDeleteUserListener extends UserEventListener
- {
- @Override
- public void preDelete(User user) throws Exception
- {
- throw new Exception("You cannot to delete user");
- }
-
- @Override
- public void postDelete(User user) throws Exception
- {
- fail("This method should not be execute because preDelete Event prevent remove user");
- }
- }
-
- private static class MyUserEventListener extends UserEventListener
- {
- public int preSaveNew, postSaveNew;
- public int preSave, postSave;
- public int preDelete, postDelete;
- public int preSetEnabled, postSetEnabled;
-
- @Override
- public void preSave(User user, boolean isNew) throws Exception
- {
- if (user == null)
- return;
- if (isNew)
- preSaveNew++;
- else
- preSave++;
- }
-
- @Override
- public void postSave(User user, boolean isNew) throws Exception
- {
- if (user == null)
- return;
- if (isNew)
- postSaveNew++;
- else
- postSave++;
- }
-
- @Override
- public void preDelete(User user) throws Exception
- {
- if (user == null)
- return;
- preDelete++;
- }
-
- @Override
- public void postDelete(User user) throws Exception
- {
- if (user == null)
- return;
- postDelete++;
- }
-
- @Override
- public void preSetEnabled(User user) throws Exception
- {
- if (user == null)
- return;
- preSetEnabled++;
- }
-
- @Override
- public void postSetEnabled(User user) throws Exception
- {
- if (user == null)
- return;
- postSetEnabled++;
- }
- }
-}
diff --git a/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestUserProfileHandler.java b/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestUserProfileHandler.java
deleted file mode 100644
index 582f2a3ba..000000000
--- a/exo.core.component.organization.tests/src/test/java/org/exoplatform/services/tck/organization/TestUserProfileHandler.java
+++ /dev/null
@@ -1,280 +0,0 @@
-/**
- *
- */
-/*
- * 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.
- */
-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 Anatoliy Bazko
- * @version $Id: TestUserProfileHandlerImpl.java 111 2008-11-11 11:11:11Z $
- */
-public class TestUserProfileHandler extends AbstractOrganizationServiceTest
-{
- private MyUserProfileEventListener listener;
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- listener = new MyUserProfileEventListener();
- upHandler.addUserProfileEventListener(listener);
- }
-
- @Override
- public void tearDown() throws Exception
- {
- upHandler.removeUserProfileEventListener(listener);
- super.tearDown();
- }
-
- /**
- * 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");
- }
-
- createUserProfile(newUserName);
-
- assertNotNull(upHandler.findUserProfileByName(newUserName));
-
- upHandler.removeUserProfile(newUserName, true);
-
- assertNull(upHandler.findUserProfileByName(newUserName));
-
- createUserProfile(newUserName);
-
- assertNotNull(upHandler.findUserProfileByName(newUserName));
-
- uHandler.removeUser(newUserName, false);
-
- assertNull(upHandler.findUserProfileByName(newUserName));
-
- // Check the listener's counters
- assertEquals(3, listener.preSaveNew);
- assertEquals(3, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * Find user profiles.
- */
- public void testFindUserProfiles() throws Exception
- {
- createUser(userName);
- createUserProfile(userName);
-
- createUser(newUserName);
- createUserProfile(newUserName);
-
- assertSizeEquals(2, upHandler.findUserProfiles());
-
- upHandler.removeUserProfile(newUserName, true);
-
- assertSizeEquals(1, upHandler.findUserProfiles());
-
- createUserProfile(newUserName);
-
- assertSizeEquals(2, upHandler.findUserProfiles());
-
- uHandler.removeUser(newUserName, false);
-
- assertSizeEquals(1, upHandler.findUserProfiles());
-
- // Check the listener's counters
- assertEquals(3, listener.preSaveNew);
- assertEquals(3, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * 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");
- }
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(0, listener.preSave);
- assertEquals(0, listener.postSave);
- assertEquals(1, listener.preDelete);
- assertEquals(1, listener.postDelete);
- }
-
- /**
- * 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);
- fail("Exception should be thrown");
- }
- catch (Exception e)
- {
- }
-
- // Check the listener's counters
- assertEquals(1, listener.preSaveNew);
- assertEquals(1, listener.postSaveNew);
- assertEquals(1, listener.preSave);
- assertEquals(1, listener.postSave);
- assertEquals(0, listener.preDelete);
- assertEquals(0, listener.postDelete);
- }
-
- /**
- * Test get listeners.
- */
- public void testGetListeners() throws Exception
- {
- if (upHandler instanceof UserProfileEventListenerHandler)
- {
- List list = ((UserProfileEventListenerHandler) upHandler).getUserProfileListeners();
- try
- {
- list.clear();
- fail("We should not able to modife list of listeners");
- }
- catch (Exception e)
- {
- }
- }
- }
-
- private static class MyUserProfileEventListener extends UserProfileEventListener
- {
- public int preSaveNew, postSaveNew;
- public int preSave, postSave;
- public int preDelete, postDelete;
-
- @Override
- public void preSave(UserProfile up, boolean isNew) throws Exception
- {
- if (up == null)
- return;
- if (isNew)
- preSaveNew++;
- else
- preSave++;
- }
-
- @Override
- public void postSave(UserProfile up, boolean isNew) throws Exception
- {
- if (up == null)
- return;
- if (isNew)
- postSaveNew++;
- else
- postSave++;
- }
-
- @Override
- public void preDelete(UserProfile up) throws Exception
- {
- if (up == null)
- return;
- preDelete++;
- }
-
- @Override
- public void postDelete(UserProfile up) throws Exception
- {
- if (up == null)
- return;
- postDelete++;
- }
- }
-}
diff --git a/exo.core.component.script.groovy/pom.xml b/exo.core.component.script.groovy/pom.xml
index 3028f80b2..2cd145cf1 100644
--- a/exo.core.component.script.groovy/pom.xml
+++ b/exo.core.component.script.groovy/pom.xml
@@ -50,8 +50,8 @@
test
- org.codehaus.groovy
- groovy-all
+ org.codehaus.groovy
+ groovy-all
diff --git a/exo.core.component.security.core/pom.xml b/exo.core.component.security.core/pom.xml
index 8083c9ecd..7fa36c395 100644
--- a/exo.core.component.security.core/pom.xml
+++ b/exo.core.component.security.core/pom.xml
@@ -54,8 +54,8 @@
test
- commons-lang
- commons-lang
+ org.apache.commons
+ commons-lang3
diff --git a/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/ConversationRegistry.java b/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/ConversationRegistry.java
index 41a5f9f0e..c472e4b20 100644
--- a/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/ConversationRegistry.java
+++ b/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/ConversationRegistry.java
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.security;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.exoplatform.container.spi.DefinitionByType;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.ValueParam;
diff --git a/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/impl/DefaultRolesExtractorImpl.java b/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/impl/DefaultRolesExtractorImpl.java
index 5f108939e..a64b245b0 100644
--- a/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/impl/DefaultRolesExtractorImpl.java
+++ b/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/impl/DefaultRolesExtractorImpl.java
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.security.impl;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.ValueParam;
import org.exoplatform.services.security.MembershipEntry;
diff --git a/pom.xml b/pom.xml
index 9eaf3bf06..6633813a7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -57,7 +57,6 @@
exo.core.component.security.core
exo.core.component.database
exo.core.component.script.groovy
- exo.core.component.organization.tests
exo.core.component.organization.api
exo.core.component.xml-processing
@@ -88,17 +87,6 @@
exo.core.component.organization.api
${project.version}
-
- ${project.groupId}
- exo.core.component.organization.tests
- ${project.version}
-
-
- org.exoplatform.core
- exo.core.component.organization.tests
- ${project.version}
- test-sources
-
org.exoplatform.core
exo.core.component.security.core