예제 #1
0
  @Test
  public void test_report_returns_provider_id_error() {

    when(sender.sendPostToServer(SERVER_URL, RESPONSE_HAPPY_PATH_DATA))
        .thenReturn(new ApiHttpResponse(403, PROVIDER_KEY_INVALID_ERROR_RESPONSE));

    ApiTransaction[] transactions = new ApiTransaction[2];
    HashMap<String, String> metrics0 = new HashMap<String, String>();
    metrics0.put("hits", "1");
    metrics0.put("transfer", "4500");

    HashMap<String, String> metrics1 = new HashMap<String, String>();
    metrics1.put("hits", "1");
    metrics1.put("transfer", "2840");

    transactions[0] = new ApiTransaction("bce4c8f4", "2009-01-01 14:23:08", metrics0);
    transactions[1] = new ApiTransaction("bad7e480", "2009-01-01 18:11:59", metrics1);

    try {
      server.report(transactions);
      fail("Should have thrown ApiException");
    } catch (ApiException e) {
      assertEquals(e.getErrorCode(), "provider_key_invalid");
      assertEquals(e.getErrorMessage(), "Provider key \"abcd1234\" is invalid");
    }
  }
예제 #2
0
  @Test
  public void test_report_happy_path() throws ApiException {

    when(sender.sendPostToServer(SERVER_URL, RESPONSE_HAPPY_PATH_DATA))
        .thenReturn(new ApiHttpResponse(202, null));

    ApiTransaction[] transactions = new ApiTransaction[2];
    HashMap<String, String> metrics0 = new HashMap<String, String>();
    metrics0.put("hits", "1");
    metrics0.put("transfer", "4500");

    HashMap<String, String> metrics1 = new HashMap<String, String>();
    metrics1.put("hits", "1");
    metrics1.put("transfer", "2840");

    transactions[0] = new ApiTransaction("bce4c8f4", "2009-01-01 14:23:08", metrics0);
    transactions[1] = new ApiTransaction("bad7e480", "2009-01-01 18:11:59", metrics1);

    assertEquals(
        RESPONSE_HAPPY_PATH_DATA, ((Api2Impl) server).formatPostData(transactions).toString());

    server.report(transactions);
  }