예제 #1
0
  private void actTest(boolean async) throws Exception {
    String cloudHost = FH.getCloudHost();
    System.out.println("cloud host is " + cloudHost);

    // the fhconfig.local.properties file exists, use the host value from that
    // file as the cloud host
    assertEquals("http://localhost:9000", cloudHost);

    // mock response for act call
    MockResponse actSuccessResponse = new MockResponse();
    actSuccessResponse.addHeader("Content-Type", "application/json");

    actSuccessResponse.setBody("{'status':'ok', 'type': 'act'}");
    mockWebServer.enqueue(actSuccessResponse);
    FHAct actCall = FH.buildActRequest("test", new JSONObject());
    FHActCallback callback =
        new FHActCallback() {

          @Override
          public void success(FHResponse pResponse) {
            resJson = pResponse.getJson();
          }

          @Override
          public void fail(FHResponse pResponse) {
            resJson = null;
          }
        };

    if (async) {
      runAsyncRequest(actCall, callback);
    } else {
      actCall.execute(callback);
    }

    assertEquals(resJson.getString("type"), "act");
    // verify request object
    RecordedRequest request = mockWebServer.takeRequest();
    assertEquals("POST", request.getMethod().toUpperCase());
    assertEquals("/cloud/test", request.getPath());

    String requestBody = new String(request.getBody(), "UTF-8");
    JSONObject requestJson = new JSONObject(requestBody);
    assertTrue(requestJson.has("__fh"));

    JSONObject fhParams = requestJson.getJSONObject("__fh");
    String deviceId = fhParams.optString("cuid", null);
    assertEquals(getDeviceId(), deviceId);
  }
예제 #2
0
 private void enqueueCloudResponse() throws Exception {
   MockResponse cloudSuccessResponse = new MockResponse();
   cloudSuccessResponse.addHeader("Content-Type", "application/json");
   cloudSuccessResponse.setBody("{'status':'ok', 'type': 'cloud'}");
   mockWebServer.enqueue(cloudSuccessResponse);
 }