use of org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseBundle in project killbill by killbill.
the class MockSubscriptionDaoMemory method createSubscriptionBundle.
@Override
public SubscriptionBaseBundle createSubscriptionBundle(final DefaultSubscriptionBaseBundle bundle, final SubscriptionCatalog catalog, final boolean renameCancelledBundleIfExist, final InternalCallContext context) {
bundles.add(new DefaultSubscriptionBaseBundle(bundle.getId(), MoreObjects.firstNonNull(bundle.getExternalKey(), UUID.randomUUID().toString()), bundle.getAccountId(), bundle.getOriginalCreatedDate(), bundle.getCreatedDate(), bundle.getUpdatedDate()));
mockNonEntityDao.addTenantRecordIdMapping(bundle.getId(), context);
return getSubscriptionBundleFromId(bundle.getId(), context);
}
use of org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseBundle in project killbill by killbill.
the class TestSubscriptionDao method afterMethod.
// to ignore events
@Override
@AfterMethod(groups = "slow")
public void afterMethod() throws Exception {
if (hasFailed()) {
final String externalKey = "12345";
final DateTime startDate = clock.getUTCNow();
final DateTime createdDate = startDate.plusSeconds(10);
final DefaultSubscriptionBaseBundle bundleDef = new DefaultSubscriptionBaseBundle(externalKey, accountId, startDate, startDate, createdDate, createdDate);
final SubscriptionBaseBundle bundle = dao.createSubscriptionBundle(bundleDef, catalog, true, internalCallContext);
final List<SubscriptionBaseBundle> result = dao.getSubscriptionBundlesForKey(externalKey, internalCallContext);
assertEquals(result.size(), 1);
assertEquals(result.get(0).getExternalKey(), bundle.getExternalKey());
// Operation succeeds but nothing new got created because bundle is empty
dao.createSubscriptionBundle(bundleDef, catalog, true, internalCallContext);
final List<SubscriptionBaseBundle> result2 = dao.getSubscriptionBundlesForKey(externalKey, internalCallContext);
assertEquals(result2.size(), 1);
// Create a subscription and this time operation should fail
final SubscriptionBuilder builder = new SubscriptionBuilder().setId(UUIDs.randomUUID()).setBundleId(bundle.getId()).setBundleExternalKey(bundle.getExternalKey()).setCategory(ProductCategory.BASE).setBundleStartDate(startDate).setAlignStartDate(startDate).setMigrated(false);
final ApiEventBuilder createBuilder = new ApiEventBuilder().setSubscriptionId(builder.getId()).setEventPlan("shotgun-monthly").setEventPlanPhase("shotgun-monthly-trial").setEventPriceList(DefaultPriceListSet.DEFAULT_PRICELIST_NAME).setEffectiveDate(startDate).setFromDisk(true);
final SubscriptionBaseEvent creationEvent = new ApiEventCreate(createBuilder);
final DefaultSubscriptionBase subscription = new DefaultSubscriptionBase(builder);
testListener.pushExpectedEvents(NextEvent.CREATE);
final SubscriptionBaseWithAddOns subscriptionBaseWithAddOns = new DefaultSubscriptionBaseWithAddOns(bundle, ImmutableList.<SubscriptionBase>of(subscription));
dao.createSubscriptionsWithAddOns(ImmutableList.<SubscriptionBaseWithAddOns>of(subscriptionBaseWithAddOns), ImmutableMap.<UUID, List<SubscriptionBaseEvent>>of(subscription.getId(), ImmutableList.<SubscriptionBaseEvent>of(creationEvent)), catalog, internalCallContext);
assertListenerStatus();
// Operation Should now fail
try {
dao.createSubscriptionBundle(bundleDef, catalog, true, internalCallContext);
Assert.fail("Should fail to create new subscription bundle with existing key");
} catch (SubscriptionBaseApiException e) {
assertEquals(ErrorCode.SUB_CREATE_ACTIVE_BUNDLE_KEY_EXISTS.getCode(), e.getCode());
}
return;
}
subscriptionTestInitializer.stopTestFramework(testListener, busService, subscriptionBaseService);
}
use of org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseBundle in project killbill by killbill.
the class TestSubscriptionDao method testDirtyFlag.
@Test(groups = "slow")
public void testDirtyFlag() throws Throwable {
final IDBI dbiSpy = Mockito.spy(dbi);
final IDBI roDbiSpy = Mockito.spy(roDbi);
final SubscriptionDao subscriptionDao = new DefaultSubscriptionDao(dbiSpy, roDbiSpy, clock, addonUtils, notificationQueueService, bus, controlCacheDispatcher, nonEntityDao, auditDao, internalCallContextFactory);
Mockito.verify(dbiSpy, Mockito.times(0)).open();
Mockito.verify(roDbiSpy, Mockito.times(0)).open();
// @BeforeMethod created the account
DBRouterUntyped.withRODBIAllowed(true, new WithProfilingCallback<Object, Throwable>() {
@Override
public Object execute() throws Throwable {
Assert.assertEquals(subscriptionDao.getSubscriptionBundleForAccount(accountId, internalCallContext).size(), 0);
Mockito.verify(dbiSpy, Mockito.times(0)).open();
Mockito.verify(roDbiSpy, Mockito.times(1)).open();
Assert.assertEquals(subscriptionDao.getSubscriptionBundleForAccount(accountId, internalCallContext).size(), 0);
Mockito.verify(dbiSpy, Mockito.times(0)).open();
Mockito.verify(roDbiSpy, Mockito.times(2)).open();
final String externalKey = UUID.randomUUID().toString();
final DateTime startDate = clock.getUTCNow();
final DateTime createdDate = startDate.plusSeconds(10);
final DefaultSubscriptionBaseBundle bundleDef = new DefaultSubscriptionBaseBundle(externalKey, accountId, startDate, startDate, createdDate, createdDate);
final SubscriptionBaseBundle bundle = subscriptionDao.createSubscriptionBundle(bundleDef, catalog, false, internalCallContext);
Mockito.verify(dbiSpy, Mockito.times(1)).open();
Mockito.verify(roDbiSpy, Mockito.times(2)).open();
Assert.assertEquals(subscriptionDao.getSubscriptionBundleForAccount(accountId, internalCallContext).size(), 1);
Mockito.verify(dbiSpy, Mockito.times(2)).open();
Mockito.verify(roDbiSpy, Mockito.times(2)).open();
Assert.assertEquals(subscriptionDao.getSubscriptionBundleForAccount(accountId, internalCallContext).size(), 1);
Mockito.verify(dbiSpy, Mockito.times(3)).open();
Mockito.verify(roDbiSpy, Mockito.times(2)).open();
return null;
}
});
DBRouterUntyped.withRODBIAllowed(true, new WithProfilingCallback<Object, Throwable>() {
@Override
public Object execute() {
Assert.assertEquals(subscriptionDao.getSubscriptionBundleForAccount(accountId, internalCallContext).size(), 1);
Mockito.verify(dbiSpy, Mockito.times(3)).open();
Mockito.verify(roDbiSpy, Mockito.times(3)).open();
return null;
}
});
}
Aggregations