[jbpm-commits] JBoss JBPM SVN: r6466 - in jbpm4/trunk/modules: test-db/src/test/java/org/jbpm/test/identity and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jul 6 21:05:57 EDT 2010


Author: rebody
Date: 2010-07-06 21:05:56 -0400 (Tue, 06 Jul 2010)
New Revision: 6466

Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/IdentitySessionImpl.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/identity/IdentityTest.java
Log:
JBPM-2693 validate duplicated user and group for IdentitySessionImpl

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/IdentitySessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/IdentitySessionImpl.java	2010-07-06 20:37:11 UTC (rev 6465)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/IdentitySessionImpl.java	2010-07-07 01:05:56 UTC (rev 6466)
@@ -38,6 +38,7 @@
 
 /**
  * @author Tom Baeyens
+ * @author Huisheng Xu
  */
 public class IdentitySessionImpl implements IdentitySession {
 
@@ -45,6 +46,14 @@
 
   public String createUser(String userName, String givenName, String familyName,
     String businessEmail) {
+    try {
+      User user = findUserById(userName);
+      if (user != null) {
+        throw new JbpmException("Cannot create user, userId: [" + userName + "] has been used");
+      }
+    } catch(Exception ex) {
+      throw new JbpmException("Cannot create user, error while validating", ex);
+    }
     UserImpl user = new UserImpl(userName, givenName, familyName);
     user.setBusinessEmail(businessEmail);
 
@@ -96,6 +105,14 @@
   }
 
   public String createGroup(String groupName, String groupType, String parentGroupId) {
+    try {
+      GroupImpl group = findGroupById(groupName);
+      if (group != null) {
+        throw new JbpmException("Cannot create group, groupId: [" + groupName + "] has been used");
+      }
+    } catch(Exception ex) {
+      throw new JbpmException("Cannot create group, error while validating", ex);
+    }
     GroupImpl group = new GroupImpl();
     String groupId = groupType != null ? groupType + "." + groupName : groupName;
     group.setId(groupId);

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/identity/IdentityTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/identity/IdentityTest.java	2010-07-06 20:37:11 UTC (rev 6465)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/identity/IdentityTest.java	2010-07-07 01:05:56 UTC (rev 6466)
@@ -26,18 +26,20 @@
 import java.util.List;
 import java.util.Set;
 
+import org.jbpm.api.JbpmException;
 import org.jbpm.api.identity.Group;
 import org.jbpm.api.identity.User;
 import org.jbpm.test.JbpmTestCase;
 
 /**
  * @author Tom Baeyens
+ * @author Huisheng Xu
  */
 public class IdentityTest extends JbpmTestCase {
-  
+
   public void testSingleUser() throws Exception {
     identityService.createUser("johndoe", "John", "Doe");
-    
+
     User user = identityService.findUserById("johndoe");
 
     assertEquals("johndoe", user.getId());
@@ -49,7 +51,7 @@
 
   public void testCreateGroup() throws Exception {
     String testGroupId = identityService.createGroup("testGroup", "unit", null);
-    
+
     Group group = identityService.findGroupById(testGroupId);
     assertEquals("testGroup", group.getName());
     assertEquals("unit", group.getType());
@@ -64,11 +66,11 @@
     identityService.createMembership("jeffyu", redhatGroupId);
 
     List<Group> groups = identityService.findGroupsByUser("jeffyu");
-    Set<String> groupNames = new HashSet<String>(); 
+    Set<String> groupNames = new HashSet<String>();
     for (Group group : groups) {
       groupNames.add(group.getName());
     }
-    
+
     assertEquals(Collections.singleton("redhat"), groupNames);
 
     identityService.deleteUser("jeffyu");
@@ -76,17 +78,17 @@
   }
 
   public void testFindGroupByUserAndGroupType() throws Exception {
-    
+
     identityService.createUser("johndoe", "John", "Doe");
     String redhatGroupId = identityService.createGroup("redhat", "unit", null);
     identityService.createMembership("johndoe", redhatGroupId, "developer");
 
     List<Group> groups = identityService.findGroupsByUserAndGroupType("johndoe", "unit");
-    Set<String> groupNames = new HashSet<String>(); 
+    Set<String> groupNames = new HashSet<String>();
     for (Group group : groups) {
       groupNames.add(group.getName());
     }
-    
+
     assertEquals(Collections.singleton("redhat"), groupNames);
 
     identityService.deleteUser("johndoe");
@@ -123,26 +125,48 @@
 
   public void testSingleUser2() throws Exception {
     identityService.createUser("johndoe", "John", "Doe");
-    
+
     List<User> users = identityService.findUsers();
     assertNotNull(users);
-    
+
     User johndoe = null;
-    
+
     for (User user : users) {
-    	if ("johndoe".equals(user.getId())) {
-    		johndoe = user;
-    	}
+        if ("johndoe".equals(user.getId())) {
+            johndoe = user;
+        }
     }
-    
+
     assertNotNull(johndoe);
-    
+
     assertEquals("johndoe", johndoe.getId());
     assertEquals("John", johndoe.getGivenName());
     assertEquals("Doe", johndoe.getFamilyName());
     assertEquals("John Doe", johndoe.toString());
-    
+
     identityService.deleteUser("johndoe");
-    
+
   }
+
+  public void testDuplicatedUser() {
+    identityService.createUser("johndoe", "John", "Doe");
+    try {
+      identityService.createUser("johndoe", "John", "Doe");
+      fail("shouldn't allow duplicated user");
+    } catch(JbpmException ex) {
+      assertEquals("Cannot create user, error while validating", ex.getMessage());
+    }
+    identityService.deleteUser("johndoe");
+  }
+
+  public void testDuplicatedGroup() {
+    identityService.createGroup("group");
+    try {
+    identityService.createGroup("group");
+      fail("shouldn't allow duplicated group");
+    } catch(JbpmException ex) {
+      assertEquals("Cannot create group, error while validating", ex.getMessage());
+    }
+    identityService.deleteGroup("group");
+  }
 }



More information about the jbpm-commits mailing list