@TimedResource @POST @Path("/{subscriptionId:" + UUID_PATTERN + "}/" + BLOCK) @Consumes(APPLICATION_JSON) @ApiOperation(value = "Block a subscription", response = BlockingStateJson.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 201, message = "Blocking state created successfully"), @ApiResponse(code = 400, message = "Invalid subscription id supplied"), @ApiResponse(code = 404, message = "Subscription not found")}) public Response addSubscriptionBlockingState(@PathParam(ID_PARAM_NAME) final UUID id, final BlockingStateJson json, @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request, @javax.ws.rs.core.Context final UriInfo uriInfo) throws SubscriptionApiException, EntitlementApiException, AccountApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Entitlement entitlement = entitlementApi.getEntitlementForId(id, tenantContext); return addBlockingState(json, entitlement.getAccountId(), id, BlockingStateType.SUBSCRIPTION, requestedDate, pluginPropertiesString, createdBy, reason, comment, request, uriInfo); }
@TimedResource @PUT @Path("/{subscriptionId:" + UUID_PATTERN + "}/" + UNDO_CANCEL) @Produces(APPLICATION_JSON) @ApiOperation(value = "Un-cancel an entitlement") @ApiResponses(value = {@ApiResponse(code = 204, message = "Successful operation"), @ApiResponse(code = 400, message = "Invalid subscription id supplied"), @ApiResponse(code = 404, message = "Entitlement not found")}) public Response uncancelSubscriptionPlan(@PathParam("subscriptionId") final UUID subscriptionId, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws EntitlementApiException { final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final Entitlement current = entitlementApi.getEntitlementForId(subscriptionId, context.createCallContextNoAccountId(createdBy, reason, comment, request)); current.uncancelEntitlement(pluginProperties, context.createCallContextNoAccountId(createdBy, reason, comment, request)); return Response.status(Status.NO_CONTENT).build(); }
@TimedResource @PUT @Path("/{subscriptionId:" + UUID_PATTERN + "}/" + UNDO_CHANGE_PLAN) @Produces(APPLICATION_JSON) @ApiOperation(value = "Undo a pending change plan on an entitlement") @ApiResponses(value = {@ApiResponse(code = 204, message = "Successful operation"), @ApiResponse(code = 400, message = "Invalid subscription id supplied"), @ApiResponse(code = 404, message = "Entitlement not found")}) public Response undoChangeSubscriptionPlan(@PathParam("subscriptionId") final UUID subscriptionId, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws EntitlementApiException { final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final Entitlement current = entitlementApi.getEntitlementForId(subscriptionId, context.createCallContextNoAccountId(createdBy, reason, comment, request)); current.undoChangePlan(pluginProperties, context.createCallContextNoAccountId(createdBy, reason, comment, request)); return Response.status(Status.NO_CONTENT).build(); }
@Override public Entitlement apply(@Nullable final Void dontcare) { try { final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(productName, billingPeriod, priceList, null); final UUID entitlementId = entitlementApi.createBaseEntitlement(accountId, new DefaultEntitlementSpecifier(spec, null, overrides), bundleExternalKey, null, billingEffectiveDate, false, true, ImmutableList.<PluginProperty>of(), callContext); assertNotNull(entitlementId); return entitlementApi.getEntitlementForId(entitlementId, callContext); } catch (final EntitlementApiException e) { fail("Unable to create entitlement", e); return null; } } }, events);
@Override public Entitlement apply(@Nullable final Void dontcare) { try { // Need to fetch again to get latest CTD updated from the system Entitlement refreshedEntitlement = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); refreshedEntitlement = refreshedEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(entitlementActionPolicy, billingActionPolicy, ImmutableList.<PluginProperty>of(), callContext); return refreshedEntitlement; } catch (final EntitlementApiException e) { fail(e.getMessage()); return null; } } }, events);
@Override public Entitlement apply(@Nullable final Void dontcare) { try { // Need to fetch again to get latest CTD updated from the system Entitlement refreshedEntitlement = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); refreshedEntitlement = refreshedEntitlement.cancelEntitlementWithDate(requestedDate, false, ImmutableList.<PluginProperty>of(), callContext); return refreshedEntitlement; } catch (final EntitlementApiException e) { fail(e.getMessage()); return null; } } }, events);
@Override public Entitlement apply(@Nullable final Void dontcare) { try { final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(productName, billingPeriod, PriceListSet.DEFAULT_PRICELIST_NAME, null); final UUID entitlementId = entitlementApi.addEntitlement(bundleId, new DefaultEntitlementSpecifier(spec), effectiveDate, effectiveDate, false, ImmutableList.<PluginProperty>of(), callContext); assertNotNull(entitlementId); return entitlementApi.getEntitlementForId(entitlementId, callContext); } catch (final EntitlementApiException e) { fail(e.getMessage()); return null; } } }, events);
protected void verifyTestResult(final UUID accountId, final UUID subscriptionId, final DateTime startDate, @Nullable final DateTime endDate, final BigDecimal amount, final DateTime chargeThroughDate, final int totalInvoiceItemCount) throws EntitlementApiException { final Entitlement entitlement = entitlementApi.getEntitlementForId(subscriptionId, callContext); final SubscriptionBase subscription = ((DefaultEntitlement) entitlement).getSubscriptionBase(); final DateTime ctd = subscription.getChargedThroughDate(); assertNotNull(ctd); log.info("Checking CTD: " + ctd.toString() + "; clock is " + clock.getUTCNow().toString()); // Either the ctd is today (start of the trial) or the clock is strictly before the CTD assertTrue(clock.getUTCToday().compareTo(new LocalDate(ctd)) == 0 || clock.getUTCNow().isBefore(ctd)); assertTrue(ctd.toDateTime(testTimeZone).toLocalDate().compareTo(new LocalDate(chargeThroughDate.getYear(), chargeThroughDate.getMonthOfYear(), chargeThroughDate.getDayOfMonth())) == 0); }
private Entitlement createEntitlement(final PlanPhaseSpecifier spec, final List<PlanPhasePriceOverride> overrides, final boolean expectPayment) throws EntitlementApiException { if (expectPayment) { busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); } else { busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE); } final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, null, overrides), UUID.randomUUID().toString(), null, null, false, true, ImmutableList.<PluginProperty>of(), testCallContext); assertListenerStatus(); return entitlementApi.getEntitlementForId(entitlementId, testCallContext); }
public void checkChargedThroughDate(final UUID entitlementId, final LocalDate expectedLocalCTD, final CallContext context) { try { final DefaultEntitlement entitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(entitlementId, context); final SubscriptionBase subscription = entitlement.getSubscriptionBase(); if (expectedLocalCTD == null) { assertNull(subscription.getChargedThroughDate()); } else { final String msg = String.format("Checking CTD for entitlement %s : expectedLocalCTD = %s, got %s", entitlementId, expectedLocalCTD, subscription.getChargedThroughDate().toLocalDate()); assertTrue(expectedLocalCTD.compareTo(subscription.getChargedThroughDate().toLocalDate()) == 0, msg); } } catch (final EntitlementApiException e) { fail("Failed to retrieve entitlement for " + entitlementId); } }
@Override public Entitlement apply(@Nullable final Void dontcare) { try { // Need to fetch again to get latest CTD updated from the system Entitlement refreshedEntitlement = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(productName, billingPeriod, priceList); if (billingPolicy == null) { refreshedEntitlement = refreshedEntitlement.changePlan(new DefaultEntitlementSpecifier(spec), ImmutableList.<PluginProperty>of(), callContext); } else { refreshedEntitlement = refreshedEntitlement.changePlanOverrideBillingPolicy(new DefaultEntitlementSpecifier(spec), null, billingPolicy, ImmutableList.<PluginProperty>of(), callContext); } return refreshedEntitlement; } catch (final EntitlementApiException e) { fail(e.getMessage()); return null; } } }, events);
private Account getAccountFromSubscriptionJson(final SubscriptionJson entitlementJson, final CallContext callContext) throws SubscriptionApiException, AccountApiException, EntitlementApiException { final UUID accountId; if (entitlementJson.getAccountId() != null) { accountId = entitlementJson.getAccountId(); } else if (entitlementJson.getSubscriptionId() != null) { final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementJson.getSubscriptionId(), callContext); accountId = entitlement.getAccountId(); } else { final SubscriptionBundle subscriptionBundle = subscriptionApi.getSubscriptionBundle(entitlementJson.getBundleId(), callContext); accountId = subscriptionBundle.getAccountId(); } return accountUserApi.getAccountById(accountId, callContext); } }
@Test(groups = "slow") public void testCreateBaseWithBillingInThePast() throws AccountApiException, EntitlementApiException, SubscriptionApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final LocalDate entitlementDate = null; final LocalDate billingDate = initialDate.minusDays(5); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CREATE); final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), entitlementDate, billingDate, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getState(), EntitlementState.ACTIVE); assertEquals(entitlement.getEffectiveStartDate(), initialDate); }
@Test(groups = "slow") public void testCreateBaseWithEntitlementInThePast() throws AccountApiException, EntitlementApiException, SubscriptionApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final LocalDate entitlementDate = initialDate.minusDays(3); final LocalDate billingDate = null; final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CREATE); final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), entitlementDate, billingDate, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getState(), EntitlementState.ACTIVE); assertEquals(entitlement.getEffectiveStartDate(), entitlementDate); }
@Test(groups = "slow") public void testCreateBaseWithDifferentInThePast() throws AccountApiException, EntitlementApiException, SubscriptionApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final LocalDate entitlementDate = initialDate.minusDays(3); final LocalDate billingDate = initialDate.minusDays(5); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CREATE); final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), entitlementDate, billingDate, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getState(), EntitlementState.ACTIVE); assertEquals(entitlement.getEffectiveStartDate(), entitlementDate); }
@Test(groups = "slow") public void testCancelFutureSubscription() throws AccountApiException, EntitlementApiException, SubscriptionApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, null); final LocalDate futureDate = new LocalDate(2013, 9, 1); // No CREATE event as this is set in the future final UUID createdEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), futureDate, futureDate, false, true, ImmutableList.<PluginProperty>of(), callContext); final Entitlement createdEntitlement = entitlementApi.getEntitlementForId(createdEntitlementId, callContext); assertEquals(createdEntitlement.getEffectiveStartDate().compareTo(futureDate), 0); assertEquals(createdEntitlement.getEffectiveEndDate(), null); final Entitlement baseEntitlement = entitlementApi.getEntitlementForId(createdEntitlement.getId(), callContext); assertEquals(baseEntitlement.getEffectiveStartDate().compareTo(futureDate), 0); assertEquals(baseEntitlement.getEffectiveEndDate(), null); final Entitlement cancelledEntitlement = baseEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(EntitlementActionPolicy.IMMEDIATE, BillingActionPolicy.IMMEDIATE, null, callContext); assertEquals(cancelledEntitlement.getEffectiveEndDate().compareTo(futureDate), 0); final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(cancelledEntitlement.getId(), callContext); assertEquals(subscription.getEffectiveEndDate().compareTo(futureDate), 0); assertListenerStatus(); }
@Test(groups = "slow") public void testCreateBaseWithEntitlementInTheFuture() throws AccountApiException, EntitlementApiException, SubscriptionApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final LocalDate entitlementDate = initialDate.plusDays(3); final LocalDate billingDate = null; final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); testListener.pushExpectedEvents(NextEvent.CREATE); final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), entitlementDate, billingDate, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getState(), EntitlementState.PENDING); assertEquals(entitlement.getEffectiveStartDate(), entitlementDate); testListener.pushExpectedEvents(NextEvent.BLOCK); clock.addDays(3); assertListenerStatus(); final Entitlement entitlementActive = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); assertEquals(entitlementActive.getState(), EntitlementState.ACTIVE); }
@Test(groups = "slow") public void testCancelWithEntitlementPolicyEOTAndNOCTD() throws AccountApiException, EntitlementApiException, SubscriptionApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); // Create entitlement and check each field testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK); final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK); final Entitlement cancelledEntitlement = entitlement.cancelEntitlementWithPolicy(EntitlementActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); assertEquals(cancelledEntitlement.getState(), EntitlementState.CANCELLED); assertEquals(cancelledEntitlement.getEffectiveEndDate(), initialDate); // Entitlement started in trial on 2013-08-07, which is when we want the billing cancellation to occur final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(entitlement.getBaseEntitlementId(), callContext); assertEquals(subscription.getBillingEndDate(), new LocalDate(2013, 8, 7)); }
@Test(groups = "slow") public void testCreateBaseWithBillingInTheFuture() throws AccountApiException, EntitlementApiException, SubscriptionApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final LocalDate entitlementDate = null; final LocalDate billingDate = initialDate.plusDays(5); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); testListener.pushExpectedEvents(NextEvent.BLOCK); final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), entitlementDate, billingDate, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getState(), EntitlementState.ACTIVE); assertEquals(entitlement.getEffectiveStartDate(), initialDate); testListener.pushExpectedEvents(NextEvent.CREATE); clock.addDays(5); assertListenerStatus(); }
@Test(groups = "slow") public void testCancelSubscriptionInTrialWith_START_OF_TERM() throws Exception { final LocalDate initialDate = new LocalDate(2015, 9, 1); clock.setDay(initialDate); final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1)); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, null); busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE); final UUID createdEntitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), initialDate, initialDate, false, true, ImmutableList.<PluginProperty>of(), callContext); final Entitlement createdEntitlement = entitlementApi.getEntitlementForId(createdEntitlementId, callContext); assertEquals(createdEntitlement.getEffectiveStartDate().compareTo(initialDate), 0); assertEquals(createdEntitlement.getEffectiveEndDate(), null); assertListenerStatus(); // Move clock a bit to make sure START_OF_TERM brings us back to initialDate clock.addDays(5); busHandler.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK, NextEvent.NULL_INVOICE); final Entitlement cancelledEntitlement = createdEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(EntitlementActionPolicy.IMMEDIATE, BillingActionPolicy.START_OF_TERM, null, callContext); assertListenerStatus(); final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(cancelledEntitlement.getId(), callContext); assertEquals(subscription.getEffectiveEndDate().compareTo(new LocalDate(2015, 9, 6)), 0); assertEquals(subscription.getBillingEndDate().compareTo(initialDate), 0); }