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);
}
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);
}
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"));
}
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"));
}
Aggregations