-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3692: Query jobs by process / case definition key
- Loading branch information
Showing
20 changed files
with
613 additions
and
5 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
...lowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/mgmt/DeadLetterJobQueryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.flowable.cmmn.test.mgmt; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
|
||
import org.flowable.cmmn.api.runtime.CaseInstance; | ||
import org.flowable.cmmn.engine.test.CmmnDeployment; | ||
import org.flowable.cmmn.engine.test.FlowableCmmnTestCase; | ||
import org.flowable.common.engine.api.scope.ScopeTypes; | ||
import org.flowable.common.engine.impl.interceptor.Command; | ||
import org.flowable.job.api.DeadLetterJobQuery; | ||
import org.flowable.job.api.Job; | ||
import org.flowable.job.service.JobServiceConfiguration; | ||
import org.flowable.job.service.impl.DeadLetterJobQueryImpl; | ||
import org.flowable.job.service.impl.persistence.entity.DeadLetterJobEntity; | ||
import org.flowable.job.service.impl.persistence.entity.DeadLetterJobEntityManager; | ||
import org.flowable.job.service.impl.persistence.entity.SuspendedJobEntity; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Simon Amport | ||
*/ | ||
public class DeadLetterJobQueryTest extends FlowableCmmnTestCase { | ||
|
||
@Test | ||
@CmmnDeployment(resources = "org/flowable/cmmn/test/one-human-task-model.cmmn") | ||
public void testQueryByCaseDefinitionKey() { | ||
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder() | ||
.caseDefinitionKey("oneTaskCase") | ||
.start(); | ||
|
||
DeadLetterJobEntity deadLetterJob = cmmnEngineConfiguration.getCommandExecutor().execute(commandContext -> { | ||
DeadLetterJobEntityManager deadLetterJobEntityManager = cmmnEngineConfiguration.getJobServiceConfiguration().getDeadLetterJobEntityManager(); | ||
DeadLetterJobEntity deadLetterJobEntity = deadLetterJobEntityManager.create(); | ||
deadLetterJobEntity.setScopeId(caseInstance.getId()); | ||
deadLetterJobEntity.setScopeDefinitionId(caseInstance.getCaseDefinitionId()); | ||
deadLetterJobEntity.setScopeType(ScopeTypes.CMMN); | ||
deadLetterJobEntity.setJobType(SuspendedJobEntity.JOB_TYPE_MESSAGE); | ||
deadLetterJobEntity.setJobHandlerType("testJobHandlerType"); | ||
|
||
deadLetterJobEntityManager.insert(deadLetterJobEntity); | ||
return deadLetterJobEntity; | ||
}); | ||
|
||
DeadLetterJobEntity deadLetterJob2 = cmmnEngineConfiguration.getCommandExecutor().execute(commandContext -> { | ||
DeadLetterJobEntityManager deadLetterJobEntityManager = cmmnEngineConfiguration.getJobServiceConfiguration().getDeadLetterJobEntityManager(); | ||
DeadLetterJobEntity deadLetterJobEntity = deadLetterJobEntityManager.create(); | ||
deadLetterJobEntity.setProcessInstanceId("PRC-1"); | ||
deadLetterJobEntity.setProcessDefinitionId("PRC-DEF-1"); | ||
deadLetterJobEntity.setJobType(SuspendedJobEntity.JOB_TYPE_MESSAGE); | ||
deadLetterJobEntity.setJobHandlerType("testJobHandlerType"); | ||
|
||
deadLetterJobEntityManager.insert(deadLetterJobEntity); | ||
return deadLetterJobEntity; | ||
}); | ||
|
||
DeadLetterJobQuery query = cmmnEngineConfiguration.getCmmnManagementService().createDeadLetterJobQuery().caseDefinitionKey("oneTaskCase"); | ||
assertThat(query.count()).isEqualTo(1); | ||
assertThat(query.list()).extracting(Job::getId).containsExactly(deadLetterJob.getId()); | ||
assertThat(query.singleResult().getId()).isEqualTo(deadLetterJob.getId()); | ||
|
||
query = cmmnEngineConfiguration.getCmmnManagementService().createDeadLetterJobQuery().caseDefinitionKey("invalid"); | ||
assertThat(query.count()).isZero(); | ||
assertThat(query.list()).isEmpty(); | ||
assertThat(query.singleResult()).isNull(); | ||
|
||
cmmnEngineConfiguration.getCommandExecutor().execute((Command<Void>) commandContext -> { | ||
JobServiceConfiguration jobServiceConfiguration = cmmnEngineConfiguration.getJobServiceConfiguration(); | ||
DeadLetterJobEntityManager deadLetterJobService = jobServiceConfiguration.getDeadLetterJobEntityManager(); | ||
List<Job> jobs = deadLetterJobService.findJobsByQueryCriteria(new DeadLetterJobQueryImpl(commandContext, jobServiceConfiguration)); | ||
for (Job job : jobs) { | ||
deadLetterJobService.delete(job.getId()); | ||
} | ||
return null; | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/mgmt/JobQueryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.flowable.cmmn.test.mgmt; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.flowable.cmmn.api.runtime.CaseInstance; | ||
import org.flowable.cmmn.engine.test.CmmnDeployment; | ||
import org.flowable.cmmn.engine.test.FlowableCmmnTestCase; | ||
import org.flowable.job.api.Job; | ||
import org.flowable.job.api.JobQuery; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Simon Amport | ||
*/ | ||
public class JobQueryTest extends FlowableCmmnTestCase { | ||
|
||
@Test | ||
@CmmnDeployment(resources = "org/flowable/cmmn/test/mgmt/TimerJobQueryTest.cmmn") | ||
public void testQueryByCaseDefinitionKey() { | ||
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder() | ||
.caseDefinitionKey("timerJobQueryTest") | ||
.start(); | ||
|
||
Job timerJob = cmmnManagementService.createTimerJobQuery().singleResult(); | ||
|
||
Job executableJob = cmmnManagementService.moveTimerToExecutableJob(timerJob.getId()); | ||
assertThat(executableJob).isNotNull(); | ||
|
||
JobQuery jobQuery = cmmnManagementService.createJobQuery().caseDefinitionKey("timerJobQueryTest"); | ||
assertThat(jobQuery.count()).isEqualTo(1); | ||
assertThat(jobQuery.singleResult().getScopeId()).isEqualTo(caseInstance.getId()); | ||
assertThat(jobQuery.list()).extracting(Job::getId) | ||
.containsExactly(executableJob.getId()); | ||
|
||
jobQuery = cmmnManagementService.createJobQuery().caseDefinitionKey("invalid"); | ||
assertThat(jobQuery.count()).isZero(); | ||
assertThat(jobQuery.singleResult()).isNull(); | ||
assertThat(jobQuery.list()).isEmpty(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/mgmt/SuspendedJobQueryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.flowable.cmmn.test.mgmt; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.flowable.cmmn.api.runtime.CaseInstance; | ||
import org.flowable.cmmn.engine.test.CmmnDeployment; | ||
import org.flowable.cmmn.engine.test.FlowableCmmnTestCase; | ||
import org.flowable.common.engine.api.scope.ScopeTypes; | ||
import org.flowable.job.api.Job; | ||
import org.flowable.job.api.SuspendedJobQuery; | ||
import org.flowable.job.service.impl.persistence.entity.SuspendedJobEntity; | ||
import org.flowable.job.service.impl.persistence.entity.SuspendedJobEntityManager; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Simon Amport | ||
*/ | ||
public class SuspendedJobQueryTest extends FlowableCmmnTestCase { | ||
|
||
@Test | ||
@CmmnDeployment(resources = "org/flowable/cmmn/test/one-task-model.cmmn") | ||
public void testQueryByCaseDefinitionKey() { | ||
|
||
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder().caseDefinitionKey("oneTaskCase").start(); | ||
|
||
SuspendedJobEntity jobEntity = cmmnEngineConfiguration.getCommandExecutor().execute(commandContext -> { | ||
SuspendedJobEntityManager suspendedJobEntityManager = cmmnEngineConfiguration.getJobServiceConfiguration().getSuspendedJobEntityManager(); | ||
SuspendedJobEntity suspendedJobEntity = suspendedJobEntityManager.create(); | ||
suspendedJobEntity.setScopeId(caseInstance.getId()); | ||
suspendedJobEntity.setScopeDefinitionId(caseInstance.getCaseDefinitionId()); | ||
suspendedJobEntity.setScopeType(ScopeTypes.CMMN); | ||
suspendedJobEntity.setJobType(SuspendedJobEntity.JOB_TYPE_MESSAGE); | ||
suspendedJobEntity.setJobHandlerType("testJobHandlerType"); | ||
|
||
suspendedJobEntityManager.insert(suspendedJobEntity); | ||
return suspendedJobEntity; | ||
}); | ||
|
||
SuspendedJobQuery suspendedJobQuery = cmmnManagementService.createSuspendedJobQuery().caseDefinitionKey("oneTaskCase"); | ||
assertThat(suspendedJobQuery.count()).isEqualTo(1); | ||
assertThat(suspendedJobQuery.singleResult().getScopeId()).isEqualTo(caseInstance.getId()); | ||
assertThat(suspendedJobQuery.list()).extracting(Job::getId).containsExactly(jobEntity.getId()); | ||
|
||
suspendedJobQuery = cmmnManagementService.createSuspendedJobQuery().caseDefinitionKey("invalid"); | ||
assertThat(suspendedJobQuery.count()).isZero(); | ||
assertThat(suspendedJobQuery.singleResult()).isNull(); | ||
assertThat(suspendedJobQuery.list()).isEmpty(); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...les/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/mgmt/TimerJobQueryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.flowable.cmmn.test.mgmt; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.tuple; | ||
|
||
import org.flowable.cmmn.api.runtime.CaseInstance; | ||
import org.flowable.cmmn.engine.test.CmmnDeployment; | ||
import org.flowable.cmmn.engine.test.FlowableCmmnTestCase; | ||
import org.flowable.job.api.Job; | ||
import org.flowable.job.api.TimerJobQuery; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Simon Amport | ||
*/ | ||
public class TimerJobQueryTest extends FlowableCmmnTestCase { | ||
|
||
@Test | ||
@CmmnDeployment(resources = "org/flowable/cmmn/test/mgmt/TimerJobQueryTest.cmmn") | ||
public void testQueryByCaseDefinitionKey() { | ||
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder() | ||
.caseDefinitionKey("timerJobQueryTest") | ||
.start(); | ||
|
||
TimerJobQuery query = cmmnManagementService.createTimerJobQuery().caseDefinitionKey("timerJobQueryTest"); | ||
assertThat(query.count()).isEqualTo(1); | ||
assertThat(query.singleResult().getScopeId()).isEqualTo(caseInstance.getId()); | ||
assertThat(query.list()) | ||
.extracting(Job::getElementId, Job::getScopeId) | ||
.containsExactly( | ||
tuple("timerEventListener1", caseInstance.getId()) | ||
); | ||
|
||
query = cmmnManagementService.createTimerJobQuery().caseDefinitionKey("invalid"); | ||
assertThat(query.count()).isZero(); | ||
assertThat(query.singleResult()).isNull(); | ||
assertThat(query.list()).isEmpty(); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...lowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/mgmt/TimerJobQueryTest.cmmn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<definitions xmlns="http://www.omg.org/spec/CMMN/20151109/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flowable="http://flowable.org/cmmn" xmlns:cmmndi="http://www.omg.org/spec/CMMN/20151109/CMMNDI" xmlns:dc="http://www.omg.org/spec/CMMN/20151109/DC" xmlns:di="http://www.omg.org/spec/CMMN/20151109/DI" targetNamespace="http://flowable.org/cmmn"> | ||
<case id="timerJobQueryTest" name="Timer Job Query Test"> | ||
<casePlanModel id="onecaseplanmodel1" name="Case plan model"> | ||
<planItem id="planItemtimerEventListener1" definitionRef="timerEventListener1"></planItem> | ||
<planItem id="planItemhumanTask1" name="Human task" definitionRef="humanTask1"> | ||
<entryCriterion id="entryCriterion1" sentryRef="sentryentryCriterion1"></entryCriterion> | ||
</planItem> | ||
<sentry id="sentryentryCriterion1"> | ||
<planItemOnPart id="sentryOnPartentryCriterion1" sourceRef="planItemtimerEventListener1"> | ||
<standardEvent>occur</standardEvent> | ||
</planItemOnPart> | ||
</sentry> | ||
<timerEventListener id="timerEventListener1"> | ||
<timerExpression><![CDATA[PT1H]]></timerExpression> | ||
</timerEventListener> | ||
<humanTask id="humanTask1" name="Human task" flowable:assignee="${initiator}" flowable:formFieldValidation="false"> | ||
</humanTask> | ||
</casePlanModel> | ||
</case> | ||
</definitions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.