Exemplo n.º 1
0
 public void setUp() throws Exception {
   super.setUp();
   mockWebServer = new MockWebServer();
   mockWebServer.play(9000);
   FH.init(getContext(), null); // this will load fhconfig.local.properties file
   FH.setLogLevel(FH.LOG_LEVEL_VERBOSE);
   DataManager.getInstance().save(FHAuthSession.SESSION_TOKEN_KEY, "testsessiontoken");
 }
Exemplo n.º 2
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);
  }
Exemplo n.º 3
0
  private void makeCloudRequest(String method, Header[] headers, JSONObject params, boolean pAsync)
      throws JSONException, Exception {
    FHCloudRequest cloudRequest = FH.buildCloudRequest("/v1/cloud/test", method, headers, params);
    FHActCallback callback =
        new FHActCallback() {

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

          @Override
          public void fail(FHResponse pResponse) {
            resJson = null;
          }
        };
    if (pAsync) {
      runAsyncRequest(cloudRequest, callback);
    } else {
      cloudRequest.execute(callback);
    }

    assertNotNull(resJson);
    assertEquals("cloud", resJson.getString("type"));
  }
Exemplo n.º 4
0
  /**
   * Set the parameters for the cloud side function
   *
   * @param pArgs the parameters that will be passed to the cloud side function
   */
  public void setArgs(JSONObject pArgs) {
    mArgs = pArgs;
    // keep backward compatibility
    if (!mArgs.has("__fh")) {
      try {
        mArgs.put("__fh", FH.getDefaultParams());
      } catch (Exception e) {

      }
    }
  }
Exemplo n.º 5
0
 @Override
 protected Header[] buildHeaders(Header[] pHeaders) {
   return FH.getDefaultParamsAsHeaders(pHeaders);
 }
Exemplo n.º 6
0
 public void tearDown() throws Exception {
   super.tearDown();
   shutdownServer();
   FH.stop();
 }