use of org.wso2.carbon.apimgt.gateway.inbound.websocket.response.GraphQLResponseProcessor in project carbon-apimgt by wso2.
the class GraphQLResponseProcessorTest method testHandleResponseSuccess.
@Test
public void testHandleResponseSuccess() {
InboundMessageContext inboundMessageContext = new InboundMessageContext();
int msgSize = 100;
String msgText = "{\"type\":\"data\",\"id\":\"1\",\"payload\":{\"data\":" + "{\"liftStatusChange\":{\"name\":\"Astra Express\"}}}}";
PowerMockito.mockStatic(InboundWebsocketProcessorUtil.class);
InboundProcessorResponseDTO responseDTO = new InboundProcessorResponseDTO();
PowerMockito.when(InboundWebsocketProcessorUtil.authenticateToken(inboundMessageContext)).thenReturn(responseDTO);
VerbInfoDTO verbInfoDTO = new VerbInfoDTO();
verbInfoDTO.setHttpVerb("SUBSCRIPTION");
verbInfoDTO.setThrottling("Unlimited");
GraphQLOperationDTO graphQLOperationDTO = new GraphQLOperationDTO(verbInfoDTO, "liftStatusChange");
inboundMessageContext.addVerbInfoForGraphQLMsgId("1", graphQLOperationDTO);
PowerMockito.when(InboundWebsocketProcessorUtil.validateScopes(inboundMessageContext, "liftStatusChange", "1")).thenReturn(responseDTO);
PowerMockito.when(InboundWebsocketProcessorUtil.doThrottleForGraphQL(msgSize, verbInfoDTO, inboundMessageContext, "1")).thenReturn(responseDTO);
GraphQLResponseProcessor responseProcessor = new GraphQLResponseProcessor();
InboundProcessorResponseDTO processorResponseDTO = responseProcessor.handleResponse(msgSize, msgText, inboundMessageContext);
Assert.assertFalse(processorResponseDTO.isError());
Assert.assertNull(processorResponseDTO.getErrorMessage());
}
use of org.wso2.carbon.apimgt.gateway.inbound.websocket.response.GraphQLResponseProcessor in project carbon-apimgt by wso2.
the class InboundWebSocketProcessor method handleResponse.
/**
* This method process websocket response messages (subscribe messages) and
* hand over the processing to relevant response intercepting processor for authentication, scope validation,
* throttling etc.
*
* @param msg Websocket request message frame
* @param inboundMessageContext InboundMessageContext
* @return InboundProcessorResponseDTO with handshake processing response
*/
public InboundProcessorResponseDTO handleResponse(WebSocketFrame msg, InboundMessageContext inboundMessageContext) throws Exception {
ResponseProcessor responseProcessor;
String msgText = null;
if (APIConstants.GRAPHQL_API.equals(inboundMessageContext.getElectedAPI().getApiType()) && msg instanceof TextWebSocketFrame) {
responseProcessor = new GraphQLResponseProcessor();
msgText = ((TextWebSocketFrame) msg).text();
} else {
responseProcessor = new ResponseProcessor();
}
return responseProcessor.handleResponse(msg.content().capacity(), msgText, inboundMessageContext);
}
Aggregations