use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.
the class PostAccountContainersHandlerTest method createRestRequest.
/**
* Creates a {@link RestRequest} for a /accounts/updateContainers request
* @param requestBody body of the request in string form.
* @param accountName if set, add this account name as a request header.
* @param accountId if set, add this account ID as a request header.
* @return the {@link RestRequest}
* @throws Exception
*/
private RestRequest createRestRequest(String requestBody, String accountName, String accountId) throws Exception {
JSONObject data = new JSONObject();
data.put(MockRestRequest.REST_METHOD_KEY, RestMethod.POST.name());
data.put(MockRestRequest.URI_KEY, Operations.ACCOUNTS_CONTAINERS);
JSONObject headers = new JSONObject();
if (accountName != null) {
headers.put(RestUtils.Headers.TARGET_ACCOUNT_NAME, accountName);
}
if (accountId != null) {
headers.put(RestUtils.Headers.TARGET_ACCOUNT_ID, accountId);
}
data.put(MockRestRequest.HEADERS_KEY, headers);
List<ByteBuffer> body = new LinkedList<>();
body.add(ByteBuffer.wrap(requestBody.getBytes(StandardCharsets.UTF_8)));
body.add(null);
RestRequest restRequest = new MockRestRequest(data, body);
restRequest.setArg(RestUtils.InternalKeys.REQUEST_PATH, RequestPath.parse(restRequest, null, null));
return restRequest;
}
use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.
the class UndeleteHandlerTest method handleGoodCaseTest.
/**
* Tests the case where undelete succeeds
* @throws Exception
*/
@Test
public void handleGoodCaseTest() throws Exception {
setupBlob();
// 1. Test undelete a deleted blob
RestRequest restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
restRequest.setArg(RestUtils.Headers.BLOB_ID, blobId);
restRequest.setArg(RestUtils.Headers.SERVICE_ID, SERVICE_ID);
verifyUndelete(restRequest, REF_ACCOUNT, REF_CONTAINER);
// 2. Test undelete it again
router.deleteBlob(blobId, SERVICE_ID).get(1, TimeUnit.SECONDS);
restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
restRequest.setArg(RestUtils.Headers.BLOB_ID, blobId);
restRequest.setArg(RestUtils.Headers.SERVICE_ID, SERVICE_ID);
verifyUndelete(restRequest, REF_ACCOUNT, REF_CONTAINER);
}
use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.
the class UndeleteHandlerTest method badArgsTest.
/**
* Tests for expected failures with bad arguments
* @throws Exception
*/
private void badArgsTest() throws Exception {
setupBlob();
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 TailoredPeersClusterMap method getRestRequest.
/**
* Get a {@link RestRequest} that requests for the peers of the given {@code datanode}
* @param datanode the name of the datanode (host:port) whose peers are required.
* @return a {@link RestRequest} that requests for the peers of the given {@code datanode}
* @throws Exception
*/
private RestRequest getRestRequest(String datanode) throws Exception {
String[] parts = datanode.split(":");
JSONObject data = new JSONObject();
data.put(MockRestRequest.REST_METHOD_KEY, RestMethod.GET.name());
data.put(MockRestRequest.URI_KEY, Operations.GET_PEERS + "?" + GetPeersHandler.NAME_QUERY_PARAM + "=" + parts[0] + "&" + GetPeersHandler.PORT_QUERY_PARAM + "=" + parts[1]);
return new MockRestRequest(data, null);
}
use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.
the class GetSignedUrlHandlerTest method handleGoodCaseTest.
/**
* Handles the case where url signing succeeds
* @throws Exception
*/
@Test
public void handleGoodCaseTest() throws Exception {
urlSigningServiceFactory.signedUrlToReturn = TestUtils.getRandomString(10);
// POST
RestRequest restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
restRequest.setArg(RestUtils.InternalKeys.REQUEST_PATH, RequestPath.parse("/signedUrl", Collections.emptyMap(), Collections.emptyList(), "Ambry-test"));
restRequest.setArg(RestUtils.Headers.URL_TYPE, RestMethod.POST.name());
restRequest.setArg(RestUtils.Headers.TARGET_ACCOUNT_NAME, REF_ACCOUNT.getName());
restRequest.setArg(RestUtils.Headers.TARGET_CONTAINER_NAME, REF_CONTAINER.getName());
verifySigningUrl(restRequest, urlSigningServiceFactory.signedUrlToReturn, REF_ACCOUNT, REF_CONTAINER);
idConverterFactory.translation = testBlobId.getID();
// GET (also makes sure that the IDConverter is used)
restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
restRequest.setArg(RestUtils.InternalKeys.REQUEST_PATH, RequestPath.parse("/signedUrl", Collections.emptyMap(), Collections.emptyList(), "Ambry-test"));
restRequest.setArg(RestUtils.Headers.URL_TYPE, RestMethod.GET.name());
// add a random string. IDConverter will convert it
restRequest.setArg(RestUtils.Headers.BLOB_ID, TestUtils.getRandomString(10));
verifySigningUrl(restRequest, urlSigningServiceFactory.signedUrlToReturn, REF_ACCOUNT, REF_CONTAINER);
}
Aggregations