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

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Nov 24 14:11:51 EST 2009


Author: jbarrez
Date: 2009-11-24 14:11:51 -0500 (Tue, 24 Nov 2009)
New Revision: 5890

Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java
Log:
Fix for JBPM-2649: HistoryActivityInstanceQueryImpl references wrong property for processDefinitionId. Also fixed 2 related bugs regarding querying using startedBefore/startedAfter

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java	2009-11-19 04:44:02 UTC (rev 5889)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java	2009-11-24 19:11:51 UTC (rev 5890)
@@ -54,7 +54,7 @@
     hql.append(" as hai ");
     
     if (processDefinitionId!=null) {
-      appendWhereClause(" hai.historyActivityInstance.processDefinitionId = '"+processDefinitionId+"' ", hql);
+      appendWhereClause(" hai.historyProcessInstance.processDefinitionId = '"+processDefinitionId+"' ", hql);
     }
 
     if (tookLessThen!=null) {
@@ -96,11 +96,11 @@
     }
     
     if (startedBefore!=null) {
-      query.setTime("startedBefore", startedBefore);
+      query.setTimestamp("startedBefore", startedBefore);
     }
     
     if (startedAfter!=null) {
-      query.setTime("startedAfter", startedAfter);
+      query.setTimestamp("startedAfter", startedAfter);
     }
   }
 

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java	2009-11-19 04:44:02 UTC (rev 5889)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java	2009-11-24 19:11:51 UTC (rev 5890)
@@ -23,12 +23,15 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import org.jbpm.api.ProcessDefinition;
 import org.jbpm.api.ProcessInstance;
 import org.jbpm.api.history.HistoryActivityInstance;
 import org.jbpm.api.history.HistoryActivityInstanceQuery;
-import org.jbpm.api.history.HistoryTask;
 import org.jbpm.test.JbpmTestCase;
 import org.jbpm.test.assertion.QueryAssertions;
 
@@ -39,7 +42,7 @@
 public class HistoryActivityInstanceQueryTest extends JbpmTestCase {
 
   public void testSimpleQuery() {
-    startAndSignalTestProcesses();
+    deployStartAndSignalTestProcesses();
     
     List<HistoryActivityInstance> histActInsts = historyService.createHistoryActivityInstanceQuery()
       .activityName("a")
@@ -60,6 +63,69 @@
     assertEquals(2, histActInsts.size());
   }
   
+  // Test for JBPM-2649
+  public void testQueryByProcessDefinitionId() {
+    String procDefId = deployTestProcess();
+    generateHistoryForTestProcess();
+
+    ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery()
+                                                 .deploymentId(procDefId).uniqueResult();
+
+    List<HistoryActivityInstance> hacs = historyService.createHistoryActivityInstanceQuery()
+                                                       .processDefinitionId(procDef.getId()).list();
+    assertEquals(9, hacs.size()); // 4 x a (ended, abc, ab, a), 3 x b (ended, abc, ab, a), etc
+
+    // Verify counts of historical activities by using its name
+    Map<String, Integer> activityCounts = new HashMap<String, Integer>();
+    for (HistoryActivityInstance hac : hacs) {
+      String name = hac.getActivityName();
+      Integer current = activityCounts.get(name);
+      activityCounts.put(name, (current == null ? 0 : current) + 1);
+    }
+
+    assertEquals(new Integer(4), activityCounts.get("a"));
+    assertEquals(new Integer(3), activityCounts.get("b"));
+    assertEquals(new Integer(2), activityCounts.get("c"));
+  }
+  
+  // Currently only verifies the size of the result set
+  public void testQueryByExecutionId() {
+    List<String> ids = deployStartAndSignalTestProcesses();
+    
+    assertEquals(3, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(0)).list().size());
+    assertEquals(3, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(1)).list().size());
+    assertEquals(2, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(2)).list().size());
+    assertEquals(1, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(3)).list().size());
+  }
+  
+  // Currently only verifies the size of the result set
+  public void testQueryByStartedAfter() {
+    Date timeStamp = new Date();
+    deployStartAndSignalTestProcesses();
+    assertEquals(9, historyService.createHistoryActivityInstanceQuery().startedAfter(timeStamp).list().size());
+  }
+  
+  // Currently only verifies the size of the result set
+  public void testQueryByStartedBefore() {
+    deployStartAndSignalTestProcesses();
+    Date timeStamp = new Date();
+    assertEquals(9, historyService.createHistoryActivityInstanceQuery().startedBefore(timeStamp).list().size());
+  }
+  
+  //Currently only verifies the size of the result set
+  public void testQueryByActivityName() {
+    deployStartAndSignalTestProcesses();
+    assertEquals(4, historyService.createHistoryActivityInstanceQuery().activityName("a").list().size());
+    assertEquals(3, historyService.createHistoryActivityInstanceQuery().activityName("b").list().size());
+    assertEquals(2, historyService.createHistoryActivityInstanceQuery().activityName("c").list().size());
+  }
+  
+  //Currently only verifies the size of the result set
+  public void testQueryByTookLessThen() {
+    deployStartAndSignalTestProcesses();
+    assertEquals(9, historyService.createHistoryActivityInstanceQuery().tookLessThen(60*60*1000).list().size());
+  }
+  
   public void testOrderByActivityName() {
     testOrderBy(HistoryActivityInstanceQuery.PROPERTY_ACTIVITYNAME, Arrays.asList("a", "a", "a", "a", "b", "b", "b", "c", "c"));
   }
@@ -80,8 +146,25 @@
     testOrderByNaturalOrdening(HistoryActivityInstanceQuery.PROPERTY_EXECUTIONID, 9);
   }
   
-  private List<String> startAndSignalTestProcesses() {
-    deployJpdlXmlString(
+  /**
+   * Generates some history data.
+   * 
+   * Calling this method will produce (in this order):
+   *   - 1 ended process instance (signalled state a,b,c)
+   *   - 1 process instance in state c (signalled a,b)
+   *   - 1 process instance in state b (signalled a)
+   *   - 1 process instance in state a (just started)
+   */
+  private List<String> deployStartAndSignalTestProcesses() {
+    deployTestProcess();
+    return generateHistoryForTestProcess();
+  }
+  
+  /**
+   * Returns deployment db id
+   */
+  private String deployTestProcess() {
+    return deployJpdlXmlString(
             "<process name='abc'>" +
             "  <start>" +
             "    <transition to='a' />" +
@@ -98,7 +181,9 @@
             "  <end name='end' />" +
             "</process>"
           );
+  }
 
+  private List<String> generateHistoryForTestProcess() {
     List<String> ids = new ArrayList<String>();
     
     ProcessInstance processInstance = executionService.startProcessInstanceByKey("abc");
@@ -134,7 +219,7 @@
   private void testOrderBy(String property, List expectedValues, 
           Integer expectedNrOfResults, boolean naturalOrderCheck) {
     
-    startAndSignalTestProcesses();
+    deployStartAndSignalTestProcesses();
 
     List<HistoryActivityInstance> listAsc = 
       historyService.createHistoryActivityInstanceQuery().orderAsc(property).list();



More information about the jbpm-commits mailing list