Search in sources :

Example 6 with VersionedCatalog

use of org.killbill.billing.catalog.api.VersionedCatalog in project killbill by killbill.

the class CatalogResource method getCatalogVersions.

@TimedResource
@GET
@Path("/versions")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a list of catalog versions", response = DateTime.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getCatalogVersions(@QueryParam(QUERY_ACCOUNT_ID) final UUID accountId, @javax.ws.rs.core.Context final HttpServletRequest request) throws Exception {
    final TenantContext tenantContext = accountId != null ? context.createTenantContextWithAccountId(accountId, request) : context.createTenantContextNoAccountId(request);
    final VersionedCatalog catalog = catalogUserApi.getCatalog(catalogName, tenantContext);
    final List<DateTime> result = new ArrayList<DateTime>();
    for (final StaticCatalog v : catalog.getVersions()) {
        result.add(new DateTime(v.getEffectiveDate()));
    }
    return Response.status(Status.OK).entity(result).build();
}
Also used : VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) DateTime(org.joda.time.DateTime) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with VersionedCatalog

use of org.killbill.billing.catalog.api.VersionedCatalog in project killbill by killbill.

the class TestSubscriptionHelper method createSubscription.

private DefaultSubscriptionBase createSubscription(final boolean noEvents, @Nullable final SubscriptionBaseBundle bundle, final String productName, final BillingPeriod term, final String planSet, final PhaseType phaseType, final LocalDate requestedDate) throws SubscriptionBaseApiException {
    final VersionedCatalog catalog;
    try {
        catalog = catalogInternalApi.getFullCatalog(true, true, internalCallContext);
    } catch (CatalogApiException e) {
        throw new SubscriptionBaseApiException(e);
    }
    // Make sure the right account information is used
    final InternalCallContext internalCallContext = bundle == null ? this.internalCallContext : internalCallContextFactory.createInternalCallContext(bundle.getAccountId(), ObjectType.ACCOUNT, this.internalCallContext.getUpdatedBy(), this.internalCallContext.getCallOrigin(), this.internalCallContext.getContextUserType(), this.internalCallContext.getUserToken(), this.internalCallContext.getTenantRecordId());
    boolean bundleExists = false;
    if (bundle != null) {
        try {
            bundleExists = (subscriptionApi.getBundleFromId(bundle.getId(), internalCallContext) != null);
        } catch (final SubscriptionBaseApiException ignored) {
        }
    }
    if (!noEvents && (requestedDate == null || requestedDate.compareTo(clock.getUTCToday()) <= 0)) {
        testListener.pushExpectedEvent(NextEvent.CREATE);
    }
    final ImmutableList<EntitlementSpecifier> entitlementSpecifiers = ImmutableList.<EntitlementSpecifier>of(new EntitlementSpecifier() {

        @Override
        public PlanPhaseSpecifier getPlanPhaseSpecifier() {
            return new PlanPhaseSpecifier(productName, term, planSet, phaseType);
        }

        @Override
        public Integer getBillCycleDay() {
            return null;
        }

        @Override
        public String getExternalKey() {
            return UUID.randomUUID().toString();
        }

        @Override
        public List<PlanPhasePriceOverride> getOverrides() {
            return null;
        }
    });
    final SubscriptionBaseWithAddOnsSpecifier subscriptionBaseWithAddOnsSpecifier = new SubscriptionBaseWithAddOnsSpecifier(bundle == null || !bundleExists ? null : bundle.getId(), bundle == null ? null : bundle.getExternalKey(), entitlementSpecifiers, requestedDate, false);
    final SubscriptionBaseWithAddOns subscriptionBaseWithAddOns = subscriptionApi.createBaseSubscriptionsWithAddOns(catalog, ImmutableList.<SubscriptionBaseWithAddOnsSpecifier>of(subscriptionBaseWithAddOnsSpecifier), false, internalCallContext).get(0);
    final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) subscriptionBaseWithAddOns.getSubscriptionBaseList().get(0);
    assertNotNull(subscription);
    testListener.assertListenerStatus();
    mockNonEntityDao.addTenantRecordIdMapping(subscription.getId(), internalCallContext);
    mockNonEntityDao.addAccountRecordIdMapping(subscription.getId(), internalCallContext);
    mockNonEntityDao.addTenantRecordIdMapping(subscription.getBundleId(), internalCallContext);
    mockNonEntityDao.addAccountRecordIdMapping(subscription.getBundleId(), internalCallContext);
    return subscription;
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) SubscriptionBaseWithAddOns(org.killbill.billing.subscription.api.SubscriptionBaseWithAddOns) SubscriptionBaseWithAddOnsSpecifier(org.killbill.billing.subscription.api.SubscriptionBaseWithAddOnsSpecifier) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) EntitlementSpecifier(org.killbill.billing.entitlement.api.EntitlementSpecifier) VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Example 8 with VersionedCatalog

