Java源码示例:org.camunda.bpm.engine.runtime.EventSubscriptionQuery
示例1
public void testQueryByTenantIdsIncludeSubscriptionsWithoutTenantId() {
EventSubscriptionQuery query = runtimeService
.createEventSubscriptionQuery()
.tenantIdIn(TENANT_ONE)
.includeEventSubscriptionsWithoutTenantId();
assertThat(query.count(), is(2L));
query = runtimeService
.createEventSubscriptionQuery()
.tenantIdIn(TENANT_TWO)
.includeEventSubscriptionsWithoutTenantId();
assertThat(query.count(), is(2L));
query = runtimeService
.createEventSubscriptionQuery()
.tenantIdIn(TENANT_ONE, TENANT_TWO)
.includeEventSubscriptionsWithoutTenantId();
assertThat(query.count(), is(3L));
}
示例2
public void testQueryWithoutAuthorization() {
// given
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
// when
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
// then
verifyQueryResults(query, 0);
}
示例3
public void testQueryWithReadPermissionOnProcessInstance() {
// given
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
String processInstanceId = startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
// when
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
// then
verifyQueryResults(query, 1);
EventSubscription eventSubscription = query.singleResult();
assertNotNull(eventSubscription);
assertEquals(processInstanceId, eventSubscription.getProcessInstanceId());
}
示例4
public void testQueryWithReadPermissionOnAnyProcessInstance() {
// given
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
// when
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
// then
verifyQueryResults(query, 7);
}
示例5
public void testQueryWithReadInstancesPermissionOnOneTaskProcess() {
// given
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, READ_INSTANCE);
// when
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
// then
verifyQueryResults(query, 3);
}
示例6
public void testQueryWithReadInstancesPermissionOnAnyProcessDefinition() {
// given
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_INSTANCE);
// when
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
// then
verifyQueryResults(query, 7);
}
示例7
public void testQueryByEventSubscriptionId() {
createExampleEventSubscriptions();
List<EventSubscription> list = runtimeService.createEventSubscriptionQuery()
.eventName("messageName2")
.list();
assertEquals(1, list.size());
EventSubscription eventSubscription = list.get(0);
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery()
.eventSubscriptionId(eventSubscription.getId());
assertEquals(1, query.count());
assertEquals(1, query.list().size());
assertNotNull(query.singleResult());
try {
runtimeService.createEventSubscriptionQuery().eventSubscriptionId(null).list();
fail("Expected ProcessEngineException");
} catch (ProcessEngineException e) {
}
cleanDb();
}
示例8
@Deployment
public void testKeepCompensation() {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");
TaskQuery taskQuery = taskService.createTaskQuery();
EventSubscriptionQuery eventSubscriptionQuery = runtimeService.createEventSubscriptionQuery();
Task task = taskQuery.singleResult();
assertNotNull(task);
assertEquals("taskBeforeInterruptingEventSuprocess", task.getTaskDefinitionKey());
List<EventSubscription> eventSubscriptions = eventSubscriptionQuery.list();
assertEquals(2, eventSubscriptions.size());
runtimeService.messageEventReceived("newMessage", pi.getId());
task = taskQuery.singleResult();
assertNotNull(task);
assertEquals("taskAfterMessageStartEvent", task.getTaskDefinitionKey());
assertEquals(1, eventSubscriptionQuery.count());
taskService.complete(task.getId());
assertProcessEnded(pi.getId());
}
示例9
@Deployment(resources = {"org/camunda/bpm/engine/test/history/HistoricActivityInstanceTest.testHistoricActivityInstanceTimerEvent.bpmn20.xml"})
public void testHistoricActivityInstanceMessageEvent() {
runtimeService.startProcessInstanceByKey("catchSignal");
JobQuery jobQuery = managementService.createJobQuery();
assertEquals(1, jobQuery.count());
EventSubscriptionQuery eventSubscriptionQuery = runtimeService.createEventSubscriptionQuery();
assertEquals(1, eventSubscriptionQuery.count());
runtimeService.correlateMessage("newInvoice");
TaskQuery taskQuery = taskService.createTaskQuery();
Task task = taskQuery.singleResult();
assertEquals("afterMessage", task.getName());
HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery().activityId("gw1");
assertEquals(1, historicActivityInstanceQuery.count());
assertNotNull(historicActivityInstanceQuery.singleResult().getEndTime());
historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery().activityId("messageEvent");
assertEquals(1, historicActivityInstanceQuery.count());
assertNotNull(historicActivityInstanceQuery.singleResult().getEndTime());
assertEquals("intermediateMessageCatch", historicActivityInstanceQuery.singleResult().getActivityType());
}
示例10
public List<EventSubscriptionDto> queryEventSubscriptions(EventSubscriptionQueryDto queryDto, Integer firstResult, Integer maxResults) {
ProcessEngine engine = getProcessEngine();
queryDto.setObjectMapper(getObjectMapper());
EventSubscriptionQuery query = queryDto.toQuery(engine);
List<EventSubscription> matchingEventSubscriptions;
if (firstResult != null || maxResults != null) {
matchingEventSubscriptions = executePaginatedQuery(query, firstResult, maxResults);
} else {
matchingEventSubscriptions = query.list();
}
List<EventSubscriptionDto> eventSubscriptionResults = new ArrayList<EventSubscriptionDto>();
for (EventSubscription eventSubscription : matchingEventSubscriptions) {
EventSubscriptionDto resultEventSubscription = EventSubscriptionDto.fromEventSubscription(eventSubscription);
eventSubscriptionResults.add(resultEventSubscription);
}
return eventSubscriptionResults;
}
示例11
public void testQueryByTenantId() {
EventSubscriptionQuery query = runtimeService
.createEventSubscriptionQuery()
.tenantIdIn(TENANT_ONE);
assertThat(query.count(), is(1L));
query = runtimeService
.createEventSubscriptionQuery()
.tenantIdIn(TENANT_TWO);
assertThat(query.count(), is(1L));
}
示例12
public void testQueryByTenantIds() {
EventSubscriptionQuery query = runtimeService
.createEventSubscriptionQuery()
.tenantIdIn(TENANT_ONE, TENANT_TWO);
assertThat(query.count(), is(2L));
}
示例13
public void testQueryBySubscriptionsWithoutTenantId() {
EventSubscriptionQuery query = runtimeService
.createEventSubscriptionQuery()
.withoutTenantId();
assertThat(query.count(), is(1L));
}
示例14
public void testQueryByNonExistingTenantId() {
EventSubscriptionQuery query = runtimeService.
createEventSubscriptionQuery()
.tenantIdIn("nonExisting");
assertThat(query.count(), is(0L));
}
示例15
public void testQueryAuthenticatedTenant() {
identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
assertThat(query.count(), is(2L));
assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));
assertThat(query.tenantIdIn(TENANT_TWO).count(), is(0L));
assertThat(query.tenantIdIn(TENANT_ONE, TENANT_TWO).includeEventSubscriptionsWithoutTenantId().count(), is(2L));
}
示例16
public void testQueryAuthenticatedTenants() {
identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE, TENANT_TWO));
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
assertThat(query.count(), is(3L));
assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));
assertThat(query.tenantIdIn(TENANT_TWO).count(), is(1L));
}
示例17
public void testQueryDisabledTenantCheck() {
processEngineConfiguration.setTenantCheckEnabled(false);
identityService.setAuthentication("user", null, null);
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
assertThat(query.count(), is(3L));
}
示例18
public void testSimpleQueryWithoutAuthorization() {
// given
startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
// when
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
// then
verifyQueryResults(query, 0);
}
示例19
public void testSimpleQueryWithReadPermissionOnProcessInstance() {
// given
String processInstanceId = startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
// when
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
// then
verifyQueryResults(query, 1);
EventSubscription eventSubscription = query.singleResult();
assertNotNull(eventSubscription);
assertEquals(processInstanceId, eventSubscription.getProcessInstanceId());
}
示例20
public void testSimpleQueryWithReadPermissionOnAnyProcessInstance() {
// given
String processInstanceId = startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
// when
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
// then
verifyQueryResults(query, 1);
EventSubscription eventSubscription = query.singleResult();
assertNotNull(eventSubscription);
assertEquals(processInstanceId, eventSubscription.getProcessInstanceId());
}
示例21
public void testSimpleQueryWithMultiple() {
// given
String processInstanceId = startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
// when
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
// then
verifyQueryResults(query, 1);
}
示例22
public void testSimpleQueryWithReadInstancesPermissionOnOneTaskProcess() {
// given
String processInstanceId = startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, READ_INSTANCE);
// when
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
// then
verifyQueryResults(query, 1);
EventSubscription eventSubscription = query.singleResult();
assertNotNull(eventSubscription);
assertEquals(processInstanceId, eventSubscription.getProcessInstanceId());
}
示例23
public void testSimpleQueryWithReadInstancesPermissionOnAnyProcessDefinition() {
// given
String processInstanceId = startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_INSTANCE);
// when
EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
// then
verifyQueryResults(query, 1);
EventSubscription eventSubscription = query.singleResult();
assertNotNull(eventSubscription);
assertEquals(processInstanceId, eventSubscription.getProcessInstanceId());
}
示例24
@Deployment
public void testCatchSignalAndMessageAndTimer() {
runtimeService.startProcessInstanceByKey("catchSignal");
assertEquals(2, runtimeService.createEventSubscriptionQuery().count());
EventSubscriptionQuery messageEventSubscriptionQuery = runtimeService.createEventSubscriptionQuery().eventType("message");
assertEquals(1, messageEventSubscriptionQuery.count());
assertEquals(1, runtimeService.createEventSubscriptionQuery().eventType("signal").count());
assertEquals(1, runtimeService.createProcessInstanceQuery().count());
assertEquals(1, managementService.createJobQuery().count());
// we can query for an execution with has both a signal AND message subscription
Execution execution = runtimeService.createExecutionQuery()
.messageEventSubscriptionName("newInvoice")
.signalEventSubscriptionName("alert")
.singleResult();
assertNotNull(execution);
ClockUtil.setCurrentTime(new Date(ClockUtil.getCurrentTime().getTime() +10000));
try {
EventSubscription messageEventSubscription = messageEventSubscriptionQuery.singleResult();
runtimeService.messageEventReceived(messageEventSubscription.getEventName(), messageEventSubscription.getExecutionId());
assertEquals(0, runtimeService.createEventSubscriptionQuery().count());
assertEquals(1, runtimeService.createProcessInstanceQuery().count());
assertEquals(0, managementService.createJobQuery().count());
Task task = taskService.createTaskQuery()
.taskName("afterMessage")
.singleResult();
assertNotNull(task);
taskService.complete(task.getId());
}finally{
ClockUtil.setCurrentTime(new Date());
}
}
示例25
@Deployment(resources="org/camunda/bpm/engine/test/bpmn/subprocess/InterruptingEventSubProcessTest.testCancelEventSubscriptions.bpmn")
public void testCancelEventSubscriptionsWhenReceivingAMessage() {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");
TaskQuery taskQuery = taskService.createTaskQuery();
EventSubscriptionQuery eventSubscriptionQuery = runtimeService.createEventSubscriptionQuery();
Task task = taskQuery.singleResult();
assertNotNull(task);
assertEquals("taskBeforeInterruptingEventSuprocess", task.getTaskDefinitionKey());
List<EventSubscription> eventSubscriptions = eventSubscriptionQuery.list();
assertEquals(2, eventSubscriptions.size());
runtimeService.messageEventReceived("newMessage", pi.getId());
task = taskQuery.singleResult();
assertNotNull(task);
assertEquals("taskAfterMessageStartEvent", task.getTaskDefinitionKey());
assertEquals(0, eventSubscriptionQuery.count());
try {
runtimeService.signalEventReceived("newSignal", pi.getId());
fail("A ProcessEngineException was expected.");
} catch (ProcessEngineException e) {
// expected exception;
}
taskService.complete(task.getId());
assertProcessEnded(pi.getId());
}
示例26
@Deployment(resources="org/camunda/bpm/engine/test/bpmn/subprocess/InterruptingEventSubProcessTest.testCancelEventSubscriptions.bpmn")
public void testCancelEventSubscriptionsWhenReceivingASignal() {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");
TaskQuery taskQuery = taskService.createTaskQuery();
EventSubscriptionQuery eventSubscriptionQuery = runtimeService.createEventSubscriptionQuery();
Task task = taskQuery.singleResult();
assertNotNull(task);
assertEquals("taskBeforeInterruptingEventSuprocess", task.getTaskDefinitionKey());
List<EventSubscription> eventSubscriptions = eventSubscriptionQuery.list();
assertEquals(2, eventSubscriptions.size());
runtimeService.signalEventReceived("newSignal", pi.getId());
task = taskQuery.singleResult();
assertNotNull(task);
assertEquals("tastAfterSignalStartEvent", task.getTaskDefinitionKey());
assertEquals(0, eventSubscriptionQuery.count());
try {
runtimeService.messageEventReceived("newMessage", pi.getId());
fail("A ProcessEngineException was expected.");
} catch (ProcessEngineException e) {
// expected exception;
}
taskService.complete(task.getId());
assertProcessEnded(pi.getId());
}
示例27
@Deployment
public void testTimeCycle() {
String processInstanceId = runtimeService.startProcessInstanceByKey("process").getId();
EventSubscriptionQuery eventSubscriptionQuery = runtimeService.createEventSubscriptionQuery();
assertEquals(0, eventSubscriptionQuery.count());
TaskQuery taskQuery = taskService.createTaskQuery();
assertEquals(1, taskQuery.count());
Task task = taskQuery.singleResult();
assertEquals("task", task.getTaskDefinitionKey());
JobQuery jobQuery = managementService.createJobQuery().timers();
assertEquals(1, jobQuery.count());
String jobId = jobQuery.singleResult().getId();
managementService.executeJob(jobId);
assertEquals(0, jobQuery.count());
assertEquals(1, taskQuery.count());
task = taskQuery.singleResult();
assertEquals("eventSubProcessTask", task.getTaskDefinitionKey());
taskService.complete(task.getId());
assertProcessEnded(processInstanceId);
}
示例28
@Deployment(resources = {"org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testInterruptingEventSubProcessEventSubscriptions.bpmn20.xml",
"org/camunda/bpm/engine/test/bpmn/callactivity/interruptingEventSubProcessEventSubscriptions.bpmn20.xml"})
public void testInterruptingMessageEventSubProcessEventSubscriptionsInsideCallActivity() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callInterruptingEventSubProcess");
// one task in the call activity subprocess should be active after starting the process instance
TaskQuery taskQuery = taskService.createTaskQuery();
Task taskInsideCallActivity = taskQuery.singleResult();
assertEquals("taskBeforeInterruptingEventSubprocess", taskInsideCallActivity.getTaskDefinitionKey());
// we should have no event subscriptions for the parent process
assertEquals(0, runtimeService.createEventSubscriptionQuery().processInstanceId(processInstance.getId()).count());
// we should have two event subscriptions for the called process instance, one for message and one for signal
String calledProcessInstanceId = taskInsideCallActivity.getProcessInstanceId();
EventSubscriptionQuery eventSubscriptionQuery = runtimeService.createEventSubscriptionQuery().processInstanceId(calledProcessInstanceId);
List<EventSubscription> subscriptions = eventSubscriptionQuery.list();
assertEquals(2, subscriptions.size());
// start the message interrupting event sub process
runtimeService.correlateMessage("newMessage");
Task taskAfterMessageStartEvent = taskQuery.processInstanceId(calledProcessInstanceId).singleResult();
assertEquals("taskAfterMessageStartEvent", taskAfterMessageStartEvent.getTaskDefinitionKey());
// no subscriptions left
assertEquals(0, eventSubscriptionQuery.count());
// Complete the task inside the called process instance
taskService.complete(taskAfterMessageStartEvent.getId());
assertProcessEnded(calledProcessInstanceId);
assertProcessEnded(processInstance.getId());
}
示例29
@Deployment(resources = {"org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testInterruptingEventSubProcessEventSubscriptions.bpmn20.xml",
"org/camunda/bpm/engine/test/bpmn/callactivity/interruptingEventSubProcessEventSubscriptions.bpmn20.xml"})
public void testInterruptingSignalEventSubProcessEventSubscriptionsInsideCallActivity() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callInterruptingEventSubProcess");
// one task in the call activity subprocess should be active after starting the process instance
TaskQuery taskQuery = taskService.createTaskQuery();
Task taskInsideCallActivity = taskQuery.singleResult();
assertEquals("taskBeforeInterruptingEventSubprocess", taskInsideCallActivity.getTaskDefinitionKey());
// we should have no event subscriptions for the parent process
assertEquals(0, runtimeService.createEventSubscriptionQuery().processInstanceId(processInstance.getId()).count());
// we should have two event subscriptions for the called process instance, one for message and one for signal
String calledProcessInstanceId = taskInsideCallActivity.getProcessInstanceId();
EventSubscriptionQuery eventSubscriptionQuery = runtimeService.createEventSubscriptionQuery().processInstanceId(calledProcessInstanceId);
List<EventSubscription> subscriptions = eventSubscriptionQuery.list();
assertEquals(2, subscriptions.size());
// start the signal interrupting event sub process
runtimeService.signalEventReceived("newSignal");
Task taskAfterSignalStartEvent = taskQuery.processInstanceId(calledProcessInstanceId).singleResult();
assertEquals("taskAfterSignalStartEvent", taskAfterSignalStartEvent.getTaskDefinitionKey());
// no subscriptions left
assertEquals(0, eventSubscriptionQuery.count());
// Complete the task inside the called process instance
taskService.complete(taskAfterSignalStartEvent.getId());
assertProcessEnded(calledProcessInstanceId);
assertProcessEnded(processInstance.getId());
}
示例30
@Override
protected void applyFilters(EventSubscriptionQuery query) {
if (eventSubscriptionId != null) {
query.eventSubscriptionId(eventSubscriptionId);
}
if (eventName != null) {
query.eventName(eventName);
}
if (eventType != null) {
query.eventType(eventType);
}
if (executionId != null) {
query.executionId(executionId);
}
if (processInstanceId != null) {
query.processInstanceId(processInstanceId);
}
if (activityId != null) {
query.activityId(activityId);
}
if (tenantIdIn != null && !tenantIdIn.isEmpty()) {
query.tenantIdIn(tenantIdIn.toArray(new String[tenantIdIn.size()]));
}
if (TRUE.equals(withoutTenantId)) {
query.withoutTenantId();
}
if (TRUE.equals(includeEventSubscriptionsWithoutTenantId)) {
query.includeEventSubscriptionsWithoutTenantId();
}
}