Search in sources :

Example 11 with RestResponse

use of com.amplifyframework.api.rest.RestResponse in project amplify-android by aws-amplify.

the class AWSRestOperationTest method responseEmittedWhenOperationSucceeds.

/**
 * Tests the happy path, wherein the server returns a response, the
 * operation hasn't been canceled, and we get a {@link RestResponse}
 * at the end of it.
 * @throws ApiException
 *         A possible outcome of the operation. This is not
 *         expected, and would constitute a test failure.
 */
@Test
public void responseEmittedWhenOperationSucceeds() throws ApiException {
    RestOperationRequest request = new RestOperationRequest(HttpMethod.GET, baseUrl.uri().getPath(), emptyMap(), emptyMap());
    RestResponse response = Await.<RestResponse, ApiException>result((onResult, onError) -> {
        AWSRestOperation operation = new AWSRestOperation(request, baseUrl.url().toString(), client, onResult, onError);
        operation.start();
    });
    assertTrue(response.getCode().isSuccessful());
    Map<String, String> expected = new HashMap<>();
    expected.put("foo", "bar,baz");
    expected.put("qux", "quux");
    expected.put("content-length", "21");
    assertEquals(expected, response.getHeaders());
}
Also used : HashMap(java.util.HashMap) RestResponse(com.amplifyframework.api.rest.RestResponse) RestOperationRequest(com.amplifyframework.api.rest.RestOperationRequest) ApiException(com.amplifyframework.api.ApiException) Test(org.junit.Test)

Aggregations

RestResponse (com.amplifyframework.api.rest.RestResponse)11 Test (org.junit.Test)11 RestOptions (com.amplifyframework.api.rest.RestOptions)9 ApiException (com.amplifyframework.api.ApiException)4 JSONObject (org.json.JSONObject)3 RestOperationRequest (com.amplifyframework.api.rest.RestOperationRequest)2 HashMap (java.util.HashMap)2 Ignore (org.junit.Ignore)2 HttpMethod (com.amplifyframework.api.rest.HttpMethod)1 Await (com.amplifyframework.testutils.Await)1 IOException (java.io.IOException)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 HttpUrl (okhttp3.HttpUrl)1 OkHttpClient (okhttp3.OkHttpClient)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 MockWebServer (okhttp3.mockwebserver.MockWebServer)1 JSONException (org.json.JSONException)1 After (org.junit.After)1