@Test(groups = "slow")
  public void testShouldBeAbleToPassNullForSomeFieldsToAvoidUpdate() throws Exception {
    final Account account = createTestAccount();
    accountDao.create(account, internalCallContext);

    // Update the address and leave other fields null
    final MutableAccountData mutableAccountData =
        new DefaultMutableAccountData(
            null, null, null, 0, null, null, null, null, null, null, null, null, null, null, null,
            null, null, null, false, false);
    final String newAddress1 = UUID.randomUUID().toString();
    mutableAccountData.setAddress1(newAddress1);

    final DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData);
    accountDao.update(newAccount, internalCallContext);

    Assert.assertEquals(
        accountDao.getById(account.getId(), internalCallContext).getAddress1(), newAddress1);
    Assert.assertEquals(
        accountDao.getById(account.getId(), internalCallContext).getAddress2(),
        account.getAddress2());
    Assert.assertEquals(
        accountDao.getById(account.getId(), internalCallContext).getCurrency(),
        account.getCurrency());
    Assert.assertEquals(
        accountDao.getById(account.getId(), internalCallContext).getExternalKey(),
        account.getExternalKey());
    Assert.assertEquals(
        accountDao.getById(account.getId(), internalCallContext).getBillCycleDay(),
        account.getBillCycleDay());
  }
  @Test(groups = "slow")
  public void testShouldBeAbleToHandleOtherBCDClass() throws Exception {
    final Account account = createTestAccount();
    accountDao.create(account, internalCallContext);

    final MutableAccountData otherAccount = account.toMutableAccountData();
    otherAccount.setAddress1(UUID.randomUUID().toString());
    otherAccount.setEmail(UUID.randomUUID().toString());
    // Same BCD, but not .equals method
    otherAccount.setBillCycleDay(
        new BillCycleDay() {
          @Override
          public int getDayOfMonthUTC() {
            return account.getBillCycleDay().getDayOfMonthUTC();
          }

          @Override
          public int getDayOfMonthLocal() {
            return account.getBillCycleDay().getDayOfMonthLocal();
          }
        });

    final DefaultAccount newAccount = new DefaultAccount(account.getId(), otherAccount);
    accountDao.update(newAccount, internalCallContext);

    final Account newFetchedAccount = accountDao.getById(account.getId(), internalCallContext);
    Assert.assertEquals(newFetchedAccount.getAddress1(), newAccount.getAddress1());
    Assert.assertEquals(newFetchedAccount.getEmail(), newAccount.getEmail());
    // Same BCD
    Assert.assertEquals(newFetchedAccount.getBillCycleDay(), account.getBillCycleDay());
  }
  @Test(groups = "slow", expectedExceptions = IllegalArgumentException.class)
  public void testShouldntBeAbleToUpdateCurrency() throws Exception {
    final Account account = createTestAccount();
    accountDao.create(account, internalCallContext);

    final MutableAccountData otherAccount = account.toMutableAccountData();
    otherAccount.setCurrency(Currency.GBP);

    accountDao.update(new DefaultAccount(account.getId(), otherAccount), internalCallContext);
  }
  @Test(groups = "slow")
  public void testShouldBeAbleToUpdateSomeFields() throws Exception {
    final Account account = createTestAccount();
    accountDao.create(account, internalCallContext);

    final MutableAccountData otherAccount = account.toMutableAccountData();
    otherAccount.setAddress1(UUID.randomUUID().toString());
    otherAccount.setEmail(UUID.randomUUID().toString());

    final DefaultAccount newAccount = new DefaultAccount(account.getId(), otherAccount);
    accountDao.update(newAccount, internalCallContext);

    Assert.assertEquals(accountDao.getById(account.getId(), internalCallContext), newAccount);
  }
  @Test(groups = "slow")
  public void testShouldBeAbleToHandleBCDOfZeroZero() throws Exception {
    final Account account = createTestAccount(0);
    accountDao.create(account, internalCallContext);
    final Account fetchedAccount = accountDao.getById(account.getId(), internalCallContext);

    final MutableAccountData otherAccount = account.toMutableAccountData();
    // Set BCD to null
    otherAccount.setBillCycleDay(null);

    final DefaultAccount newAccount = new DefaultAccount(account.getId(), otherAccount);
    accountDao.update(newAccount, internalCallContext);

    // Same BCD (zero/zero)
    Assert.assertEquals(accountDao.getById(account.getId(), internalCallContext), fetchedAccount);
  }
  private void addBillingEventsForSubscription(
      final List<SubscriptionBase> subscriptions,
      final SubscriptionBaseBundle bundle,
      final Account account,
      final InternalCallContext context,
      final DefaultBillingEventSet result) {

    boolean updatedAccountBCD = false;
    for (final SubscriptionBase subscription : subscriptions) {
      for (final EffectiveSubscriptionInternalEvent transition :
          subscriptionApi.getBillingTransitions(subscription, context)) {
        try {
          final int bcdLocal =
              bcdCalculator.calculateBcd(bundle, subscription, transition, account, context);

          if (account.getBillCycleDayLocal() == 0 && !updatedAccountBCD) {
            final MutableAccountData modifiedData = account.toMutableAccountData();
            modifiedData.setBillCycleDayLocal(bcdLocal);
            accountApi.updateAccount(account.getExternalKey(), modifiedData, context);
            updatedAccountBCD = true;
          }

          final BillingEvent event =
              new DefaultBillingEvent(
                  account,
                  transition,
                  subscription,
                  bcdLocal,
                  account.getCurrency(),
                  catalogService.getFullCatalog());
          result.add(event);
        } catch (CatalogApiException e) {
          log.error(
              "Failing to identify catalog components while creating BillingEvent from transition: "
                  + transition.getId().toString(),
              e);
        } catch (Exception e) {
          log.warn("Failed while getting BillingEvent", e);
        }
      }
    }
  }
  @Test(groups = "slow", expectedExceptions = IllegalArgumentException.class)
  public void testShouldntBeAbleToUpdateBillCycleDay() throws Exception {
    final Account account = createTestAccount();
    accountDao.create(account, internalCallContext);

    final MutableAccountData otherAccount = account.toMutableAccountData();
    otherAccount.setBillCycleDay(
        new BillCycleDay() {
          @Override
          public int getDayOfMonthUTC() {
            return account.getBillCycleDay().getDayOfMonthUTC() + 2;
          }

          @Override
          public int getDayOfMonthLocal() {
            return account.getBillCycleDay().getDayOfMonthLocal() + 2;
          }
        });

    accountDao.update(new DefaultAccount(account.getId(), otherAccount), internalCallContext);
  }
Exemple #8
0
  @PUT
  @Path("/{accountId:" + UUID_PATTERN + "}/" + EMAIL_NOTIFICATIONS)
  @Consumes(APPLICATION_JSON)
  @Produces(APPLICATION_JSON)
  public Response getEmailNotificationsForAccount(
      final InvoiceEmailJson json,
      @PathParam("accountId") final String accountIdString,
      @HeaderParam(HDR_CREATED_BY) final String createdBy,
      @HeaderParam(HDR_REASON) final String reason,
      @HeaderParam(HDR_COMMENT) final String comment,
      @javax.ws.rs.core.Context final HttpServletRequest request)
      throws AccountApiException {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);

    final UUID accountId = UUID.fromString(accountIdString);
    final Account account = accountUserApi.getAccountById(accountId, callContext);

    final MutableAccountData mutableAccountData = account.toMutableAccountData();
    mutableAccountData.setIsNotifiedForInvoices(json.isNotifiedForInvoices());
    accountUserApi.updateAccount(accountId, mutableAccountData, callContext);

    return Response.status(Status.OK).build();
  }