[jbpm-commits] JBoss JBPM SVN: r5652 - 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
Thu Sep 17 08:04:55 EDT 2009
Author: jbarrez
Date: 2009-09-17 08:04:55 -0400 (Thu, 17 Sep 2009)
New Revision: 5652
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java
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/HistoryDetailQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryTaskQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/JobQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessDefinitionQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java
Log:
Added test cases for orderBy of query API
Copied: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java (from rev 5433, jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/deploy/DeploymentQueryTest.java)
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java 2009-09-17 12:04:55 UTC (rev 5652)
@@ -0,0 +1,187 @@
+/*
+ * 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.query;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jbpm.api.Deployment;
+import org.jbpm.api.DeploymentQuery;
+import org.jbpm.test.JbpmTestCase;
+import org.jbpm.test.assertion.QueryAssertions;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class DeploymentQueryTest extends JbpmTestCase {
+
+ public void testSuspendDeployment() {
+ List<String> deploymentIds = deployTestProcesses();
+
+ repositoryService.suspendDeployment(deploymentIds.get(2));
+
+ // find all deployments
+
+ List<Deployment> deployments = repositoryService
+ .createDeploymentQuery()
+ .list();
+
+ Set<String> expectedDeploymentNames = new HashSet<String>();
+ expectedDeploymentNames.add("Claim");
+ expectedDeploymentNames.add("Hire");
+ expectedDeploymentNames.add("Fire");
+
+ assertEquals(expectedDeploymentNames, getDeploymentNames(deployments));
+
+ // find suspended deployments
+
+ deployments = repositoryService
+ .createDeploymentQuery()
+ .suspended()
+ .list();
+
+ expectedDeploymentNames = new HashSet<String>();
+ expectedDeploymentNames.add("Hire");
+
+ assertEquals(expectedDeploymentNames, getDeploymentNames(deployments));
+
+ // find active deployments
+
+ deployments = repositoryService
+ .createDeploymentQuery()
+ .notSuspended()
+ .list();
+
+ expectedDeploymentNames = new HashSet<String>();
+ expectedDeploymentNames.add("Claim");
+ expectedDeploymentNames.add("Fire");
+
+ assertEquals(expectedDeploymentNames, getDeploymentNames(deployments));
+
+ deleteCascade(deploymentIds);
+ }
+
+ private Set<String> getDeploymentNames(List<Deployment> deployments) {
+ Set<String> deploymentNames = new HashSet<String>();
+ for (Deployment deployment: deployments) {
+ deploymentNames.add(deployment.getName());
+ }
+ return deploymentNames;
+ }
+
+ private List<String> deployTestProcesses() {
+ List<String> processIds = new ArrayList<String>();
+
+ String deploymentClaimId = repositoryService
+ .createDeployment()
+ .setName("Claim")
+ .addResourceFromString("process.jpdl.xml",
+ "<process name='claim'>" +
+ " <start>" +
+ " <transition to='c' />" +
+ " </start>" +
+ " <state name='c' />" +
+ "</process>"
+ )
+ .deploy();
+
+ String deploymentHireId = repositoryService
+ .createDeployment()
+ .setName("Hire")
+ .addResourceFromString("process.jpdl.xml",
+ "<process name='hire'>" +
+ " <start>" +
+ " <transition to='h' />" +
+ " </start>" +
+ " <state name='h' />" +
+ "</process>"
+ )
+ .deploy();
+
+ String deploymentFireId = repositoryService
+ .createDeployment()
+ .setName("Fire")
+ .addResourceFromString("process.jpdl.xml",
+ "<process name='fire'>" +
+ " <start>" +
+ " <transition to='f' />" +
+ " </start>" +
+ " <state name='f' />" +
+ "</process>"
+ )
+ .deploy();
+
+ processIds.add(deploymentClaimId);
+ processIds.add(deploymentFireId);
+ processIds.add(deploymentHireId);
+
+ return processIds;
+ }
+
+ private void deleteCascade(List<String> deploymentIds) {
+ for (String deploymentId : deploymentIds) {
+ repositoryService.deleteDeploymentCascade(deploymentId);
+ }
+ }
+
+ public void testOrderByName() {
+ testOrderBy(DeploymentQuery.PROPERTY_NAME, Arrays.asList("Claim", "Fire", "Hire"));
+ }
+
+ public void testOrderByTimeStamp() {
+ testOrderByNaturalOrdening(DeploymentQuery.PROPERTY_TIMESTAMP, 3);
+ }
+
+ private void testOrderBy(String property, List expectedValues) {
+ testOrderBy(property, expectedValues, null, false);
+ }
+
+ private void testOrderByNaturalOrdening(String property, int expectedNrOfResults) {
+ testOrderBy(property, null, expectedNrOfResults, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void testOrderBy(String property, List expectedValues,
+ Integer expectedNrOfResults, boolean naturalOrderCheck) {
+
+ List<String> deploymentIds = deployTestProcesses();
+
+ List<Deployment> deploymentsAsc =
+ repositoryService.createDeploymentQuery().orderAsc(property).list();
+
+ List<Deployment> deploymentsDesc =
+ repositoryService.createDeploymentQuery().orderDesc(property).list();
+
+ if (naturalOrderCheck) {
+ QueryAssertions.assertOrderIsNatural(Deployment.class, property, deploymentsAsc, deploymentsDesc, 3);
+ } else {
+ QueryAssertions.assertOrderOnProperty(Deployment.class, property, deploymentsAsc, deploymentsDesc, expectedValues);
+ }
+
+ deleteCascade(deploymentIds);
+ }
+
+}
Copied: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java (from rev 5433, jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/HistoryActivityInstanceQeuryTest.java)
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java 2009-09-17 12:04:55 UTC (rev 5652)
@@ -0,0 +1,153 @@
+/*
+ * 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.query;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+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;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class HistoryActivityInstanceQueryTest extends JbpmTestCase {
+
+ public void testSimpleQuery() {
+ startAndSignalTestProcesses();
+
+ List<HistoryActivityInstance> histActInsts = historyService.createHistoryActivityInstanceQuery()
+ .activityName("a")
+ .list();
+
+ assertEquals(4, histActInsts.size());
+
+ histActInsts = historyService.createHistoryActivityInstanceQuery()
+ .activityName("b")
+ .list();
+
+ assertEquals(3, histActInsts.size());
+
+ histActInsts = historyService.createHistoryActivityInstanceQuery()
+ .activityName("c")
+ .list();
+
+ assertEquals(2, histActInsts.size());
+ }
+
+ public void testOrderByActivityName() {
+ testOrderBy(HistoryActivityInstanceQuery.PROPERTY_ACTIVITYNAME, Arrays.asList("a", "a", "a", "a", "b", "b", "b", "c", "c"));
+ }
+
+ public void testOrderByStartTime() {
+ testOrderByNaturalOrdening(HistoryActivityInstanceQuery.PROPERTY_STARTTIME, 9);
+ }
+
+ public void testOrderByEndTime() {
+ testOrderByNaturalOrdening(HistoryActivityInstanceQuery.PROPERTY_ENDTIME, 9);
+ }
+
+ public void testOrderByDuration() {
+ testOrderByNaturalOrdening(HistoryActivityInstanceQuery.PROPERTY_DURATION, 9);
+ }
+
+ public void testOrderByExecutionId() {
+ testOrderByNaturalOrdening(HistoryActivityInstanceQuery.PROPERTY_EXECUTIONID, 9);
+ }
+
+ private List<String> startAndSignalTestProcesses() {
+ deployJpdlXmlString(
+ "<process name='abc'>" +
+ " <start>" +
+ " <transition to='a' />" +
+ " </start>" +
+ " <state name='a'>" +
+ " <transition to ='b' />" +
+ " </state>" +
+ " <state name='b'>" +
+ " <transition to ='c' />" +
+ " </state>" +
+ " <state name='c'>" +
+ " <transition to ='end' />" +
+ " </state>" +
+ " <end name='end' />" +
+ "</process>"
+ );
+
+ List<String> ids = new ArrayList<String>();
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("abc");
+ executionService.signalExecutionById(processInstance.getId());
+ executionService.signalExecutionById(processInstance.getId());
+ executionService.signalExecutionById(processInstance.getId());
+ ids.add(processInstance.getId());
+
+ processInstance = executionService.startProcessInstanceByKey("abc");
+ executionService.signalExecutionById(processInstance.getId());
+ executionService.signalExecutionById(processInstance.getId());
+ ids.add(processInstance.getId());
+
+ processInstance = executionService.startProcessInstanceByKey("abc");
+ executionService.signalExecutionById(processInstance.getId());
+ ids.add(processInstance.getId());
+
+ processInstance = executionService.startProcessInstanceByKey("abc");
+ ids.add(processInstance.getId());
+
+ return ids;
+ }
+
+ private void testOrderBy(String property, List expectedValues) {
+ testOrderBy(property, expectedValues, null, false);
+ }
+
+ private void testOrderByNaturalOrdening(String property, int expectedNrOfResults) {
+ testOrderBy(property, null, expectedNrOfResults, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void testOrderBy(String property, List expectedValues,
+ Integer expectedNrOfResults, boolean naturalOrderCheck) {
+
+ startAndSignalTestProcesses();
+
+ List<HistoryActivityInstance> listAsc =
+ historyService.createHistoryActivityInstanceQuery().orderAsc(property).list();
+
+ List<HistoryActivityInstance> listDesc =
+ historyService.createHistoryActivityInstanceQuery().orderDesc(property).list();
+
+ if (naturalOrderCheck) {
+ QueryAssertions.assertOrderIsNatural(HistoryActivityInstance.class, property, listAsc, listDesc, expectedNrOfResults);
+ } else {
+ QueryAssertions.assertOrderOnProperty(HistoryActivityInstance.class, property, listAsc, listDesc, expectedValues);
+ }
+
+ }
+
+}
Copied: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryDetailQueryTest.java (from rev 5433, jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/HistoryDetailQueryTest.java)
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryDetailQueryTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryDetailQueryTest.java 2009-09-17 12:04:55 UTC (rev 5652)
@@ -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.test.query;
+
+import java.util.List;
+
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.api.history.HistoryComment;
+import org.jbpm.api.history.HistoryDetail;
+import org.jbpm.api.history.HistoryDetailQuery;
+import org.jbpm.api.history.HistoryTask;
+import org.jbpm.api.task.Task;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.test.JbpmTestCase;
+import org.jbpm.test.assertion.QueryAssertions;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class HistoryDetailQueryTest extends JbpmTestCase {
+
+ public void testTaskCommentDetail() {
+ deployJpdlXmlString(
+ "<process name='TaskCommentDetail'>" +
+ " <start>" +
+ " <transition to='t' />" +
+ " </start>" +
+ " <task name='t' assignee='johndoe'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("TaskCommentDetail");
+
+ String taskId = taskService.createTaskQuery().uniqueResult().getId();
+
+ taskService.addTaskComment(taskId, "hello");
+
+ List<HistoryDetail> historyDetails = historyService.createHistoryDetailQuery().list();
+ assertEquals(historyDetails.toString(), 1, historyDetails.size());
+
+ historyDetails = historyService
+ .createHistoryDetailQuery()
+ .comments()
+ .list();
+
+ assertEquals(historyDetails.toString(), 1, historyDetails.size());
+
+ HistoryComment historyComment = (HistoryComment) historyDetails.get(0);
+ assertEquals("hello", historyComment.getMessage());
+ }
+
+ public void testTaskCommentRepliesDetail() {
+ deployJpdlXmlString(
+ "<process name='TaskCommentRepliesDetail'>" +
+ " <start>" +
+ " <transition to='t' />" +
+ " </start>" +
+ " <task name='t' assignee='johndoe'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("TaskCommentRepliesDetail");
+
+ String taskId = taskService.createTaskQuery().uniqueResult().getId();
+
+ processEngine.setAuthenticatedUserId("johndoe");
+ String helloCommentId = taskService.addTaskComment(taskId, "hi, how are you guys?").getId();
+
+ processEngine.setAuthenticatedUserId("joesmoe");
+ taskService.addReplyComment(helloCommentId, "i'm doing fine, thanks");
+
+ processEngine.setAuthenticatedUserId("jackblack");
+ taskService.addReplyComment(helloCommentId, "i got a hangover");
+
+ List<HistoryDetail> historyDetails = historyService.createHistoryDetailQuery().list();
+ assertEquals(historyDetails.toString(), 3, historyDetails.size());
+
+ historyDetails = historyService
+ .createHistoryDetailQuery()
+ .comments()
+ .list();
+ }
+
+
+ public void testOrderBy() {
+
+ Task task = taskService.newTask();
+ taskService.saveTask(task);
+
+ // add some comments
+ taskService.addTaskComment(task.getId(), "aaaaaaa");
+ taskService.addTaskComment(task.getId(), "xxxxxxx");
+ String commentId = taskService.addTaskComment(task.getId(), "ggggggg").getId();
+ taskService.addReplyComment(commentId, "jjjjjj");
+
+ List<HistoryDetail> listAsc =
+ historyService.createHistoryDetailQuery().orderAsc(HistoryDetailQuery.PROPERTY_TIME).list();
+
+ List<HistoryDetail> listDesc =
+ historyService.createHistoryDetailQuery().orderDesc(HistoryDetailQuery.PROPERTY_TIME).list();
+
+ QueryAssertions.assertOrderIsNatural(HistoryDetail.class, HistoryDetailQuery.PROPERTY_TIME, listAsc, listDesc, 4);
+
+ taskService.deleteTaskCascade(task.getId());
+ }
+
+}
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java 2009-09-17 12:04:55 UTC (rev 5652)
@@ -0,0 +1,105 @@
+/*
+ * 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.query;
+
+import java.util.List;
+
+import org.jbpm.api.history.HistoryProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstanceQuery;
+import org.jbpm.test.JbpmTestCase;
+import org.jbpm.test.assertion.QueryAssertions;
+
+
+/**
+ * @author Joram Barrez
+ */
+public class HistoryProcessInstanceQueryTest extends JbpmTestCase {
+
+ public void testOrderByStartTime() {
+ testOrderByNaturalOrdening(HistoryProcessInstanceQuery.PROPERTY_STARTTIME, 4);
+ }
+
+ public void testOrderByEndTime() {
+ testOrderByNaturalOrdening(HistoryProcessInstanceQuery.PROPERTY_ENDTIME, 4);
+ }
+
+ public void testOrderByDuration() {
+ testOrderByNaturalOrdening(HistoryProcessInstanceQuery.PROPERTY_DURATION, 4);
+ }
+
+
+ /* -------------------------------------------------------------
+ * HELPER METHODS
+ * ------------------------------------------------------------- */
+
+ // Don't delete because it isn't used. Could be handy in the future!
+ private void testOrderBy(String property, List<Object> expectedValues) {
+ createTestHistoryProcessInstances();
+
+ List<HistoryProcessInstance> histProcListAsc =
+ historyService.createHistoryProcessInstanceQuery()
+ .orderAsc(property)
+ .list();
+
+ List<HistoryProcessInstance> histProcListDesc =
+ historyService.createHistoryProcessInstanceQuery()
+ .orderDesc(property)
+ .list();
+
+ QueryAssertions.assertOrderOnProperty(HistoryProcessInstance.class, property, histProcListAsc, histProcListDesc, expectedValues);
+ }
+
+ private void testOrderByNaturalOrdening(String property, int expectedNrOfResults) {
+ createTestHistoryProcessInstances();
+
+ List<HistoryProcessInstance> histProcListAsc =
+ historyService.createHistoryProcessInstanceQuery()
+ .orderAsc(property)
+ .list();
+
+ List<HistoryProcessInstance> histProcListDesc =
+ historyService.createHistoryProcessInstanceQuery()
+ .orderDesc(property)
+ .list();
+
+ QueryAssertions.assertOrderIsNatural(HistoryProcessInstance.class, property, histProcListAsc, histProcListDesc, expectedNrOfResults);
+ }
+
+ private void createTestHistoryProcessInstances() {
+ deployJpdlXmlString(
+ "<process name='theProcess'>" +
+ " <start>" +
+ " <transition to='end' />" +
+ " </start>" +
+ " <end name='end' />" +
+ "</process>");
+
+ for (int i = 0; i < 4; i++) {
+ executionService.startProcessInstanceByKey("theProcess");
+ }
+
+ }
+
+}
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryTaskQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryTaskQueryTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryTaskQueryTest.java 2009-09-17 12:04:55 UTC (rev 5652)
@@ -0,0 +1,141 @@
+/*
+ * 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.query;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import org.jbpm.api.history.HistoryTask;
+import org.jbpm.api.history.HistoryTaskQuery;
+import org.jbpm.test.JbpmTestCase;
+import org.jbpm.test.assertion.QueryAssertions;
+
+
+/**
+ * @author Joram Barrez
+ */
+public class HistoryTaskQueryTest extends JbpmTestCase {
+
+ public void testOrderByName() {
+ testOrderBy(HistoryTaskQuery.PROPERTY_ASSIGNEE, Arrays.asList("Alex", "Joram", "Tom"));
+ }
+
+ public void testOrderByStartTime() {
+ testOrderByNaturalOrdening(HistoryTaskQuery.PROPERTY_CREATETIME, 3);
+ }
+
+ public void testOrderByEndTime() {
+ testOrderByNaturalOrdening(HistoryTaskQuery.PROPERTY_ENDTIME, 3);
+ }
+
+ public void testOrderByDuration() {
+ testOrderByNaturalOrdening(HistoryTaskQuery.PROPERTY_DURATION, 3);
+ }
+
+ public void testOrderByexecutionId() {
+ testOrderByNaturalOrdening(HistoryTaskQuery.PROPERTY_EXECUTIONID, 3);
+ }
+
+ public void testOrderByOutcome() {
+ testOrderByNaturalOrdening(HistoryTaskQuery.PROPERTY_OUTCOME, 3);
+ }
+
+ public void testOrderByState() {
+ testOrderByNaturalOrdening(HistoryTaskQuery.PROPERTY_STATE, 3);
+ }
+
+ private void createTestHistoryTasks() {
+ String processXml1 =
+ "<process name='theProcess1'>" +
+ " <start>" +
+ " <transition to='theTask' />" +
+ " </start>" +
+ " <task name='theTask' assignee='Alex'>" +
+ " <transition to='theEnd' />" +
+ " </task>" +
+ " <end name='theEnd' />" +
+ "</process>";
+
+ String processXml3 = processXml1.replace("1", "2").replace("Alex", "Tom");
+ String processXml2 = processXml1.replace("1", "3").replace("Alex", "Joram");
+
+ deployJpdlXmlString(processXml1);
+ deployJpdlXmlString(processXml2);
+ deployJpdlXmlString(processXml3);
+
+ executionService.startProcessInstanceByKey("theProcess1");
+ executionService.startProcessInstanceByKey("theProcess2");
+ executionService.startProcessInstanceByKey("theProcess3");
+
+ taskService.completeTask(taskService.findPersonalTasks("Alex").get(0).getId());
+ taskService.completeTask(taskService.findPersonalTasks("Joram").get(0).getId());
+ taskService.completeTask(taskService.findPersonalTasks("Tom").get(0).getId());
+
+ taskService.findPersonalTasks("Alex");
+ }
+
+ private void testOrderBy(String property, List expectedValues) {
+ testOrderBy(property, expectedValues, null, false);
+ }
+
+ private void testOrderByNaturalOrdening(String property, int expectedNrOfResults) {
+ testOrderBy(property, null, expectedNrOfResults, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void testOrderBy(String property, List expectedValues,
+ Integer expectedNrOfResults, boolean naturalOrderCheck) {
+
+ createTestHistoryTasks();
+
+ List<HistoryTask> historyTasksAsc =
+ historyService.createHistoryTaskQuery().orderAsc(property).list();
+
+ List<HistoryTask> historyTasksDesc =
+ historyService.createHistoryTaskQuery().orderDesc(property).list();
+
+ if (naturalOrderCheck) {
+ QueryAssertions.assertOrderIsNatural(HistoryTask.class, property, historyTasksAsc, historyTasksDesc, expectedNrOfResults);
+ } else {
+ QueryAssertions.assertOrderOnProperty(HistoryTask.class, property, historyTasksAsc, historyTasksDesc, expectedValues);
+ }
+
+ }
+
+ private Date stringToDate(String dateString) {
+ DateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy");
+ try {
+ return dateFormat.parse(dateString);
+ } catch (ParseException e) {
+ throw new RuntimeException("Couldn't convert " + dateString);
+ }
+ }
+
+
+}
Copied: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/JobQueryTest.java (from rev 5433, jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/mgmt/JobQueryTest.java)
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/JobQueryTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/JobQueryTest.java 2009-09-17 12:04:55 UTC (rev 5652)
@@ -0,0 +1,126 @@
+package org.jbpm.test.query;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.jbpm.api.JobQuery;
+import org.jbpm.api.job.Job;
+import org.jbpm.test.JbpmTestCase;
+import org.jbpm.test.assertion.QueryAssertions;
+
+
+public class JobQueryTest extends JbpmTestCase {
+
+ public void testQueryOutstandingTimers() {
+ startTestProcessInstances();
+
+ List<Job> timers = managementService.createJobQuery()
+ .timers()
+ .list();
+
+ assertEquals(4, timers.size());
+ }
+
+ public void testQueryBacklogMessages() {
+ deployJpdlXmlString(
+ "<process name='MessagesQueryTest' >" +
+ " <start>" +
+ " <transition to='t' />" +
+ " </start>" +
+ " <state name='t' continue='async' />" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("MessagesQueryTest");
+ executionService.startProcessInstanceByKey("MessagesQueryTest");
+ executionService.startProcessInstanceByKey("MessagesQueryTest");
+ executionService.startProcessInstanceByKey("MessagesQueryTest");
+
+ List<Job> jobs = managementService.createJobQuery()
+ .messages()
+ .list();
+
+ assertEquals(4, jobs.size());
+ }
+
+ private void startTestProcessInstances() {
+ deployJpdlXmlString(
+ "<process name='TimerQueryTest' >" +
+ " <start>" +
+ " <transition to='t' />" +
+ " </start>" +
+ " <state name='t'>" +
+ " <transition name='timeout' to='t'>" +
+ " <timer duedate='20 seconds' />" +
+ " </transition>" +
+ " </state>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("TimerQueryTest");
+ executionService.startProcessInstanceByKey("TimerQueryTest");
+ executionService.startProcessInstanceByKey("TimerQueryTest");
+ executionService.startProcessInstanceByKey("TimerQueryTest");
+ }
+
+
+ public static class Dog implements Serializable {
+ private static final long serialVersionUID = 1L;
+ public void bark() {
+ throw new RuntimeException("wooof");
+ }
+ }
+
+ public void testErrorMessages() {
+ deployJpdlXmlString(
+ "<process name='ErrorMsgQueryTest' >" +
+ " <start>" +
+ " <transition to='t' />" +
+ " </start>" +
+ " <java name='t' " +
+ " continue='async' " +
+ " class='"+Dog.class.getName()+"'" +
+ " method='bark'>" +
+ " </java>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("ErrorMsgQueryTest");
+ executionService.startProcessInstanceByKey("ErrorMsgQueryTest");
+ executionService.startProcessInstanceByKey("ErrorMsgQueryTest");
+
+
+ List<Job> messages = managementService.createJobQuery()
+ .messages()
+ .list();
+
+ assertEquals(3, messages.size());
+
+ managementService.executeJob(messages.get(0).getId());
+ managementService.executeJob(messages.get(0).getId());
+ managementService.executeJob(messages.get(0).getId());
+
+ List<Job> errorJobs = managementService.createJobQuery()
+ .exception(true)
+ .list();
+
+ assertEquals(1, errorJobs.size());
+
+ assertTextPresent("wooof", errorJobs.get(0).getException());
+
+ messages = managementService.createJobQuery()
+ .messages()
+ .exception(false)
+ .list();
+
+ assertEquals(2, messages.size());
+ }
+
+ public void testOrderByDueDate() {
+ startTestProcessInstances();
+ List<Job> jobsAsc = managementService.createJobQuery().orderAsc(JobQuery.PROPERTY_DUEDATE).list();
+ List<Job> jobsDesc = managementService.createJobQuery().orderDesc(JobQuery.PROPERTY_DUEDATE).list();
+ QueryAssertions.assertOrderIsNatural(Job.class, JobQuery.PROPERTY_DUEDATE, jobsAsc, jobsDesc, 4);
+ }
+
+}
Copied: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessDefinitionQueryTest.java (from rev 5433, jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/ProcessDefinitionQueryTest.java)
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessDefinitionQueryTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessDefinitionQueryTest.java 2009-09-17 12:04:55 UTC (rev 5652)
@@ -0,0 +1,138 @@
+/*
+ * 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.query;
+
+import java.util.List;
+
+import org.jbpm.api.ProcessDefinition;
+import org.jbpm.api.ProcessDefinitionQuery;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ProcessDefinitionQueryTest extends JbpmTestCase {
+
+ public void testQueryProcessDefinitionsEmpty() {
+ List<ProcessDefinition> processDefinitions = repositoryService
+ .createProcessDefinitionQuery()
+ .list();
+
+ assertEquals(0, processDefinitions.size());
+ }
+
+ public void testQueryProcessDefinitionsNameLike() {
+ deployJpdlXmlString(
+ "<process name='make print'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='use phone'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='make friends'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='clean whiteboard'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='fix coffeemaker'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery()
+ .processDefinitionNameLike("%make%")
+ .orderAsc(ProcessDefinitionQuery.PROPERTY_NAME)
+ .list();
+
+ assertEquals("fix coffeemaker", processDefinitions.get(0).getName());
+ assertEquals("make friends", processDefinitions.get(1).getName());
+ assertEquals("make print", processDefinitions.get(2).getName());
+ }
+
+ public void testQueryProcessDefinitionsKeyLike() {
+ deployJpdlXmlString(
+ "<process name='make print'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='use phone'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='make friends'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='make friends'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='make friends'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='clean whiteboard'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='fix coffeemaker'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery()
+ .processDefinitionNameLike("make%")
+ .orderAsc(ProcessDefinitionQuery.PROPERTY_ID)
+ .list();
+
+ assertEquals("make_friends-1", processDefinitions.get(0).getId());
+ assertEquals("make_friends-2", processDefinitions.get(1).getId());
+ assertEquals("make_friends-3", processDefinitions.get(2).getId());
+ assertEquals("make_print-1", processDefinitions.get(3).getId());
+ }
+}
Copied: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java (from rev 5627, jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryTest.java)
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java 2009-09-17 12:04:55 UTC (rev 5652)
@@ -0,0 +1,190 @@
+/*
+ * 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.query;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import org.jbpm.api.TaskQuery;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+import org.jbpm.test.assertion.QueryAssertions;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TaskQueryTest extends JbpmTestCase {
+
+ public void testPropertyNames() {
+ Task task = taskService.newTask();
+ task.setName("write task query test");
+ task.setAssignee("koen");
+ task.setPriority(Integer.MAX_VALUE);
+ task.setDescription("make sure the test fails if property names are incorrect");
+ task.setDuedate(new Date());
+ String taskId = taskService.saveTask(task);
+
+ checkProperty(taskService.createTaskQuery(), task, TaskQuery.PROPERTY_ASSIGNEE);
+ checkProperty(taskService.createTaskQuery(), task, TaskQuery.PROPERTY_CREATEDATE);
+ checkProperty(taskService.createTaskQuery(), task, TaskQuery.PROPERTY_DUEDATE);
+ checkProperty(taskService.createTaskQuery(), task, TaskQuery.PROPERTY_NAME);
+ checkProperty(taskService.createTaskQuery(), task, TaskQuery.PROPERTY_PRIORITY);
+ checkProperty(taskService.createTaskQuery(), task, TaskQuery.PROPERTY_PROGRESS);
+
+ taskService.deleteTaskCascade(taskId);
+ }
+
+ private void checkProperty(TaskQuery taskQuery, Task task, String propertyName) {
+ List<Task> taskList = taskQuery.orderAsc(propertyName).list();
+ assertNotNull(taskList);
+ assertContainsTask(taskList, task.getName());
+ assertEquals(1, taskList.size());
+ }
+
+ public void testSimplestTaskQuery() {
+ List<Task> tasks = createTestTasks();
+
+ List<Task> taskList = taskService
+ .createTaskQuery()
+ .list();
+ assertNotNull(taskList);
+
+ assertContainsTask(taskList, "do laundry");
+ assertContainsTask(taskList, "change dyper");
+ assertContainsTask(taskList, "start new business");
+ assertContainsTask(taskList, "find venture capital");
+
+ assertEquals(4, taskList.size());
+
+ deleteTasks(tasks);
+ }
+
+ public void testOrderByName() {
+ testOrderBy(TaskQuery.PROPERTY_NAME,
+ new String[] {"change dyper", "do laundry", "find venture capital", "start new business"});
+ }
+
+ public void testOrderByAssignee() {
+ testOrderBy(TaskQuery.PROPERTY_ASSIGNEE, new String[] {null, "Joram", "Koen", "Tom"});
+ }
+
+ public void testOrderByCreateTime() {
+ testOrderByResultsInNaturalOrdening(TaskQuery.PROPERTY_CREATEDATE, 4);
+ }
+
+ public void testOrderByDueDate() {
+ testOrderByResultsInNaturalOrdening(TaskQuery.PROPERTY_DUEDATE, 4);
+ }
+
+ public void testOrderByPriority() {
+ testOrderByResultsInNaturalOrdening(TaskQuery.PROPERTY_PRIORITY, 4);
+ }
+
+ public void testOrderByProgress() {
+ testOrderBy(TaskQuery.PROPERTY_PROGRESS, new Integer[] {2, 15, 75, 99});
+ }
+
+
+ /* -------------------------------------------------------------------
+ * HELPER METHODS
+ * ------------------------------------------------------------------- */
+
+ private List<Task> createTestTasks() {
+ List<Task> result = new ArrayList<Task>();
+
+ Task task1 = taskService.newTask();
+ task1.setName("do laundry");
+ task1.setAssignee("Tom");
+ task1.setPriority(3);
+ task1.setDuedate(stringToDate("10/10/1985"));
+ task1.setProgress(15);
+
+ Task task2 = taskService.newTask();
+ task2.setName("change dyper");
+ task2.setAssignee("Koen");
+ task2.setPriority(1);
+ task2.setDuedate(stringToDate("28/06/1989"));
+ task2.setProgress(2);
+
+ Task task3 = taskService.newTask();
+ task3.setName("start new business");
+ task3.setAssignee("Joram");
+ task3.setPriority(4);
+ task3.setProgress(75);
+
+ Task task4 = taskService.newTask();
+ task4.setName("find venture capital");
+ task4.setPriority(7);
+ task4.setDuedate(stringToDate("09/09/2009"));
+ task4.setProgress(99);
+
+ for (Task t : new Task[] {task1, task2, task3, task4}) {
+ taskService.saveTask(t);
+ result.add(t);
+ }
+
+ return result;
+ }
+
+ private void testOrderBy(String property, Object[] expectedValues) {
+ List<Task> tasks = createTestTasks();
+
+ List<Task> taskListAsc = taskService.createTaskQuery().orderAsc(property).list();
+ List<Task> taskListDesc = taskService.createTaskQuery().orderDesc(property).list();
+
+ QueryAssertions.assertOrderOnProperty(Task.class, property, taskListAsc, taskListDesc, Arrays.asList(expectedValues));
+
+ deleteTasks(tasks);
+ }
+
+ private void testOrderByResultsInNaturalOrdening(String property, int expectedNrOfResults) {
+ List<Task> tasks = createTestTasks();
+ List<Task> taskListAsc = taskService.createTaskQuery().orderAsc(property).list();
+ List<Task> taskListDesc = taskService.createTaskQuery().orderDesc(property).list();
+
+ QueryAssertions.assertOrderIsNatural(Task.class, property, taskListAsc, taskListDesc, expectedNrOfResults);
+
+ deleteTasks(tasks);
+ }
+
+ private void deleteTasks(List<Task> tasks) {
+ for (Task t : tasks) {
+ taskService.deleteTaskCascade(t.getId());
+ }
+ }
+
+ private Date stringToDate(String dateString) {
+ DateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy");
+ try {
+ return dateFormat.parse(dateString);
+ } catch (ParseException e) {
+ throw new RuntimeException("Couldn't convert " + dateString);
+ }
+ }
+
+}
More information about the jbpm-commits
mailing list