Exemplo n.º 1
0
  @Test
  public void test_application_not_found_on_authorize() throws ApiException {

    when(sender.sendGetToServer(
            SERVER_URL
                + "/transactions/authorize.xml"
                + "?app_id="
                + APP_ID
                + "&provider_key="
                + PROVIDER_KEY))
        .thenReturn(new ApiHttpResponse(404, APPLICATION_ID_ERROR_RESPONSE));

    AuthorizeResponse response = null;
    try {
      response = server.authorize(null, null);
      fail("Should have thrown ApiException");
    } catch (ApiException e) {
      assertEquals("application_not_found", e.getErrorCode());
      assertEquals("Application with id=\"12345678\" was not found", e.getErrorMessage());
    }
  }
Exemplo n.º 2
0
  @Test
  public void test_provider_key_invalid_on_authorize() throws ApiException {

    when(sender.sendGetToServer(
            SERVER_URL
                + "/transactions/authorize.xml"
                + "?app_id="
                + APP_ID
                + "&provider_key="
                + PROVIDER_KEY))
        .thenReturn(new ApiHttpResponse(403, PROVIDER_KEY_INVALID_ERROR_RESPONSE));

    AuthorizeResponse response = null;
    try {
      response = server.authorize(null, null);
      fail("Should have thrown ApiException");
    } catch (ApiException e) {
      assertEquals("provider_key_invalid", e.getErrorCode());
      assertEquals("Provider key \"abcd1234\" is invalid", e.getErrorMessage());
    }
  }
Exemplo n.º 3
0
  @Test
  public void test_referrer_is_sent_for_authorize() throws ApiException {

    when(sender.sendGetToServer(
            SERVER_URL
                + "/transactions/authorize.xml"
                + "?app_id="
                + APP_ID
                + "&provider_key="
                + PROVIDER_KEY
                + "&app_key="
                + APP_KEY
                + "&referrer="
                + REFERRER_IP))
        .thenReturn(new ApiHttpResponse(200, HAPPY_PATH_RESPONSE));

    AuthorizeResponse response = server.authorize(APP_KEY, REFERRER_IP);
    assertEquals(true, response.getAuthorized());
    assertEquals("Basic", response.getPlan());
    assertEquals("", response.getReason());
  }
Exemplo n.º 4
0
  @Test
  public void test_authorize_exceeded_path() throws ApiException {

    when(sender.sendGetToServer(
            SERVER_URL
                + "/transactions/authorize.xml"
                + "?app_id="
                + APP_ID
                + "&provider_key="
                + PROVIDER_KEY
                + "&app_key="
                + APP_KEY))
        .thenReturn(new ApiHttpResponse(200, EXCEEDED_PATH_RESPONSE));

    AuthorizeResponse response = server.authorize(APP_KEY, null);
    assertEquals(false, response.getAuthorized());
    assertEquals("Pro", response.getPlan());
    assertEquals("Usage limits are exceeded", response.getReason());
    assertEquals(2, response.getUsageReports().size());

    assertUsageRecord(
        response.getUsageReports().get(0),
        "hits",
        "month",
        "2010-08-01 00:00:00 +00:00",
        "2010-09-01 00:00:00 +00:00",
        "17344",
        "20000",
        false);

    assertUsageRecord(
        response.getUsageReports().get(1),
        "hits",
        "day",
        "2010-08-04 00:00:00 +00:00",
        "2010-08-05 00:00:00 +00:00",
        "732",
        "1000",
        true);
  }