[jbpm-commits] JBoss JBPM SVN: r4878 - in jbpm4/branches/idm/modules: distro/src/main/files/jboss/jbpm.cfg.idm and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Sun May 24 14:41:18 EDT 2009


Author: jeff.yuchang
Date: 2009-05-24 14:41:17 -0400 (Sun, 24 May 2009)
New Revision: 4878

Added:
   jbpm4/branches/idm/modules/distro/src/main/files/jboss/jbpm.cfg.idm/jbpm.integration.test.cfg.xml
   jbpm4/branches/idm/modules/examples/src/test/java/org/jbpm/examples/identity/
   jbpm4/branches/idm/modules/examples/src/test/java/org/jbpm/examples/identity/IdentityTest.java
Modified:
   jbpm4/branches/idm/modules/distro/src/main/files/jboss/build.xml
   jbpm4/branches/idm/modules/examples/src/test/resources/jbpm.cfg.xml
   jbpm4/branches/idm/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/JBossIdmIdentitySessionImpl.java
Log:
Update the build.xml, so the integration test can have correct jbpm.cfg.xml.
* Update the identity test case and its impl.


Modified: jbpm4/branches/idm/modules/distro/src/main/files/jboss/build.xml
===================================================================
--- jbpm4/branches/idm/modules/distro/src/main/files/jboss/build.xml	2009-05-23 13:48:09 UTC (rev 4877)
+++ jbpm4/branches/idm/modules/distro/src/main/files/jboss/build.xml	2009-05-24 18:41:17 UTC (rev 4878)
@@ -205,11 +205,9 @@
   </target>
 	
   <target name="internal.install.jbpm.into.jboss.identity" if="jbpm.identity.idm">
-  	<copy todir="${jboss.server.config.dir}/deploy/jbpm/jbpm-service.sar" overwrite="true">
-  		<fileset dir="${jbpm.home}/jboss/jbpm.cfg.idm">
-  		  <include name="jbpm.cfg.xml"/>
-  		</fileset>
-  	</copy>
+    <copy file="${jbpm.home}/jboss/jbpm.cfg.idm/jbpm.cfg.xml"
+          tofile="${jboss.server.config.dir}/deploy/jbpm/jbpm-service.sar/jbpm.cfg.xml"
+          overwrite="true" />
   </target>
 	
   <!-- ### THE JBOSS INTEGRATION TEST SPECIFICS ####################### -->
@@ -217,11 +215,18 @@
     <copy todir="${jboss.server.config.dir}/deploy/jbpm/jbpm-service.sar" overwrite="true">
        <fileset dir="${jbpm.home}/jboss/jbpm.cfg.integration.tests" />
     </copy>
+  	<antcall target="internal.install.idm.into.jboss.integrationtestspecifics" />
     <ant antfile="${jbpm.home}/examples/build.xml" target="examples.jar" />
   	<mkdir dir="${jboss.server.config.dir}/deploy/jbpm/userlibs" />
     <copy file="${jbpm.home}/examples/target/examples.jar"
     	    todir="${jboss.server.config.dir}/deploy/jbpm/userlibs" />
 	</target>
+	
+	<target name="internal.install.idm.into.jboss.integrationtestspecifics" if="jbpm.identity.idm">
+	    <copy file="${jbpm.home}/jboss/jbpm.cfg.idm/jbpm.integration.test.cfg.xml"
+	          tofile="${jboss.server.config.dir}/deploy/jbpm/jbpm-service.sar/jbpm.cfg.xml"
+	          overwrite="true" />
+    </target>
 
   <!-- ### THE HSQLDB SPECIFIC PART ####################################### -->
   <target name="internal.install.jbpm.into.jboss.db.hsqldb" />

Added: jbpm4/branches/idm/modules/distro/src/main/files/jboss/jbpm.cfg.idm/jbpm.integration.test.cfg.xml
===================================================================
--- jbpm4/branches/idm/modules/distro/src/main/files/jboss/jbpm.cfg.idm/jbpm.integration.test.cfg.xml	                        (rev 0)
+++ jbpm4/branches/idm/modules/distro/src/main/files/jboss/jbpm.cfg.idm/jbpm.integration.test.cfg.xml	2009-05-24 18:41:17 UTC (rev 4878)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbpm-configuration>
+
+  <import resource="jbpm.default.cfg.xml" />
+  <import resource="jbpm.tx.jta.cfg.xml" />
+  <import resource="jbpm.jpdl.cfg.xml" />
+  <import resource="jbpm.jboss.idm.cfg.xml" />
+
+  <import resource="jbpm.mail.templates.examples.xml" />
+
+  <!-- Job executor is excluded for running the example test cases.
+       To enable timers and messages in production use, this should be included.
+  import resource="jbpm.jobexecutor.cfg.xml" / -->
+
+</jbpm-configuration>

