@Test(groups = "fast") public void testCatalogServiceFile() throws ServiceException { final DefaultCatalogService service = new DefaultCatalogService(new CatalogConfig() { @Override public String getCatalogURI() { return "file:src/test/resources/WeaponsHire.xml"; } }, new VersionedCatalogLoader(new DefaultClock())); service.loadCatalog(); Assert.assertNotNull(service.getFullCatalog()); Assert.assertEquals(service.getFullCatalog().getCatalogName(), "Firearms"); } }
@Override @BeforeClass(groups = "fast") public void beforeClass() throws Exception { super.beforeClass(); final VersionedCatalogLoader versionedCatalogLoader = new VersionedCatalogLoader(clock); final CatalogConfig config = new ConfigurationObjectFactory(new ConfigSource() { final Map<String, String> properties = ImmutableMap.<String, String>of("killbill.catalog.uri", "file:src/test/resources/testInput.xml"); @Override public String getString(final String propertyName) { return properties.get(propertyName); } }).build(CatalogConfig.class); catalogService = new DefaultCatalogService(config, versionedCatalogLoader); planAligner = new PlanAligner(catalogService); catalogService.loadCatalog(); }
private Catalog initCatalog(final CatalogService catalogService) throws Exception { ((DefaultCatalogService) catalogService).loadCatalog(); final Catalog catalog = catalogService.getFullCatalog(); assertNotNull(catalog); return catalog; }
private TimedPhase getNextTimedPhaseOnChange(final DefaultSubscriptionBase defaultSubscriptionBase, final String newProductName, final DateTime effectiveChangeDate) throws CatalogApiException, SubscriptionBaseApiException { // The date is used for different catalog versions - we don't care here final Plan newPlan = catalogService.getFullCatalog().findPlan(newProductName, clock.getUTCNow()); return planAligner.getNextTimedPhaseOnChange(defaultSubscriptionBase, newPlan, priceList, effectiveChangeDate, effectiveChangeDate); }
public Catalog initCatalog(final CatalogService catalogService) throws Exception { ((DefaultCatalogService) catalogService).loadCatalog(); final Catalog catalog = catalogService.getFullCatalog(); assertNotNull(catalog); return catalog; }
private TimedPhase[] getTimedPhasesOnCreate(final String productName, final PhaseType initialPhase, final DefaultSubscriptionBase defaultSubscriptionBase, final DateTime effectiveDate) throws CatalogApiException, SubscriptionBaseApiException { // The date is used for different catalog versions - we don't care here final Plan plan = catalogService.getFullCatalog().findPlan(productName, clock.getUTCNow()); // Same here for the requested date final TimedPhase[] phases = planAligner.getCurrentAndNextTimedPhaseOnCreate(defaultSubscriptionBase, plan, initialPhase, priceList, clock.getUTCNow(), effectiveDate); Assert.assertEquals(phases.length, 2); return phases; } }
@Test(groups = "fast") public void testCatalogServiceDirectory() throws ServiceException { final DefaultCatalogService service = new DefaultCatalogService(new CatalogConfig() { @Override public String getCatalogURI() { return "file:src/test/resources/versionedCatalog"; } }, new VersionedCatalogLoader(new DefaultClock())); service.loadCatalog(); Assert.assertNotNull(service.getFullCatalog()); Assert.assertEquals(service.getFullCatalog().getCatalogName(), "WeaponsHireSmall"); }
private void changeSubscription(final DateTime effectiveChangeDate, final DefaultSubscriptionBase defaultSubscriptionBase, final String previousProductName, final String newProductName, final PhaseType commonPhaseType) { final SubscriptionBaseEvent previousEvent = createSubscriptionEvent(defaultSubscriptionBase.getStartDate(), previousProductName, commonPhaseType, ApiEventType.CREATE, defaultSubscriptionBase.getActiveVersion()); final SubscriptionBaseEvent event = createSubscriptionEvent(effectiveChangeDate, newProductName, commonPhaseType, ApiEventType.CHANGE, defaultSubscriptionBase.getActiveVersion()); defaultSubscriptionBase.rebuildTransitions(ImmutableList.<SubscriptionBaseEvent>of(previousEvent, event), catalogService.getFullCatalog()); final List<SubscriptionBaseTransition> newTransitions = defaultSubscriptionBase.getAllTransitions(); Assert.assertEquals(newTransitions.size(), 2); Assert.assertNull(newTransitions.get(0).getPreviousPhase()); Assert.assertEquals(newTransitions.get(0).getNextPhase(), newTransitions.get(1).getPreviousPhase()); Assert.assertNotNull(newTransitions.get(1).getNextPhase()); }
private DefaultSubscriptionBase createSubscriptionStartedInThePast(final String productName, final PhaseType phaseType) { final SubscriptionBuilder builder = new SubscriptionBuilder(); builder.setBundleStartDate(clock.getUTCNow().minusHours(10)); // Make sure to set the dates apart builder.setAlignStartDate(new DateTime(builder.getBundleStartDate().plusHours(5))); // Create the transitions final DefaultSubscriptionBase defaultSubscriptionBase = new DefaultSubscriptionBase(builder, null, clock); final SubscriptionBaseEvent event = createSubscriptionEvent(builder.getAlignStartDate(), productName, phaseType, ApiEventType.CREATE, defaultSubscriptionBase.getActiveVersion()); defaultSubscriptionBase.rebuildTransitions(ImmutableList.<SubscriptionBaseEvent>of(event), catalogService.getFullCatalog()); Assert.assertEquals(defaultSubscriptionBase.getAllTransitions().size(), 1); Assert.assertNull(defaultSubscriptionBase.getAllTransitions().get(0).getPreviousPhase()); Assert.assertNotNull(defaultSubscriptionBase.getAllTransitions().get(0).getNextPhase()); return defaultSubscriptionBase; }