[jbpm-commits] JBoss JBPM SVN: r5030 - in jbpm4/trunk/modules: test-base/src/main/java/org/jbpm/test and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Jun 12 05:21:13 EDT 2009


Author: tom.baeyens at jboss.com
Date: 2009-06-12 05:21:13 -0400 (Fri, 12 Jun 2009)
New Revision: 5030

Added:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryCandidatesTest.java
Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskQueryImpl.java
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/BaseJbpmTestCase.java
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
Log:
JBPM-2332 fixed task query where clause brackets for candidates

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskQueryImpl.java	2009-06-11 14:47:45 UTC (rev 5029)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskQueryImpl.java	2009-06-12 09:21:13 UTC (rev 5030)
@@ -143,7 +143,7 @@
         for (Group group: groups) {
           groupIds.add(group.getId());
         }
-        appendWhereClause("(participant.userId = :candidateUserId) or (participant.groupId in (:candidateGroupIds) ) ", hql);
+        appendWhereClause("((participant.userId = :candidateUserId) or (participant.groupId in (:candidateGroupIds)))", hql);
       }
     }
     

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/BaseJbpmTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/BaseJbpmTestCase.java	2009-06-11 14:47:45 UTC (rev 5029)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/BaseJbpmTestCase.java	2009-06-12 09:21:13 UTC (rev 5030)
@@ -56,6 +56,8 @@
   }
 
   static protected Log log = Log.getLog(BaseJbpmTestCase.class.getName());
+  
+  Throwable exception; 
 
   protected void setUp() throws Exception {
     assertNull("there is already an environment open", Environment.getCurrent());
@@ -83,11 +85,13 @@
       log.error("");
       log.error("ASSERTION FAILURE: "+e.getMessage(), e);
       log.error("");
+      exception = e;
       throw e;
     } catch (Throwable t) {
       log.error("");
       log.error("TEST THROWS EXCEPTION: "+t.getMessage(), t);
       log.error("");
+      exception = t;
       throw t;
     }
   }

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java	2009-06-11 14:47:45 UTC (rev 5029)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java	2009-06-12 09:21:13 UTC (rev 5030)
@@ -54,8 +54,8 @@
     clean((EnvironmentFactory) processEngine);
   }
 
-  public static void verifyClean(ProcessEngine processEngine) {
-    verifyClean((EnvironmentFactory) processEngine);
+  public static String verifyClean(ProcessEngine processEngine) {
+    return verifyClean((EnvironmentFactory) processEngine);
   }
 
   public static void clean(EnvironmentFactory environmentFactory) {
@@ -146,12 +146,12 @@
     }
   }
 
-  public static void verifyClean(EnvironmentFactory environmentFactory) {
+  public static String verifyClean(EnvironmentFactory environmentFactory) {
     SessionFactory sessionFactory = environmentFactory.get(SessionFactory.class);
     // when running this with a remote ejb invocation configuration, there is no
     // session factory and no cleanup needs to be done
     if (sessionFactory==null) {
-      return;
+      return null;
     }
     
     String[] tableNames = (String[]) environmentFactory.get(TABLE_NAMES_KEY);
@@ -174,7 +174,7 @@
       environmentFactory.set(TABLE_NAMES_KEY, tableNames);
     }
 
-    String recordsLeft = "";
+    String recordsLeftMsg = "";
     Session session = sessionFactory.openSession();
     try {
       for (String tableName : tableNames) {
@@ -183,17 +183,17 @@
         sqlQuery.addScalar("RECORD_COUNT_", Hibernate.LONG);
         Long recordCount = (Long) sqlQuery.uniqueResult();
         if (recordCount>0L) {
-          recordsLeft += tableName+"["+recordCount+"] ";
-          log.error("FIXME: JBPM-2004 "+recordCount+" records left in table "+tableName);
+          recordsLeftMsg += tableName+":"+recordCount+", ";
         }
       }
     } finally {
       session.close();
     }
     
-    if (recordsLeft.length()>0) {
+    if (recordsLeftMsg.length()>0) {
       clean(environmentFactory);
-      throw new RuntimeException(recordsLeft);
     }
+    
+    return recordsLeftMsg;
   }
 }

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java	2009-06-11 14:47:45 UTC (rev 5029)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java	2009-06-12 09:21:13 UTC (rev 5030)
@@ -28,6 +28,7 @@
 import org.jbpm.api.ExecutionService;
 import org.jbpm.api.HistoryService;
 import org.jbpm.api.IdentityService;
+import org.jbpm.api.JbpmException;
 import org.jbpm.api.ManagementService;
 import org.jbpm.api.ProcessEngine;
 import org.jbpm.api.RepositoryService;