Added: jbpm4/branches/idm/modules/examples/src/test/java/org/jbpm/examples/identity/IdentityTest.java
===================================================================
--- jbpm4/branches/idm/modules/examples/src/test/java/org/jbpm/examples/identity/IdentityTest.java	                        (rev 0)
+++ jbpm4/branches/idm/modules/examples/src/test/java/org/jbpm/examples/identity/IdentityTest.java	2009-05-24 18:41:17 UTC (rev 4878)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.examples.identity;
+
+import java.util.List;
+
+import org.jbpm.api.identity.Group;
+import org.jbpm.api.identity.User;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Tom Baeyens
+ * @author Jeff Yu
+ */
+public class IdentityTest extends JbpmTestCase {
+  
+  private String johndoe = "johndoe";
+  private String redhatGroupId ;
+	
+  public void setUp() throws Exception {
+	super.setUp();
+	
+	identityService.createUser("johndoe", "John", "Doe");
+	redhatGroupId = identityService.createGroup("redhat", Group.TYPE_UNIT, null);
+	
+  }
+  
+  
+  public void tearDown() throws Exception {
+	super.tearDown();
+	
+	identityService.deleteUser(johndoe);
+	identityService.deleteGroup(redhatGroupId);
+  }
+	
+	
+  public void testSingleUser() throws Exception {   
+    User user = identityService.findUserById(johndoe);
+    
+    assertEquals("johndoe", user.getId());
+    assertEquals("John", user.getGivenName());
+    assertEquals("Doe", user.getFamilyName());
+    
+  }
+  
+  
+  public void testCreateGroup() throws Exception {
+	  String testGroupId = identityService.createGroup("testGroup", Group.TYPE_UNIT, null);	  
+	  Group group = identityService.findGroupById(testGroupId);
+	  assertEquals("testGroup", group.getName());
+	  assertEquals(Group.TYPE_UNIT, group.getType());
+	  
+	  identityService.deleteGroup(testGroupId);
+  }
+  
+  public void testFindGroupsByUser() throws Exception {
+	  identityService.createMembership(johndoe, redhatGroupId, "Developer");
+	  
+	  List<Group> groups = identityService.findGroupsByUser(johndoe);
+	  assertTrue(groups.size() > 0);
+	  
+	  for (Group group : groups) {
+		  if (redhatGroupId.equals(group.getId())) {
+			  assertTrue(true);
+			  return;
+		  }
+	  }
+	  fail("Can't find the group by userid: " + johndoe);
+  }
+  
+  public void testFindGroupByUserAndGroupType() throws Exception {
+	  identityService.createMembership(johndoe, redhatGroupId, "Developer");
+	  List<Group> groups = identityService.findGroupsByUserAndGroupType(johndoe, Group.TYPE_UNIT);
+	  assertTrue(groups.size() > 0);
+	  
+	  for (Group group : groups) {
+		  if (redhatGroupId.equals(group.getId())) {
+			  assertTrue(true);
+			  return;
+		  }
+	  }
+	  fail("Can't find the groups by userid " + johndoe + " and group type :" + Group.TYPE_UNIT);
+  }
+
+  public void testSingleGroup() throws Exception {
+    identityService.createUser("joesmoe", "Joe", "Smoe");
+    identityService.createUser("jackblack", "Jack", "Black");
+    
+    String jbossId = identityService.createGroup("jboss", Group.TYPE_UNIT, redhatGroupId);
+    String jbpmId = identityService.createGroup("jbpm", Group.TYPE_UNIT, jbossId);
+    
+    identityService.createMembership("johndoe", jbpmId, "developer");
+    identityService.createMembership("joesmoe", jbpmId, "developer");
+    identityService.createMembership("jackblack", jbossId, "manager");
+    
+    List<Group> groups = identityService.findGroupsByUserAndGroupType("johndoe", Group.TYPE_UNIT);
+
+     assertEquals(1, groups.size());
+     Group group = groups.get(0);
+     System.out.println(group.getName());
+     
+     identityService.deleteGroup(jbpmId);
+     identityService.deleteGroup(jbossId);
+     
+     identityService.deleteUser("joesmoe");
+     identityService.deleteUser("jackblack");
+  }
+}

Modified: jbpm4/branches/idm/modules/examples/src/test/resources/jbpm.cfg.xml
===================================================================
--- jbpm4/branches/idm/modules/examples/src/test/resources/jbpm.cfg.xml	2009-05-23 13:48:09 UTC (rev 4877)
+++ jbpm4/branches/idm/modules/examples/src/test/resources/jbpm.cfg.xml	2009-05-24 18:41:17 UTC (rev 4878)
@@ -5,7 +5,7 @@
   <import resource="jbpm.default.cfg.xml" />
   <import resource="jbpm.tx.hibernate.cfg.xml" />
   <import resource="jbpm.jpdl.cfg.xml" />
-  <import resource="jbpm.identity.cfg.xml" />
+  <import resource="jbpm.jboss.idm.cfg.xml" />
 
   <!-- Job executor is excluded for running the example test cases. -->
   <!-- To enable timers and messages in production use, this should be included. -->

