Search in sources :

Example 1 with CloudProcessDeployedEvent

use of org.activiti.cloud.api.process.model.events.CloudProcessDeployedEvent in project activiti-cloud by Activiti.

the class MapBuilder method testGraphqlSubscriptionPROCESS_DEPLOYED.

@Test
public void testGraphqlSubscriptionPROCESS_DEPLOYED() throws JsonProcessingException {
    ReplayProcessor<String> data = ReplayProcessor.create();
    keycloakTokenProducer.setKeycloakTestUser(TESTADMIN);
    final String auth = keycloakTokenProducer.authorizationHeaders().getFirst(AUTHORIZATION);
    Map<String, Object> variables = new StringObjectMapBuilder().put("appName", "default-app").get();
    Map<String, Object> payload = new StringObjectMapBuilder().put("query", "subscription($appName: String!) { " + "  engineEvents(appName: [$appName], eventType: PROCESS_DEPLOYED) { " + "    processDefinitionKey " + "    eventType " + "  } " + "}").put("variables", variables).get();
    GraphQLMessage start = GraphQLMessage.builder().type(GraphQLMessageType.START).id("1").payload(payload).build();
    String startMessage = objectMapper.writeValueAsString(start);
    // given
    CloudProcessDeployedEvent event1 = new CloudProcessDeployedEventImpl("id", new Date().getTime(), new ProcessDefinitionEntity()) {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setProcessModelContent("processModelContent");
            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)).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(mapBuilder().put("processDefinitionKey", "processDefinitionKey").put("eventType", "PROCESS_DEPLOYED").get())));
    String dataMessage = objectMapper.writeValueAsString(GraphQLMessage.builder().type(GraphQLMessageType.DATA).id("1").payload(message).build());
    StepVerifier.create(data).expectNext(dataMessage).expectComplete().verify(TIMEOUT);
}
Also used : CloudProcessDeployedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessDeployedEventImpl) ProcessDefinitionEntity(org.activiti.cloud.services.query.model.ProcessDefinitionEntity) WebsocketSender(reactor.netty.http.client.HttpClient.WebsocketSender) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) Date(java.util.Date) CloudProcessDeployedEvent(org.activiti.cloud.api.process.model.events.CloudProcessDeployedEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with CloudProcessDeployedEvent

use of org.activiti.cloud.api.process.model.events.CloudProcessDeployedEvent in project activiti-cloud by Activiti.

the class ProcessDeployedEventHandler method handle.

@Override
public void handle(CloudRuntimeEvent<?, ?> event) {
    CloudProcessDeployedEvent processDeployedEvent = (CloudProcessDeployedEvent) event;
    ProcessDefinition eventProcessDefinition = processDeployedEvent.getEntity();
    LOGGER.debug("Handling process deployed event for " + eventProcessDefinition.getKey());
    ProcessDefinitionEntity processDefinition = new ProcessDefinitionEntity(processDeployedEvent.getServiceName(), processDeployedEvent.getServiceFullName(), processDeployedEvent.getServiceVersion(), processDeployedEvent.getAppName(), processDeployedEvent.getAppVersion());
    processDefinition.setId(eventProcessDefinition.getId());
    processDefinition.setDescription(eventProcessDefinition.getDescription());
    processDefinition.setFormKey(eventProcessDefinition.getFormKey());
    processDefinition.setKey(eventProcessDefinition.getKey());
    processDefinition.setName(eventProcessDefinition.getName());
    processDefinition.setVersion(eventProcessDefinition.getVersion());
    processDefinition.setServiceType(processDeployedEvent.getServiceType());
    processDefinitionRepository.save(processDefinition);
    ProcessModelEntity processModelEntity = new ProcessModelEntity(processDefinition, processDeployedEvent.getProcessModelContent());
    processModelEntity.setId(processDefinition.getId());
    processModelRepository.save(processModelEntity);
}
Also used : ProcessDefinition(org.activiti.api.process.model.ProcessDefinition) ProcessDefinitionEntity(org.activiti.cloud.services.query.model.ProcessDefinitionEntity) ProcessModelEntity(org.activiti.cloud.services.query.model.ProcessModelEntity) CloudProcessDeployedEvent(org.activiti.cloud.api.process.model.events.CloudProcessDeployedEvent)

Example 3 with CloudProcessDeployedEvent

use of org.activiti.cloud.api.process.model.events.CloudProcessDeployedEvent in project activiti-cloud by Activiti.

the class CloudProcessDeployedProducerTest method shouldSendMessageWithDeployedProcessesWhenWebApplicationTypeIsServlet.

@Test
public void shouldSendMessageWithDeployedProcessesWhenWebApplicationTypeIsServlet() {
    // given
    ProcessDefinition def1 = mock(ProcessDefinition.class);
    ProcessDefinition def2 = mock(ProcessDefinition.class);
    List<ProcessDeployedEvent> processDeployedEventList = Arrays.asList(new ProcessDeployedEventImpl(def1, "content1"), new ProcessDeployedEventImpl(def2, "content2"));
    given(messageBuilderAppenderChain.withPayload(any())).willReturn(MessageBuilder.withPayload(new CloudRuntimeEvent<?, ?>[2]));
    // when
    processDeployedProducer.sendProcessDeployedEvents(new ProcessDeployedEvents(processDeployedEventList));
    // then
    verify(runtimeBundleInfoAppender, times(2)).appendRuntimeBundleInfoTo(any(CloudRuntimeEventImpl.class));
    verify(auditProducer).send(any());
    verify(messageBuilderAppenderChain).withPayload(messagePayloadCaptor.capture());
    List<CloudProcessDeployedEvent> cloudProcessDeployedEvents = Arrays.stream(messagePayloadCaptor.getValue()).map(CloudProcessDeployedEvent.class::cast).collect(Collectors.toList());
    assertThat(cloudProcessDeployedEvents).extracting(CloudProcessDeployedEvent::getEntity, CloudProcessDeployedEvent::getProcessModelContent).containsOnly(tuple(def1, "content1"), tuple(def2, "content2"));
}
Also used : CloudRuntimeEventImpl(org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl) ProcessDeployedEvents(org.activiti.api.runtime.event.impl.ProcessDeployedEvents) ProcessDefinition(org.activiti.api.process.model.ProcessDefinition) ProcessDeployedEvent(org.activiti.api.process.model.events.ProcessDeployedEvent) CloudProcessDeployedEvent(org.activiti.cloud.api.process.model.events.CloudProcessDeployedEvent) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) ProcessDeployedEventImpl(org.activiti.api.runtime.event.impl.ProcessDeployedEventImpl) CloudProcessDeployedEvent(org.activiti.cloud.api.process.model.events.CloudProcessDeployedEvent) Test(org.junit.jupiter.api.Test)

