Ejemplo n.º 1
0
  /**
   * Test for: CreditCardFilter.For now it uses a value already in DB for the blacklisted cc number.
   * In prepare-test db the cc number 5555555555554444 is blacklisted.
   */
  @Test
  public void testBlacklistCreditCardFilter() {
    UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE, "5555555555554444");
    user.setId(api.createUser(user));

    ItemTypeWS itemType = buildItemType();
    itemType.setId(api.createItemCategory(itemType));

    ItemDTOEx item = buildItem(itemType.getId(), api.getCallerCompanyId());
    item.setId(api.createItem(item));

    InvoiceWS invoice = buildInvoice(user.getId(), item.getId());
    invoice.setId(api.saveLegacyInvoice(invoice));

    // get invoice id
    invoice = api.getLatestInvoice(user.getId());
    assertNotNull("Couldn't get last invoice", invoice);
    Integer invoiceId = invoice.getId();
    assertNotNull("Invoice id was null", invoiceId);

    // try paying the invoice
    System.out.println("Trying to pay invoice for blacklisted user ...");
    PaymentAuthorizationDTOEx authInfo = api.payInvoice(invoiceId);
    assertNotNull("Payment result empty", authInfo);

    // check that it was failed by the test blacklist filter
    assertFalse(
        "Payment wasn't failed for user: "******"Processor response", "Credit card number is blacklisted.", authInfo.getResponseMessage());

    // cleanup
    api.deleteInvoice(invoiceId);
    api.deleteItem(item.getId());
    api.deleteItemCategory(itemType.getId());
    api.deleteUser(user.getId());
  }
Ejemplo n.º 2
0
  public void testGet() {
    try {
      JbillingAPI api = JbillingAPIFactory.getAPI();

      // get
      // try getting one that doesn't belong to us
      try {
        System.out.println("Getting invalid invoice");
        api.getInvoiceWS(75);
        fail("Invoice 75 belongs to entity 2");
      } catch (Exception e) {
      }

      System.out.println("Getting invoice");
      InvoiceWS retInvoice = api.getInvoiceWS(15);
      assertNotNull("invoice not returned", retInvoice);
      assertEquals("invoice id", retInvoice.getId(), new Integer(15));
      System.out.println("Got = " + retInvoice);

      // latest
      // first, from a guy that is not mine
      try {
        api.getLatestInvoice(13);
        fail("User 13 belongs to entity 2");
      } catch (Exception e) {
      }
      System.out.println("Getting latest invoice");
      retInvoice = api.getLatestInvoice(2);
      assertNotNull("invoice not returned", retInvoice);
      assertEquals("invoice's user id", retInvoice.getUserId(), new Integer(2));
      System.out.println("Got = " + retInvoice);
      Integer lastInvoice = retInvoice.getId();

      // List of last
      // first, from a guy that is not mine
      try {
        api.getLastInvoices(13, 5);
        fail("User 13 belongs to entity 2");
      } catch (Exception e) {
      }
      System.out.println("Getting last 5 invoices");
      Integer invoices[] = api.getLastInvoices(2, 5);
      assertNotNull("invoice not returned", invoices);

      retInvoice = api.getInvoiceWS(invoices[0]);
      assertEquals("invoice's user id", new Integer(2), retInvoice.getUserId());
      System.out.println("Got = " + invoices.length + " invoices");
      for (int f = 0; f < invoices.length; f++) {
        System.out.println(" Invoice " + (f + 1) + invoices[f]);
      }

      // now I want just the two latest
      System.out.println("Getting last 2 invoices");
      invoices = api.getLastInvoices(2, 2);
      assertNotNull("invoice not returned", invoices);
      retInvoice = api.getInvoiceWS(invoices[0]);
      assertEquals("invoice's user id", new Integer(2), retInvoice.getUserId());
      assertEquals("invoice's has to be latest", lastInvoice, retInvoice.getId());
      assertEquals("there should be only 2", 2, invoices.length);

      // get some by date
      System.out.println("Getting by date (empty)");
      Integer invoices2[] = api.getInvoicesByDate("2000-01-01", "2005-01-01");
      // CXF returns null instead of empty arrays
      // assertNotNull("invoice not returned", invoices2);
      if (invoices2 != null) {
        assertTrue("array not empty", invoices2.length == 0);
      }

      System.out.println("Getting by date");
      invoices2 = api.getInvoicesByDate("2006-01-01", "2007-01-01");
      assertNotNull("invoice not returned", invoices2);
      assertFalse("array not empty", invoices2.length == 0);
      System.out.println("Got array " + invoices2.length + " getting " + invoices2[0]);
      retInvoice = api.getInvoiceWS(invoices2[0]);
      assertNotNull("invoice not there", retInvoice);
      System.out.println("Got invoice " + retInvoice);

      System.out.println("Done!");

    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception caught:" + e);
    }
  }