use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.
the class TtlUpdateHandlerTest method badArgsTest.
/**
* Tests for expected failures with bad arguments
* @throws Exception
*/
private void badArgsTest() throws Exception {
RestRequest restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
restRequest.setArg(RestUtils.Headers.BLOB_ID, blobId);
// no service ID
verifyFailureWithErrorCode(restRequest, RestServiceErrorCode.MissingArgs);
restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
restRequest.setArg(RestUtils.Headers.SERVICE_ID, SERVICE_ID);
// no blob ID
verifyFailureWithErrorCode(restRequest, RestServiceErrorCode.MissingArgs);
restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
// not a valid blob ID
restRequest.setArg(RestUtils.Headers.BLOB_ID, "abcd");
idConverterFactory.translation = "abcd";
restRequest.setArg(RestUtils.Headers.SERVICE_ID, SERVICE_ID);
verifyFailureWithErrorCode(restRequest, RestServiceErrorCode.BadRequest);
}
use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.
the class StorageQuotaEnforcerTest method createRestRequest.
/**
* Create a {@link MockRestRequest} with account and container headers.
* @param accountService The {@link AccountService}.
* @param accountId the account id.
* @param containerId the container id.
* @return a {@link MockRestRequest} with account and container headers.
* @throws Exception
*/
private RestRequest createRestRequest(AccountService accountService, short accountId, short containerId) throws Exception {
JSONObject data = new JSONObject();
data.put(MockRestRequest.REST_METHOD_KEY, RestMethod.GET.name());
data.put(MockRestRequest.URI_KEY, "/");
JSONObject headers = new JSONObject();
headers.put(RestUtils.InternalKeys.TARGET_ACCOUNT_KEY, accountService.getAccountById(accountId));
headers.put(RestUtils.InternalKeys.TARGET_CONTAINER_KEY, accountService.getAccountById(accountId).getContainerById(containerId));
data.put(MockRestRequest.HEADERS_KEY, headers);
return new MockRestRequest(data, null);
}
use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.
the class NonBlockingRouterTest method createRestRequestForPutOperation.
private RestRequest createRestRequestForPutOperation() throws Exception {
JSONObject header = new JSONObject();
header.put(MockRestRequest.REST_METHOD_KEY, RestMethod.POST.name());
header.put(MockRestRequest.URI_KEY, "/");
return new MockRestRequest(header, null);
}
use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.
the class AmbryIdConverterFactoryTest method testConversion.
/**
* Tests the conversion by the {@code idConverter}.
* @param idConverter the {@link IdConverter} instance to use.
* @param restMethod the {@link RestMethod} of the {@link RestRequest} that will be created.
* @param input the input string
* @param expectedOutput the expected output from the {@code idConverter}.
* @throws Exception
*/
private void testConversion(IdConverter idConverter, RestMethod restMethod, String input, String expectedOutput) throws Exception {
JSONObject requestData = new JSONObject();
requestData.put(MockRestRequest.REST_METHOD_KEY, restMethod);
requestData.put(MockRestRequest.URI_KEY, "/");
RestRequest restRequest = new MockRestRequest(requestData, null);
IdConversionCallback callback = new IdConversionCallback();
assertEquals("Converted ID does not match expected (Future)", expectedOutput, idConverter.convert(restRequest, input, callback).get());
assertEquals("Converted ID does not match expected (Callback)", expectedOutput, callback.result);
}
use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.
the class PutBlobOptionsTest method testOptions.
/**
* Test that the chunk upload and max size options can be assigned and retrieved correctly.
* @throws Exception
*/
@Test
public void testOptions() throws Exception {
PutBlobOptions options = new PutBlobOptionsBuilder().chunkUpload(true).build();
assertTrue("chunkUpload from options not as expected.", options.isChunkUpload());
assertEquals("maxUploadSize from options not as expected.", Long.MAX_VALUE, options.getMaxUploadSize());
options = new PutBlobOptionsBuilder().chunkUpload(false).maxUploadSize(3).build();
assertFalse("chunkUpload from options not as expected.", options.isChunkUpload());
assertEquals("maxUploadSize from options not as expected.", 3, options.getMaxUploadSize());
JSONObject header = new JSONObject();
header.put(MockRestRequest.URI_KEY, "/");
header.put(MockRestRequest.REST_METHOD_KEY, RestMethod.GET.name());
RestRequest restRequest = new MockRestRequest(header, null);
options = new PutBlobOptionsBuilder().restRequest(restRequest).build();
assertEquals("RestRequest mismatch", restRequest, options.getRestRequest());
}
Aggregations