當前位置: 首頁>>代碼示例>>Java>>正文


Java RecordedRequest.getUtf8Body方法代碼示例

本文整理匯總了Java中okhttp3.mockwebserver.RecordedRequest.getUtf8Body方法的典型用法代碼示例。如果您正苦於以下問題:Java RecordedRequest.getUtf8Body方法的具體用法?Java RecordedRequest.getUtf8Body怎麽用?Java RecordedRequest.getUtf8Body使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在okhttp3.mockwebserver.RecordedRequest的用法示例。


在下文中一共展示了RecordedRequest.getUtf8Body方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkValidUnusedEmail

import okhttp3.mockwebserver.RecordedRequest; //導入方法依賴的package包/類
@Test
public void checkValidUnusedEmail() throws InterruptedException {
    JsonObject body = new JsonObject();
    body.addProperty("message", UserAdapter.USER_DOESNT_EXIST);
    mMockServer.enqueue(new MockResponse()
            .setResponseCode(HttpURLConnection.HTTP_NOT_FOUND)
            .setBody(body.toString()));
    ValidationCallback mockCallback = mock(ValidationCallback.class);

    mUserAdapter.checkValidUnusedEmail("[email protected]", mockCallback);

    RecordedRequest request = mMockServer.takeRequest();
    String json = request.getUtf8Body();
    JsonObject requestJson = new JsonParser().parse(json).getAsJsonObject();
    assertEquals("POST", request.getMethod());
    assertEquals("/users/search", request.getPath());
    assertEquals("application/json; charset=UTF-8", request.getHeader("Content-Type"));
    assertEquals("[email protected]", requestJson.get("email").getAsString());

    verify(mockCallback, timeout(1000)).onValidationResponse(UserAdapter.VALID_UNUSED);
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:22,代碼來源:RegisterAdapterTest.java

示例2: checkUsedEmail

import okhttp3.mockwebserver.RecordedRequest; //導入方法依賴的package包/類
@Test
public void checkUsedEmail() throws InterruptedException {
    JsonObject body = new JsonObject();
    body.addProperty("message", UserAdapter.USER_EXISTS);
    mMockServer.enqueue(new MockResponse()
            .setResponseCode(HttpURLConnection.HTTP_OK)
            .setBody(body.toString()));
    ValidationCallback mockCallback = mock(ValidationCallback.class);

    mUserAdapter.checkValidUnusedEmail("[email protected]", mockCallback);

    RecordedRequest request = mMockServer.takeRequest();
    String json = request.getUtf8Body();
    JsonObject requestJson = new JsonParser().parse(json).getAsJsonObject();
    assertEquals("POST", request.getMethod());
    assertEquals("/users/search", request.getPath());
    assertEquals("application/json; charset=UTF-8", request.getHeader("Content-Type"));
    assertEquals("[email protected]", requestJson.get("email").getAsString());

    verify(mockCallback, timeout(1000)).onValidationResponse(UserAdapter.USED);
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:22,代碼來源:RegisterAdapterTest.java

示例3: checkValidUnusedUsername

import okhttp3.mockwebserver.RecordedRequest; //導入方法依賴的package包/類
@Test
public void checkValidUnusedUsername() throws InterruptedException {
    JsonObject body = new JsonObject();
    body.addProperty("message", UserAdapter.USER_DOESNT_EXIST);
    mMockServer.enqueue(new MockResponse()
            .setResponseCode(HttpURLConnection.HTTP_NOT_FOUND)
            .setBody(body.toString()));
    ValidationCallback mockCallback = mock(ValidationCallback.class);

    mUserAdapter.checkValidUnusedUsername("validUsername", mockCallback);
    RecordedRequest request = mMockServer.takeRequest();
    String json = request.getUtf8Body();
    JsonObject requestJson = new JsonParser().parse(json).getAsJsonObject();
    assertEquals("POST", request.getMethod());
    assertEquals("/users/search", request.getPath());
    assertEquals("application/json; charset=UTF-8", request.getHeader("Content-Type"));
    assertEquals("validUsername", requestJson.get("username").getAsString());
    verify(mockCallback, timeout(1000)).onValidationResponse(UserAdapter.VALID_UNUSED);
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:20,代碼來源:RegisterAdapterTest.java

示例4: checkUsedUsername

import okhttp3.mockwebserver.RecordedRequest; //導入方法依賴的package包/類
@Test
public void checkUsedUsername() throws InterruptedException {
    JsonObject body = new JsonObject();
    body.addProperty("message", UserAdapter.USER_EXISTS);
    mMockServer.enqueue(new MockResponse()
            .setResponseCode(HttpURLConnection.HTTP_OK)
            .setBody(body.toString()));
    ValidationCallback mockCallback = mock(ValidationCallback.class);

    mUserAdapter.checkValidUnusedUsername("usedUsername", mockCallback);
    RecordedRequest request = mMockServer.takeRequest();
    String json = request.getUtf8Body();
    JsonObject requestJson = new JsonParser().parse(json).getAsJsonObject();
    assertEquals("POST", request.getMethod());
    assertEquals("/users/search", request.getPath());
    assertEquals("application/json; charset=UTF-8", request.getHeader("Content-Type"));
    assertEquals("usedUsername", requestJson.get("username").getAsString());
    verify(mockCallback, timeout(1000)).onValidationResponse(UserAdapter.USED);
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:20,代碼來源:RegisterAdapterTest.java

示例5: registerNotExistingUser

import okhttp3.mockwebserver.RecordedRequest; //導入方法依賴的package包/類
@Test
public void registerNotExistingUser() throws InterruptedException {
    JsonObject body = new JsonObject();
    body.addProperty("message", UserAdapter.USER_CREATED);
    mMockServer.enqueue(new MockResponse()
            .setResponseCode(HttpURLConnection.HTTP_CREATED)
            .setBody(body.toString()));
    SimpleCallback mockCallback = mock(SimpleCallback.class);

    mUserAdapter.registerUser(mUser, mockCallback);

    RecordedRequest request = mMockServer.takeRequest();
    String json = request.getUtf8Body();
    JsonObject requestJson = new JsonParser().parse(json).getAsJsonObject();
    assertEquals("POST", request.getMethod());
    assertEquals("/users", request.getPath());
    assertEquals("application/json; charset=UTF-8", request.getHeader("Content-Type"));
    assertEquals("username", requestJson.get("username").getAsString());
    assertEquals("name", requestJson.get("first_name").getAsString());
    assertEquals("surname", requestJson.get("last_name").getAsString());
    assertEquals("[email protected]", requestJson.get("email").getAsString());
    assertEquals("a59aea522d1b3a2d0d4b927e4f065909d10a6f8c289901f591644d885aff23ca",
            requestJson.get("password").getAsString());
    assertEquals("a59aea522d1b3a2d0d4b927e4f065909d10a6f8c289901f591644d885aff23ca",
            requestJson.get("password_confirmation").getAsString());
    verify(mockCallback, timeout(1000)).onSuccess();
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:28,代碼來源:RegisterAdapterTest.java

示例6: registerExistingUser

import okhttp3.mockwebserver.RecordedRequest; //導入方法依賴的package包/類
@Test
public void registerExistingUser() throws InterruptedException {
    JsonObject body = new JsonObject();
    body.addProperty("message", UserAdapter.USER_NOT_CREATED);
    mMockServer.enqueue(new MockResponse()
            .setResponseCode(HttpURLConnection.HTTP_BAD_REQUEST)
            .setBody(body.toString()));
    SimpleCallback mockCallback = mock(SimpleCallback.class);

    mUserAdapter.registerUser(mUser, mockCallback);

    RecordedRequest request = mMockServer.takeRequest();
    String json = request.getUtf8Body();
    JsonObject requestJson = new JsonParser().parse(json).getAsJsonObject();
    assertEquals("POST", request.getMethod());
    assertEquals("/users", request.getPath());
    assertEquals("application/json; charset=UTF-8", request.getHeader("Content-Type"));
    assertEquals("username", requestJson.get("username").getAsString());
    assertEquals("name", requestJson.get("first_name").getAsString());
    assertEquals("surname", requestJson.get("last_name").getAsString());
    assertEquals("[email protected]", requestJson.get("email").getAsString());
    assertEquals("a59aea522d1b3a2d0d4b927e4f065909d10a6f8c289901f591644d885aff23ca",
            requestJson.get("password").getAsString());
    assertEquals("a59aea522d1b3a2d0d4b927e4f065909d10a6f8c289901f591644d885aff23ca",
            requestJson.get("password_confirmation").getAsString());

    verify(mockCallback, timeout(1000)).onFailure();

}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:30,代碼來源:RegisterAdapterTest.java


注:本文中的okhttp3.mockwebserver.RecordedRequest.getUtf8Body方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。