Search in sources :

Example 1 with InboundWebSocketProcessor

use of org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundWebSocketProcessor in project carbon-apimgt by wso2.

the class WebsocketInboundHandlerTestCase method setup.

@Before
public void setup() throws Exception {
    inboundWebSocketProcessor = Mockito.mock(InboundWebSocketProcessor.class);
    channelHandlerContext = Mockito.mock(ChannelHandlerContext.class);
    Channel channel = Mockito.mock(Channel.class);
    ChannelId channelId = Mockito.mock(ChannelId.class);
    Mockito.when(channelHandlerContext.channel()).thenReturn(channel);
    Mockito.when(channel.id()).thenReturn(channelId);
    Mockito.when(channelId.asLongText()).thenReturn(channelIdString);
    Mockito.when(channel.attr(WebSocketUtils.WSO2_PROPERTIES)).thenReturn(getChannelAttributeMap());
    PowerMockito.mockStatic(WebSocketUtils.class);
    SocketAddress socketAddress = Mockito.mock(SocketAddress.class);
    Mockito.when(channel.remoteAddress()).thenReturn(socketAddress);
    PowerMockito.when(WebSocketUtils.getApiProperties(channelHandlerContext)).thenReturn(new HashMap<>());
    APIMgtGoogleAnalyticsUtils apiMgtGoogleAnalyticsUtils = Mockito.mock(APIMgtGoogleAnalyticsUtils.class);
    PowerMockito.whenNew(APIMgtGoogleAnalyticsUtils.class).withAnyArguments().thenReturn(apiMgtGoogleAnalyticsUtils);
    Mockito.doNothing().when(apiMgtGoogleAnalyticsUtils).init("carbon.super");
    Mockito.doNothing().when(apiMgtGoogleAnalyticsUtils).publishGATrackingData(Mockito.anyObject(), Mockito.anyObject(), Mockito.anyObject());
    websocketInboundHandler = new WebsocketInboundHandler() {

        @Override
        protected String getRemoteIP(ChannelHandlerContext ctx) {
            return remoteIP;
        }

        @Override
        public InboundWebSocketProcessor initializeWebSocketProcessor() {
            return inboundWebSocketProcessor;
        }
    };
    websocketAPI = new API(UUID.randomUUID().toString(), 1, "admin", "WSAPI", "1.0.0", "/wscontext", "Unlimited", APIConstants.API_TYPE_WS, APIConstants.PUBLISHED_STATUS, false);
}
Also used : InboundWebSocketProcessor(org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundWebSocketProcessor) Channel(io.netty.channel.Channel) APIMgtGoogleAnalyticsUtils(org.wso2.carbon.apimgt.gateway.utils.APIMgtGoogleAnalyticsUtils) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) API(org.wso2.carbon.apimgt.keymgt.model.entity.API) ChannelId(io.netty.channel.ChannelId) SocketAddress(java.net.SocketAddress) Before(org.junit.Before)

Aggregations

Channel (io.netty.channel.Channel)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelId (io.netty.channel.ChannelId)1 SocketAddress (java.net.SocketAddress)1 Before (org.junit.Before)1 InboundWebSocketProcessor (org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundWebSocketProcessor)1 APIMgtGoogleAnalyticsUtils (org.wso2.carbon.apimgt.gateway.utils.APIMgtGoogleAnalyticsUtils)1 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)1