@Test(groups = "slow") public void testShouldntInsertMultipleNotificationsPerOverdueable() throws Exception { final UUID accountId = UUID.randomUUID(); final Account overdueable = Mockito.mock(Account.class); Mockito.when(overdueable.getId()).thenReturn(accountId); insertOverdueCheckAndVerifyQueueContent(overdueable, 10, 10); insertOverdueCheckAndVerifyQueueContent(overdueable, 5, 5); insertOverdueCheckAndVerifyQueueContent(overdueable, 15, 5); // Verify the final content of the queue Assert.assertEquals(Iterables.size(overdueQueue.getFutureNotificationForSearchKeys(internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId())), 1); }
@Test(groups = "fast") public void testComputeTargetDateWithDayLightSaving() { final DateTime dateTime1 = new DateTime("2015-01-01T08:01:01.000Z"); final DateTime dateTime2 = new DateTime("2015-09-01T08:01:01.000Z"); final DateTime dateTime3 = new DateTime("2015-12-01T08:01:01.000Z"); // Alaska Standard Time final DateTimeZone timeZone = DateTimeZone.forID("America/Juneau"); // Time zone is AKDT (UTC-8h) between March and November final DateTime referenceDateTimeWithDST = new DateTime("2015-09-01T08:01:01.000Z"); refreshCallContext(referenceDateTimeWithDST, timeZone); assertEquals(internalCallContext.toLocalDate(dateTime1), new LocalDate("2015-01-01")); assertEquals(internalCallContext.toLocalDate(dateTime2), new LocalDate("2015-09-01")); assertEquals(internalCallContext.toLocalDate(dateTime3), new LocalDate("2015-12-01")); // Time zone is AKST (UTC-9h) otherwise final DateTime referenceDateTimeWithoutDST = new DateTime("2015-02-01T08:01:01.000Z"); refreshCallContext(referenceDateTimeWithoutDST, timeZone); assertEquals(internalCallContext.toLocalDate(dateTime1), new LocalDate("2014-12-31")); assertEquals(internalCallContext.toLocalDate(dateTime2), new LocalDate("2015-08-31")); assertEquals(internalCallContext.toLocalDate(dateTime3), new LocalDate("2015-11-30")); }
@Test(groups = "slow", description = "Test Account DAO: custom fields") public void testCustomFields() throws CustomFieldApiException { final UUID accountId = UUID.randomUUID(); final String fieldName = UUID.randomUUID().toString().substring(0, 4); final String fieldValue = UUID.randomUUID().toString(); customFieldDao.create(new CustomFieldModelDao(internalCallContext.getCreatedDate(), fieldName, fieldValue, accountId, ObjectType.ACCOUNT), internalCallContext); final List<CustomFieldModelDao> customFieldMap = customFieldDao.getCustomFieldsForObject(accountId, ObjectType.ACCOUNT, internalCallContext); Assert.assertEquals(customFieldMap.size(), 1); final CustomFieldModelDao customField = customFieldMap.get(0); Assert.assertEquals(customField.getFieldName(), fieldName); Assert.assertEquals(customField.getFieldValue(), fieldValue); }
private List<NotificationEventWithMetadata> getFutureRetryableEvents() throws NoSuchNotificationQueue { final NotificationQueue notificationQueue = queueService.getNotificationQueue(RetryableService.RETRYABLE_SERVICE_NAME, TEST_LISTENER); return ImmutableList.<NotificationEventWithMetadata>copyOf(notificationQueue.getFutureNotificationForSearchKeys(internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId())); }
private void verifyAuditLogsForTag(final List<AuditLog> auditLogs, final AuditLevel level) { if (AuditLevel.NONE.equals(level)) { Assert.assertEquals(auditLogs.size(), 0); return; } Assert.assertEquals(auditLogs.size(), 1); Assert.assertEquals(auditLogs.get(0).getUserToken(), internalCallContext.getUserToken().toString()); Assert.assertEquals(auditLogs.get(0).getChangeType(), ChangeType.INSERT); Assert.assertEquals(auditLogs.get(0).getComment(), internalCallContext.getComments()); Assert.assertEquals(auditLogs.get(0).getReasonCode(), internalCallContext.getReasonCode()); Assert.assertEquals(auditLogs.get(0).getUserName(), internalCallContext.getCreatedBy()); Assert.assertNotNull(auditLogs.get(0).getCreatedDate()); } }
@Test(groups = "fast") public void testNewUserTagDefinitionDeletionEvent() throws Exception { final UUID tagDefinitionId = UUID.randomUUID(); final String tagDefinitionName = UUID.randomUUID().toString(); final String tagDefinitionDescription = UUID.randomUUID().toString(); final boolean controlTag = false; final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag); final UUID userToken = internalCallContext.getUserToken(); final TagEventBuilder tagEventBuilder = new TagEventBuilder(); final TagDefinitionInternalEvent event = tagEventBuilder.newUserTagDefinitionDeletionEvent(tagDefinitionId, new TagDefinitionModelDao(tagDefinition), 1L, 2L, UUID.randomUUID()); Assert.assertTrue(event instanceof UserTagDefinitionDeletionInternalEvent); Assert.assertEquals(event, new DefaultUserTagDefinitionDeletionEvent(tagDefinitionId, tagDefinition, 1L, 2L, UUID.randomUUID())); Assert.assertTrue(event.equals(new DefaultUserTagDefinitionDeletionEvent(tagDefinitionId, tagDefinition, 1L, 2L, UUID.randomUUID()))); verifyTagDefinitionEvent(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, tagDefinition, userToken, event); }
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/675") public void testHandleLockExceptions() throws PaymentApiException { final Payment payment = paymentApi.createPurchase(account, Currency.EUR, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(new PluginProperty(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, PaymentPluginStatus.PENDING.toString(), false)), callContext); final UUID userToken = UUID.randomUUID(); Assert.assertTrue(Iterables.isEmpty(incompletePaymentTransactionTask.janitorQueue.getFutureNotificationForSearchKeys(internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId()))); lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), account.getId().toString(), paymentConfig.getMaxGlobalLockRetries()); incompletePaymentTransactionTask.processNotification(notificationKey, userToken, internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId()); final Iterable<NotificationEventWithMetadata<NotificationEvent>> futureNotifications = incompletePaymentTransactionTask.janitorQueue.getFutureNotificationForSearchKeys(internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId()); Assert.assertFalse(Iterables.isEmpty(futureNotifications)); final NotificationEventWithMetadata<NotificationEvent> notificationEventWithMetadata = ImmutableList.<NotificationEventWithMetadata<NotificationEvent>>copyOf(futureNotifications).get(0); Assert.assertEquals(notificationEventWithMetadata.getUserToken(), userToken); Assert.assertEquals(notificationEventWithMetadata.getEvent().getClass(), JanitorNotificationKey.class); final JanitorNotificationKey event = (JanitorNotificationKey) notificationEventWithMetadata.getEvent();
@Test(groups = "slow", expectedExceptions = TagDefinitionApiException.class) public void testTagDefinitionDeletionForDefinitionInUse() throws TagDefinitionApiException, TagApiException { final String definitionName = "TestTag12345"; eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION); tagDefinitionDao.create(definitionName, "Some test tag", ObjectType.ACCOUNT.name(), internalCallContext); assertListenerStatus(); final TagDefinitionModelDao tagDefinition = tagDefinitionDao.getByName(definitionName, internalCallContext); assertNotNull(tagDefinition); final UUID objectId = UUID.randomUUID(); final Tag tag = new DescriptiveTag(tagDefinition.getId(), ObjectType.ACCOUNT, objectId, internalCallContext.getCreatedDate()); eventsListener.pushExpectedEvent(NextEvent.TAG); tagDao.create(new TagModelDao(tag), internalCallContext); assertListenerStatus(); tagDefinitionDao.deleteById(tagDefinition.getId(), internalCallContext); }
@Test(groups = "slow") public void testInvalidation() { final InvoiceTrackingSqlDao dao = dbi.onDemand(InvoiceTrackingSqlDao.class); LocalDate endRange = new LocalDate(2019, 1, 31); final UUID invoiceId1 = UUID.randomUUID(); final UUID invoiceId2 = UUID.randomUUID(); final UUID subscriptionId = UUID.randomUUID(); Assert.assertEquals(result.size(), 4); final InternalCallContext updatedContext = new InternalCallContext(internalCallContext.getTenantRecordId(), internalCallContext.getAccountRecordId(), internalCallContext.getFixedOffsetTimeZone(), clock.getUTCNow(), internalCallContext.getUserToken(), "invalidation-user", internalCallContext.getCallOrigin(), internalCallContext.getContextUserType(), internalCallContext.getReasonCode(), internalCallContext.getComments(), internalCallContext.getCreatedDate(), clock.getUTCNow()); Assert.assertEquals(result2.size(), 1);
@Test(groups = "slow") public void testCreateCustomField() throws CustomFieldApiException { final UUID id = UUID.randomUUID(); final ObjectType objectType = ObjectType.ACCOUNT; String fieldName = "TestField1"; String fieldValue = "Kitty Hawk"; eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD); customFieldDao.create(new CustomFieldModelDao(internalCallContext.getCreatedDate(), fieldName, fieldValue, id, objectType), internalCallContext); assertListenerStatus(); fieldName = "TestField2"; fieldValue = "Cape Canaveral"; eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD); customFieldDao.create(new CustomFieldModelDao(internalCallContext.getCreatedDate(), fieldName, fieldValue, id, objectType), internalCallContext); assertListenerStatus(); } }
@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 = "fast") public void testComputeUTCDateTimeFromLocalDate1() { final DateTime effectiveDateTime = DATE_TIME_FORMATTER.parseDateTime(effectiveDateTime1); final DateTimeZone timeZone = DateTimeZone.forOffsetHours(-8); refreshCallContext(effectiveDateTime, timeZone); final LocalDate endDate = new LocalDate(2013, 01, 19); final DateTime endDateTimeInUTC = internalCallContext.toUTCDateTime(endDate); assertTrue(endDateTimeInUTC.compareTo(effectiveDateTime.plusYears(1)) == 0); }
@Test(groups = "slow") public void testCreateSubscriptionWithBCD() throws SubscriptionBaseApiException { final DateTime init = clock.getUTCNow(); this.internalCallContext.getUpdatedBy(), this.internalCallContext.getCallOrigin(), this.internalCallContext.getContextUserType(), this.internalCallContext.getUserToken(), this.internalCallContext.getTenantRecordId()); testListener.assertListenerStatus(); assertEquals(subscriptionBaseWithAddOns.size(), 1); assertEquals(subscriptionBaseWithAddOns.get(0).getSubscriptionBaseList().size(), 1); assertNotNull(subscription); assertNotNull(subscription.getBillCycleDayLocal()); assertEquals(subscription.getBillCycleDayLocal().intValue(), 18);
@Test(groups = "slow") public void testCreatePlanNoProduct() throws Exception { final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class); final StaticCatalog standaloneCatalogWithPriceOverride = new StandaloneCatalogWithPriceOverride(catalog, priceOverride, internalCallContext.getTenantRecordId(), internalCallContextFactory); try { final PlanSpecifier specWithNullProduct = new PlanSpecifier(null, BillingPeriod.ANNUAL, "DEFAULT"); standaloneCatalogWithPriceOverride.createOrFindCurrentPlan(specWithNullProduct, null); Assert.fail(); } catch (final CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_NULL_PRODUCT_NAME.getCode()); } }
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/842") public void testCreateAmbiguousPlan() throws Exception { final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class); final StaticCatalog standaloneCatalogWithPriceOverride = new StandaloneCatalogWithPriceOverride(catalog, priceOverride, internalCallContext.getTenantRecordId(), internalCallContextFactory); Mockito.when(overrides.getOverrides()).thenReturn(ImmutableList.of(override)); final Plan plan = standaloneCatalogWithPriceOverride.createOrFindCurrentPlan(spec, overrides); Assert.assertTrue(plan.getName().startsWith("standard-monthly-67890-")); final Matcher m = DefaultPriceOverride.CUSTOM_PLAN_NAME_PATTERN.matcher(plan.getName()); Assert.assertTrue(m.matches()); Assert.assertNotNull(catalog.findCurrentPlan("standard-monthly")); Assert.assertNotNull(standaloneCatalogWithPriceOverride.findCurrentPlan("standard-monthly"));
@Test(groups = "slow") public void testUndoChangePlanOnPendingSubscription() throws SubscriptionBaseApiException { final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null, internalCallContext.toLocalDate(futureStartDate)); assertNotNull(subscription); assertEquals(refreshedSubscription.getAllTransitions().size(), 3); assertEquals(refreshedSubscription.getAllTransitions().get(0).getTransitionType(), SubscriptionBaseTransitionType.CREATE); assertEquals(refreshedSubscription.getAllTransitions().get(1).getTransitionType(), SubscriptionBaseTransitionType.CHANGE); assertEquals(refreshedSubscription.getAllTransitions().get(2).getTransitionType(), SubscriptionBaseTransitionType.PHASE);
@Test(groups = "slow") public void testWithParking() throws InvoiceApiException, AccountApiException, CatalogApiException, SubscriptionBaseApiException, TagDefinitionApiException { final UUID accountId = account.getId(); final LocalDate target = internalCallContext.toLocalDate(effectiveDate); Assert.assertTrue(tagUserApi.getTagsForAccount(accountId, true, callContext).isEmpty()); Assert.fail(); } catch (final InvoiceApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.UNEXPECTED_ERROR.getCode()); Assert.assertTrue(e.getCause().getMessage().startsWith("Double billing detected"));
@Test(groups = "slow") public void test() throws Exception { final UUID accountId = new UUID(0L, 1L); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(accountId); Mockito.when(accountApi.getImmutableAccountDataByRecordId(Mockito.eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); final DateTime now = clock.getUTCNow(); final DateTime readyTime = now.plusMillis(2000); final OverdueCheckNotificationKey notificationKey = new OverdueCheckNotificationKey(accountId); checkPoster.insertOverdueNotification(accountId, readyTime, OverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE, notificationKey, internalCallContext); // Move time in the future after the notification effectiveDate clock.setDeltaFromReality(3000); await().atMost(5, SECONDS).until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return mockDispatcher.getEventCount() == 1; } }); Assert.assertEquals(mockDispatcher.getEventCount(), 1); Assert.assertEquals(mockDispatcher.getLatestAccountId(), accountId); } }
@Test(groups = "slow") public void testDryRunReInsertion() throws Exception { final Account account = invoiceUtil.createAccount(callContext); final Long accountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(account.getId(), ObjectType.ACCOUNT, null); final LocalDate notificationDate = clock.getUTCToday().plusDays(30); final SubscriptionBase subscription = invoiceUtil.createSubscription(); final UUID subscriptionId = subscription.getId(); final FutureAccountNotifications futureAccountNotifications = createFutureAccountNotifications(subscriptionId, notificationDate); invoiceDao.setFutureAccountNotificationsForEmptyInvoice(account.getId(), futureAccountNotifications, internalCallContext); invoiceDao.setFutureAccountNotificationsForEmptyInvoice(account.getId(), futureAccountNotifications, internalCallContext); final NotificationQueue nextBillingQueue = notificationQueueService.getNotificationQueue(KILLBILL_SERVICES.INVOICE_SERVICE.getServiceName(), DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE); final Iterable<NotificationEventWithMetadata<NextBillingDateNotificationKey>> futureNotifications = nextBillingQueue.getFutureNotificationForSearchKeys(accountRecordId, internalCallContext.getTenantRecordId()); final ImmutableList<NotificationEventWithMetadata<NextBillingDateNotificationKey>> futureNotificationsList = ImmutableList.copyOf(futureNotifications); Assert.assertEquals(futureNotificationsList.size(), 1); // We expect only one notification for which effectiveDate matches our original effectiveDate (conversion DateTime -> LocalDate -> DateTime) final NotificationEventWithMetadata<NextBillingDateNotificationKey> notification = futureNotificationsList.get(0); Assert.assertEquals(notification.getEffectiveDate(), internalCallContext.toUTCDateTime(notificationDate)); final Iterable<UUID> uuidKeys = notification.getEvent().getUuidKeys(); Assert.assertFalse(Iterables.isEmpty(uuidKeys)); final List<UUID> uuidKeysList = ImmutableList.copyOf(uuidKeys); Assert.assertEquals(uuidKeysList.size(), 1); Assert.assertEquals(uuidKeysList.get(0), subscriptionId); }
@Test(groups = "slow", description = "Test Account creation generates an event") public void testBusEvents() throws Exception { final AccountEventHandler eventHandler = new AccountEventHandler(); bus.register(eventHandler); final AccountModelDao accountModelDao = createTestAccount(); final AccountData defaultAccount = new DefaultAccount(accountModelDao); final Account account = createAccount(defaultAccount); await().atMost(10, SECONDS).until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return eventHandler.getAccountCreationInternalEvents().size() == 1; } }); final AccountCreationInternalEvent accountCreationInternalEvent = eventHandler.getAccountCreationInternalEvents().get(0); Assert.assertEquals(accountCreationInternalEvent.getId(), account.getId()); // account_record_id is most likely 1, although, depending on the DB, we cannot be sure Assert.assertNotNull(accountCreationInternalEvent.getSearchKey1()); Assert.assertEquals(accountCreationInternalEvent.getSearchKey2(), internalCallContext.getTenantRecordId()); }