@Override public String getBundleExternalKey() { return bundle.getExternalKey(); }
@Override public List<SubscriptionBaseBundle> getSubscriptionBundlesForKey(final String bundleKey, final InternalTenantContext context) { final List<SubscriptionBaseBundle> results = new ArrayList<SubscriptionBaseBundle>(); for (final SubscriptionBaseBundle cur : bundles) { if (cur.getExternalKey().equals(bundleKey)) { results.add(cur); } } return results; }
@Override public List<SubscriptionBaseBundle> getSubscriptionBundlesForAccountAndKey(final UUID accountId, final String bundleKey, final InternalTenantContext context) { final List<SubscriptionBaseBundle> results = new ArrayList<SubscriptionBaseBundle>(); for (final SubscriptionBaseBundle cur : bundles) { if (cur.getExternalKey().equals(bundleKey) && cur.getAccountId().equals(accountId)) { results.add(cur); } } return results; }
transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, false, false, callContext); assertListenerStatus(); final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext); assertEquals(bundlesForAccountAndKey.size(), 1);
testListener.pushExpectedEvent(NextEvent.TRANSFER); testListener.pushExpectedEvent(NextEvent.CANCEL); transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, false, false, callContext); assertListenerStatus(); final DateTime afterTransferDate = clock.getUTCNow(); final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext); assertEquals(bundlesForAccountAndKey.size(), 1);
transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, false, false, callContext); assertListenerStatus(); final DateTime afterTransferDate = clock.getUTCNow(); final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext); assertEquals(bundlesForAccountAndKey.size(), 1);
final DateTime transferRequestedDate = clock.getUTCNow(); testListener.pushExpectedEvent(NextEvent.TRANSFER); transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, true, false, callContext); assertListenerStatus(); final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext); assertEquals(bundlesForAccountAndKey.size(), 1);
transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, true, false, callContext); assertListenerStatus(); final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext); assertEquals(bundlesForAccountAndKey.size(), 1);
transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, false, true, callContext); assertListenerStatus();
testListener.pushExpectedEvent(NextEvent.TRANSFER); testListener.pushExpectedEvent(NextEvent.TRANSFER); transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, true, false, callContext); assertListenerStatus(); final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext); assertEquals(bundlesForAccountAndKey.size(), 1); testListener.pushExpectedEvent(NextEvent.TRANSFER); testListener.pushExpectedEvent(NextEvent.TRANSFER); transferApi.transferBundle(newBundle.getAccountId(), finalNewAccountId, newBundle.getExternalKey(), newTransferRequestedDate, true, false, callContext); assertListenerStatus();
transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, false, false, callContext); assertListenerStatus(); final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext); assertEquals(bundlesForAccountAndKey.size(), 1);
@Test(groups = "slow") public void testCreateBundlesWithSameExternalKeys() throws SubscriptionBaseApiException { final DateTime init = clock.getUTCNow(); final DateTime requestedDate = init.minusYears(1); final String productName = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME; testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.PHASE); final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) subscriptionInternalApi.createSubscription(bundle.getId(), testUtil.getProductSpecifier(productName, planSetName, term, null), requestedDate, internalCallContext); assertListenerStatus(); assertNotNull(subscription); testListener.pushExpectedEvent(NextEvent.CANCEL); subscription.cancelWithDate(clock.getUTCNow(), callContext); assertListenerStatus(); final SubscriptionBaseBundle newBundle = subscriptionInternalApi.createBundleForAccount(bundle.getAccountId(), DefaultSubscriptionTestInitializer.DEFAULT_BUNDLE_KEY, internalCallContext); assertNotNull(newBundle); assertEquals(newBundle.getOriginalCreatedDate().compareTo(bundle.getCreatedDate()), 0); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.PHASE); final DefaultSubscriptionBase newSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.createSubscription(newBundle.getId(), testUtil.getProductSpecifier(productName, planSetName, term, null), requestedDate, internalCallContext); subscriptionInternalApi.updateExternalKey(newBundle.getId(), "myNewSuperKey", internalCallContext); final SubscriptionBaseBundle bundleWithNewKey = subscriptionInternalApi.getBundleFromId(newBundle.getId(), internalCallContext); assertEquals(bundleWithNewKey.getExternalKey(), "myNewSuperKey"); assertListenerStatus(); assertNotNull(newSubscription); }