use of org.killbill.billing.catalog.api.VersionedCatalog in project killbill by killbill.

the class DefaultSubscriptionTestInitializer method initCatalog.

public VersionedCatalog initCatalog(final CatalogService catalogService, final InternalTenantContext context) throws Exception {
    ((DefaultCatalogService) catalogService).loadCatalog();
    final VersionedCatalog catalog = catalogService.getFullCatalog(true, true, context);
    assertNotNull(catalog);
    return catalog;
}
Also used : VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) DefaultCatalogService(org.killbill.billing.catalog.DefaultCatalogService)

Example 9 with VersionedCatalog

use of org.killbill.billing.catalog.api.VersionedCatalog in project killbill by killbill.

the class TestVersionedCatalogLoader method testLoad.

@Test(groups = "fast")
public void testLoad() throws CatalogApiException {
    final VersionedCatalog c = loader.loadDefaultCatalog(Resources.getResource("org/killbill/billing/catalog/versionedCatalog").toString());
    Assert.assertEquals(c.getVersions().size(), 4);
    DateTime dt = new DateTime("2011-01-01T00:00:00+00:00");
    Assert.assertEquals(c.getVersions().get(0).getEffectiveDate(), dt.toDate());
    dt = new DateTime("2011-02-02T00:00:00+00:00");
    Assert.assertEquals(c.getVersions().get(1).getEffectiveDate(), dt.toDate());
    dt = new DateTime("2011-02-03T00:00:00+00:00");
    Assert.assertEquals(c.getVersions().get(2).getEffectiveDate(), dt.toDate());
    dt = new DateTime("2011-03-03T00:00:00+00:00");
    Assert.assertEquals(c.getVersions().get(3).getEffectiveDate(), dt.toDate());
}
Also used : VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) DefaultVersionedCatalog(org.killbill.billing.catalog.DefaultVersionedCatalog) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 10 with VersionedCatalog

use of org.killbill.billing.catalog.api.VersionedCatalog in project killbill by killbill.

the class TestVersionedCatalogLoader method testLoadCatalogFromExternalFile.

@Test(groups = "fast")
public void testLoadCatalogFromExternalFile() throws CatalogApiException, IOException, URISyntaxException {
    final File originFile = new File(Resources.getResource("org/killbill/billing/catalog/SpyCarBasic.xml").toURI());
    final File destinationFile = new File(Files.createTempDir().toString() + "/SpyCarBasicRelocated.xml");
    destinationFile.deleteOnExit();
    Files.copy(originFile, destinationFile);
    final VersionedCatalog c = loader.loadDefaultCatalog(destinationFile.toURI().toString());
    Assert.assertEquals(c.getCatalogName(), "SpyCarBasic");
}
Also used : VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) DefaultVersionedCatalog(org.killbill.billing.catalog.DefaultVersionedCatalog) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

VersionedCatalog (org.killbill.billing.catalog.api.VersionedCatalog)33 Test (org.testng.annotations.Test)14 DefaultVersionedCatalog (org.killbill.billing.catalog.DefaultVersionedCatalog)11 UUID (java.util.UUID)10 DateTime (org.joda.time.DateTime)8 LocalDate (org.joda.time.LocalDate)8 BigDecimal (java.math.BigDecimal)7 ArrayList (java.util.ArrayList)7 Account (org.killbill.billing.account.api.Account)7 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)7 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)7 Invoice (org.killbill.billing.invoice.api.Invoice)7 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)6 StaticCatalog (org.killbill.billing.catalog.api.StaticCatalog)6 DefaultEntitlementSpecifier (org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier)6 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)5 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4