use of org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent 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.events.CloudProcessStartedEvent in project activiti-cloud by Activiti.
the class ProcessStartedEventHandler method handle.
@Override
public void handle(CloudRuntimeEvent<?, ?> event) {
CloudProcessStartedEvent startedEvent = (CloudProcessStartedEvent) event;
String processInstanceId = startedEvent.getEntity().getId();
LOGGER.debug("Handling start of process Instance " + processInstanceId);
Optional<ProcessInstanceEntity> findResult = processInstanceRepository.findById(processInstanceId);
ProcessInstanceEntity processInstanceEntity = findResult.orElseThrow(() -> new QueryException("Unable to find process instance with the given id: " + processInstanceId));
if (ProcessInstance.ProcessInstanceStatus.CREATED.equals(processInstanceEntity.getStatus())) {
processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.RUNNING);
// instance name is not available in ProcessCreatedEvent, so we need to updated it here
processInstanceEntity.setName(startedEvent.getEntity().getName());
processInstanceEntity.setLastModified(new Date(startedEvent.getTimestamp()));
processInstanceEntity.setStartDate(startedEvent.getEntity().getStartDate());
processInstanceRepository.save(processInstanceEntity);
}
}
use of org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent in project activiti-cloud by Activiti.
the class ProcessStartedEventHandlerTest method handleShouldUpdateProcessInstanceStatusToRunningAndUpdateInstanceName.
@Test
public void handleShouldUpdateProcessInstanceStatusToRunningAndUpdateInstanceName() {
// given
CloudProcessStartedEvent event = buildProcessStartedEvent();
ProcessInstanceEntity currentProcessInstanceEntity = mock(ProcessInstanceEntity.class);
given(currentProcessInstanceEntity.getStatus()).willReturn(ProcessInstance.ProcessInstanceStatus.CREATED);
given(processInstanceRepository.findById(event.getEntity().getId())).willReturn(Optional.of(currentProcessInstanceEntity));
// when
handler.handle(event);
// then
verify(processInstanceRepository).save(currentProcessInstanceEntity);
verify(currentProcessInstanceEntity).setStatus(ProcessInstance.ProcessInstanceStatus.RUNNING);
verify(currentProcessInstanceEntity).setName(event.getEntity().getName());
verify(currentProcessInstanceEntity).setStartDate(event.getEntity().getStartDate());
}
use of org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent in project activiti-cloud by Activiti.
the class ToCloudProcessRuntimeEventConverterTest method fromShouldConvertInternalProcessStartedEventToExternalEvent.
@Test
public void fromShouldConvertInternalProcessStartedEventToExternalEvent() {
// given
ProcessInstanceImpl processInstance = new ProcessInstanceImpl();
processInstance.setId("10");
processInstance.setProcessDefinitionId("myProcessDef");
ProcessStartedEventImpl event = new ProcessStartedEventImpl(processInstance);
event.setNestedProcessDefinitionId("myParentProcessDef");
event.setNestedProcessInstanceId("2");
// when
CloudProcessStartedEvent processStarted = converter.from(event);
// then
assertThat(processStarted).isInstanceOf(CloudProcessStartedEvent.class);
assertThat(processStarted.getEntity().getId()).isEqualTo("10");
assertThat(processStarted.getEntity().getProcessDefinitionId()).isEqualTo("myProcessDef");
assertThat(processStarted.getNestedProcessDefinitionId()).isEqualTo("myParentProcessDef");
assertThat(processStarted.getNestedProcessInstanceId()).isEqualTo("2");
verify(runtimeBundleInfoAppender).appendRuntimeBundleInfoTo(any(CloudRuntimeEventImpl.class));
}
use of org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent in project activiti-cloud by Activiti.
the class ProcessStartedEventHandlerTest method handleShouldThrowExceptionWhenRelatedProcessInstanceIsNotFound.
@Test
public void handleShouldThrowExceptionWhenRelatedProcessInstanceIsNotFound() {
// given
CloudProcessStartedEvent event = buildProcessStartedEvent();
given(processInstanceRepository.findById("200")).willReturn(Optional.empty());
// then
// when
assertThatExceptionOfType(QueryException.class).isThrownBy(() -> handler.handle(event)).withMessageContaining("Unable to find process instance with the given id: ");
}
Aggregations