private void verify(Expectation expected) throws AssertionFailedError {
      user = api.getUserWS(user.getUserId());
      order = api.getOrder(order.getId());

      logger.info(S("user: {}", userDetailsAsString(user)));
      logger.info(S("order: {}", orderDetailsAsString(order)));
      boolean isOk;
      isOk =
          assertEqualsBilling(
              S("userId: {}.", user.getId()), expected.nextInvoiceDate, user.getNextInvoiceDate());
      if (!isOk) {
        failed = true;
        return;
      }
      isOk =
          assertEqualsBilling(
              S("orderId: {}.", order.getId()),
              expected.nextBillableDay,
              order.getNextBillableDay());
      if (!isOk) {
        failed = true;
        return;
      }

      if (null != expected.invoiceTotal) {
        verifyInvoice(expected);
      }
    }
  public void testWrongPluginParameters() throws JbillingAPIException, IOException {
    long currentTimeMillis = System.currentTimeMillis();
    UserWS user = SureTaxCompositionTaskTest.createUser(currentTimeMillis, "");
    // Create an item with wrong Transaction Type code
    Integer itemId1 =
        CreateObjectUtil.createItem(
            "Long Distance Call intra-state", "1.5", currentTimeMillis + "", "2201", api);
    ItemDTOEx item1 = api.getItem(itemId1, null, null);
    MetaFieldValueWS[] metaFields = new MetaFieldValueWS[1];
    MetaFieldValueWS transTypeMetaField = new MetaFieldValueWS();
    transTypeMetaField.setStringValue("010101");
    transTypeMetaField.setFieldName("Transaction Type Code");
    metaFields[0] = transTypeMetaField;
    item1.setMetaFields(metaFields);
    api.updateItem(item1);
    // purchase order with taxable items
    Calendar cal = Calendar.getInstance();
    // I want to set the active since to 07 June 2012 , so the billing
    // process sees it and invoices it
    // set the calendar to 06/07
    cal.set(2010, 5, 7);
    OrderWS order =
        CreateObjectUtil.createOrderObject(
            user.getUserId(), 1, ServerConstants.ORDER_BILLING_POST_PAID, 1, cal.getTime());

    CreateObjectUtil.addLine(
        order,
        10,
        ServerConstants.ORDER_LINE_TYPE_ITEM,
        itemId1,
        new BigDecimal(1.5),
        "Long Distance Call-intra state");

    order.setDueDateUnitId(PeriodUnitDTO.DAY);
    order.setDueDateValue(0); // order due

    order.setId(api.createOrder(order)); // create order
    order = api.getOrder(order.getId());
    assertNotNull("order created", order.getId());

    Integer[] invoiceIds = null;
    try {
      invoiceIds =
          api.createInvoiceWithDate(
              user.getUserId(),
              new Date(),
              PeriodUnitDTO.DAY,
              45,
              false); // getAllInvoicesForUser(user.getUserId());
    } catch (Exception e) {
      if (e instanceof SessionInternalError && e.getMessage().contains("Invalid Validation Key")) {
        // do nothing
      } else {
        assertTrue("Wrong exception raised", false);
      }
    }
    assertNull("No invoices must be generated", invoiceIds);
  }
 private String orderDetailsAsString(OrderWS order) {
   order = api.getOrder(order.getId());
   return S(
       "order[{}]:type: {}, period: {}, activeSince: {}, nextBillableDay: {}",
       order.getId(),
       order.getBillingTypeStr(),
       order.getPeriodStr(),
       order.getActiveSince(),
       order.getNextBillableDay());
 }
 public void verify(Date date) throws AssertionFailedError {
   if (failed) {
     logger.debug(
         S("userId: {}, orderId: {}. skip failed scenario", user.getId(), order.getId()));
     return;
   }
   if (expectations.containsKey(date)) {
     verify(expectations.get(date));
   } else {
     logger.debug(
         S(
             "userId: {}, orderId: {}. no expectation for billing at {}",
             user.getId(),
             order.getId(),
             date));
   }
 }
 public void applyChanges(Date date) {
   if (failed) {
     logger.debug(
         S("userId: {}, orderId: {}. skip failed scenario", user.getId(), order.getId()));
     return;
   }
   if (changes.containsKey(date)) {
     for (TestOrderChangeBuilder change : changes.get(date)) {
       change.buildNewAndApply();
     }
   } else {
     logger.debug(
         S(
             "userId: {}, orderId: {}. no changes before billing at {}",
             user.getId(),
             order.getId(),
             date));
   }
 }