Search in sources :

Example 31 with MockRestRequest

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);
}
Also used : JSONObject(org.json.JSONObject) MockRestRequest(com.github.ambry.rest.MockRestRequest)

Example 32 with MockRestRequest

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);
}
Also used : JSONObject(org.json.JSONObject) MockRestRequest(com.github.ambry.rest.MockRestRequest)

Example 33 with MockRestRequest

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);
}
Also used : MockRestRequest(com.github.ambry.rest.MockRestRequest) ServerSecurityService(com.github.ambry.rest.ServerSecurityService) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) RestServiceErrorCode(com.github.ambry.rest.RestServiceErrorCode) ServerConfig(com.github.ambry.config.ServerConfig) Test(org.junit.Test) ThrowingConsumer(com.github.ambry.utils.ThrowingConsumer) ExecutionException(java.util.concurrent.ExecutionException) AmbryRequests(com.github.ambry.protocol.AmbryRequests) Mockito(org.mockito.Mockito) RestServiceException(com.github.ambry.rest.RestServiceException) SSLSession(javax.net.ssl.SSLSession) TestUtils(com.github.ambry.utils.TestUtils) ServerMetrics(com.github.ambry.commons.ServerMetrics) Callback(com.github.ambry.commons.Callback) Assert(org.junit.Assert) RestRequest(com.github.ambry.rest.RestRequest) RestServiceException(com.github.ambry.rest.RestServiceException) MockRestRequest(com.github.ambry.rest.MockRestRequest) RestRequest(com.github.ambry.rest.RestRequest) MockRestRequest(com.github.ambry.rest.MockRestRequest) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 34 with MockRestRequest

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);
}
Also used : JSONObject(org.json.JSONObject) MockRestRequest(com.github.ambry.rest.MockRestRequest)

Aggregations

MockRestRequest (com.github.ambry.rest.MockRestRequest)34 JSONObject (org.json.JSONObject)20 RestRequest (com.github.ambry.rest.RestRequest)18 RestServiceException (com.github.ambry.rest.RestServiceException)7 Test (org.junit.Test)7 ByteBuffer (java.nio.ByteBuffer)6 ReadableStreamChannel (com.github.ambry.router.ReadableStreamChannel)5 MockRestResponseChannel (com.github.ambry.rest.MockRestResponseChannel)4 InputStream (java.io.InputStream)4 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 VerifiableProperties (com.github.ambry.config.VerifiableProperties)2 BlobProperties (com.github.ambry.messageformat.BlobProperties)2 LinkedList (java.util.LinkedList)2 Properties (java.util.Properties)2 Callback (com.github.ambry.commons.Callback)1 ServerMetrics (com.github.ambry.commons.ServerMetrics)1 ServerConfig (com.github.ambry.config.ServerConfig)1 BlobInfo (com.github.ambry.messageformat.BlobInfo)1