use of io.gravitee.policy.api.annotations.OnRequest in project gravitee-gateway by gravitee-io.
the class PolicyTest method onRequest_mockParameters.
@Test
public void onRequest_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 onRequestMethod = resolvePolicyMethod(DummyPolicy.class, OnRequest.class);
when(policyDefinition.method(OnRequest.class)).thenReturn(onRequestMethod);
Policy policy = PolicyImpl.target(policyInst).definition(policyDefinition).build();
Request mockRequest = mock(Request.class);
Response mockResponse = mock(Response.class);
policy.onRequest(mockRequest, mockResponse);
verify(policyInst, atLeastOnce()).onRequest(any(PolicyChain.class), eq(mockRequest), eq(mockResponse));
}
use of io.gravitee.policy.api.annotations.OnRequest 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.OnRequest in project gravitee-gateway by gravitee-io.
the class PolicyTest method onRequest_emptyParameters.
@Test
public void onRequest_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 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());
}
use of io.gravitee.policy.api.annotations.OnRequest 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());
}
Aggregations