Example 4 with CloudProcessDeployedEvent

use of org.activiti.cloud.api.process.model.events.CloudProcessDeployedEvent in project activiti-cloud by Activiti.

the class AuditProducerIT method shouldProduceEventsForProcessDeployment.

@Test
public void shouldProduceEventsForProcessDeployment() {
    // when
    List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getAllReceivedEvents();
    assertThat(streamHandler.getReceivedHeaders()).containsKeys(RUNTIME_BUNDLE_INFO_HEADERS);
    // then
    List<CloudProcessDeployedEvent> processDeployedEvents = receivedEvents.stream().filter(event -> PROCESS_DEPLOYED.name().equals(event.getEventType().name())).map(CloudProcessDeployedEvent.class::cast).collect(Collectors.toList());
    assertThat(processDeployedEvents).extracting(event -> event.getEntity().getKey()).contains(SIMPLE_PROCESS);
    CloudProcessDeployedEvent processDeployedEvent = processDeployedEvents.stream().filter(event -> SIMPLE_PROCESS.equals(event.getEntity().getKey())).findFirst().orElse(null);
    assertThat(processDeployedEvent).isNotNull();
    assertThat(processDeployedEvent.getProcessModelContent()).isXmlEqualToContentOf(new File("src/test/resources/processes/SimpleProcess.bpmn20.xml"));
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) DirtiesContext(org.springframework.test.annotation.DirtiesContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Task(org.activiti.api.task.model.Task) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) CloudTaskCandidateUserRemovedEvent(org.activiti.cloud.api.task.model.events.CloudTaskCandidateUserRemovedEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) VARIABLE_CREATED(org.activiti.api.model.shared.event.VariableEvent.VariableEvents.VARIABLE_CREATED) INTEGRATION_REQUESTED(org.activiti.api.process.model.events.IntegrationEvent.IntegrationEvents.INTEGRATION_REQUESTED) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) ActiveProfiles(org.springframework.test.context.ActiveProfiles) CloudTask(org.activiti.cloud.api.task.model.CloudTask) PagedResources(org.springframework.hateoas.PagedResources) Map(java.util.Map) PROCESS_RESUMED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_RESUMED) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Awaitility.await(org.awaitility.Awaitility.await) PROCESS_STARTED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED) CloudProcessDeployedEvent(org.activiti.cloud.api.process.model.events.CloudProcessDeployedEvent) Collection(java.util.Collection) RuntimeEvent(org.activiti.api.model.shared.event.RuntimeEvent) ApplicationElement(org.activiti.api.model.shared.model.ApplicationElement) BPMNActivityEvent(org.activiti.api.process.model.events.BPMNActivityEvent) PROCESS_COMPLETED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED) TestPropertySource(org.springframework.test.context.TestPropertySource) SEQUENCE_FLOW_TAKEN(org.activiti.api.process.model.events.SequenceFlowEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN) Collectors(java.util.stream.Collectors) Resource(org.springframework.hateoas.Resource) PROCESS_SUSPENDED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_SUSPENDED) Test(org.junit.jupiter.api.Test) TASK_ACTIVATED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_ACTIVATED) TASK_UPDATED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_UPDATED) List(java.util.List) Stream(java.util.stream.Stream) TASK_CANDIDATE_USER_REMOVED(org.activiti.api.task.model.events.TaskCandidateUserEvent.TaskCandidateUserEvents.TASK_CANDIDATE_USER_REMOVED) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CandidateGroup(org.activiti.cloud.api.process.model.impl.CandidateGroup) PROCESS_CANCELLED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_CANCELLED) ApplicationElementImpl(org.activiti.api.runtime.model.impl.ApplicationElementImpl) PROCESS_DEPLOYED(org.activiti.api.process.model.events.ProcessDefinitionEvent.ProcessDefinitionEvents.PROCESS_DEPLOYED) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) INTEGRATION_RESULT_RECEIVED(org.activiti.api.process.model.events.IntegrationEvent.IntegrationEvents.INTEGRATION_RESULT_RECEIVED) TASK_CREATED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_CREATED) CloudTaskCancelledEvent(org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent) TASK_CANDIDATE_GROUP_REMOVED(org.activiti.api.task.model.events.TaskCandidateGroupEvent.TaskCandidateGroupEvents.TASK_CANDIDATE_GROUP_REMOVED) HashMap(java.util.HashMap) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) TASK_ASSIGNED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) TaskRestTemplate(org.activiti.cloud.starter.tests.helper.TaskRestTemplate) ACTIVITY_STARTED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED) TASK_CANDIDATE_GROUP_ADDED(org.activiti.api.task.model.events.TaskCandidateGroupEvent.TaskCandidateGroupEvents.TASK_CANDIDATE_GROUP_ADDED) CloudTaskCreatedEvent(org.activiti.cloud.api.task.model.events.CloudTaskCreatedEvent) CloudProcessDefinition(org.activiti.cloud.api.process.model.CloudProcessDefinition) CandidateUser(org.activiti.cloud.api.process.model.impl.CandidateUser) TASK_COMPLETED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_COMPLETED) VARIABLE_UPDATED(org.activiti.api.model.shared.event.VariableEvent.VariableEvents.VARIABLE_UPDATED) PROCESS_UPDATED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_UPDATED) TASK_CANDIDATE_USER_ADDED(org.activiti.api.task.model.events.TaskCandidateUserEvent.TaskCandidateUserEvents.TASK_CANDIDATE_USER_ADDED) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) CloudBPMNActivityStartedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent) HttpMethod(org.springframework.http.HttpMethod) PROCESS_CREATED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED) TASK_CANCELLED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_CANCELLED) File(java.io.File) TaskCandidateGroup(org.activiti.api.task.model.TaskCandidateGroup) HttpStatus(org.springframework.http.HttpStatus) ProcessInstanceRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate) TASK_SUSPENDED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_SUSPENDED) ACTIVITY_COMPLETED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED) ACTIVITY_CANCELLED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED) TaskCandidateUser(org.activiti.api.task.model.TaskCandidateUser) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Resources(org.springframework.hateoas.Resources) ResponseEntity(org.springframework.http.ResponseEntity) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) Collections(java.util.Collections) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) File(java.io.File) CloudProcessDeployedEvent(org.activiti.cloud.api.process.model.events.CloudProcessDeployedEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

CloudProcessDeployedEvent (org.activiti.cloud.api.process.model.events.CloudProcessDeployedEvent)4 Test (org.junit.jupiter.api.Test)3 ProcessDefinition (org.activiti.api.process.model.ProcessDefinition)2 CloudRuntimeEvent (org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent)2 ProcessDefinitionEntity (org.activiti.cloud.services.query.model.ProcessDefinitionEntity)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 RuntimeEvent (org.activiti.api.model.shared.event.RuntimeEvent)1 VARIABLE_CREATED (org.activiti.api.model.shared.event.VariableEvent.VariableEvents.VARIABLE_CREATED)1 VARIABLE_UPDATED (org.activiti.api.model.shared.event.VariableEvent.VariableEvents.VARIABLE_UPDATED)1 ApplicationElement (org.activiti.api.model.shared.model.ApplicationElement)1 ProcessInstance (org.activiti.api.process.model.ProcessInstance)1