@Override public Plan findPlan(final String productName, final BillingPeriod term, final String priceListName, final DateTime requestedDate, final DateTime subscriptionStartDate) throws CatalogApiException { return findPlan(new PlanRequestWrapper(productName, term, priceListName), requestedDate, subscriptionStartDate); }
private StandaloneCatalog versionForDate(final DateTime date) throws CatalogApiException { return versions.get(indexOfVersionForDate(date.toDate())); }
@Override public Plan findPlan(final String productName, final BillingPeriod term, final String priceListName, final DateTime requestedDate) throws CatalogApiException { return versionForDate(requestedDate).findCurrentPlan(productName, term, priceListName); }
final VersionedCatalog result = new VersionedCatalog(clock); for (final URI u : xmlURIs) { final StandaloneCatalog catalog = XMLLoader.getObjectFromUri(u, StandaloneCatalog.class); result.add(catalog);
@Test(groups = "fast") public void testLimits() throws Exception { PlanPhase phase = catalog.findCurrentPhase("pistol-monthly-evergreen"); Assert.assertNotNull(phase); Assert.assertTrue(catalog.compliesWithLimits("pistol-monthly-evergreen", "targets", 3)); Assert.assertTrue(catalog.compliesWithLimits("pistol-monthly-evergreen", "targets", 2000)); Assert.assertFalse(catalog.compliesWithLimits("pistol-monthly-evergreen", "targets", 2)); Assert.assertTrue(catalog.compliesWithLimits("pistol-monthly-evergreen", "misfires", 3)); Assert.assertFalse(catalog.compliesWithLimits("pistol-monthly-evergreen", "misfires", 21)); Assert.assertTrue(catalog.compliesWithLimits("pistol-monthly-evergreen", "misfires", -1)); Assert.assertTrue(catalog.compliesWithLimits("shotgun-monthly-evergreen", "shells", 100)); Assert.assertFalse(catalog.compliesWithLimits("shotgun-monthly-evergreen", "shells", 400)); Assert.assertTrue(catalog.compliesWithLimits("shotgun-monthly-evergreen", "shells", 250)); Assert.assertTrue(catalog.compliesWithLimits("shotgun-annual-evergreen", "shells", 100)); Assert.assertFalse(catalog.compliesWithLimits("shotgun-annual-evergreen", "shells", 400)); Assert.assertFalse(catalog.compliesWithLimits("shotgun-annual-evergreen", "shells", 250));
@Test(groups = "fast") public void testLoad() throws IOException, SAXException, InvalidConfigException, JAXBException, TransformerException, URISyntaxException, ServiceException { final VersionedCatalog c = loader.load(Resources.getResource("versionedCatalog").toString()); Assert.assertEquals(c.size(), 3); final Iterator<StandaloneCatalog> it = c.iterator(); DateTime dt = new DateTime("2011-01-01T00:00:00+00:00"); Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate()); dt = new DateTime("2011-02-02T00:00:00+00:00"); Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate()); dt = new DateTime("2011-03-03T00:00:00+00:00"); Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate()); } }
public void add(final StandaloneCatalog e) throws CatalogApiException { if (catalogName == null) { catalogName = e.getCatalogName(); } else { if (!catalogName.equals(getCatalogName())) { throw new CatalogApiException(ErrorCode.CAT_CATALOG_NAME_MISMATCH, catalogName, e.getCatalogName()); } } versions.add(e); Collections.sort(versions, new Comparator<StandaloneCatalog>() { @Override public int compare(final StandaloneCatalog c1, final StandaloneCatalog c2) { return c1.getEffectiveDate().compareTo(c2.getEffectiveDate()); } }); }
@Override public PriceList findPriceList(final String name, final DateTime requestedDate) throws CatalogApiException { return versionForDate(requestedDate).findCurrentPriceList(name); }
@Override public PlanPhase findPhase(final String phaseName, final DateTime requestedDate, final DateTime subscriptionStartDate) throws CatalogApiException { final String planName = DefaultPlanPhase.planName(phaseName); final Plan plan = findPlan(planName, requestedDate, subscriptionStartDate); return plan.findPhase(phaseName); }
private List<StandaloneCatalog> versionsBeforeDate(final Date date) throws CatalogApiException { final List<StandaloneCatalog> result = new ArrayList<StandaloneCatalog>(); final int index = indexOfVersionForDate(date); for (int i = 0; i <= index; i++) { result.add(versions.get(i)); } return result; }
@Override public boolean canCreatePlan(final PlanSpecifier specifier, final DateTime requestedDate) throws CatalogApiException { return versionForDate(requestedDate).canCreatePlan(specifier); }
@Test(groups = "fast") public void testErrorOnDateTooEarly() { final DateTime dt0 = new DateTime("1977-01-01T00:00:00+00:00"); try { vc.findPlan("foo", dt0); Assert.fail("Date is too early an exception should have been thrown"); } catch (CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_NO_CATALOG_FOR_GIVEN_DATE.getCode()); } } }
@Override public DefaultProduct[] getProducts(final DateTime requestedDate) throws CatalogApiException { return versionForDate(requestedDate).getCurrentProducts(); }
vc.findPlan("pistol-monthly", dt0, dt0); Assert.fail("Exception should have been thrown there are no plans for this date"); } catch (CatalogApiException e) { final Plan newSubPlan1 = vc.findPlan("pistol-monthly", dt1, dt1); final Plan newSubPlan2 = vc.findPlan("pistol-monthly", dt2, dt2); final Plan newSubPlan214 = vc.findPlan("pistol-monthly", dt214, dt214); final Plan newSubPlan3 = vc.findPlan("pistol-monthly", dt3, dt3); final Plan exSubPlan2 = vc.findPlan("pistol-monthly", dt2, dt1); final Plan exSubPlan214 = vc.findPlan("pistol-monthly", dt214, dt1); final Plan exSubPlan3 = vc.findPlan("pistol-monthly", dt3, dt1);
@Override public Currency[] getSupportedCurrencies(final DateTime requestedDate) throws CatalogApiException { return versionForDate(requestedDate).getCurrentSupportedCurrencies(); }
@Override public PlanAlignmentChange planChangeAlignment(final PlanPhaseSpecifier from, final PlanSpecifier to, final DateTime requestedDate) throws CatalogApiException { return versionForDate(requestedDate).planChangeAlignment(from, to); }
@Override public Product findProduct(final String name, final DateTime requestedDate) throws CatalogApiException { return versionForDate(requestedDate).findCurrentProduct(name); }
@Override public BillingActionPolicy planCancelPolicy(final PlanPhaseSpecifier planPhase, final DateTime requestedDate) throws CatalogApiException { return versionForDate(requestedDate).planCancelPolicy(planPhase); }
@Override public BillingAlignment billingAlignment(final PlanPhaseSpecifier planPhase, final DateTime requestedDate) throws CatalogApiException { return versionForDate(requestedDate).billingAlignment(planPhase); }