Search in sources :

Example 11 with DefaultSubscriptionBaseBundle

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);
}
Also used : DefaultSubscriptionBaseBundle(org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseBundle)

Example 12 with DefaultSubscriptionBaseBundle

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);
}
Also used : ApiEventCreate(org.killbill.billing.subscription.events.user.ApiEventCreate) DefaultSubscriptionBaseWithAddOns(org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseWithAddOns) SubscriptionBaseWithAddOns(org.killbill.billing.subscription.api.SubscriptionBaseWithAddOns) DefaultSubscriptionBaseBundle(org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseBundle) SubscriptionBuilder(org.killbill.billing.subscription.api.user.SubscriptionBuilder) DateTime(org.joda.time.DateTime) ApiEventBuilder(org.killbill.billing.subscription.events.user.ApiEventBuilder) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) DefaultSubscriptionBaseBundle(org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseBundle) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) DefaultSubscriptionBaseWithAddOns(org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseWithAddOns) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException) AfterMethod(org.testng.annotations.AfterMethod)

Example 13 with DefaultSubscriptionBaseBundle

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;
        }
    });
}
Also used : IDBI(org.skife.jdbi.v2.IDBI) DefaultSubscriptionBaseBundle(org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseBundle) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) DefaultSubscriptionBaseBundle(org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseBundle) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

DefaultSubscriptionBaseBundle (org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseBundle)13 DateTime (org.joda.time.DateTime)9 SubscriptionBaseBundle (org.killbill.billing.subscription.api.user.SubscriptionBaseBundle)9 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)6 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)6 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)5 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)5 Test (org.testng.annotations.Test)4 ImmutableList (com.google.common.collect.ImmutableList)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 SubscriptionBuilder (org.killbill.billing.subscription.api.user.SubscriptionBuilder)3 SubscriptionBundleModelDao (org.killbill.billing.subscription.engine.dao.model.SubscriptionBundleModelDao)3 SubscriptionModelDao (org.killbill.billing.subscription.engine.dao.model.SubscriptionModelDao)3 ApiEventBuilder (org.killbill.billing.subscription.events.user.ApiEventBuilder)3 Predicate (com.google.common.base.Predicate)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)2 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)2