Search in sources :

Example 16 with PolicyChain

use of io.gravitee.gateway.policy.impl.PolicyChain in project gravitee-gateway by gravitee-io.

the class RequestPolicyChainTest method doNext_singlePolicy.

@Test
public void doNext_singlePolicy() throws Exception {
    PolicyChain chain = RequestPolicyChain.create(policies(), mock(ExecutionContext.class));
    chain.setResultHandler(result -> {
    });
    chain.doNext(null, null);
    verify(policy, atLeastOnce()).onRequest(anyVararg());
    verify(policy, never()).onResponse(anyVararg());
}
Also used : PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) RequestPolicyChain(io.gravitee.gateway.policy.impl.RequestPolicyChain) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) Test(org.junit.Test)

Example 17 with PolicyChain

use of io.gravitee.gateway.policy.impl.PolicyChain in project gravitee-gateway by gravitee-io.

the class ResponsePolicyChainTest method doNext_multiplePolicyOrder.

@Test
public void doNext_multiplePolicyOrder() throws Exception {
    PolicyChain chain = ResponsePolicyChain.create(Arrays.asList(policy, policy2), mock(ExecutionContext.class));
    chain.setResultHandler(result -> {
    });
    InOrder inOrder = inOrder(policy, policy2);
    chain.doNext(null, null);
    inOrder.verify(policy2).onResponse(anyVararg());
    inOrder.verify(policy).onResponse(anyVararg());
}
Also used : PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) ResponsePolicyChain(io.gravitee.gateway.policy.impl.ResponsePolicyChain) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 18 with PolicyChain

use of io.gravitee.gateway.policy.impl.PolicyChain in project gravitee-gateway by gravitee-io.

the class ResponsePolicyChainTest method doNext_streamablePolicies.

@Test
public void doNext_streamablePolicies() throws Exception {
    StreamablePolicy policy4 = spy(new StreamablePolicy());
    StreamablePolicy policy5 = spy(new StreamablePolicy());
    ExecutionContext executionContext = mock(ExecutionContext.class);
    ReadWriteStream streamPolicy4 = spy(new BufferedReadWriteStream());
    when(policy4.onResponseContent(any(Request.class), any(Response.class), any(io.gravitee.policy.api.PolicyChain.class), eq(executionContext))).thenReturn(streamPolicy4);
    ReadWriteStream streamPolicy5 = spy(new BufferedReadWriteStream());
    when(policy5.onResponseContent(any(Request.class), any(Response.class), any(io.gravitee.policy.api.PolicyChain.class), eq(executionContext))).thenReturn(streamPolicy5);
    InOrder inOrder = inOrder(streamPolicy4, streamPolicy5);
    PolicyChain chain = ResponsePolicyChain.create(Arrays.asList(policy4, policy5), executionContext);
    chain.setResultHandler(result -> {
    });
    chain.doNext(null, null);
    inOrder.verify(streamPolicy4, atLeastOnce()).bodyHandler(any(Handler.class));
    inOrder.verify(streamPolicy4, atLeastOnce()).endHandler(any(Handler.class));
    inOrder.verify(streamPolicy5, atLeastOnce()).bodyHandler(any(Handler.class));
    inOrder.verify(streamPolicy5, atLeastOnce()).endHandler(any(Handler.class));
    verify(policy4, atLeastOnce()).onResponse(null, null, chain, executionContext);
}
Also used : ReadWriteStream(io.gravitee.gateway.api.stream.ReadWriteStream) BufferedReadWriteStream(io.gravitee.gateway.api.stream.BufferedReadWriteStream) Response(io.gravitee.gateway.api.Response) PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) ResponsePolicyChain(io.gravitee.gateway.policy.impl.ResponsePolicyChain) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) InOrder(org.mockito.InOrder) BufferedReadWriteStream(io.gravitee.gateway.api.stream.BufferedReadWriteStream) Request(io.gravitee.gateway.api.Request) Handler(io.gravitee.gateway.api.handler.Handler) Test(org.junit.Test)

Example 19 with PolicyChain

use of io.gravitee.gateway.policy.impl.PolicyChain in project gravitee-gateway by gravitee-io.

the class ResponsePolicyChainTest method doNext_multiplePolicy.