Modified: jbpm4/branches/idm/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/JBossIdmIdentitySessionImpl.java
===================================================================
--- jbpm4/branches/idm/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/JBossIdmIdentitySessionImpl.java	2009-05-23 13:48:09 UTC (rev 4877)
+++ jbpm4/branches/idm/modules/pvm/src/main/java/org/jbpm/pvm/internal/identity/impl/JBossIdmIdentitySessionImpl.java	2009-05-24 18:41:17 UTC (rev 4878)
@@ -31,9 +31,8 @@
 import org.jboss.identity.idm.api.IdentitySession;
 import org.jboss.identity.idm.api.RoleType;
 import org.jboss.identity.idm.common.exception.IdentityException;
+import org.jboss.identity.idm.common.p3p.P3PConstants;
 import org.jboss.identity.idm.impl.api.SimpleAttribute;
-import org.jboss.identity.idm.impl.api.model.SimpleUser;
-import org.jboss.identity.idm.common.p3p.P3PConstants;
 import org.jbpm.api.JbpmException;
 import org.jbpm.api.env.Environment;
 import org.jbpm.api.identity.Group;
@@ -61,12 +60,19 @@
     	
       org.jboss.identity.idm.api.User idUser= identitySession.getPersistenceManager().createUser(userName);
       
-      Attribute[] attributes = new Attribute[] {
-        new SimpleAttribute(P3PConstants.INFO_USER_NAME_GIVEN, givenName),
-        new SimpleAttribute(P3PConstants.INFO_USER_NAME_FAMILY, familyName), 
-        new SimpleAttribute(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, businessEmail)
-      };
-      identitySession.getAttributesManager().addAttributes(idUser, attributes);
+      List<Attribute> attrs = new ArrayList<Attribute>();
+      if (givenName != null) {
+    	  attrs.add(new SimpleAttribute(P3PConstants.INFO_USER_NAME_GIVEN, givenName));
+      }
+      if (familyName != null) {
+    	  attrs.add(new SimpleAttribute(P3PConstants.INFO_USER_NAME_FAMILY, familyName));
+      }
+      if (businessEmail != null) {
+    	  attrs.add(new SimpleAttribute(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, businessEmail));
+      }
+      
+      
+      identitySession.getAttributesManager().addAttributes(idUser, attrs.toArray(new Attribute[attrs.size()]));
       return idUser.getId();
       
     } catch (IdentityException e) {
@@ -129,8 +135,9 @@
 
   public List<User> findUsersByGroup(String groupId) {
 	try {
+		org.jboss.identity.idm.api.Group idGroup = findIdmGroupById(groupId);
 		Collection<org.jboss.identity.idm.api.User> idusers = 
-				identitySession.getRelationshipManager().findAssociatedUsers(groupId, false, null);
+				identitySession.getRelationshipManager().findAssociatedUsers(idGroup, false);
 		List<User> users = new ArrayList<User>();
 		
 		for (org.jboss.identity.idm.api.User iduser : idusers) {
@@ -155,6 +162,7 @@
   public String createGroup(String groupName, String groupType, String parentGroupId) {
     
     try {
+            	
       org.jboss.identity.idm.api.Group group = identitySession.getPersistenceManager().createGroup(groupName, groupType);
       String groupId = group.getId();
       
@@ -175,8 +183,7 @@
   
   public Group findGroupById(String groupId) {
 	try {
-		org.jboss.identity.idm.api.Group idGroup = identitySession.getPersistenceManager().
-													findGroupById(groupId);
+		org.jboss.identity.idm.api.Group idGroup = findIdmGroupById(groupId);
 		GroupImpl group = new GroupImpl();
 		group.setId(idGroup.getId());
 		group.setType(idGroup.getGroupType());
@@ -238,7 +245,8 @@
 
   public List<Group> findGroupsByUserAndGroupType(String userName, String groupType) {
     try {
-      org.jboss.identity.idm.api.User idUser = new SimpleUser(userName);
+      org.jboss.identity.idm.api.User idUser = identitySession.getPersistenceManager().findUser(userName);
+      
       Collection<org.jboss.identity.idm.api.Group> idGroups = identitySession.getRelationshipManager()
       													.findAssociatedGroups(idUser, groupType);
       List<Group> groups = new ArrayList<Group>();
@@ -309,7 +317,13 @@
 
   protected org.jboss.identity.idm.api.Group findIdmGroupById(String groupId) {
 	try {
-		return identitySession.getPersistenceManager().findGroupById(groupId);
+		Collection<org.jboss.identity.idm.api.Group> groups = identitySession.getPersistenceManager().findGroup(Group.TYPE_UNIT);
+		for (org.jboss.identity.idm.api.Group group : groups) {
+			if (groupId.equals(group.getId())) {
+				return group;
+			}
+		}
+		return null;
 	} catch (IdentityException e) {
 		throw new JbpmException("couldn't find the group by groupId: " + groupId, e);
 	}  




More information about the jbpm-commits mailing list