Java Code Examples for com.squareup.okhttp.mockwebserver.RecordedRequest#getMethod()

The following examples show how to use com.squareup.okhttp.mockwebserver.RecordedRequest#getMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UTAdRequestTest.java    From mobile-sdk-android with Apache License 2.0 6 votes vote down vote up
@NonNull
private JSONObject inspectPostData() throws InterruptedException, JSONException {
    System.out.println("Testing POST data...");
    RecordedRequest recordedRequest = server.takeRequest();
    String method = recordedRequest.getMethod();
    assertNotNull(method);
    assertEquals("POST", method.toUpperCase());
    assertNotNull(recordedRequest.getBody());
    String requestBody = recordedRequest.getBody().readUtf8();
    assertNotNull(requestBody);
    JSONObject postData = new JSONObject(requestBody);
    assertTrue(postData.has("tags"));
    assertTrue(postData.has("user"));
    assertTrue(postData.has("device"));
    assertTrue(postData.has("app"));

    System.out.println("POST data validity passed!");
    return postData;
}
 
Example 2
Source File: MiscHandle.java    From httplite with Apache License 2.0 5 votes vote down vote up
@Override
public MockResponse handle(RecordedRequest request, String root) {
    String path = request.getPath();
    RequestInfo requestInfo = new RequestInfo();
    int index = path.indexOf("?");
    if (index > -1) {
        String queryString = path.substring(index + 1);
        path = path.substring(0, index);
        requestInfo.params = HttpUtil.getParamsMap(queryString, Util.UTF_8.name());
    }
    if(path.startsWith("/download/")){
        MockResponse mr = handleDownload(request, root);
        mr.addHeader("RequestHeaders",request.getHeaders().toString());
        mr.addHeader("RequestParams",requestInfo.params);
        return mr;
    }
    requestInfo.method = request.getMethod();
    requestInfo.path = path;
    requestInfo.headers = request.getHeaders().toMultimap();
    String methodUp = requestInfo.method.toUpperCase();
    if(methodUp.equals("POST")||methodUp.equals("PUT")){
        requestInfo.bodyInfo = createBodyInfo(request);
    }
    BaseResult<RequestInfo> result = new BaseResult<>();
    result.requestMethod = requestInfo.method;
    result.requestPath = requestInfo.path;
    result.data = requestInfo;
    return new MockResponse().setStatus("HTTP/1.1 200").addHeader("content-type: application/json; charset=utf-8")
            .setBody(JSON.toJSONString(result));
}