use of org.apache.synapse.transport.passthru.config.TargetConfiguration in project wso2-synapse by wso2.
the class DeliveryAgentTest method test.
/**
* This method tests whether the message is queued by the delivery agent when the connection is null
*
* @throws Exception
*/
@Test
public void test() throws Exception {
MessageContext messageContext = new MessageContext();
ServiceContext svcCtx = new ServiceContext();
OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx);
messageContext.setServiceContext(svcCtx);
messageContext.setOperationContext(opCtx);
TargetConfiguration targetConfiguration = PowerMockito.mock(TargetConfiguration.class);
TargetConnections conns = PowerMockito.mock(TargetConnections.class);
ProxyConfig config = PowerMockito.mock(ProxyConfig.class);
EndpointReference epr = new EndpointReference("http://127.0.0.1:3001/services");
DeliveryAgent agent = new DeliveryAgent(targetConfiguration, conns, config);
agent.submit(messageContext, epr);
Assert.assertEquals("127.0.0.1", messageContext.getProperty("PROXY_PROFILE_TARGET_HOST"));
}
use of org.apache.synapse.transport.passthru.config.TargetConfiguration 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.passthru.config.TargetConfiguration 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