Search in sources :

Example 1 with GraphQLMessage

use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.

the class GraphQLBrokerSubProtocolHandlerTest method testHandleConnectionAckMessageToClient.

@Test
public void testHandleConnectionAckMessageToClient() throws IOException {
    // given
    WebSocketSession session = spy(mockWebSocketSession("sess1"));
    doNothing().when(session).sendMessage(any(TextMessage.class));
    Message<GraphQLMessage> message = connectionAckMessage("operationId", session);
    // when
    testSubject.handleMessageToClient(session, message);
    // then
    verify(session).sendMessage(any(TextMessage.class));
}
Also used : GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) TextMessage(org.springframework.web.socket.TextMessage) WebSocketSession(org.springframework.web.socket.WebSocketSession) StandardWebSocketSession(org.springframework.web.socket.adapter.standard.StandardWebSocketSession) Test(org.junit.jupiter.api.Test)

Example 2 with GraphQLMessage

use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage 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 3 with GraphQLMessage

use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage 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 4 with GraphQLMessage

use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.

the class MapBuilder method testGraphqlSubscriptionCloudBPMNTimerEvents.

@Test
public void testGraphqlSubscriptionCloudBPMNTimerEvents() 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").put("eventTypes", Arrays.array("TIMER_SCHEDULED", "TIMER_FIRED", "TIMER_EXECUTED", "TIMER_CANCELLED", "TIMER_FAILED", "TIMER_RETRIES_DECREMENTED")).get();
    Map<String, Object> payload = new StringObjectMapBuilder().put("query", "subscription($appName: String!, $eventTypes: [EngineEventType!]) { " + "  engineEvents(appName: [$appName], eventType: $eventTypes) { " + "    processInstanceId " + "    processDefinitionId " + "    entity " + "    eventType " + "  } " + "}").put("variables", variables).get();
    GraphQLMessage start = GraphQLMessage.builder().type(GraphQLMessageType.START).id("1").payload(payload).build();
    String startMessage = objectMapper.writeValueAsString(start);
    // given
    CloudBPMNTimerScheduledEvent event1 = new CloudBPMNTimerScheduledEventImpl("id", new Date().getTime(), new BPMNTimerImpl("timerId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    // given
    CloudBPMNTimerFiredEvent event2 = new CloudBPMNTimerFiredEventImpl("id", new Date().getTime(), new BPMNTimerImpl("timerId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    // given
    CloudBPMNTimerExecutedEvent event3 = new CloudBPMNTimerExecutedEventImpl("id", new Date().getTime(), new BPMNTimerImpl("timerId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    // given
    CloudBPMNTimerCancelledEvent event4 = new CloudBPMNTimerCancelledEventImpl("id", new Date().getTime(), new BPMNTimerImpl("timerId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    // given
    CloudBPMNTimerFailedEvent event5 = new CloudBPMNTimerFailedEventImpl("id", new Date().getTime(), new BPMNTimerImpl("timerId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    // given
    CloudBPMNTimerRetriesDecrementedEvent event6 = new CloudBPMNTimerRetriesDecrementedEventImpl("id", new Date().getTime(), new BPMNTimerImpl("timerId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            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, event3, event4, event5, event6)).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("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("entity", new BPMNTimerImpl("timerId")).put("eventType", "TIMER_SCHEDULED").get(), mapBuilder().put("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("entity", new BPMNTimerImpl("timerId")).put("eventType", "TIMER_FIRED").get(), mapBuilder().put("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("entity", new BPMNTimerImpl("timerId")).put("eventType", "TIMER_EXECUTED").get(), mapBuilder().put("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("entity", new BPMNTimerImpl("timerId")).put("eventType", "TIMER_CANCELLED").get(), mapBuilder().put("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("entity", new BPMNTimerImpl("timerId")).put("eventType", "TIMER_FAILED").get(), mapBuilder().put("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("entity", new BPMNTimerImpl("timerId")).put("eventType", "TIMER_RETRIES_DECREMENTED").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 : CloudBPMNTimerExecutedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerExecutedEvent) CloudBPMNTimerCancelledEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerCancelledEventImpl) CloudBPMNTimerScheduledEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerScheduledEventImpl) CloudBPMNTimerRetriesDecrementedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerRetriesDecrementedEventImpl) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) Date(java.util.Date) CloudBPMNTimerRetriesDecrementedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerRetriesDecrementedEvent) CloudBPMNTimerFailedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerFailedEventImpl) CloudBPMNTimerFiredEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerFiredEventImpl) CloudBPMNTimerFailedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerFailedEvent) CloudBPMNTimerExecutedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerExecutedEventImpl) CloudBPMNTimerScheduledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent) BPMNTimerImpl(org.activiti.api.runtime.model.impl.BPMNTimerImpl) CloudBPMNTimerFiredEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerFiredEvent) CloudBPMNTimerCancelledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerCancelledEvent) WebsocketSender(reactor.netty.http.client.HttpClient.WebsocketSender) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with GraphQLMessage

use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.

the class MapBuilder method testGraphqlSubscriptionSIGNAL_RECEIVED.

@Test
public void testGraphqlSubscriptionSIGNAL_RECEIVED() 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").put("eventType", "SIGNAL_RECEIVED").get();
    Map<String, Object> payload = new StringObjectMapBuilder().put("query", "subscription($appName: String!, $eventType: EngineEventType!) { " + "  engineEvents(appName: [$appName], eventType: [$eventType]) { " + "    processInstanceId " + "    processDefinitionId " + "    eventType " + "  } " + "}").put("variables", variables).get();
    GraphQLMessage start = GraphQLMessage.builder().type(GraphQLMessageType.START).id("1").payload(payload).build();
    String startMessage = objectMapper.writeValueAsString(start);
    // given
    CloudBPMNSignalReceivedEvent event1 = new CloudBPMNSignalReceivedEventImpl("id", new Date().getTime(), new BPMNSignalImpl("elementId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            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)).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("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("eventType", "SIGNAL_RECEIVED").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 : BPMNSignalImpl(org.activiti.api.runtime.model.impl.BPMNSignalImpl) CloudBPMNSignalReceivedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNSignalReceivedEvent) WebsocketSender(reactor.netty.http.client.HttpClient.WebsocketSender) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) CloudBPMNSignalReceivedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNSignalReceivedEventImpl) Date(java.util.Date) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

GraphQLMessage (org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage)35 Test (org.junit.jupiter.api.Test)14 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 WebsocketSender (reactor.netty.http.client.HttpClient.WebsocketSender)6 Date (java.util.Date)5 TextMessage (org.springframework.web.socket.TextMessage)5 ExecutionResult (graphql.ExecutionResult)4 Principal (java.security.Principal)4 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)4 WebSocketSession (org.springframework.web.socket.WebSocketSession)4 Timed (com.codahale.metrics.annotation.Timed)3 HashMap (java.util.HashMap)3 GraphQLMessageType (org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessageType)3 Message (org.springframework.messaging.Message)3 MessageHeaders (org.springframework.messaging.MessageHeaders)3 SimpMessageType (org.springframework.messaging.simp.SimpMessageType)3 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2