Search in sources :

Example 6 with GraphQLMessage

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

the class GraphQLBrokerMessageHandlerTest method testHandleStartMessageBrokerAvailableDataNullSendError.

@Test
public void testHandleStartMessageBrokerAvailableDataNullSendError() {
    // given
    Message<GraphQLMessage> message = startMessage("id", "sess1");
    ExecutionResult executionResult = mock(ExecutionResult.class);
    when(graphQLExecutor.execute(anyString(), any())).thenReturn(executionResult);
    when(executionResult.getErrors()).thenReturn(Collections.emptyList());
    when(executionResult.getData()).thenReturn(null);
    // when
    this.messageHandler.handleMessage(message);
    // then
    verify(this.clientOutboundChannel).send(this.messageCaptor.capture());
    assertThat(messageCaptor.getValue().getPayload()).isInstanceOf(GraphQLMessage.class);
    assertThat(messageCaptor.getValue().getPayload().getType()).isEqualTo(GraphQLMessageType.ERROR);
    assertThat(messageCaptor.getValue().getPayload().getId()).isEqualTo("id");
    assertThat(messageCaptor.getValue().getPayload().getPayload()).containsKey("errors");
}
Also used : ExecutionResult(graphql.ExecutionResult) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) Test(org.junit.jupiter.api.Test)

Example 7 with GraphQLMessage

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

the class GraphQLBrokerMessageHandlerTest method testHandleStopMessageCompletesSubscriber.

@Test
public void testHandleStopMessageCompletesSubscriber() {
    // given
    Message<GraphQLMessage> message = stopMessage("subscriptionId", "sessionId");
    GraphQLBrokerChannelSubscriber subscriber = mock(GraphQLBrokerChannelSubscriber.class);
    GraphQLBrokerSubscriptionRegistry registry = messageHandler.getGraphQLsubscriptionRegistry();
    registry.subscribe("sessionId", "subscriptionId", subscriber);
    // when
    this.messageHandler.handleMessage(message);
    // then
    verify(subscriber).onComplete();
}
Also used : GraphQLBrokerChannelSubscriber(org.activiti.cloud.services.notifications.graphql.ws.transport.GraphQLBrokerChannelSubscriber) GraphQLBrokerSubscriptionRegistry(org.activiti.cloud.services.notifications.graphql.ws.transport.GraphQLBrokerSubscriptionRegistry) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) Test(org.junit.jupiter.api.Test)

Example 8 with GraphQLMessage

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

the class GraphQLBrokerMessageHandlerTest method connectionInitMessage.

private Message<GraphQLMessage> connectionInitMessage(String operationId, String sessionId) {
    SimpMessageHeaderAccessor headerAccessor = simpHeaderAccessor(mockWebSocketSession(sessionId));
    headerAccessor.setHeader(StompHeaderAccessor.HEART_BEAT_HEADER, new long[] { 0, 5000 });
    GraphQLMessage payload = new GraphQLMessage(operationId, GraphQLMessageType.CONNECTION_INIT);
    return MessageBuilder.createMessage(payload, headerAccessor.getMessageHeaders());
}
Also used : GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor)

Example 9 with GraphQLMessage

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

the class GraphQLBrokerMessageHandlerTest method testHandleStartMessageBrokerUnavailableSendsError.

@Test
public void testHandleStartMessageBrokerUnavailableSendsError() {
    // given
    this.messageHandler.on(new BrokerAvailabilityEvent(false, this));
    Message<GraphQLMessage> message = startMessage("id", "sess1");
    // when
    this.messageHandler.handleMessage(message);
    // then
    verify(this.clientOutboundChannel).send(this.messageCaptor.capture());
    assertThat(messageCaptor.getValue().getPayload()).isInstanceOf(GraphQLMessage.class);
    assertThat(messageCaptor.getValue().getPayload().getType()).isEqualTo(GraphQLMessageType.ERROR);
    assertThat(messageCaptor.getValue().getPayload().getId()).isEqualTo("id");
    assertThat(messageCaptor.getValue().getPayload().getPayload()).containsKey("errors");
}
Also used : BrokerAvailabilityEvent(org.springframework.messaging.simp.broker.BrokerAvailabilityEvent) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) Test(org.junit.jupiter.api.Test)

Example 10 with GraphQLMessage

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

the class GraphQLBrokerMessageHandlerTest method testHandleStartMessageBrokerAvailableExecutorErrorSendsError.

@Test
public void testHandleStartMessageBrokerAvailableExecutorErrorSendsError() {
    // given
    Message<GraphQLMessage> message = startMessage("id", "sess1");
    ExecutionResult executionResult = mock(ExecutionResult.class);
    when(graphQLExecutor.execute(anyString(), any())).thenReturn(executionResult);
    when(executionResult.getErrors()).thenReturn(Collections.singletonList(mock(GraphQLError.class)));
    when(executionResult.getData()).thenReturn(null);
    // when
    this.messageHandler.handleMessage(message);
    // then
    verify(this.clientOutboundChannel).send(this.messageCaptor.capture());
    assertThat(messageCaptor.getValue().getPayload()).isInstanceOf(GraphQLMessage.class);
    assertThat(messageCaptor.getValue().getPayload().getType()).isEqualTo(GraphQLMessageType.ERROR);
    assertThat(messageCaptor.getValue().getPayload().getId()).isEqualTo("id");
    assertThat(messageCaptor.getValue().getPayload().getPayload()).containsKey("errors");
}
Also used : ExecutionResult(graphql.ExecutionResult) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) Test(org.junit.jupiter.api.Test)

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