use of org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl in project activiti-cloud by Activiti.
the class MapBuilder method testGraphqlWsSubprotocolServerStartStopSubscription.
@Test
public void testGraphqlWsSubprotocolServerStartStopSubscription() throws JsonProcessingException {
ReplayProcessor<String> data = ReplayProcessor.create();
keycloakTokenProducer.setKeycloakTestUser(TESTADMIN);
final String auth = keycloakTokenProducer.authorizationHeaders().getFirst(AUTHORIZATION);
Map<String, Object> variables = mapBuilder().put("appName", "default-app").put("eventTypes", Arrays.array("PROCESS_CREATED", "PROCESS_STARTED")).get();
Map<String, Object> payload = mapBuilder().put("query", "subscription($appName: String!, $eventTypes: [EngineEventType!]) { " + " engineEvents(appName: [$appName], eventType: $eventTypes) { " + " processInstanceId " + " eventType " + " } " + "}").put("variables", variables).get();
GraphQLMessage start = GraphQLMessage.builder().type(GraphQLMessageType.START).id("1").payload(payload).build();
String startMessage = objectMapper.writeValueAsString(start);
// given
CloudProcessCreatedEvent event1 = new CloudProcessCreatedEventImpl() {
{
setAppName("default-app");
setServiceName("rb-my-app");
setServiceFullName("serviceFullName");
setServiceType("runtime-bundle");
setServiceVersion("");
setProcessInstanceId("processInstanceId");
setProcessDefinitionId("processDefinitionId");
setProcessDefinitionKey("processDefinitionKey");
setProcessDefinitionVersion(1);
setBusinessKey("businessKey");
}
};
CloudProcessStartedEvent event2 = new CloudProcessStartedEventImpl() {
{
setAppName("default-app");
setServiceName("rb-my-app");
setServiceType("runtime-bundle");
setServiceFullName("serviceFullName");
setServiceType("runtime-bundle");
setServiceVersion("");
setProcessInstanceId("processInstanceId");
setProcessDefinitionId("processDefinitionId");
setProcessDefinitionKey("processDefinitionKey");
setProcessDefinitionVersion(1);
setBusinessKey("businessKey");
}
};
WebsocketSender client = HttpClient.create().baseUrl("ws://localhost:" + port).wiretap(true).headers(h -> h.add(AUTHORIZATION, auth)).websocket(GRAPHQL_WS).uri(WS_GRAPHQL_URI);
// start subscription
client.handle((i, o) -> {
o.options(NettyPipeline.SendOptions::flushOnEach).sendString(Mono.just(startMessage)).then().log("start").subscribe();
return i.receive().asString().log("data").take(1).doOnSubscribe(s -> producerChannel.output().send(MessageBuilder.withPayload(Arrays.array(event1, event2)).setHeader("routingKey", "eventProducer").build())).delaySubscription(Duration.ofSeconds(1)).subscribeWith(data);
}).collectList().subscribe();
// then
Map<String, Object> message = Maps.of("data", Maps.of("engineEvents", Arrays.array(Maps.of("processInstanceId", "processInstanceId", "eventType", "PROCESS_CREATED"), Maps.of("processInstanceId", "processInstanceId", "eventType", "PROCESS_STARTED"))));
String dataMessage = objectMapper.writeValueAsString(GraphQLMessage.builder().type(GraphQLMessageType.DATA).id("1").payload(message).build());
StepVerifier.create(data).expectNext(dataMessage).expectComplete().verify(TIMEOUT);
}
use of org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl in project activiti-cloud by Activiti.
the class QueryProcessDiagramIT method shouldHandleBPMNDiagramEvents.
@Test
public void shouldHandleBPMNDiagramEvents() throws InterruptedException {
// given
ProcessInstanceImpl process = new ProcessInstanceImpl();
process.setId(UUID.randomUUID().toString());
process.setName("process");
process.setProcessDefinitionKey("mySimpleProcess2");
process.setProcessDefinitionId(processDefinitionId2);
process.setProcessDefinitionVersion(1);
BPMNActivityImpl startActivity = new BPMNActivityImpl("startEvent1", "", "startEvent");
startActivity.setProcessDefinitionId(process.getProcessDefinitionId());
startActivity.setProcessInstanceId(process.getId());
BPMNSequenceFlowImpl sequenceFlow = new BPMNSequenceFlowImpl("sid-68945AF1-396F-4B8A-B836-FC318F62313F", "startEvent1", "sid-CDFE7219-4627-43E9-8CA8-866CC38EBA94");
sequenceFlow.setProcessDefinitionId(process.getProcessDefinitionId());
sequenceFlow.setProcessInstanceId(process.getId());
BPMNActivityImpl taskActivity = new BPMNActivityImpl("sid-CDFE7219-4627-43E9-8CA8-866CC38EBA94", "Perform Action", "userTask");
taskActivity.setProcessDefinitionId(process.getProcessDefinitionId());
taskActivity.setProcessInstanceId(process.getId());
eventsAggregator.addEvents(new CloudProcessCreatedEventImpl(process), new CloudProcessStartedEventImpl(process, null, null), new CloudBPMNActivityStartedEventImpl(startActivity, processDefinitionId, process.getId()), new CloudBPMNActivityCompletedEventImpl(startActivity, processDefinitionId, process.getId()), new CloudSequenceFlowTakenEventImpl(sequenceFlow), new CloudBPMNActivityStartedEventImpl(taskActivity, processDefinitionId, process.getId()));
// when
eventsAggregator.sendAll();
// then
await().untilAsserted(() -> {
List<BPMNActivityEntity> activities = bpmnActivityRepository.findByProcessInstanceId(process.getId());
assertThat(activities).hasSize(2);
assertThat(activities).extracting(BPMNActivityEntity::getElementId, BPMNActivityEntity::getActivityType, BPMNActivityEntity::getStatus).containsExactly(tuple(startActivity.getElementId(), startActivity.getActivityType(), BPMNActivityEntity.BPMNActivityStatus.COMPLETED), tuple(taskActivity.getElementId(), taskActivity.getActivityType(), BPMNActivityEntity.BPMNActivityStatus.STARTED));
List<BPMNSequenceFlowEntity> sequenceFlows = bpmnSequenceFlowRepository.findByProcessInstanceId(process.getId());
assertThat(sequenceFlows).hasSize(1);
assertThat(sequenceFlows).extracting(BPMNSequenceFlowEntity::getElementId, BPMNSequenceFlowEntity::getSourceActivityElementId, BPMNSequenceFlowEntity::getTargetActivityElementId).containsExactly(tuple(sequenceFlow.getElementId(), sequenceFlow.getSourceActivityElementId(), sequenceFlow.getTargetActivityElementId()));
});
}
use of org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl in project activiti-cloud by Activiti.
the class QueryProcessInstancesEntityIT method shouldGetProcessDefinitionVersion.
@Test
public void shouldGetProcessDefinitionVersion() {
// given
ProcessInstanceImpl process = new ProcessInstanceImpl();
process.setId("process-instance-id");
process.setName("process");
process.setProcessDefinitionKey("process-definition-key");
process.setProcessDefinitionId("process-definition-id");
process.setProcessDefinitionVersion(10);
eventsAggregator.addEvents(new CloudProcessCreatedEventImpl(process), new CloudProcessStartedEventImpl(process, null, null));
eventsAggregator.sendAll();
await().untilAsserted(() -> {
// when
ResponseEntity<ProcessInstance> responseEntity = testRestTemplate.exchange(PROC_URL + "/" + process.getId(), HttpMethod.GET, keycloakTokenProducer.entityWithAuthorizationHeader(), new ParameterizedTypeReference<ProcessInstance>() {
});
// then
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(responseEntity.getBody()).isNotNull();
assertThat(responseEntity.getBody().getProcessDefinitionVersion()).isEqualTo(10);
});
}
use of org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl in project activiti-cloud by Activiti.
the class QueryProcessInstancesEntityIT method shouldSuspendResumeProcess.
@Test
public void shouldSuspendResumeProcess() {
// given
ProcessInstanceImpl process = new ProcessInstanceImpl();
process.setId("process-instance-id");
process.setName("process");
process.setProcessDefinitionKey("process-definition-key");
process.setProcessDefinitionId("process-definition-id");
process.setProcessDefinitionVersion(10);
eventsAggregator.addEvents(new CloudProcessCreatedEventImpl(process), new CloudProcessStartedEventImpl(process, null, null));
eventsAggregator.sendAll();
await().untilAsserted(() -> {
// when
ResponseEntity<ProcessInstance> responseEntity = testRestTemplate.exchange(PROC_URL + "/" + process.getId(), HttpMethod.GET, keycloakTokenProducer.entityWithAuthorizationHeader(), new ParameterizedTypeReference<ProcessInstance>() {
});
// then
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(responseEntity.getBody()).isNotNull();
assertThat(responseEntity.getBody().getProcessDefinitionVersion()).isEqualTo(10);
});
eventsAggregator.addEvents(new CloudProcessSuspendedEventImpl(process));
eventsAggregator.sendAll();
await().untilAsserted(() -> {
// when
ResponseEntity<ProcessInstance> responseEntity = testRestTemplate.exchange(PROC_URL + "/" + process.getId(), HttpMethod.GET, keycloakTokenProducer.entityWithAuthorizationHeader(), new ParameterizedTypeReference<ProcessInstance>() {
});
// then
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(responseEntity.getBody()).isNotNull();
assertThat(responseEntity.getBody().getProcessDefinitionVersion()).isEqualTo(10);
assertThat(responseEntity.getBody().getProcessDefinitionKey()).isEqualTo("process-definition-key");
assertThat(responseEntity.getBody().getStatus()).isEqualTo(ProcessInstanceStatus.SUSPENDED);
});
eventsAggregator.addEvents(new CloudProcessResumedEventImpl(process));
eventsAggregator.sendAll();
await().untilAsserted(() -> {
// when
ResponseEntity<ProcessInstance> responseEntity = testRestTemplate.exchange(PROC_URL + "/" + process.getId(), HttpMethod.GET, keycloakTokenProducer.entityWithAuthorizationHeader(), new ParameterizedTypeReference<ProcessInstance>() {
});
// then
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(responseEntity.getBody()).isNotNull();
assertThat(responseEntity.getBody().getProcessDefinitionVersion()).isEqualTo(10);
assertThat(responseEntity.getBody().getProcessDefinitionKey()).isEqualTo("process-definition-key");
assertThat(responseEntity.getBody().getStatus()).isEqualTo(ProcessInstanceStatus.RUNNING);
});
}
use of org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl in project activiti-cloud by Activiti.
the class QueryProcessDiagramIT method startAnotherProcessInstance.
protected ProcessInstanceImpl startAnotherProcessInstance() {
ProcessInstanceImpl process = new ProcessInstanceImpl();
process.setId(UUID.randomUUID().toString());
process.setName("process");
process.setProcessDefinitionKey("mySimpleProcess2");
process.setProcessDefinitionId(processDefinitionId2);
process.setProcessDefinitionVersion(1);
BPMNActivityImpl startActivity = new BPMNActivityImpl("startEvent1", "", "startEvent");
startActivity.setProcessDefinitionId(process.getProcessDefinitionId());
startActivity.setProcessInstanceId(process.getId());
startActivity.setExecutionId(UUID.randomUUID().toString());
BPMNSequenceFlowImpl sequenceFlow = new BPMNSequenceFlowImpl("sid-68945AF1-396F-4B8A-B836-FC318F62313F", "startEvent1", "sid-CDFE7219-4627-43E9-8CA8-866CC38EBA94");
sequenceFlow.setProcessDefinitionId(process.getProcessDefinitionId());
sequenceFlow.setProcessInstanceId(process.getId());
BPMNActivityImpl taskActivity = new BPMNActivityImpl("sid-CDFE7219-4627-43E9-8CA8-866CC38EBA94", "Perform Action", "userTask");
taskActivity.setProcessDefinitionId(process.getProcessDefinitionId());
taskActivity.setProcessInstanceId(process.getId());
taskActivity.setExecutionId(UUID.randomUUID().toString());
eventsAggregator.addEvents(new CloudProcessCreatedEventImpl(process), new CloudProcessStartedEventImpl(process, null, null), new CloudBPMNActivityStartedEventImpl(startActivity, processDefinitionId, process.getId()), new CloudBPMNActivityCompletedEventImpl(startActivity, processDefinitionId, process.getId()), new CloudSequenceFlowTakenEventImpl(sequenceFlow), new CloudBPMNActivityStartedEventImpl(taskActivity, processDefinitionId, process.getId()));
return process;
}
Aggregations