use of com.github.ambry.utils.ThrowingBiConsumer in project ambry by linkedin.
the class GetAccountsHandlerTest method badRequestsTest.
/**
* Test bad request cases.
* @throws Exception
*/
@Test
public void badRequestsTest() throws Exception {
Account existingAccount = accountService.createAndAddRandomAccount();
Account nonExistentAccount = accountService.generateRandomAccount();
ThrowingBiConsumer<RestRequest, RestServiceErrorCode> testAction = (request, expectedErrorCode) -> {
TestUtils.assertException(RestServiceException.class, () -> sendRequestGetResponse(request, new MockRestResponseChannel()), e -> assertEquals("Unexpected error code", expectedErrorCode, e.getErrorCode()));
};
// cannot supply both ID and name
testAction.accept(createRestRequest(existingAccount.getName(), Short.toString(existingAccount.getId()), null, Operations.ACCOUNTS), RestServiceErrorCode.BadRequest);
// non-numerical ID
testAction.accept(createRestRequest(null, "ABC", null, Operations.ACCOUNTS), RestServiceErrorCode.InvalidArgs);
// account that doesn't exist
testAction.accept(createRestRequest(nonExistentAccount.getName(), null, null, Operations.ACCOUNTS), RestServiceErrorCode.NotFound);
testAction.accept(createRestRequest(null, Short.toString(nonExistentAccount.getId()), null, Operations.ACCOUNTS), RestServiceErrorCode.NotFound);
}
use of com.github.ambry.utils.ThrowingBiConsumer in project ambry by linkedin.
the class PostAccountsHandlerTest method badRequestsTest.
/**
* Test bad request cases.
* @throws Exception
*/
@Test
public void badRequestsTest() throws Exception {
ThrowingBiConsumer<String, RestServiceErrorCode> testAction = (requestBody, expectedErrorCode) -> {
TestUtils.assertException(RestServiceException.class, () -> sendRequestGetResponse(requestBody, new MockRestResponseChannel()), e -> assertEquals("Unexpected error code", expectedErrorCode, e.getErrorCode()));
};
// non json input
testAction.accept("ABC", RestServiceErrorCode.BadRequest);
// invalid json
testAction.accept(new JSONObject().append("accounts", "ABC").toString(), RestServiceErrorCode.BadRequest);
// AccountService update failure
accountService.setShouldUpdateSucceed(false);
testAction.accept(new String(AccountCollectionSerde.serializeAccountsInJson(Collections.emptyList())), RestServiceErrorCode.InternalServerError);
}
Aggregations