Search in sources :

Example 6 with RequestChain

use of io.apiman.gateway.engine.policy.RequestChain in project apiman by apiman.

the class PolicyChainTest method shouldExecuteRequestChainTwice.

@Test
public void shouldExecuteRequestChainTwice() {
    policies.add(pwcOne);
    policies.add(pwcTwo);
    requestChain = new RequestChain(policies, mockContext);
    requestChain.bodyHandler(mockBodyHandler);
    requestChain.endHandler(mockEndHandler);
    requestChain.doApply(mockRequest);
    requestChain.write(mockBuffer);
    requestChain.write(mockBuffer);
    requestChain.end();
    verify(mockBodyHandler, times(2)).handle(mockBuffer);
    verify(mockEndHandler, times(1)).handle((Void) null);
    InOrder order = inOrder(policyOne, policyTwo);
    order.verify(policyOne).apply(mockRequest, mockContext, pwcOne.getConfiguration(), requestChain);
    order.verify(policyTwo).apply(mockRequest, mockContext, pwcTwo.getConfiguration(), requestChain);
}
Also used : InOrder(org.mockito.InOrder) RequestChain(io.apiman.gateway.engine.policy.RequestChain) Test(org.junit.Test)

Example 7 with RequestChain

use of io.apiman.gateway.engine.policy.RequestChain in project apiman by apiman.

the class PolicyChainTest method shouldCallErrorHandlerOnThrowError.

@Test
public void shouldCallErrorHandlerOnThrowError() {
    policies.add(pwcOne);
    policies.add(pwcTwo);
    requestChain = new RequestChain(policies, mockContext);
    IAsyncHandler<Throwable> mThrowableFailureHandler = mock(IAsyncHandler.class);
    Throwable mThrowable = mock(Throwable.class);
    requestChain.policyErrorHandler(mThrowableFailureHandler);
    requestChain.bodyHandler(mockBodyHandler);
    requestChain.endHandler(mockEndHandler);
    requestChain.doApply(mockRequest);
    requestChain.throwError(mThrowable);
    verify(mThrowableFailureHandler).handle(mThrowable);
}
Also used : RequestChain(io.apiman.gateway.engine.policy.RequestChain) Test(org.junit.Test)

Example 8 with RequestChain

use of io.apiman.gateway.engine.policy.RequestChain in project apiman by apiman.

the class PolicyChainTest method shouldExecuteWithoutHandlers.

@Test
public void shouldExecuteWithoutHandlers() {
    policies.add(pwcOne);
    requestChain = new RequestChain(policies, mockContext);
    requestChain.doApply(mockRequest);
    requestChain.end();
}
Also used : RequestChain(io.apiman.gateway.engine.policy.RequestChain) Test(org.junit.Test)

Aggregations

RequestChain (io.apiman.gateway.engine.policy.RequestChain)8 Test (org.junit.Test)7 ApiRequest (io.apiman.gateway.engine.beans.ApiRequest)2 ApiResponse (io.apiman.gateway.engine.beans.ApiResponse)2 PolicyFailure (io.apiman.gateway.engine.beans.PolicyFailure)2 IApimanBuffer (io.apiman.gateway.engine.io.IApimanBuffer)2 IPolicy (io.apiman.gateway.engine.policy.IPolicy)2 IPolicyContext (io.apiman.gateway.engine.policy.IPolicyContext)2 PolicyWithConfiguration (io.apiman.gateway.engine.policy.PolicyWithConfiguration)2 ApimanStrLookup (io.apiman.common.util.ApimanStrLookup)1 GatewayConfigProperties (io.apiman.gateway.engine.GatewayConfigProperties)1 IApiConnection (io.apiman.gateway.engine.IApiConnection)1 IApiConnectionResponse (io.apiman.gateway.engine.IApiConnectionResponse)1 IApiConnector (io.apiman.gateway.engine.IApiConnector)1 IApiRequestExecutor (io.apiman.gateway.engine.IApiRequestExecutor)1 IConnectorConfig (io.apiman.gateway.engine.IConnectorConfig)1 IConnectorFactory (io.apiman.gateway.engine.IConnectorFactory)1 IEngineResult (io.apiman.gateway.engine.IEngineResult)1 IMetrics (io.apiman.gateway.engine.IMetrics)1 IRegistry (io.apiman.gateway.engine.IRegistry)1