use of org.killbill.clock.ClockMock in project killbill by killbill.
the class TestResource method updateTestClockTime.
@PUT
@Path("/clock")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Move the current time", response = ClockResource.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid timezone supplied") })
public Response updateTestClockTime(@QueryParam("days") final Integer addDays, @QueryParam("weeks") final Integer addWeeks, @QueryParam("months") final Integer addMonths, @QueryParam("years") final Integer addYears, @QueryParam("timeZone") final String timeZoneStr, @QueryParam("timeoutSec") @DefaultValue("5") final Long timeoutSec, @javax.ws.rs.core.Context final HttpServletRequest request) {
final ClockMock testClock = getClockMock();
if (addDays != null) {
testClock.addDays(addDays);
} else if (addWeeks != null) {
testClock.addWeeks(addWeeks);
} else if (addMonths != null) {
testClock.addMonths(addMonths);
} else if (addYears != null) {
testClock.addYears(addYears);
}
waitForNotificationToComplete(request, timeoutSec);
return getCurrentTime(timeZoneStr);
}
use of org.killbill.clock.ClockMock in project killbill by killbill.
the class TestResource method setTestClockTime.
@POST
@Path("/clock")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Set the current time", response = ClockResource.class)
@ApiResponses(value = { /* @ApiResponse(code = 200, message = "Successful"), */
@ApiResponse(code = 400, message = "Invalid time or timezone supplied") })
public Response setTestClockTime(@QueryParam(QUERY_REQUESTED_DT) final String requestedClockDate, @QueryParam("timeZone") final String timeZoneStr, @QueryParam("timeoutSec") @DefaultValue("5") final Long timeoutSec, @javax.ws.rs.core.Context final HttpServletRequest request) {
final ClockMock testClock = getClockMock();
if (requestedClockDate == null) {
testClock.resetDeltaFromReality();
} else {
final DateTime newTime = DATE_TIME_FORMATTER.parseDateTime(requestedClockDate).toDateTime(DateTimeZone.UTC);
testClock.setTime(newTime);
}
waitForNotificationToComplete(request, timeoutSec);
return getCurrentTime(timeZoneStr);
}
use of org.killbill.clock.ClockMock in project killbill by killbill.
the class TestInvoiceDao method testRefundedInvoiceWithInvoiceItemAdjustmentWithRepair.
@Test(groups = "slow")
public void testRefundedInvoiceWithInvoiceItemAdjustmentWithRepair() throws InvoiceApiException, EntityPersistenceException {
final UUID accountId = account.getId();
final UUID subscriptionId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final LocalDate startDate = new LocalDate(2010, 1, 1);
((ClockMock) clock).setDay(startDate);
final LocalDate recuringStartDate = clock.getUTCNow().plusDays(30).toLocalDate();
final LocalDate recuringEndDate = recuringStartDate.plusMonths(1);
final LocalDate targetDate = recuringStartDate.plusDays(1);
// FIRST CREATE INITIAL INVOICE WITH ONE RECURRING ITEM
final Invoice invoice = new DefaultInvoice(accountId, targetDate, targetDate, Currency.USD);
final UUID invoiceId = invoice.getId();
final InvoiceItem invoiceItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "test product", "test-plan", "test-phase-rec", null, recuringStartDate, recuringEndDate, new BigDecimal("239.00"), new BigDecimal("239.00"), Currency.USD);
invoice.addInvoiceItem(invoiceItem);
invoiceUtil.createInvoice(invoice, context);
((ClockMock) clock).addDays(1);
// SECOND CREATE THE PAYMENT
final BigDecimal paymentAmount = new BigDecimal("239.00");
final UUID paymentId = UUID.randomUUID();
final DefaultInvoicePayment defaultInvoicePayment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoiceId, clock.getUTCNow(), paymentAmount, Currency.USD, Currency.USD, "cookie", true);
invoiceDao.notifyOfPaymentCompletion(new InvoicePaymentModelDao(defaultInvoicePayment), UUID.randomUUID(), context);
// AND THEN THIRD THE REFUND
final Map<UUID, BigDecimal> invoiceItemMap = new HashMap<UUID, BigDecimal>();
invoiceItemMap.put(invoiceItem.getId(), new BigDecimal("239.00"));
invoiceDao.createRefund(paymentId, UUID.randomUUID(), paymentAmount, true, invoiceItemMap, UUID.randomUUID().toString(), true, context);
final InvoiceModelDao savedInvoice = invoiceDao.getById(invoiceId, context);
assertNotNull(savedInvoice);
assertEquals(savedInvoice.getInvoiceItems().size(), 2);
final List<Invoice> invoices = new ArrayList<Invoice>();
invoices.add(new DefaultInvoice(savedInvoice));
// NOW COMPUTE A DIFFERENT ITEM TO TRIGGER REPAIR
final BillingEventSet events = new MockBillingEventSet();
final SubscriptionBase subscription = getZombieSubscription(subscriptionId);
final Product product = Mockito.mock(Product.class);
Mockito.when(product.getName()).thenReturn("product");
final Plan plan = Mockito.mock(Plan.class);
Mockito.when(plan.getName()).thenReturn("plan");
Mockito.when(plan.getProduct()).thenReturn(product);
Mockito.when(plan.getRecurringBillingMode()).thenReturn(BillingMode.IN_ADVANCE);
final PlanPhase phase1 = Mockito.mock(PlanPhase.class);
Mockito.when(phase1.getName()).thenReturn("plan-phase1");
final BillingEvent event1 = invoiceUtil.createMockBillingEvent(null, subscription, recuringStartDate.toDateTimeAtStartOfDay(), plan, phase1, null, TEN, Currency.USD, BillingPeriod.MONTHLY, 31, BillingMode.IN_ADVANCE, "new-event", 1L, SubscriptionBaseTransitionType.CREATE);
events.add(event1);
final InvoiceWithMetadata newInvoiceWithMetadata = generator.generateInvoice(account, events, new AccountInvoices(null, null, invoices), null, targetDate, Currency.USD, null, context);
final Invoice newInvoice = newInvoiceWithMetadata.getInvoice();
invoiceUtil.createInvoice(newInvoice, context);
// VERIFY THAT WE STILL HAVE ONLY 2 ITEMS, MEANING THERE WERE NO REPAIR AND NO CBA GENERATED
final Invoice firstInvoice = new DefaultInvoice(invoiceDao.getById(invoiceId, context));
assertNotNull(firstInvoice);
assertEquals(firstInvoice.getInvoiceItems().size(), 2);
}
use of org.killbill.clock.ClockMock in project killbill by killbill.
the class TestDateConversion method testNullConversion.
//
// BASIC Tests to understand how toLocalDate converts different inputs (null, LocalDate, DateTime)
//
@Test(groups = "fast")
public void testNullConversion() throws AccountApiException {
final String input = null;
final LocalDate result = toLocalDate(input);
Assert.assertNull(result);
final UUID accountId = setupAccount(DateTimeZone.forOffsetHours(-8));
((ClockMock) clock).setTime(new DateTime("2013-08-26T06:50:20Z"));
final LocalDate result2 = toLocalDateDefaultToday(accountId, input, null);
Assert.assertTrue(result2.compareTo(new LocalDate(2013, 8, 25)) == 0);
((ClockMock) clock).resetDeltaFromReality();
}
Aggregations