Refine search
@Test(groups = "fast") public void testFutureEffectiveDateWithBCDEqualsComputedEffectiveDay() throws Exception { // Set by test as : 2012-05-07T00:03:42.000Z final DateTime now = clock.getUTCNow(); int newBCD = 3; // effectiveDate = 2012-05-07T00:03:42.000Z => ComputedEffectiveDay = 7 LocalDate effectiveDate = new LocalDate(2012, 7, 3); // newBCD == ComputedEffectiveDay final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext); Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-07-03"))); }
@Test(groups = "fast", description="Test Account event deserialization") public void testDefaultAccountChangeEvent() throws Exception { final List<ChangedField> changes = new ArrayList<ChangedField>(); changes.add(new DefaultChangedField("fieldXX", "valueX", "valueXXX", clock.getUTCNow())); changes.add(new DefaultChangedField("fieldYY", "valueY", "valueYYY", clock.getUTCNow())); final AccountChangeInternalEvent e = new DefaultAccountChangeEvent(changes, UUID.randomUUID(), 1L, 2L, null); final String json = mapper.writeValueAsString(e); final Class<?> claz = Class.forName("org.killbill.billing.account.api.user.DefaultAccountChangeEvent"); final Object obj = mapper.readValue(json, claz); Assert.assertTrue(obj.equals(e)); }
@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; } });
@Test(groups = "fast") public void testFutureEffectiveDateWithBCDAfterEndOfTheMonth() throws Exception { // Set by test as : 2012-05-07T00:03:42.000Z final DateTime now = clock.getUTCNow(); int newBCD = 31; // effectiveDate = 2012-06-03 => ComputedEffectiveDay = 3 LocalDate effectiveDate = new LocalDate(2012, 6, 3); // newBCD > 30 (max day in June) final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext); Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-06-30"))); }
@Test(groups = "fast") public void testNullEffectiveDateWithBCDEqualsComputedEffectiveDay() throws Exception { // Set by test as : 2012-05-07T00:03:42.000Z final DateTime now = clock.getUTCNow(); int newBCD = 7; // effectiveDate = 2012-05-07T00:03:42.000Z => ComputedEffectiveDay = 7 LocalDate effectiveDate = null; // newBCD == ComputedEffectiveDay final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext); final DateTime nowAfterCall = clock.getUTCNow(); // In that case because we want the event to fire right NOW, we don't use the account reference time but instead use the clock.getUTCNOW(). In case test // takes longer than 1 mSec we need to check a (very small) range of dates Assert.assertTrue(result.compareTo(now) >= 0); Assert.assertTrue(result.compareTo(nowAfterCall) <= 0); }
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(true, true, internalCallContext).findPlan(productName, clock.getUTCNow()); // Same here for the requested date final TimedPhase[] phases = planAligner.getCurrentAndNextTimedPhaseOnCreate(defaultSubscriptionBase.getAlignStartDate(), defaultSubscriptionBase.getBundleStartDate(), plan, initialPhase, priceList, effectiveDate, catalog, internalCallContext); Assert.assertEquals(phases.length, 2); return phases; } }
@Test(groups = "fast") public void testPastEffectiveDateWithBCDPriorComputedEffectiveDay() throws Exception { // Set by test as : 2012-05-07T00:03:42.000Z final DateTime now = clock.getUTCNow(); int newBCD = 3; // effectiveDate = 2012-05-07T00:03:42.000Z => ComputedEffectiveDay = 7 LocalDate effectiveDate = new LocalDate(2012, 2, 7); // newBCD < ComputedEffectiveDay final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext); Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-03-03"))); }
@Test(groups = "slow") public void testBasicWithNullPrices() throws Exception { final CatalogOverridePhaseDefinitionModelDao obj1 = new CatalogOverridePhaseDefinitionModelDao("p2", "USD", null, new BigDecimal("54.21"), clock.getUTCNow()); performTestInTransaction(new WithCatalogOverridePhaseDefinitionSqlDaoTransaction<Void>() { @Override public Void doTransaction(final CatalogOverridePhaseDefinitionSqlDao sqlDao) { sqlDao.create(obj1, internalCallContext); final Long lastInserted = sqlDao.getLastInsertId(); final CatalogOverridePhaseDefinitionModelDao rehydrated = sqlDao.getByRecordId(lastInserted, internalCallContext); assertEquals(rehydrated.getParentPhaseName(), obj1.getParentPhaseName()); assertNull(rehydrated.getFixedPrice()); assertEquals(rehydrated.getRecurringPrice().compareTo(obj1.getRecurringPrice()), 0); assertEquals(rehydrated.getCurrency(), obj1.getCurrency()); return null; } }); }
private void addTag() throws TagDefinitionApiException, TagApiException { // Create a tag definition eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION); final TagDefinitionModelDao tagDefinition = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 5), UUID.randomUUID().toString().substring(0, 5), ObjectType.ACCOUNT.name(), internalCallContext); assertListenerStatus(); Assert.assertEquals(tagDefinitionDao.getById(tagDefinition.getId(), internalCallContext), tagDefinition); // Create a tag final UUID objectId = UUID.randomUUID(); final Tag theTag = new DescriptiveTag(tagDefinition.getId(), ObjectType.ACCOUNT, objectId, clock.getUTCNow()); eventsListener.pushExpectedEvent(NextEvent.TAG); tagDao.create(new TagModelDao(theTag), internalCallContext); assertListenerStatus(); final List<TagModelDao> tags = tagDao.getTagsForObject(objectId, ObjectType.ACCOUNT, false, internalCallContext); Assert.assertEquals(tags.size(), 1); tag = tags.get(0); Assert.assertEquals(tag.getTagDefinitionId(), tagDefinition.getId()); }
@Test(groups = "fast") public void testFutureEffectiveDateWithBCDPriorComputedEffectiveDay() throws Exception { // Set by test as : 2012-05-07T00:03:42.000Z final DateTime now = clock.getUTCNow(); int newBCD = 3; // effectiveDate = 2012-05-07T00:03:42.000Z => ComputedEffectiveDay = 7 LocalDate effectiveDate = new LocalDate(2012, 7, 7); // newBCD < ComputedEffectiveDay final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext); Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-08-03"))); }
@Test(groups = "slow") public void testGetByAttributes() throws Exception { final CatalogOverrideBlockDefinitionModelDao objWithNoNullPrice = new CatalogOverrideBlockDefinitionModelDao("p2", "USD", BigDecimal.ONE, new Double("1"), new Double("5"), clock.getUTCNow()); performTestInTransaction(new WithCatalogOverrideBlockDefinitionSqlDaoTransaction<Void>() { @Override public Void doTransaction(final CatalogOverrideBlockDefinitionSqlDao sqlDao) { sqlDao.create(objWithNoNullPrice, internalCallContext); checkRehydrated(objWithNoNullPrice, sqlDao); return null; } private void checkRehydrated(final CatalogOverrideBlockDefinitionModelDao obj, final CatalogOverrideBlockDefinitionSqlDao sqlDao) { final CatalogOverrideBlockDefinitionModelDao rehydrated = sqlDao.getByAttributes(obj.getParentUnitName(), obj.getCurrency(), obj.getPrice(),obj.getMax(),obj.getSize(), internalCallContext); assertEquals(rehydrated.getParentUnitName(), obj.getParentUnitName()); assertEquals(rehydrated.getCurrency(), obj.getCurrency()); assertEquals(rehydrated.getPrice().compareTo(obj.getPrice()), 0); assertEquals(rehydrated.getSize(), obj.getSize()); assertEquals(rehydrated.getMax(), obj.getMax()); } }); }
final PlanPhase trialPhase = subscription.getCurrentPhase(); final DateTime expectedPhaseTrialChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), trialPhase.getDuration()); assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL); Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); PlanPhase currentPhase = subscription.getCurrentPhase(); assertEquals(currentPhase.getPhaseType(), PhaseType.DISCOUNT); it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus();
@Test(groups = "fast") public void testPastEffectiveDateWithBCDAfterComputedEffectiveDay() throws Exception { // Set by test as : 2012-05-07T00:03:42.000Z final DateTime now = clock.getUTCNow(); int newBCD = 10; // effectiveDate = 2012-05-07T00:03:42.000Z => ComputedEffectiveDay = 7 LocalDate effectiveDate = new LocalDate(2012, 2, 3); // newBCD > ComputedEffectiveDay final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext); Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-02-10"))); }
@Test(groups = "slow") public void testBasic() throws Exception { final CatalogOverrideTierDefinitionModelDao obj1 = new CatalogOverrideTierDefinitionModelDao("USD", BigDecimal.ONE,null, clock.getUTCNow()); performTestInTransaction(new WithCatalogOverrideTierDefinitionSqlDaoTransaction<Void>() { @Override public Void doTransaction(final CatalogOverrideTierDefinitionSqlDao sqlDao) { sqlDao.create(obj1, internalCallContext); final Long lastInserted = sqlDao.getLastInsertId(); final CatalogOverrideTierDefinitionModelDao rehydrated = sqlDao.getByRecordId(lastInserted, internalCallContext); assertEquals(rehydrated.getFixedPrice().compareTo(obj1.getFixedPrice()), 0); assertEquals(rehydrated.getCurrency(), obj1.getCurrency()); return null; } }); }
@Test(groups = "fast") public void testFutureEffectiveDateWithBCDAfterComputedEffectiveDay() throws Exception { // Set by test as : 2012-05-07T00:03:42.000Z final DateTime now = clock.getUTCNow(); int newBCD = 10; // effectiveDate = 2012-05-07T00:03:42.000Z => ComputedEffectiveDay = 7 LocalDate effectiveDate = new LocalDate(2012, 7, 3); // newBCD > ComputedEffectiveDay final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext); Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-07-10"))); }
@Test(groups = "slow") public void testBasic() throws Exception { final CatalogOverridePlanDefinitionModelDao obj1 = new CatalogOverridePlanDefinitionModelDao("p1", true, clock.getUTCNow()); performTestInTransaction(new WithCatalogOverridePlanDefinitionSqlDaoTransaction<Void>() { @Override public Void doTransaction(final CatalogOverridePlanDefinitionSqlDao sqlDao) { sqlDao.create(obj1, internalCallContext); final Long lastInserted = sqlDao.getLastInsertId(); final CatalogOverridePlanDefinitionModelDao rehydrated = sqlDao.getByRecordId(lastInserted, internalCallContext); assertEquals(rehydrated.getParentPlanName(), obj1.getParentPlanName()); assertEquals(rehydrated.getIsActive(), obj1.getIsActive()); return null; } }); }
@Test(groups = "fast") public void testPastEffectiveDateWithBCDEqualsComputedEffectiveDay() throws Exception { // Set by test as : 2012-05-07T00:03:42.000Z final DateTime now = clock.getUTCNow(); int newBCD = 3; // effectiveDate = 2012-05-07T00:03:42.000Z => ComputedEffectiveDay = 7 LocalDate effectiveDate = new LocalDate(2012, 2, 3); // newBCD == ComputedEffectiveDay final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext); Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-02-03"))); }
@Test(groups = "slow") public void testBasic() throws Exception { final CatalogOverridePhaseDefinitionModelDao obj1 = new CatalogOverridePhaseDefinitionModelDao("p1", "EUR", BigDecimal.ONE, BigDecimal.TEN, clock.getUTCNow()); performTestInTransaction(new WithCatalogOverridePhaseDefinitionSqlDaoTransaction<Void>() { @Override public Void doTransaction(final CatalogOverridePhaseDefinitionSqlDao sqlDao) { sqlDao.create(obj1, internalCallContext); final Long lastInserted = sqlDao.getLastInsertId(); final CatalogOverridePhaseDefinitionModelDao rehydrated = sqlDao.getByRecordId(lastInserted, internalCallContext); assertEquals(rehydrated.getParentPhaseName(), obj1.getParentPhaseName()); assertEquals(rehydrated.getFixedPrice().compareTo(obj1.getFixedPrice()), 0); assertEquals(rehydrated.getRecurringPrice().compareTo(obj1.getRecurringPrice()), 0); assertEquals(rehydrated.getCurrency(), obj1.getCurrency()); return null; } }); }
@Test(groups = "fast") public void testPastEffectiveDateWithBCDAfterEndOfTheMonth() throws Exception { // Set by test as : 2012-05-07T00:03:42.000Z final DateTime now = clock.getUTCNow(); int newBCD = 31; // effectiveDate = 2012-02-03 => ComputedEffectiveDay = 3 LocalDate effectiveDate = new LocalDate(2012, 2, 3); // newBCD > 30 (max day in June) final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext); Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-2-29"))); }
@Test(groups = "slow") public void testBasic() throws Exception { final CatalogOverrideUsageDefinitionModelDao obj1 = new CatalogOverrideUsageDefinitionModelDao("u1", "CONSUMABLE", "USD",BigDecimal.ONE,null, clock.getUTCNow()); performTestInTransaction(new WithCatalogOverrideUsageDefinitionSqlDaoTransaction<Void>() { @Override public Void doTransaction(final CatalogOverrideUsageDefinitionSqlDao sqlDao) { sqlDao.create(obj1, internalCallContext); final Long lastInserted = sqlDao.getLastInsertId(); final CatalogOverrideUsageDefinitionModelDao rehydrated = sqlDao.getByRecordId(lastInserted, internalCallContext); assertEquals(rehydrated.getParentUsageName(), obj1.getParentUsageName()); assertEquals(rehydrated.getType(), obj1.getType()); assertEquals(rehydrated.getCurrency(), obj1.getCurrency()); assertEquals(rehydrated.getFixedPrice().compareTo(obj1.getFixedPrice()), 0); return null; } }); }