@Test
public void doNext_multiplePolicy() throws Exception {
    ExecutionContext executionContext = mock(ExecutionContext.class);
    PolicyChain chain = ResponsePolicyChain.create(Arrays.asList(policy, policy2), executionContext);
    chain.setResultHandler(result -> {
    });
    chain.doNext(null, null);
    verify(policy, atLeastOnce()).onResponse(null, null, chain, executionContext);
    verify(policy2, atLeastOnce()).onResponse(null, null, chain, executionContext);
}
Also used : PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) ResponsePolicyChain(io.gravitee.gateway.policy.impl.ResponsePolicyChain) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) Test(org.junit.Test)

Example 20 with PolicyChain

use of io.gravitee.gateway.policy.impl.PolicyChain in project gravitee-gateway by gravitee-io.

the class ResponsePolicyChainTest method doNext_streamablePolicies_streaming.

@Test
public void doNext_streamablePolicies_streaming() throws Exception {
    StreamablePolicy policy4 = spy(new StreamablePolicy());
    StreamablePolicy policy5 = spy(new StreamablePolicy());
    ExecutionContext executionContext = mock(ExecutionContext.class);
    ReadWriteStream streamPolicy4 = spy(new BufferedReadWriteStream());
    when(policy4.onResponseContent(any(Request.class), any(Response.class), any(io.gravitee.policy.api.PolicyChain.class), eq(executionContext))).thenReturn(streamPolicy4);
    ReadWriteStream streamPolicy5 = spy(new BufferedReadWriteStream());
    when(policy5.onResponseContent(any(Request.class), any(Response.class), any(io.gravitee.policy.api.PolicyChain.class), eq(executionContext))).thenReturn(streamPolicy5);
    InOrder inOrder = inOrder(streamPolicy4, streamPolicy5);
    PolicyChain chain = ResponsePolicyChain.create(Arrays.asList(policy4, policy5), executionContext);
    chain.setResultHandler(result -> {
    });
    chain.bodyHandler(mock(Handler.class));
    chain.endHandler(mock(Handler.class));
    chain.doNext(null, null);
    chain.write(Buffer.buffer("TEST"));
    chain.write(Buffer.buffer("TEST"));
    chain.end();
    inOrder.verify(streamPolicy4, atLeastOnce()).bodyHandler(any(Handler.class));
    inOrder.verify(streamPolicy4, atLeastOnce()).endHandler(any(Handler.class));
    inOrder.verify(streamPolicy5, atLeastOnce()).bodyHandler(any(Handler.class));
    inOrder.verify(streamPolicy5, atLeastOnce()).endHandler(any(Handler.class));
    verify(policy4, atLeastOnce()).onResponse(null, null, chain, executionContext);
}
Also used : ReadWriteStream(io.gravitee.gateway.api.stream.ReadWriteStream) BufferedReadWriteStream(io.gravitee.gateway.api.stream.BufferedReadWriteStream) Response(io.gravitee.gateway.api.Response) PolicyChain(io.gravitee.gateway.policy.impl.PolicyChain) ResponsePolicyChain(io.gravitee.gateway.policy.impl.ResponsePolicyChain) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) InOrder(org.mockito.InOrder) BufferedReadWriteStream(io.gravitee.gateway.api.stream.BufferedReadWriteStream) Request(io.gravitee.gateway.api.Request) Handler(io.gravitee.gateway.api.handler.Handler) Test(org.junit.Test)

Aggregations

PolicyChain (io.gravitee.gateway.policy.impl.PolicyChain)21 Test (org.junit.Test)20 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)17 RequestPolicyChain (io.gravitee.gateway.policy.impl.RequestPolicyChain)12 ResponsePolicyChain (io.gravitee.gateway.policy.impl.ResponsePolicyChain)9 Request (io.gravitee.gateway.api.Request)8 InOrder (org.mockito.InOrder)7 Response (io.gravitee.gateway.api.Response)6 Handler (io.gravitee.gateway.api.handler.Handler)6 BufferedReadWriteStream (io.gravitee.gateway.api.stream.BufferedReadWriteStream)6 ReadWriteStream (io.gravitee.gateway.api.stream.ReadWriteStream)6 Metrics (io.gravitee.reporter.api.http.Metrics)2 DirectProxyConnection (io.gravitee.gateway.http.core.direct.DirectProxyConnection)1