Search in sources :

Example 1 with CloudProcessCreatedEventImpl

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);
}
Also used : CloudProcessStartedEvent(org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent) CloudProcessCreatedEvent(org.activiti.cloud.api.process.model.events.CloudProcessCreatedEvent) CloudProcessStartedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessStartedEventImpl) CloudProcessCreatedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl) WebsocketSender(reactor.netty.http.client.HttpClient.WebsocketSender) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with CloudProcessCreatedEventImpl

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()));
    });
}
Also used : CloudBPMNActivityCompletedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNActivityCompletedEventImpl) BPMNSequenceFlowImpl(org.activiti.api.runtime.model.impl.BPMNSequenceFlowImpl) BPMNSequenceFlowEntity(org.activiti.cloud.services.query.model.BPMNSequenceFlowEntity) BPMNActivityImpl(org.activiti.api.runtime.model.impl.BPMNActivityImpl) CloudProcessStartedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessStartedEventImpl) CloudSequenceFlowTakenEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudSequenceFlowTakenEventImpl) ProcessInstanceImpl(org.activiti.api.runtime.model.impl.ProcessInstanceImpl) CloudProcessCreatedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl) CloudBPMNActivityStartedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNActivityStartedEventImpl) BPMNActivityEntity(org.activiti.cloud.services.query.model.BPMNActivityEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with CloudProcessCreatedEventImpl

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);
    });
}
Also used : CloudProcessStartedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessStartedEventImpl) ProcessInstanceImpl(org.activiti.api.runtime.model.impl.ProcessInstanceImpl) CloudProcessCreatedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with CloudProcessCreatedEventImpl

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);
    });
}
Also used : CloudProcessResumedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessResumedEventImpl) CloudProcessStartedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessStartedEventImpl) ProcessInstanceImpl(org.activiti.api.runtime.model.impl.ProcessInstanceImpl) CloudProcessSuspendedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessSuspendedEventImpl) CloudProcessCreatedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with CloudProcessCreatedEventImpl

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;
}
Also used : CloudBPMNActivityCompletedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNActivityCompletedEventImpl) BPMNSequenceFlowImpl(org.activiti.api.runtime.model.impl.BPMNSequenceFlowImpl) BPMNActivityImpl(org.activiti.api.runtime.model.impl.BPMNActivityImpl) CloudProcessStartedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessStartedEventImpl) CloudSequenceFlowTakenEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudSequenceFlowTakenEventImpl) ProcessInstanceImpl(org.activiti.api.runtime.model.impl.ProcessInstanceImpl) CloudProcessCreatedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl) CloudBPMNActivityStartedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNActivityStartedEventImpl)

Aggregations

CloudProcessCreatedEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl)14 CloudProcessStartedEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudProcessStartedEventImpl)11 ProcessInstanceImpl (org.activiti.api.runtime.model.impl.ProcessInstanceImpl)9 CloudBPMNActivityCompletedEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudBPMNActivityCompletedEventImpl)5 CloudBPMNActivityStartedEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudBPMNActivityStartedEventImpl)5 CloudSequenceFlowTakenEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudSequenceFlowTakenEventImpl)5 Test (org.junit.jupiter.api.Test)5 ProcessInstance (org.activiti.api.process.model.ProcessInstance)4 BPMNActivityImpl (org.activiti.api.runtime.model.impl.BPMNActivityImpl)4 BPMNSequenceFlowImpl (org.activiti.api.runtime.model.impl.BPMNSequenceFlowImpl)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 CloudProcessInstance (org.activiti.cloud.api.process.model.CloudProcessInstance)2 CloudProcessCompletedEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudProcessCompletedEventImpl)2 CloudProcessResumedEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudProcessResumedEventImpl)2 CloudProcessSuspendedEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudProcessSuspendedEventImpl)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1