use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.
the class StorageQuotaEnforcerTest method createRestRequest.
/**
* Create a {@link MockRestRequest} without any header.
* @return a {@link MockRestRequest} without any header.
* @throws Exception
*/
private RestRequest createRestRequest() throws Exception {
JSONObject data = new JSONObject();
data.put(MockRestRequest.REST_METHOD_KEY, RestMethod.GET.name());
data.put(MockRestRequest.URI_KEY, "/");
return new MockRestRequest(data, null);
}
use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.
the class NonBlockingRouterTest method createRestRequestForGetOperation.
private RestRequest createRestRequestForGetOperation() throws Exception {
JSONObject header = new JSONObject();
header.put(MockRestRequest.REST_METHOD_KEY, RestMethod.GET.name());
header.put(MockRestRequest.URI_KEY, "/something.bin");
return new MockRestRequest(header, null);
}
use of com.github.ambry.rest.MockRestRequest 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);
}
use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.
the class QuotaTestUtils method createRestRequest.
/**
* Create {@link MockRestRequest} object using the specified {@link Account}, {@link Container} and {@link RestMethod}.
* @param account {@link Account} object.
* @param container {@link Container} object.
* @param restMethod {@link RestMethod} object.
* @return MockRestRequest object.
* @throws Exception in case of any exception.
*/
public static MockRestRequest createRestRequest(Account account, Container container, RestMethod restMethod) throws Exception {
JSONObject data = new JSONObject();
data.put(MockRestRequest.REST_METHOD_KEY, restMethod.name());
data.put(MockRestRequest.URI_KEY, "/");
JSONObject headers = new JSONObject();
headers.put(RestUtils.InternalKeys.TARGET_ACCOUNT_KEY, account);
headers.put(RestUtils.InternalKeys.TARGET_CONTAINER_KEY, container);
data.put(MockRestRequest.HEADERS_KEY, headers);
return new MockRestRequest(data, null);
}
Aggregations