use of com.github.ambry.utils.ThrowingConsumer in project ambry by linkedin.
the class AmbryServerSecurityServiceTest method validateRequestTest.
/**
* Tests for {@link AmbryServerSecurityService#validateRequest(RestRequest, Callback)}
* @throws Exception
*/
@Test
public void validateRequestTest() throws Exception {
// request is null
TestUtils.assertException(IllegalArgumentException.class, () -> serverSecurityService.validateRequest(null).get(), null);
// success case
RestRequest request = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
serverSecurityService.validateRequest(request, (r, e) -> {
Assert.assertNull("result not null", r);
Assert.assertNull("exception not null", e);
});
// service is closed
serverSecurityService.close();
ThrowingConsumer<ExecutionException> errorAction = e -> {
Assert.assertTrue("Exception should have been an instance of RestServiceException", e.getCause() instanceof RestServiceException);
RestServiceException re = (RestServiceException) e.getCause();
Assert.assertEquals("Unexpected RestServerErrorCode (Future)", RestServiceErrorCode.ServiceUnavailable, re.getErrorCode());
};
TestUtils.assertException(ExecutionException.class, () -> serverSecurityService.validateRequest(request).get(), errorAction);
}
Aggregations