@@ -105,7 +106,15 @@
       repositoryService.deleteDeploymentCascade(deploymentDbid);
     }
 
-    Db.verifyClean(processEngine);
+    String recordsLeftMsg = Db.verifyClean(processEngine);
+    if (recordsLeftMsg.length()>0) {
+      String message = "database was not clean after test: "+recordsLeftMsg;
+      if (exception==null) {
+        throw new JbpmException(message);
+      } else {
+        throw new JbpmException(message, exception);
+      }
+    }
 
     super.tearDown();
   }

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryCandidatesTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryCandidatesTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryCandidatesTest.java	2009-06-12 09:21:13 UTC (rev 5030)
@@ -0,0 +1,130 @@
+/*
+ * 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.test.task;
+
+import java.util.List;
+
+import org.jbpm.api.task.Participation;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TaskQueryCandidatesTest extends JbpmTestCase {
+  
+  String salesGroupId;
+  String developmentGroupId;
+
+  public void setUp() throws Exception {
+    super.setUp();
+    
+    identityService.createUser("johndoe", "John", "Doe");
+    identityService.createUser("joesmoe", "Joe", "Smoe");
+    identityService.createUser("jackblack", "Jack", "Black");
+    
+    salesGroupId = identityService.createGroup("sales");
+    identityService.createMembership("johndoe", salesGroupId);
+    identityService.createMembership("joesmoe", salesGroupId);
+
+    developmentGroupId = identityService.createGroup("development");
+    identityService.createMembership("jackblack", developmentGroupId);
+  }
+
+  public void tearDown() throws Exception {
+    identityService.deleteUser("johndoe");
+    identityService.deleteUser("joesmoe");
+    identityService.deleteUser("jackblack");
+    identityService.deleteGroup(salesGroupId);
+    identityService.deleteGroup(developmentGroupId);
+   
+    super.tearDown();
+  }
+    
+
+  public void testDirectUserCandidate() {
+    // this is the task we'll be looking for
+    Task task = taskService.newTask();
+    task.setName("do laundry");
+    long taskDbid = taskService.saveTask(task);
+    taskService.addTaskParticipatingUser(taskDbid, "johndoe", Participation.CANDIDATE);
+
+    // this tasks are a diversion to see if the query only selects the above task
+    task = taskService.newTask();
+    task.setName("dishes");
+    task.setAssignee("johndoe");
+    long johnsOtherTaskDbid = taskService.saveTask(task);
+    // this tasks are a diversion to see if the query only selects the above task
+    task = taskService.newTask();
+    task.setName("dishes");
+    long joesOtherTaskDbid = taskService.saveTask(task);
+    
+    
+    List<Task> groupTasks = taskService.findGroupTasks("johndoe");
+    assertEquals(1, groupTasks.size());
+    assertEquals(taskDbid, groupTasks.get(0).getDbid());
+    
+    groupTasks = taskService.findGroupTasks("joesmoe");
+    assertEquals(0, groupTasks.size());
+    
+    groupTasks = taskService.findGroupTasks("jackblack");
+    assertEquals(0, groupTasks.size());
+    
+    taskService.deleteTask(taskDbid);
+    taskService.deleteTask(johnsOtherTaskDbid);
+    taskService.deleteTask(joesOtherTaskDbid);
+  }
+
+  public void testGroupCandidate() {
+    Task task = taskService.newTask();
+    task.setName("do laundry");
+    long taskDbid = taskService.saveTask(task);
+    taskService.addTaskParticipatingGroup(taskDbid, salesGroupId, Participation.CANDIDATE);
+
+    // this tasks are a diversion to see if the query only selects the above task
+    task = taskService.newTask();
+    task.setName("dishes");
+    task.setAssignee("johndoe");
+    long johnsOtherTaskDbid = taskService.saveTask(task);
+    // this tasks are a diversion to see if the query only selects the above task
+    task = taskService.newTask();
+    task.setName("dishes");
+    long joesOtherTaskDbid = taskService.saveTask(task);
+    
+
+    List<Task> groupTasks = taskService.findGroupTasks("johndoe");
+    assertEquals(1, groupTasks.size());
+    assertEquals(taskDbid, groupTasks.get(0).getDbid());
+    
+    groupTasks = taskService.findGroupTasks("joesmoe");
+    assertEquals(1, groupTasks.size());
+    assertEquals(taskDbid, groupTasks.get(0).getDbid());
+    
+    groupTasks = taskService.findGroupTasks("jackblack");
+    assertEquals(0, groupTasks.size());
+    
+    taskService.deleteTask(taskDbid);
+    taskService.deleteTask(johnsOtherTaskDbid);
+    taskService.deleteTask(joesOtherTaskDbid);
+  }
+}


Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryCandidatesTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the jbpm-commits mailing list