use of org.apache.synapse.transport.http.conn.ClientConnFactory in project wso2-synapse by wso2.
the class TargetHandlerTest method testRequestReady.
/**
* Testing whether request-ready connection is processed
*
* @throws Exception
*/
@Test
public void testRequestReady() throws Exception {
DeliveryAgent deliveryAgent = mock(DeliveryAgent.class);
ClientConnFactory connFactory = mock(ClientConnFactory.class);
TargetConfiguration configuration = mock(TargetConfiguration.class);
TargetHandler targetHandler = new TargetHandler(deliveryAgent, connFactory, configuration);
NHttpClientConnection conn = mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
HttpContext context = mock(HttpContext.class);
when(conn.getContext()).thenReturn(context);
mockStatic(TargetContext.class);
when(TargetContext.getState(any(NHttpClientConnection.class))).thenReturn(ProtocolState.REQUEST_READY);
targetHandler.requestReady(conn);
}
use of org.apache.synapse.transport.http.conn.ClientConnFactory in project wso2-synapse by wso2.
the class TargetHandlerTest method testOutputReady.
/**
* Testing whether output-ready connection is processed
*
* @throws Exception
*/
@Test
public void testOutputReady() throws Exception {
DeliveryAgent deliveryAgent = mock(DeliveryAgent.class);
ClientConnFactory connFactory = mock(ClientConnFactory.class);
ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
TargetContext targetContext = new TargetContext(targetConfiguration);
MessageContext messageContext = new MessageContext();
targetContext.setRequestMsgCtx(messageContext);
TargetHandler targetHandler = new TargetHandler(deliveryAgent, connFactory, targetConfiguration);
TargetRequest request = mock(TargetRequest.class);
NHttpClientConnection conn = mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
ContentEncoder encoder = mock(ContentEncoder.class);
mockStatic(TargetContext.class);
when(TargetContext.get(conn)).thenReturn(targetContext);
when(TargetContext.getState(conn)).thenReturn(ProtocolState.REQUEST_HEAD);
when(TargetContext.getRequest(conn)).thenReturn(request);
when(request.hasEntityBody()).thenReturn(true);
when(request.write(conn, encoder)).thenReturn(12);
when(encoder.isCompleted()).thenReturn(true);
targetHandler.outputReady(conn, encoder);
}
use of org.apache.synapse.transport.http.conn.ClientConnFactory in project wso2-synapse by wso2.
the class TargetHandlerTest method testInputReady.
/**
* Testing whether input-ready connection is processed
*
* @throws Exception
*/
@Test
public void testInputReady() throws Exception {
DeliveryAgent deliveryAgent = mock(DeliveryAgent.class);
ClientConnFactory connFactory = mock(ClientConnFactory.class);
ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
TargetContext targetContext = new TargetContext(targetConfiguration);
MessageContext messageContext = new MessageContext();
targetContext.setRequestMsgCtx(messageContext);
TargetHandler targetHandler = new TargetHandler(deliveryAgent, connFactory, targetConfiguration);
TargetResponse response = mock(TargetResponse.class);
NHttpClientConnection conn = mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
ContentDecoder decoder = mock(ContentDecoder.class);
mockStatic(TargetContext.class);
when(TargetContext.get(conn)).thenReturn(targetContext);
when(TargetContext.getState(conn)).thenReturn(ProtocolState.RESPONSE_HEAD);
when(TargetContext.getResponse(conn)).thenReturn(response);
when(decoder.isCompleted()).thenReturn(true);
targetHandler.inputReady(conn, decoder);
}
Aggregations