Search in sources :

Example 1 with ClientConnFactory

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);
}
Also used : TargetConfiguration(org.apache.synapse.transport.passthru.config.TargetConfiguration) HttpContext(org.apache.http.protocol.HttpContext) ClientConnFactory(org.apache.synapse.transport.http.conn.ClientConnFactory) NHttpClientConnection(org.apache.http.nio.NHttpClientConnection) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with ClientConnFactory

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);
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) TargetConfiguration(org.apache.synapse.transport.passthru.config.TargetConfiguration) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) ContentEncoder(org.apache.http.nio.ContentEncoder) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) NHttpClientConnection(org.apache.http.nio.NHttpClientConnection) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) ClientConnFactory(org.apache.synapse.transport.http.conn.ClientConnFactory) MessageContext(org.apache.axis2.context.MessageContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with ClientConnFactory

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);
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) TargetConfiguration(org.apache.synapse.transport.passthru.config.TargetConfiguration) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) ContentDecoder(org.apache.http.nio.ContentDecoder) NHttpClientConnection(org.apache.http.nio.NHttpClientConnection) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) ClientConnFactory(org.apache.synapse.transport.http.conn.ClientConnFactory) MessageContext(org.apache.axis2.context.MessageContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

NHttpClientConnection (org.apache.http.nio.NHttpClientConnection)3 ClientConnFactory (org.apache.synapse.transport.http.conn.ClientConnFactory)3 TargetConfiguration (org.apache.synapse.transport.passthru.config.TargetConfiguration)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 MessageContext (org.apache.axis2.context.MessageContext)2 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)2 NativeWorkerPool (org.apache.axis2.transport.base.threads.NativeWorkerPool)2 WorkerPool (org.apache.axis2.transport.base.threads.WorkerPool)2 PassThroughTransportMetricsCollector (org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector)2 ContentDecoder (org.apache.http.nio.ContentDecoder)1 ContentEncoder (org.apache.http.nio.ContentEncoder)1 HttpContext (org.apache.http.protocol.HttpContext)1