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();
}
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;
}
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;
}
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());
}
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");
}
Aggregations