forked from flowable/flowable-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flowable#3692: Query jobs by case definition key
- Loading branch information
Showing
17 changed files
with
391 additions
and
2 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
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
/* 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.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(); | ||
|
||
assertThat(cmmnManagementService.createJobQuery().caseDefinitionKey("timerJobQueryTest").count()).isEqualTo(1); | ||
assertThat(cmmnManagementService.createJobQuery().caseDefinitionKey("timerJobQueryTest").singleResult().getScopeId()).isEqualTo(caseInstance.getId()); | ||
assertThat(cmmnManagementService.createJobQuery().caseDefinitionKey("timerJobQueryTest").list()).extracting(Job::getId) | ||
.containsExactly(executableJob.getId()); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...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,56 @@ | ||
/* 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.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; | ||
}); | ||
|
||
assertThat(cmmnManagementService.createSuspendedJobQuery().caseDefinitionKey("oneTaskCase").count()).isEqualTo(1); | ||
assertThat(cmmnManagementService.createSuspendedJobQuery().caseDefinitionKey("oneTaskCase").singleResult().getScopeId()).isEqualTo(caseInstance.getId()); | ||
assertThat(cmmnManagementService.createSuspendedJobQuery().caseDefinitionKey("oneTaskCase").list()).extracting(Job::getId).containsExactly(jobEntity.getId()); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...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,48 @@ | ||
/* 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()) | ||
); | ||
} | ||
|
||
} |
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
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
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.