use of com.github.ambry.rest.RestServiceErrorCode 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);
}
use of com.github.ambry.rest.RestServiceErrorCode in project ambry by linkedin.
the class PostAccountContainersHandlerTest method badRequestsTest.
/**
* Test bad request cases.
* @throws Exception
*/
@Test
public void badRequestsTest() throws Exception {
ThrowingBiConsumer<RestRequest, RestServiceErrorCode> testAction = (request, expectedErrorCode) -> {
TestUtils.assertException(RestServiceException.class, () -> sendRequestGetResponse(request, new MockRestResponseChannel()), e -> assertEquals("Unexpected error code", expectedErrorCode, e.getErrorCode()));
};
String accountName = theAccount.getName();
// Empty container list should fail
String emptyContainers = new String(AccountCollectionSerde.serializeContainersInJson(Collections.emptyList()));
RestRequest request = createRestRequest(emptyContainers, accountName, null);
testAction.accept(request, RestServiceErrorCode.BadRequest);
// non json input
request = createRestRequest("ABC", accountName, null);
testAction.accept(request, RestServiceErrorCode.BadRequest);
// invalid json
String invalidJson = new JSONObject().append("accounts", "ABC").toString();
request = createRestRequest(invalidJson, accountName, null);
testAction.accept(request, RestServiceErrorCode.BadRequest);
// No account specified
String oneContainer = new String(AccountCollectionSerde.serializeContainersInJson(Collections.singleton(accountService.getRandomContainer(theAccount.getId()))));
request = createRestRequest(oneContainer, null, null);
testAction.accept(request, RestServiceErrorCode.BadRequest);
// AccountService update failure
accountService.setShouldUpdateSucceed(false);
request = createRestRequest(oneContainer, accountName, null);
testAction.accept(request, RestServiceErrorCode.InternalServerError);
}
Aggregations