private List<SubscriptionBundle> filterBundles(final List<SubscriptionBundle> subscriptionBundlesForAccountId, final List<String> bundlesFilter) { List<SubscriptionBundle> result = new ArrayList<SubscriptionBundle>(); for (SubscriptionBundle subscriptionBundle : subscriptionBundlesForAccountId) { if (bundlesFilter.contains(subscriptionBundle.getId().toString())) { result.add(subscriptionBundle); } } return result; }
private String getBundleExternalKey(final Invoice invoice, final List<SubscriptionBundle> bundles) { final Set<UUID> b = new HashSet<UUID>(); for (final InvoiceItem cur : invoice.getInvoiceItems()) { b.add(cur.getBundleId()); } boolean first = true; final StringBuilder tmp = new StringBuilder(); for (final UUID cur : b) { for (final SubscriptionBundle bt : bundles) { if (bt.getId().equals(cur)) { if (!first) { tmp.append(","); } tmp.append(bt.getExternalKey()); first = false; break; } } } return tmp.toString(); } }
public BundleJson(final SubscriptionBundle bundle, @Nullable final Currency currency, @Nullable final AccountAuditLogs accountAuditLogs) throws CatalogApiException { super(toAuditLogJson(accountAuditLogs == null ? null : accountAuditLogs.getAuditLogsForBundle(bundle.getId()))); this.accountId = bundle.getAccountId(); this.bundleId = bundle.getId(); this.externalKey = bundle.getExternalKey(); this.subscriptions = new LinkedList<SubscriptionJson>(); for (final Subscription subscription : bundle.getSubscriptions()) { this.subscriptions.add(new SubscriptionJson(subscription, currency, accountAuditLogs)); } this.timeline = new BundleTimelineJson(bundle.getTimeline(), accountAuditLogs); }
private void subscriptionBundleChecker(final List<SubscriptionBundle> bundles, final LocalDate billingStartDate, final Entitlement entitlement, final int idx) { Assert.assertEquals(bundles.get(idx).getId(), entitlement.getBundleId()); Assert.assertEquals(bundles.get(idx).getSubscriptions().size(), 1); Assert.assertEquals(bundles.get(idx).getSubscriptions().get(0).getId(), entitlement.getId()); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().size(), 3); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(0).getEffectiveDate(), entitlement.getEffectiveStartDate()); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(1).getEffectiveDate(), billingStartDate); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(2).getEffectiveDate(), new LocalDate(2013, 9, 6)); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(2).getSubscriptionEventType(), SubscriptionEventType.PHASE); }
private void subscriptionBundleChecker(final List<SubscriptionBundle> bundles, final LocalDate initialDate, final Entitlement entitlement, final int idx) { Assert.assertEquals(bundles.get(idx).getId(), entitlement.getBundleId()); Assert.assertEquals(bundles.get(idx).getSubscriptions().size(), 1); Assert.assertEquals(bundles.get(idx).getSubscriptions().get(0).getId(), entitlement.getId()); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().size(), 4); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(0).getEffectiveDate(), initialDate); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(1).getEffectiveDate(), initialDate); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(2).getEffectiveDate(), initialDate); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(2).getSubscriptionEventType(), SubscriptionEventType.SERVICE_STATE_CHANGE); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(2).getServiceName(), "service"); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(2).getServiceStateName(), "stateName"); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(3).getEffectiveDate(), new LocalDate(2013, 9, 6)); Assert.assertEquals(bundles.get(idx).getTimeline().getSubscriptionEvents().get(3).getSubscriptionEventType(), SubscriptionEventType.PHASE); }
private List<AuditLog> getAuditLogsForBundle(final UUID bundleId, final TenantContext context) { try { final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(bundleId, context); return auditUserApi.getAccountAuditLogs(bundle.getAccountId(), AuditLevel.FULL, context).getAuditLogsForBundle(bundle.getId()); } catch (final SubscriptionApiException e) { Assert.fail(e.toString()); return null; } }
@Test(groups = "slow", description = "Test overdue for draft external charge", retryAnalyzer = FlakyRetryAnalyzer.class) public void testShouldNotBeInOverdueAfterDraftExternalCharge() throws Exception { // 2012-05-01T00:03:42.000Z clock.setTime(new DateTime(2012, 5, 1, 0, 3, 42, 0)); setupAccount(); // Create a subscription without failing payments final DefaultEntitlement baseEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE); bundle = subscriptionApi.getSubscriptionBundle(baseEntitlement.getBundleId(), callContext); invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), null, InvoiceItemType.FIXED, new BigDecimal("0"))); invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 5, 1), callContext); // 2012-05-06 => Create an external charge on a new invoice addDaysAndCheckForCompletion(5); final InvoiceItem externalCharge = new ExternalChargeInvoiceItem(null, account.getId(), bundle.getId(), "For overdue", new LocalDate(2012, 5, 6), new LocalDate(2012, 6, 6), BigDecimal.TEN, Currency.USD, null); invoiceUserApi.insertExternalCharges(account.getId(), clock.getUTCToday(), ImmutableList.<InvoiceItem>of(externalCharge), false, null, callContext).get(0); assertListenerStatus(); invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 6), new LocalDate(2012, 6, 6), InvoiceItemType.EXTERNAL_CHARGE, BigDecimal.TEN)); // 2012-05-31 => DAY 30 have to get out of trial before first payment addDaysAndCheckForCompletion(25, NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT); invoiceChecker.checkInvoice(account.getId(), 3, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 31), new LocalDate(2012, 6, 30), InvoiceItemType.RECURRING, new BigDecimal("249.95"))); invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 6, 30), callContext); // Should still be in clear state - the invoice for the bundle has been paid, but not the invoice with the external charge (because it is in draft mode) // We refresh overdue just to be safe, see below checkODState(OverdueWrapper.CLEAR_STATE_NAME); // 2012-06-06 => Past 30 days since the external charge addDaysAndCheckForCompletion(6); // We should still be clear checkODState(OverdueWrapper.CLEAR_STATE_NAME); Assert.assertEquals(invoiceUserApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext).size(), 0); }
assertNotEquals(initialBundle.getId(), newBundle.getId()); assertEquals(initialBundle.getAccountId(), newBundle.getAccountId()); assertEquals(initialBundle.getExternalKey(), newBundle.getExternalKey()); assertNotEquals(initialBundle.getId(), newerBundle.getId()); assertEquals(initialBundle.getAccountId(), newerBundle.getAccountId()); assertEquals(initialBundle.getExternalKey(), newerBundle.getExternalKey());
assertEquals(activeBundle.getId(), entitlement.getBundleId());