use of io.gravitee.policy.api.annotations.OnResponse in project gravitee-gateway by gravitee-io.
the class PolicyTest method onResponse.
@Test
public void onResponse() throws Exception {
PolicyMetadata policyDefinition = mock(PolicyMetadata.class);
when(policyDefinition.policy()).then((Answer<Class>) invocationOnMock -> DummyPolicy.class);
DummyPolicy policyInst = Mockito.spy((DummyPolicy) policyFactory.create(policyDefinition, null));
Method onResponseMethod = resolvePolicyMethod(DummyPolicy.class, OnResponse.class);
when(policyDefinition.method(OnResponse.class)).thenReturn(onResponseMethod);
Policy policy = PolicyImpl.target(policyInst).definition(policyDefinition).build();
policy.onResponse();
verify(policyInst, never()).onRequest(any(), any(), any());
verify(policyInst, atLeastOnce()).onResponse(any(), any(), any());
}
use of io.gravitee.policy.api.annotations.OnResponse in project gravitee-gateway by gravitee-io.
the class PolicyTest method onResponse_emptyParameters.
@Test
public void onResponse_emptyParameters() throws Exception {
PolicyMetadata policyDefinition = mock(PolicyMetadata.class);
when(policyDefinition.policy()).then((Answer<Class>) invocationOnMock -> DummyPolicy.class);
DummyPolicy policyInst = Mockito.spy((DummyPolicy) policyFactory.create(policyDefinition, null));
Method onResponseMethod = resolvePolicyMethod(DummyPolicy.class, OnResponse.class);
when(policyDefinition.method(OnResponse.class)).thenReturn(onResponseMethod);
Policy policy = PolicyImpl.target(policyInst).definition(policyDefinition).build();
policy.onResponse();
verify(policyInst, atLeastOnce()).onResponse(any(), any(), any());
}
use of io.gravitee.policy.api.annotations.OnResponse in project gravitee-gateway by gravitee-io.
the class PolicyTest method onRequest.
@Test
public void onRequest() throws Exception {
PolicyMetadata policyDefinition = mock(PolicyMetadata.class);
when(policyDefinition.policy()).then((Answer<Class>) invocationOnMock -> DummyPolicy.class);
DummyPolicy policyInst = Mockito.spy((DummyPolicy) policyFactory.create(policyDefinition, null));
Method onRequestMethod = resolvePolicyMethod(DummyPolicy.class, OnRequest.class);
when(policyDefinition.method(OnRequest.class)).thenReturn(onRequestMethod);
Policy policy = PolicyImpl.target(policyInst).definition(policyDefinition).build();
policy.onRequest();
verify(policyInst, atLeastOnce()).onRequest(any(), any(), any());
verify(policyInst, never()).onResponse(any(), any(), any());
}
use of io.gravitee.policy.api.annotations.OnResponse in project gravitee-gateway by gravitee-io.
the class PolicyTest method onResponse_mockParameters.
@Test
public void onResponse_mockParameters() throws Exception {
PolicyMetadata policyDefinition = mock(PolicyMetadata.class);
when(policyDefinition.policy()).then((Answer<Class>) invocationOnMock -> DummyPolicy.class);
DummyPolicy policyInst = Mockito.spy((DummyPolicy) policyFactory.create(policyDefinition, null));
Method onResponseMethod = resolvePolicyMethod(DummyPolicy.class, OnResponse.class);
when(policyDefinition.method(OnResponse.class)).thenReturn(onResponseMethod);
Policy policy = PolicyImpl.target(policyInst).definition(policyDefinition).build();
Request mockRequest = mock(Request.class);
Response mockResponse = mock(Response.class);
policy.onResponse(mockRequest, mockResponse);
verify(policyInst, atLeastOnce()).onResponse(eq(mockRequest), eq(mockResponse), any(PolicyChain.class));
}
Aggregations