Exemplo n.º 1
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.º 2
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);
  }