Details
diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/SubscriptionJson.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/SubscriptionJson.java
index 40f4e42..ffda798 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/SubscriptionJson.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/SubscriptionJson.java
@@ -31,12 +31,17 @@ import org.killbill.billing.ObjectType;
import org.killbill.billing.catalog.api.BillingPeriod;
import org.killbill.billing.catalog.api.CatalogApiException;
import org.killbill.billing.catalog.api.Currency;
+import org.killbill.billing.catalog.api.PhaseType;
import org.killbill.billing.catalog.api.Plan;
import org.killbill.billing.catalog.api.PlanPhase;
import org.killbill.billing.catalog.api.PriceList;
import org.killbill.billing.catalog.api.Product;
+import org.killbill.billing.catalog.api.ProductCategory;
+import org.killbill.billing.entitlement.api.Entitlement.EntitlementSourceType;
+import org.killbill.billing.entitlement.api.Entitlement.EntitlementState;
import org.killbill.billing.entitlement.api.Subscription;
import org.killbill.billing.entitlement.api.SubscriptionEvent;
+import org.killbill.billing.entitlement.api.SubscriptionEventType;
import org.killbill.billing.util.audit.AccountAuditLogs;
import org.killbill.billing.util.audit.AuditLog;
@@ -55,22 +60,16 @@ public class SubscriptionJson extends JsonBase {
private final LocalDate startDate;
@ApiModelProperty(required = true)
private final String productName;
- @ApiModelProperty(dataType = "org.killbill.billing.catalog.api.ProductCategory", required = true)
- private final String productCategory;
- @ApiModelProperty(dataType = "org.killbill.billing.catalog.api.BillingPeriod", required = true)
- private final String billingPeriod;
- @ApiModelProperty(dataType = "org.killbill.billing.catalog.api.PhaseType")
- private final String phaseType;
+ private final ProductCategory productCategory;
+ @ApiModelProperty(required = true)
+ private final BillingPeriod billingPeriod;
+ private final PhaseType phaseType;
@ApiModelProperty(required = true)
private final String priceList;
@ApiModelProperty(required = true)
private final String planName;
- //@ApiModelProperty(dataType = "org.killbill.billing.entitlement.api.Entitlement.EntitlementState")
- @ApiModelProperty(dataType = "string", allowableValues = "PENDING,ACTIVE,BLOCKED,CANCELLED")
- private final String state;
- //@ApiModelProperty(dataType = "org.killbill.billing.entitlement.api.Entitlement.EntitlementSourceType")
- @ApiModelProperty(dataType = "string", allowableValues = "NATIVE,MIGRATED,TRANSFERRED")
- private final String sourceType;
+ private final EntitlementState state;
+ private final EntitlementSourceType sourceType;
private final LocalDate cancelledDate;
private final LocalDate chargedThroughDate;
private final LocalDate billingStartDate;
@@ -83,14 +82,13 @@ public class SubscriptionJson extends JsonBase {
public static class EventSubscriptionJson extends JsonBase {
private final UUID eventId;
- private final String billingPeriod;
+ private final BillingPeriod billingPeriod;
private final LocalDate effectiveDate;
private final String plan;
private final String product;
private final String priceList;
private final String phase;
- @ApiModelProperty(dataType = "org.killbill.billing.entitlement.api.SubscriptionEventType")
- private final String eventType;
+ private final SubscriptionEventType eventType;
private final Boolean isBlockedBilling;
private final Boolean isBlockedEntitlement;
private final String serviceName;
@@ -98,12 +96,12 @@ public class SubscriptionJson extends JsonBase {
@JsonCreator
public EventSubscriptionJson(@JsonProperty("eventId") final UUID eventId,
- @JsonProperty("billingPeriod") final String billingPeriod,
+ @JsonProperty("billingPeriod") final BillingPeriod billingPeriod,
@JsonProperty("effectiveDate") final LocalDate effectiveDate,
@JsonProperty("plan") final String plan,
@JsonProperty("product") final String product,
@JsonProperty("priceList") final String priceList,
- @JsonProperty("eventType") final String eventType,
+ @JsonProperty("eventType") final SubscriptionEventType eventType,
@JsonProperty("isBlockedBilling") final Boolean isBlockedBilling,
@JsonProperty("isBlockedEntitlement") final Boolean isBlockedEntitlement,
@JsonProperty("serviceName") final String serviceName,
@@ -134,12 +132,12 @@ public class SubscriptionJson extends JsonBase {
final PriceList priceList = subscriptionEvent.getNextPriceList() != null ? subscriptionEvent.getNextPriceList() : subscriptionEvent.getPrevPriceList();
final PlanPhase phase = subscriptionEvent.getNextPhase() != null ? subscriptionEvent.getNextPhase() : subscriptionEvent.getPrevPhase();
this.eventId = subscriptionEvent.getId();
- this.billingPeriod = billingPeriod != null ? billingPeriod.toString() : null;
+ this.billingPeriod = billingPeriod;
this.effectiveDate = subscriptionEvent.getEffectiveDate();
this.plan = plan != null ? plan.getName() : null;
this.product = product != null ? product.getName() : null;
this.priceList = priceList != null ? priceList.getName() : null;
- this.eventType = subscriptionEvent.getSubscriptionEventType().toString();
+ this.eventType = subscriptionEvent.getSubscriptionEventType();
this.isBlockedBilling = subscriptionEvent.isBlockedBilling();
this.isBlockedEntitlement = subscriptionEvent.isBlockedEntitlement();
this.serviceName = subscriptionEvent.getServiceName();
@@ -165,7 +163,7 @@ public class SubscriptionJson extends JsonBase {
return eventId;
}
- public String getBillingPeriod() {
+ public BillingPeriod getBillingPeriod() {
return billingPeriod;
}
@@ -185,7 +183,7 @@ public class SubscriptionJson extends JsonBase {
return priceList;
}
- public String getEventType() {
+ public SubscriptionEventType getEventType() {
return eventType;
}
@@ -304,13 +302,13 @@ public class SubscriptionJson extends JsonBase {
@JsonProperty("externalKey") @Nullable final String externalKey,
@JsonProperty("startDate") @Nullable final LocalDate startDate,
@JsonProperty("productName") @Nullable final String productName,
- @JsonProperty("productCategory") @Nullable final String productCategory,
- @JsonProperty("billingPeriod") @Nullable final String billingPeriod,
- @JsonProperty("phaseType") @Nullable final String phaseType,
+ @JsonProperty("productCategory") @Nullable final ProductCategory productCategory,
+ @JsonProperty("billingPeriod") @Nullable final BillingPeriod billingPeriod,
+ @JsonProperty("phaseType") @Nullable final PhaseType phaseType,
@JsonProperty("priceList") @Nullable final String priceList,
@JsonProperty("planName") @Nullable final String planName,
- @JsonProperty("state") @Nullable final String state,
- @JsonProperty("sourceType") @Nullable final String sourceType,
+ @JsonProperty("state") @Nullable final EntitlementState state,
+ @JsonProperty("sourceType") @Nullable final EntitlementSourceType sourceType,
@JsonProperty("cancelledDate") @Nullable final LocalDate cancelledDate,
@JsonProperty("chargedThroughDate") @Nullable final LocalDate chargedThroughDate,
@JsonProperty("billingStartDate") @Nullable final LocalDate billingStartDate,
@@ -355,19 +353,19 @@ public class SubscriptionJson extends JsonBase {
this.productName = subscription.getLastActiveProduct().getName();
}
if (subscription.getLastActiveProductCategory() == null) {
- this.productCategory = (firstEvent == null || firstEvent.getNextProduct() == null) ? null : firstEvent.getNextProduct().getCategory().name();
+ this.productCategory = (firstEvent == null || firstEvent.getNextProduct() == null) ? null : firstEvent.getNextProduct().getCategory();
} else {
- this.productCategory = subscription.getLastActiveProductCategory().name();
+ this.productCategory = subscription.getLastActiveProductCategory();
}
if (subscription.getLastActivePlan() == null) {
- this.billingPeriod = (firstEvent == null || firstEvent.getNextPlan() == null) ? null : firstEvent.getNextPlan().getRecurringBillingPeriod().name();
+ this.billingPeriod = (firstEvent == null || firstEvent.getNextPlan() == null) ? null : firstEvent.getNextPlan().getRecurringBillingPeriod();
} else {
- this.billingPeriod = subscription.getLastActivePlan().getRecurringBillingPeriod().toString();
+ this.billingPeriod = subscription.getLastActivePlan().getRecurringBillingPeriod();
}
if (subscription.getLastActivePhase() == null) {
- this.phaseType = (firstEvent == null || firstEvent.getNextPhase() == null) ? null : firstEvent.getNextPhase().getPhaseType().name();
+ this.phaseType = (firstEvent == null || firstEvent.getNextPhase() == null) ? null : firstEvent.getNextPhase().getPhaseType();
} else {
- this.phaseType = subscription.getLastActivePhase().getPhaseType().toString();
+ this.phaseType = subscription.getLastActivePhase().getPhaseType();
}
if (subscription.getLastActivePriceList() == null) {
this.priceList = (firstEvent == null || firstEvent.getNextPriceList() == null) ? null : firstEvent.getNextPriceList().getName();
@@ -381,8 +379,8 @@ public class SubscriptionJson extends JsonBase {
}
- this.state = subscription.getState().name();
- this.sourceType = subscription.getSourceType().name();
+ this.state = subscription.getState();
+ this.sourceType = subscription.getSourceType();
this.cancelledDate = subscription.getEffectiveEndDate();
this.chargedThroughDate = subscription.getChargedThroughDate();
this.billingStartDate = subscription.getBillingStartDate();
@@ -445,15 +443,15 @@ public class SubscriptionJson extends JsonBase {
return productName;
}
- public String getProductCategory() {
+ public ProductCategory getProductCategory() {
return productCategory;
}
- public String getBillingPeriod() {
+ public BillingPeriod getBillingPeriod() {
return billingPeriod;
}
- public String getPhaseType() {
+ public PhaseType getPhaseType() {
return phaseType;
}
@@ -465,11 +463,11 @@ public class SubscriptionJson extends JsonBase {
return planName;
}
- public String getState() {
+ public EntitlementState getState() {
return state;
}
- public String getSourceType() {
+ public EntitlementSourceType getSourceType() {
return sourceType;
}
diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/SubscriptionResource.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/SubscriptionResource.java
index f13e34e..5885f9d 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/SubscriptionResource.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/SubscriptionResource.java
@@ -152,9 +152,9 @@ public class SubscriptionResource extends JaxRsResourceBase {
@ApiOperation(value = "Retrieve a subscription by id", response = SubscriptionJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid subscription id supplied"),
@ApiResponse(code = 404, message = "Subscription not found")})
- public Response getEntitlement(@PathParam("subscriptionId") final UUID subscriptionId,
- @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode,
- @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, AccountApiException, CatalogApiException {
+ public Response getSubscription(@PathParam("subscriptionId") final UUID subscriptionId,
+ @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode,
+ @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, AccountApiException, CatalogApiException {
final TenantContext context = this.context.createTenantContextNoAccountId(request);
final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(subscriptionId, context);
final Account account = accountUserApi.getAccountById(subscription.getAccountId(), context);
@@ -167,37 +167,37 @@ public class SubscriptionResource extends JaxRsResourceBase {
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
- @ApiOperation(value = "Create an entitlement", response = SubscriptionJson.class)
- @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid entitlement supplied")})
- public Response createEntitlement(final SubscriptionJson entitlement,
- @ApiParam(hidden = true) @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, /* This is deprecated, only used for backward compatibility */
+ @ApiOperation(value = "Create an subscription", response = SubscriptionJson.class)
+ @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid subscription supplied")})
+ public Response createSubscription(final SubscriptionJson subscription,
+ @ApiParam(hidden = true) @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, /* This is deprecated, only used for backward compatibility */
@QueryParam(QUERY_ENTITLEMENT_REQUESTED_DT) final String entitlementDate,
- @QueryParam(QUERY_BILLING_REQUESTED_DT) final String billingDate,
- @QueryParam(QUERY_BUNDLES_RENAME_KEY_IF_EXIST_UNUSED) @DefaultValue("true") final Boolean renameKeyIfExistsAndUnused,
- @QueryParam(QUERY_MIGRATED) @DefaultValue("false") final Boolean isMigrated,
- @QueryParam(QUERY_BCD) final Integer newBCD,
- @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
- @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec,
- @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 EntitlementApiException, AccountApiException, SubscriptionApiException {
- verifyNonNullOrEmpty(entitlement, "SubscriptionJson body should be specified");
- if (entitlement.getPlanName() == null) {
- verifyNonNullOrEmpty(entitlement.getProductName(), "SubscriptionJson productName needs to be set",
- entitlement.getProductCategory(), "SubscriptionJson productCategory needs to be set",
- entitlement.getBillingPeriod(), "SubscriptionJson billingPeriod needs to be set",
- entitlement.getPriceList(), "SubscriptionJson priceList needs to be set");
+ @QueryParam(QUERY_BILLING_REQUESTED_DT) final String billingDate,
+ @QueryParam(QUERY_BUNDLES_RENAME_KEY_IF_EXIST_UNUSED) @DefaultValue("true") final Boolean renameKeyIfExistsAndUnused,
+ @QueryParam(QUERY_MIGRATED) @DefaultValue("false") final Boolean isMigrated,
+ @QueryParam(QUERY_BCD) final Integer newBCD,
+ @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
+ @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec,
+ @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 EntitlementApiException, AccountApiException, SubscriptionApiException {
+ verifyNonNullOrEmpty(subscription, "SubscriptionJson body should be specified");
+ if (subscription.getPlanName() == null) {
+ verifyNonNullOrEmpty(subscription.getProductName(), "SubscriptionJson productName needs to be set",
+ subscription.getProductCategory(), "SubscriptionJson productCategory needs to be set",
+ subscription.getBillingPeriod(), "SubscriptionJson billingPeriod needs to be set",
+ subscription.getPriceList(), "SubscriptionJson priceList needs to be set");
}
logDeprecationParameterWarningIfNeeded(QUERY_REQUESTED_DT, QUERY_ENTITLEMENT_REQUESTED_DT, QUERY_BILLING_REQUESTED_DT);
// For ADD_ON we can provide externalKey or the bundleId
- final boolean createAddOnEntitlement = ProductCategory.ADD_ON.toString().equals(entitlement.getProductCategory());
+ final boolean createAddOnEntitlement = ProductCategory.ADD_ON.toString().equals(subscription.getProductCategory());
if (createAddOnEntitlement) {
- Preconditions.checkArgument(entitlement.getExternalKey() != null || entitlement.getBundleId() != null, "SubscriptionJson bundleId or externalKey should be specified for ADD_ON");
+ Preconditions.checkArgument(subscription.getExternalKey() != null || subscription.getBundleId() != null, "SubscriptionJson bundleId or externalKey should be specified for ADD_ON");
}
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
@@ -207,19 +207,19 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Override
public Entitlement doOperation(final CallContext ctx) throws InterruptedException, TimeoutException, EntitlementApiException, SubscriptionApiException, AccountApiException {
- final Account account = getAccountFromSubscriptionJson(entitlement, callContext);
- final PhaseType phaseType = entitlement.getPhaseType() != null ? PhaseType.valueOf(entitlement.getPhaseType()) : null;
- final PlanPhaseSpecifier spec = entitlement.getPlanName() != null ?
- new PlanPhaseSpecifier(entitlement.getPlanName(), phaseType) :
- new PlanPhaseSpecifier(entitlement.getProductName(),
- BillingPeriod.valueOf(entitlement.getBillingPeriod()), entitlement.getPriceList(), phaseType);
+ final Account account = getAccountFromSubscriptionJson(subscription, callContext);
+ final PhaseType phaseType = subscription.getPhaseType();
+ final PlanPhaseSpecifier spec = subscription.getPlanName() != null ?
+ new PlanPhaseSpecifier(subscription.getPlanName(), phaseType) :
+ new PlanPhaseSpecifier(subscription.getProductName(),
+ subscription.getBillingPeriod(), subscription.getPriceList(), phaseType);
final LocalDate resolvedEntitlementDate = requestedDate != null ? toLocalDate(requestedDate) : toLocalDate(entitlementDate);
final LocalDate resolvedBillingDate = requestedDate != null ? toLocalDate(requestedDate) : toLocalDate(billingDate);
- final List<PlanPhasePriceOverride> overrides = PhasePriceOverrideJson.toPlanPhasePriceOverrides(entitlement.getPriceOverrides(), spec, account.getCurrency());
+ final List<PlanPhasePriceOverride> overrides = PhasePriceOverrideJson.toPlanPhasePriceOverrides(subscription.getPriceOverrides(), spec, account.getCurrency());
final Entitlement result = createAddOnEntitlement ?
- entitlementApi.addEntitlement(getBundleIdForAddOnCreation(entitlement), spec, overrides, resolvedEntitlementDate, resolvedBillingDate, isMigrated, pluginProperties, callContext) :
- entitlementApi.createBaseEntitlement(account.getId(), spec, entitlement.getExternalKey(), overrides, resolvedEntitlementDate, resolvedBillingDate, isMigrated, renameKeyIfExistsAndUnused, pluginProperties, callContext);
+ entitlementApi.addEntitlement(getBundleIdForAddOnCreation(subscription), spec, overrides, resolvedEntitlementDate, resolvedBillingDate, isMigrated, pluginProperties, callContext) :
+ entitlementApi.createBaseEntitlement(account.getId(), spec, subscription.getExternalKey(), overrides, resolvedEntitlementDate, resolvedBillingDate, isMigrated, renameKeyIfExistsAndUnused, pluginProperties, callContext);
if (newBCD != null) {
result.updateBCD(newBCD, null, callContext);
}
@@ -243,7 +243,7 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Override
public Response doResponseOk(final Entitlement createdEntitlement) {
- return uriBuilder.buildResponse(uriInfo, SubscriptionResource.class, "getEntitlement", createdEntitlement.getId(), request);
+ return uriBuilder.buildResponse(uriInfo, SubscriptionResource.class, "getSubscription", createdEntitlement.getId(), request);
}
};
@@ -253,42 +253,17 @@ public class SubscriptionResource extends JaxRsResourceBase {
@TimedResource
@POST
- @Path("/createEntitlementWithAddOns")
+ @Path("/createSubscriptionWithAddOns")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Create an entitlement with addOn products", response = BundleJson.class)
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid entitlement supplied")})
- public Response createEntitlementWithAddOns(final List<SubscriptionJson> entitlements,
- @ApiParam(hidden = true) @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, /* This is deprecated, only used for backward compatibility */
- @QueryParam(QUERY_ENTITLEMENT_REQUESTED_DT) final String entitlementDate,
- @QueryParam(QUERY_BILLING_REQUESTED_DT) final String billingDate,
- @QueryParam(QUERY_MIGRATED) @DefaultValue("false") final Boolean isMigrated,
- @QueryParam(QUERY_BUNDLES_RENAME_KEY_IF_EXIST_UNUSED) @DefaultValue("true") final Boolean renameKeyIfExistsAndUnused,
- @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
- @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec,
- @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 EntitlementApiException, AccountApiException, SubscriptionApiException {
- final List<BulkSubscriptionsBundleJson> entitlementsWithAddOns = ImmutableList.of(new BulkSubscriptionsBundleJson(entitlements));
- return createEntitlementsWithAddOnsInternal(entitlementsWithAddOns, requestedDate, entitlementDate, billingDate, isMigrated, renameKeyIfExistsAndUnused, callCompletion, timeoutSec, pluginPropertiesString, createdBy, reason, comment, request, uriInfo, ObjectType.BUNDLE);
- }
-
- @TimedResource
- @POST
- @Path("/createEntitlementsWithAddOns")
- @Consumes(APPLICATION_JSON)
- @Produces(APPLICATION_JSON)
- @ApiOperation(value = "Create multiple entitlements with addOn products", response = BundleJson.class, responseContainer = "List")
- @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid entitlements supplied")})
- public Response createEntitlementsWithAddOns(final List<BulkSubscriptionsBundleJson> entitlementsWithAddOns,
+ public Response createSubscriptionWithAddOns(final List<SubscriptionJson> entitlements,
@ApiParam(hidden = true) @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, /* This is deprecated, only used for backward compatibility */
- @QueryParam(QUERY_ENTITLEMENT_REQUESTED_DT) final String entitlementDate,
+ @QueryParam(QUERY_ENTITLEMENT_REQUESTED_DT) final String entitlementDate,
@QueryParam(QUERY_BILLING_REQUESTED_DT) final String billingDate,
- @QueryParam(QUERY_BUNDLES_RENAME_KEY_IF_EXIST_UNUSED) @DefaultValue("true") final Boolean renameKeyIfExistsAndUnused,
@QueryParam(QUERY_MIGRATED) @DefaultValue("false") final Boolean isMigrated,
+ @QueryParam(QUERY_BUNDLES_RENAME_KEY_IF_EXIST_UNUSED) @DefaultValue("true") final Boolean renameKeyIfExistsAndUnused,
@QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
@QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec,
@QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString,
@@ -297,23 +272,48 @@ public class SubscriptionResource extends JaxRsResourceBase {
@HeaderParam(HDR_COMMENT) final String comment,
@javax.ws.rs.core.Context final HttpServletRequest request,
@javax.ws.rs.core.Context final UriInfo uriInfo) throws EntitlementApiException, AccountApiException, SubscriptionApiException {
- return createEntitlementsWithAddOnsInternal(entitlementsWithAddOns, requestedDate, entitlementDate, billingDate, isMigrated, renameKeyIfExistsAndUnused, callCompletion, timeoutSec, pluginPropertiesString, createdBy, reason, comment, request, uriInfo, ObjectType.ACCOUNT);
+ final List<BulkSubscriptionsBundleJson> entitlementsWithAddOns = ImmutableList.of(new BulkSubscriptionsBundleJson(entitlements));
+ return createSubscriptionsWithAddOnsInternal(entitlementsWithAddOns, requestedDate, entitlementDate, billingDate, isMigrated, renameKeyIfExistsAndUnused, callCompletion, timeoutSec, pluginPropertiesString, createdBy, reason, comment, request, uriInfo, ObjectType.BUNDLE);
}
- public Response createEntitlementsWithAddOnsInternal(final List<BulkSubscriptionsBundleJson> entitlementsWithAddOns,
- final String requestedDate,
- final String entitlementDate,
- final String billingDate,
- final Boolean isMigrated,
- final Boolean renameKeyIfExistsAndUnused,
- final Boolean callCompletion,
- final long timeoutSec,
- final List<String> pluginPropertiesString,
- final String createdBy,
- final String reason,
- final String comment,
- final HttpServletRequest request,
- final UriInfo uriInfo, final ObjectType responseObject) throws EntitlementApiException, AccountApiException, SubscriptionApiException {
+ @TimedResource
+ @POST
+ @Path("/createSubscriptionsWithAddOns")
+ @Consumes(APPLICATION_JSON)
+ @Produces(APPLICATION_JSON)
+ @ApiOperation(value = "Create multiple entitlements with addOn products", response = BundleJson.class, responseContainer = "List")
+ @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid entitlements supplied")})
+ public Response createSubscriptionsWithAddOns(final List<BulkSubscriptionsBundleJson> entitlementsWithAddOns,
+ @ApiParam(hidden = true) @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, /* This is deprecated, only used for backward compatibility */
+ @QueryParam(QUERY_ENTITLEMENT_REQUESTED_DT) final String entitlementDate,
+ @QueryParam(QUERY_BILLING_REQUESTED_DT) final String billingDate,
+ @QueryParam(QUERY_BUNDLES_RENAME_KEY_IF_EXIST_UNUSED) @DefaultValue("true") final Boolean renameKeyIfExistsAndUnused,
+ @QueryParam(QUERY_MIGRATED) @DefaultValue("false") final Boolean isMigrated,
+ @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
+ @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec,
+ @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 EntitlementApiException, AccountApiException, SubscriptionApiException {
+ return createSubscriptionsWithAddOnsInternal(entitlementsWithAddOns, requestedDate, entitlementDate, billingDate, isMigrated, renameKeyIfExistsAndUnused, callCompletion, timeoutSec, pluginPropertiesString, createdBy, reason, comment, request, uriInfo, ObjectType.ACCOUNT);
+ }
+
+ public Response createSubscriptionsWithAddOnsInternal(final List<BulkSubscriptionsBundleJson> entitlementsWithAddOns,
+ final String requestedDate,
+ final String entitlementDate,
+ final String billingDate,
+ final Boolean isMigrated,
+ final Boolean renameKeyIfExistsAndUnused,
+ final Boolean callCompletion,
+ final long timeoutSec,
+ final List<String> pluginPropertiesString,
+ final String createdBy,
+ final String reason,
+ final String comment,
+ final HttpServletRequest request,
+ final UriInfo uriInfo, final ObjectType responseObject) throws EntitlementApiException, AccountApiException, SubscriptionApiException {
Preconditions.checkArgument(Iterables.size(entitlementsWithAddOns) > 0, "Subscription bulk list mustn't be null or empty.");
@@ -330,7 +330,7 @@ public class SubscriptionResource extends JaxRsResourceBase {
bulkBaseEntitlementWithAddOns.getBaseEntitlementAndAddOns(), new Predicate<SubscriptionJson>() {
@Override
public boolean apply(final SubscriptionJson subscription) {
- return ProductCategory.BASE.toString().equalsIgnoreCase(subscription.getProductCategory());
+ return ProductCategory.BASE.equals(subscription.getProductCategory());
}
});
Preconditions.checkArgument(Iterables.size(baseEntitlements) > 0, "SubscriptionJson Base Entitlement needs to be provided");
@@ -341,7 +341,7 @@ public class SubscriptionResource extends JaxRsResourceBase {
bulkBaseEntitlementWithAddOns.getBaseEntitlementAndAddOns(), new Predicate<SubscriptionJson>() {
@Override
public boolean apply(final SubscriptionJson subscription) {
- return ProductCategory.ADD_ON.toString().equalsIgnoreCase(subscription.getProductCategory());
+ return ProductCategory.ADD_ON.equals(subscription.getProductCategory());
}
}
);
@@ -396,7 +396,7 @@ public class SubscriptionResource extends JaxRsResourceBase {
final PlanPhaseSpecifier planPhaseSpecifier = baseEntitlement.getPlanName() != null ?
new PlanPhaseSpecifier(baseEntitlement.getPlanName(), null) :
new PlanPhaseSpecifier(baseEntitlement.getProductName(),
- BillingPeriod.valueOf(baseEntitlement.getBillingPeriod()), baseEntitlement.getPriceList(), null);
+ baseEntitlement.getBillingPeriod(), baseEntitlement.getPriceList(), null);
final List<PlanPhasePriceOverride> overrides = PhasePriceOverrideJson.toPlanPhasePriceOverrides(baseEntitlement.getPriceOverrides(), planPhaseSpecifier, currency);
EntitlementSpecifier specifier = new EntitlementSpecifier() {
@@ -426,7 +426,7 @@ public class SubscriptionResource extends JaxRsResourceBase {
final PlanPhaseSpecifier planPhaseSpecifier = entitlement.getPlanName() != null ?
new PlanPhaseSpecifier(entitlement.getPlanName(), null) :
new PlanPhaseSpecifier(entitlement.getProductName(),
- BillingPeriod.valueOf(entitlement.getBillingPeriod()), entitlement.getPriceList(), null);
+ entitlement.getBillingPeriod(), entitlement.getPriceList(), null);
final List<PlanPhasePriceOverride> overrides = PhasePriceOverrideJson.toPlanPhasePriceOverrides(entitlement.getPriceOverrides(), planPhaseSpecifier, currency);
EntitlementSpecifier specifier = new EntitlementSpecifier() {
@@ -510,12 +510,12 @@ public class SubscriptionResource extends JaxRsResourceBase {
@ApiOperation(value = "Un-cancel an entitlement")
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid subscription id supplied"),
@ApiResponse(code = 404, message = "Entitlement not found")})
- public Response uncancelEntitlementPlan(@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 {
+ 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));
@@ -529,12 +529,12 @@ public class SubscriptionResource extends JaxRsResourceBase {
@ApiOperation(value = "Undo a pending change plan on an entitlement")
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid subscription id supplied"),
@ApiResponse(code = 404, message = "Entitlement not found")})
- public Response undoChangeEntitlementPlan(@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 {
+ 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));
@@ -549,17 +549,17 @@ public class SubscriptionResource extends JaxRsResourceBase {
@ApiOperation(value = "Change entitlement plan")
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid subscription id supplied"),
@ApiResponse(code = 404, message = "Entitlement not found")})
- public Response changeEntitlementPlan(final SubscriptionJson entitlement,
- @PathParam("subscriptionId") final UUID subscriptionId,
- @QueryParam(QUERY_REQUESTED_DT) final String requestedDate,
- @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
- @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec,
- @QueryParam(QUERY_BILLING_POLICY) final BillingActionPolicy billingPolicy,
- @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, AccountApiException, SubscriptionApiException {
+ public Response changeSubscriptionPlan(final SubscriptionJson entitlement,
+ @PathParam("subscriptionId") final UUID subscriptionId,
+ @QueryParam(QUERY_REQUESTED_DT) final String requestedDate,
+ @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
+ @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec,
+ @QueryParam(QUERY_BILLING_POLICY) final BillingActionPolicy billingPolicy,
+ @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, AccountApiException, SubscriptionApiException {
verifyNonNullOrEmpty(entitlement, "SubscriptionJson body should be specified");
if (entitlement.getPlanName() == null) {
verifyNonNullOrEmpty(entitlement.getProductName(), "SubscriptionJson productName needs to be set",
@@ -583,11 +583,11 @@ public class SubscriptionResource extends JaxRsResourceBase {
final Entitlement newEntitlement;
final Account account = accountUserApi.getAccountById(current.getAccountId(), callContext);
- final PhaseType phaseType = entitlement.getPhaseType() != null ? PhaseType.valueOf(entitlement.getPhaseType()) : null;
+ final PhaseType phaseType = entitlement.getPhaseType();
final PlanPhaseSpecifier planSpec = entitlement.getPlanName() != null ?
new PlanPhaseSpecifier(entitlement.getPlanName(), phaseType) :
new PlanPhaseSpecifier(entitlement.getProductName(),
- BillingPeriod.valueOf(entitlement.getBillingPeriod()), entitlement.getPriceList(), phaseType);
+ entitlement.getBillingPeriod(), entitlement.getPriceList(), phaseType);
final List<PlanPhasePriceOverride> overrides = PhasePriceOverrideJson.toPlanPhasePriceOverrides(entitlement.getPriceOverrides(), planSpec, account.getCurrency());
if (requestedDate == null && billingPolicy == null) {
@@ -598,7 +598,7 @@ public class SubscriptionResource extends JaxRsResourceBase {
newEntitlement = current.changePlanOverrideBillingPolicy(planSpec, overrides, null, billingPolicy, pluginProperties, ctx);
}
isImmediateOp = newEntitlement.getLastActiveProduct().getName().equals(entitlement.getProductName()) &&
- newEntitlement.getLastActivePlan().getRecurringBillingPeriod() == BillingPeriod.valueOf(entitlement.getBillingPeriod()) &&
+ newEntitlement.getLastActivePlan().getRecurringBillingPeriod() == entitlement.getBillingPeriod() &&
newEntitlement.getLastActivePriceList().getName().equals(entitlement.getPriceList());
return Response.status(Status.OK).build();
}
@@ -613,7 +613,7 @@ public class SubscriptionResource extends JaxRsResourceBase {
if (operationResponse.getStatus() != Status.OK.getStatusCode()) {
return operationResponse;
}
- return getEntitlement(subscriptionId, new AuditMode(AuditLevel.NONE.toString()), request);
+ return getSubscription(subscriptionId, new AuditMode(AuditLevel.NONE.toString()), request);
}
};
@@ -647,19 +647,19 @@ public class SubscriptionResource extends JaxRsResourceBase {
@ApiOperation(value = "Cancel an entitlement plan")
@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid subscription id supplied"),
@ApiResponse(code = 404, message = "Entitlement not found")})
- public Response cancelEntitlementPlan(@PathParam("subscriptionId") final UUID subscriptionId,
- @QueryParam(QUERY_REQUESTED_DT) final String requestedDate,
- @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
- @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("5") final long timeoutSec,
- @QueryParam(QUERY_ENTITLEMENT_POLICY) final EntitlementActionPolicy entitlementPolicy,
- @QueryParam(QUERY_BILLING_POLICY) final BillingActionPolicy billingPolicy,
- @QueryParam(QUERY_USE_REQUESTED_DATE_FOR_BILLING) @DefaultValue("false") final Boolean useRequestedDateForBilling,
- @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 UriInfo uriInfo,
- @javax.ws.rs.core.Context final HttpServletRequest request) throws EntitlementApiException, AccountApiException, SubscriptionApiException {
+ public Response cancelSubscriptionPlan(@PathParam("subscriptionId") final UUID subscriptionId,
+ @QueryParam(QUERY_REQUESTED_DT) final String requestedDate,
+ @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
+ @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("5") final long timeoutSec,
+ @QueryParam(QUERY_ENTITLEMENT_POLICY) final EntitlementActionPolicy entitlementPolicy,
+ @QueryParam(QUERY_BILLING_POLICY) final BillingActionPolicy billingPolicy,
+ @QueryParam(QUERY_USE_REQUESTED_DATE_FOR_BILLING) @DefaultValue("false") final Boolean useRequestedDateForBilling,
+ @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 UriInfo uriInfo,
+ @javax.ws.rs.core.Context final HttpServletRequest request) throws EntitlementApiException, AccountApiException, SubscriptionApiException {
final CallContext callContext = context.createCallContextNoAccountId(createdBy, reason, comment, request);
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
diff --git a/jaxrs/src/test/java/org/killbill/billing/jaxrs/json/TestBundleJsonWithSubscriptions.java b/jaxrs/src/test/java/org/killbill/billing/jaxrs/json/TestBundleJsonWithSubscriptions.java
index 2b3e45c..2d74cb8 100644
--- a/jaxrs/src/test/java/org/killbill/billing/jaxrs/json/TestBundleJsonWithSubscriptions.java
+++ b/jaxrs/src/test/java/org/killbill/billing/jaxrs/json/TestBundleJsonWithSubscriptions.java
@@ -24,6 +24,11 @@ import java.util.UUID;
import org.joda.time.LocalDate;
import org.killbill.billing.catalog.api.BillingPeriod;
+import org.killbill.billing.catalog.api.PhaseType;
+import org.killbill.billing.catalog.api.ProductCategory;
+import org.killbill.billing.entitlement.api.Entitlement.EntitlementSourceType;
+import org.killbill.billing.entitlement.api.Entitlement.EntitlementState;
+import org.killbill.billing.entitlement.api.SubscriptionEventType;
import org.killbill.billing.jaxrs.JaxrsTestSuiteNoDB;
import org.killbill.billing.jaxrs.json.SubscriptionJson.EventSubscriptionJson;
import org.testng.Assert;
@@ -43,12 +48,12 @@ public class TestBundleJsonWithSubscriptions extends JaxrsTestSuiteNoDB {
final List<AuditLogJson> auditLogs = createAuditLogsJson(clock.getUTCNow());
final EventSubscriptionJson event = new EventSubscriptionJson(UUID.randomUUID(),
- BillingPeriod.NO_BILLING_PERIOD.toString(),
+ BillingPeriod.NO_BILLING_PERIOD,
new LocalDate(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
+ SubscriptionEventType.START_BILLING,
true,
false,
UUID.randomUUID().toString(),
@@ -64,13 +69,13 @@ public class TestBundleJsonWithSubscriptions extends JaxrsTestSuiteNoDB {
externalKey,
new LocalDate(),
UUID.randomUUID().toString(),
+ ProductCategory.BASE,
+ BillingPeriod.MONTHLY,
+ PhaseType.EVERGREEN,
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
+ EntitlementState.ACTIVE,
+ EntitlementSourceType.NATIVE,
new LocalDate(),
new LocalDate(),
new LocalDate(),
diff --git a/jaxrs/src/test/java/org/killbill/billing/jaxrs/json/TestBundleTimelineJson.java b/jaxrs/src/test/java/org/killbill/billing/jaxrs/json/TestBundleTimelineJson.java
index 18e2914..4beac86 100644
--- a/jaxrs/src/test/java/org/killbill/billing/jaxrs/json/TestBundleTimelineJson.java
+++ b/jaxrs/src/test/java/org/killbill/billing/jaxrs/json/TestBundleTimelineJson.java
@@ -22,6 +22,7 @@ import java.util.UUID;
import org.joda.time.LocalDate;
import org.killbill.billing.catalog.api.BillingPeriod;
+import org.killbill.billing.entitlement.api.SubscriptionEventType;
import org.killbill.billing.jaxrs.JaxrsTestSuiteNoDB;
import org.killbill.billing.jaxrs.json.SubscriptionJson.EventSubscriptionJson;
import org.testng.Assert;
@@ -34,12 +35,12 @@ public class TestBundleTimelineJson extends JaxrsTestSuiteNoDB {
@Test(groups = "fast")
public void testJson() throws Exception {
final EventSubscriptionJson event = new EventSubscriptionJson(UUID.randomUUID(),
- BillingPeriod.NO_BILLING_PERIOD.toString(),
+ BillingPeriod.NO_BILLING_PERIOD,
new LocalDate(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
+ SubscriptionEventType.PHASE,
true,
false,
UUID.randomUUID().toString(),
diff --git a/jaxrs/src/test/java/org/killbill/billing/jaxrs/json/TestEntitlementJsonWithEvents.java b/jaxrs/src/test/java/org/killbill/billing/jaxrs/json/TestEntitlementJsonWithEvents.java
index 093e5ca..ca9b40f 100644
--- a/jaxrs/src/test/java/org/killbill/billing/jaxrs/json/TestEntitlementJsonWithEvents.java
+++ b/jaxrs/src/test/java/org/killbill/billing/jaxrs/json/TestEntitlementJsonWithEvents.java
@@ -28,6 +28,10 @@ import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
import org.killbill.billing.catalog.api.BillingPeriod;
import org.killbill.billing.catalog.api.PhaseType;
+import org.killbill.billing.catalog.api.ProductCategory;
+import org.killbill.billing.entitlement.api.Entitlement.EntitlementSourceType;
+import org.killbill.billing.entitlement.api.Entitlement.EntitlementState;
+import org.killbill.billing.entitlement.api.SubscriptionEventType;
import org.killbill.billing.jaxrs.JaxrsTestSuiteNoDB;
import org.killbill.billing.jaxrs.json.SubscriptionJson.EventSubscriptionJson;
import org.killbill.billing.subscription.api.SubscriptionBaseTransitionType;
@@ -43,52 +47,50 @@ public class TestEntitlementJsonWithEvents extends JaxrsTestSuiteNoDB {
@Test(groups = "fast")
public void testJson() throws Exception {
- final UUID accountId = UUID.randomUUID();
- final UUID bundleId = UUID.randomUUID();
- final UUID subscriptionId = UUID.randomUUID();
final String externalKey = UUID.randomUUID().toString();
final DateTime effectiveDate = DefaultClock.toUTCDateTime(new DateTime(DateTimeZone.UTC));
final UUID eventId = UUID.randomUUID();
final List<AuditLogJson> auditLogs = createAuditLogsJson(clock.getUTCNow());
+
+
final EventSubscriptionJson newEvent = new EventSubscriptionJson(eventId,
- BillingPeriod.NO_BILLING_PERIOD.toString(),
+ BillingPeriod.NO_BILLING_PERIOD,
effectiveDate.toLocalDate(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
- SubscriptionBaseTransitionType.CREATE.toString(),
+ SubscriptionEventType.PHASE,
false,
true,
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
- PhaseType.DISCOUNT.toString(),
+ UUID.randomUUID().toString(),
auditLogs);
final PhasePriceOverrideJson priceOverride = new PhasePriceOverrideJson("foo", "bar", null, BigDecimal.TEN, BigDecimal.ONE,null);
- final SubscriptionJson entitlementJsonWithEvents = new SubscriptionJson(accountId,
- bundleId,
- subscriptionId,
- externalKey,
- new LocalDate(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- new LocalDate(),
- new LocalDate(),
- new LocalDate(),
- new LocalDate(),
- null,
- ImmutableList.<EventSubscriptionJson>of(newEvent),
- ImmutableList.of(priceOverride),
- null);
-
+ final SubscriptionJson entitlementJsonWithEvents = new SubscriptionJson(UUID.randomUUID(),
+ UUID.randomUUID(),
+ UUID.randomUUID(),
+ externalKey,
+ new LocalDate(),
+ UUID.randomUUID().toString(),
+ ProductCategory.BASE,
+ BillingPeriod.MONTHLY,
+ PhaseType.EVERGREEN,
+ UUID.randomUUID().toString(),
+ UUID.randomUUID().toString(),
+ EntitlementState.ACTIVE,
+ EntitlementSourceType.NATIVE,
+ new LocalDate(),
+ new LocalDate(),
+ new LocalDate(),
+ new LocalDate(),
+ null,
+ ImmutableList.<EventSubscriptionJson>of(newEvent),
+ ImmutableList.of(priceOverride),
+ auditLogs);
final String asJson = mapper.writeValueAsString(entitlementJsonWithEvents);
final SubscriptionJson fromJson = mapper.readValue(asJson, SubscriptionJson.class);
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestEntitlement.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestEntitlement.java
index 899ca00..ae21135 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestEntitlement.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestEntitlement.java
@@ -35,14 +35,16 @@ import org.killbill.billing.catalog.api.PhaseType;
import org.killbill.billing.catalog.api.PriceListSet;
import org.killbill.billing.catalog.api.ProductCategory;
import org.killbill.billing.client.KillBillClientException;
-import org.killbill.billing.client.model.Account;
-import org.killbill.billing.client.model.BulkBaseSubscriptionAndAddOns;
-import org.killbill.billing.client.model.Bundle;
+import org.killbill.billing.client.model.BulkSubscriptionsBundles;
import org.killbill.billing.client.model.Bundles;
-import org.killbill.billing.client.model.Invoice;
-import org.killbill.billing.client.model.PhasePriceOverride;
-import org.killbill.billing.client.model.Subscription;
+import org.killbill.billing.client.model.Subscriptions;
import org.killbill.billing.client.model.Tags;
+import org.killbill.billing.client.model.gen.Account;
+import org.killbill.billing.client.model.gen.BulkSubscriptionsBundle;
+import org.killbill.billing.client.model.gen.Bundle;
+import org.killbill.billing.client.model.gen.Invoice;
+import org.killbill.billing.client.model.gen.PhasePriceOverride;
+import org.killbill.billing.client.model.gen.Subscription;
import org.killbill.billing.entitlement.api.Entitlement.EntitlementActionPolicy;
import org.killbill.billing.entitlement.api.Entitlement.EntitlementState;
import org.killbill.billing.entitlement.api.SubscriptionEventType;
@@ -60,8 +62,6 @@ import static org.testng.Assert.assertTrue;
public class TestEntitlement extends TestJaxrsBase {
- private static final int CALL_COMPLETION_TIMEOUT_SEC = 5;
-
@Test(groups = "slow", description = "Can change plan and cancel a subscription")
public void testEntitlementInTrialOk() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
@@ -72,11 +72,11 @@ public class TestEntitlement extends TestJaxrsBase {
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
- final Subscription entitlementJson = createEntitlement(accountJson.getAccountId(), "99999", productName,
+ final Subscription entitlementJson = createSubscription(accountJson.getAccountId(), "99999", productName,
ProductCategory.BASE, term, true);
// Retrieves with GET
- Subscription objFromJson = killBillClient.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
+ Subscription objFromJson = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
Assert.assertEquals(objFromJson.getPriceOverrides().size(), 2);
Assert.assertEquals(objFromJson.getPriceOverrides().get(0).getFixedPrice(), BigDecimal.ZERO);
Assert.assertNull(objFromJson.getPriceOverrides().get(0).getRecurringPrice());
@@ -99,8 +99,7 @@ public class TestEntitlement extends TestJaxrsBase {
newInput.setProductCategory(ProductCategory.BASE);
newInput.setBillingPeriod(entitlementJson.getBillingPeriod());
newInput.setPriceList(entitlementJson.getPriceList());
- objFromJson = killBillClient.updateSubscription(newInput, CALL_COMPLETION_TIMEOUT_SEC, requestOptions);
- Assert.assertNotNull(objFromJson);
+ subscriptionApi.changeSubscriptionPlan(newInput, entitlementJson.getSubscriptionId(), null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
// MOVE AFTER TRIAL
final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31));
@@ -109,10 +108,10 @@ public class TestEntitlement extends TestJaxrsBase {
crappyWaitForLackOfProperSynchonization();
// Cancel IMM (Billing EOT)
- killBillClient.cancelSubscription(newInput.getSubscriptionId(), CALL_COMPLETION_TIMEOUT_SEC, requestOptions);
+ subscriptionApi.cancelSubscriptionPlan(newInput.getSubscriptionId(), null, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
// Retrieves to check EndDate
- objFromJson = killBillClient.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
+ objFromJson = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
assertNotNull(objFromJson.getCancelledDate());
assertTrue(objFromJson.getCancelledDate().compareTo(new LocalDate(clock.getUTCNow())) == 0);
}
@@ -127,11 +126,11 @@ public class TestEntitlement extends TestJaxrsBase {
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
- final Subscription entitlementJson = createEntitlement(accountJson.getAccountId(), "99999", productName,
+ final Subscription entitlementJson = createSubscription(accountJson.getAccountId(), "99999", productName,
ProductCategory.BASE, term, true);
// Retrieves with GET
- Subscription objFromJson = killBillClient.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
+ Subscription objFromJson = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
Assert.assertEquals(objFromJson.getPriceOverrides().size(), 2);
Assert.assertEquals(objFromJson.getPriceOverrides().get(0).getPhaseName(), "shotgun-monthly-trial");
Assert.assertEquals(objFromJson.getPriceOverrides().get(0).getFixedPrice(), BigDecimal.ZERO);
@@ -153,11 +152,11 @@ public class TestEntitlement extends TestJaxrsBase {
crappyWaitForLackOfProperSynchonization();
// Cancel EOT
- killBillClient.cancelSubscription(entitlementJson.getSubscriptionId(), EntitlementActionPolicy.END_OF_TERM,
- BillingActionPolicy.END_OF_TERM, CALL_COMPLETION_TIMEOUT_SEC, requestOptions);
+ subscriptionApi.cancelSubscriptionPlan(entitlementJson.getSubscriptionId(), null, EntitlementActionPolicy.END_OF_TERM,
+ BillingActionPolicy.END_OF_TERM, NULL_PLUGIN_PROPERTIES, requestOptions);
// Retrieves to check EndDate
- objFromJson = killBillClient.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
+ objFromJson = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
assertNotNull(objFromJson.getCancelledDate());
Assert.assertEquals(objFromJson.getPriceOverrides().size(), 2);
Assert.assertEquals(objFromJson.getPriceOverrides().get(0).getPhaseName(), "shotgun-monthly-trial");
@@ -168,9 +167,9 @@ public class TestEntitlement extends TestJaxrsBase {
Assert.assertEquals(objFromJson.getPriceOverrides().get(1).getRecurringPrice(), new BigDecimal("249.95"));
// Uncancel
- killBillClient.uncancelSubscription(entitlementJson.getSubscriptionId(), requestOptions);
+ subscriptionApi.uncancelSubscriptionPlan(entitlementJson.getSubscriptionId(), NULL_PLUGIN_PROPERTIES, requestOptions);
- objFromJson = killBillClient.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
+ objFromJson = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
assertNull(objFromJson.getCancelledDate());
Assert.assertEquals(objFromJson.getPriceOverrides().size(), 2);
Assert.assertEquals(objFromJson.getPriceOverrides().get(0).getPhaseName(), "shotgun-monthly-trial");
@@ -192,11 +191,11 @@ public class TestEntitlement extends TestJaxrsBase {
subscription.setBillingPeriod(BillingPeriod.ANNUAL);
subscription.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
- assertNull(killBillClient.updateSubscription(subscription, CALL_COMPLETION_TIMEOUT_SEC, requestOptions));
+ subscriptionApi.changeSubscriptionPlan(subscription, subscriptionId, null, null, null, requestOptions);
- killBillClient.cancelSubscription(subscriptionId, requestOptions);
+ subscriptionApi.cancelSubscriptionPlan(subscriptionId, null, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
- assertNull(killBillClient.getSubscription(subscriptionId, requestOptions));
+ assertNull(subscriptionApi.getSubscription(subscriptionId, requestOptions));
}
@Test(groups = "slow", description = "Can override billing policy on change")
@@ -209,11 +208,11 @@ public class TestEntitlement extends TestJaxrsBase {
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.ANNUAL;
- final Subscription subscriptionJson = createEntitlement(accountJson.getAccountId(), "99999", productName,
+ final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), "99999", productName,
ProductCategory.BASE, term, true);
// Retrieves with GET
- Subscription objFromJson = killBillClient.getSubscription(subscriptionJson.getSubscriptionId(), requestOptions);
+ Subscription objFromJson = subscriptionApi.getSubscription(subscriptionJson.getSubscriptionId(), requestOptions);
// Equality in java client is not correctly implemented so manually check PriceOverrides section and then reset before equality
objFromJson.setPriceOverrides(null);
subscriptionJson.setPriceOverrides(null);
@@ -229,8 +228,9 @@ public class TestEntitlement extends TestJaxrsBase {
newInput.setProductCategory(ProductCategory.BASE);
newInput.setBillingPeriod(BillingPeriod.MONTHLY);
newInput.setPriceList(subscriptionJson.getPriceList());
- objFromJson = killBillClient.updateSubscription(newInput, BillingActionPolicy.IMMEDIATE, CALL_COMPLETION_TIMEOUT_SEC, requestOptions );
- Assert.assertNotNull(objFromJson);
+ subscriptionApi.changeSubscriptionPlan(newInput, subscriptionJson.getSubscriptionId(), null, BillingActionPolicy.IMMEDIATE, NULL_PLUGIN_PROPERTIES, requestOptions);
+
+ objFromJson = subscriptionApi.getSubscription(subscriptionJson.getSubscriptionId(), requestOptions);
assertEquals(objFromJson.getBillingPeriod(), BillingPeriod.MONTHLY);
}
@@ -255,30 +255,29 @@ public class TestEntitlement extends TestJaxrsBase {
overrides.add(new PhasePriceOverride(null, null, PhaseType.TRIAL.toString(), BigDecimal.TEN, null, null));
input.setPriceOverrides(overrides);
- final Subscription subscription = killBillClient.createSubscription(input, null, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, requestOptions);
+ final Subscription subscription = subscriptionApi.createSubscription(input, null, null, null, null, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(subscription.getPriceOverrides().size(), 2);
Assert.assertEquals(subscription.getEvents().size(), 3);
- Assert.assertEquals(subscription.getEvents().get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT.name());
+ Assert.assertEquals(subscription.getEvents().get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT);
assertMatches(subscription.getEvents().get(0).getPlan(), "shotgun-monthly-[1-9]+");
assertMatches(subscription.getEvents().get(0).getPhase(), "shotgun-monthly-[1-9]+-trial");
- Assert.assertEquals(subscription.getEvents().get(0).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
+ Assert.assertEquals(subscription.getEvents().get(0).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME);
Assert.assertEquals(subscription.getEvents().get(0).getProduct(), "Shotgun");
- Assert.assertEquals(subscription.getEvents().get(1).getEventType(), SubscriptionEventType.START_BILLING.name());
+ Assert.assertEquals(subscription.getEvents().get(1).getEventType(), SubscriptionEventType.START_BILLING);
assertMatches(subscription.getEvents().get(1).getPlan(), "shotgun-monthly-[1-9]+");
assertMatches(subscription.getEvents().get(1).getPhase(), "shotgun-monthly-[1-9]+-trial");
- Assert.assertEquals(subscription.getEvents().get(1).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
+ Assert.assertEquals(subscription.getEvents().get(1).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME);
Assert.assertEquals(subscription.getEvents().get(1).getProduct(), "Shotgun");
- Assert.assertEquals(subscription.getEvents().get(2).getEventType(), SubscriptionEventType.PHASE.name());
+ Assert.assertEquals(subscription.getEvents().get(2).getEventType(), SubscriptionEventType.PHASE);
assertMatches(subscription.getEvents().get(2).getPlan(), "shotgun-monthly-[1-9]+");
assertMatches(subscription.getEvents().get(2).getPhase(), "shotgun-monthly-[1-9]+-evergreen");
- Assert.assertEquals(subscription.getEvents().get(2).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
+ Assert.assertEquals(subscription.getEvents().get(2).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME);
Assert.assertEquals(subscription.getEvents().get(2).getProduct(), "Shotgun");
-
- final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, false, AuditLevel.FULL, requestOptions);
+ final List<Invoice> invoices = accountApi.getInvoices(accountJson.getAccountId(), true, false, false, false, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 1);
assertEquals(invoices.get(0).getAmount().compareTo(BigDecimal.TEN), 0);
@@ -286,7 +285,7 @@ public class TestEntitlement extends TestJaxrsBase {
clock.addDays(30);
crappyWaitForLackOfProperSynchonization();
- final Subscription subscription2 = killBillClient.getSubscription(subscription.getSubscriptionId(), requestOptions);
+ final Subscription subscription2 = subscriptionApi.getSubscription(subscription.getSubscriptionId(), requestOptions);
Assert.assertEquals(subscription2.getEvents().size(), 3);
clock.addDays(3);
@@ -295,28 +294,29 @@ public class TestEntitlement extends TestJaxrsBase {
final Subscription newInput = new Subscription();
newInput.setSubscriptionId(subscription2.getSubscriptionId());
newInput.setPlanName("pistol-monthly");
- final Subscription subscription3 = killBillClient.updateSubscription(newInput, null, BillingActionPolicy.IMMEDIATE, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, requestOptions);
+ subscriptionApi.changeSubscriptionPlan(newInput, subscription2.getSubscriptionId(), null, BillingActionPolicy.IMMEDIATE, NULL_PLUGIN_PROPERTIES, requestOptions);
+ final Subscription subscription3 = subscriptionApi.getSubscription(subscription.getSubscriptionId(), requestOptions);
Assert.assertEquals(subscription3.getEvents().size(), 4);
- Assert.assertEquals(subscription3.getEvents().get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT.name());
+ Assert.assertEquals(subscription3.getEvents().get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT);
assertMatches(subscription3.getEvents().get(0).getPlan(), "shotgun-monthly-[1-9]+");
assertMatches(subscription3.getEvents().get(0).getPhase(), "shotgun-monthly-[1-9]+-trial");
Assert.assertEquals(subscription3.getEvents().get(0).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
Assert.assertEquals(subscription3.getEvents().get(0).getProduct(), "Shotgun");
- Assert.assertEquals(subscription3.getEvents().get(1).getEventType(), SubscriptionEventType.START_BILLING.name());
+ Assert.assertEquals(subscription3.getEvents().get(1).getEventType(), SubscriptionEventType.START_BILLING);
assertMatches(subscription3.getEvents().get(1).getPlan(), "shotgun-monthly-[1-9]+");
assertMatches(subscription3.getEvents().get(1).getPhase(), "shotgun-monthly-[1-9]+-trial");
Assert.assertEquals(subscription3.getEvents().get(1).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
Assert.assertEquals(subscription3.getEvents().get(1).getProduct(), "Shotgun");
- Assert.assertEquals(subscription3.getEvents().get(2).getEventType(), SubscriptionEventType.PHASE.name());
+ Assert.assertEquals(subscription3.getEvents().get(2).getEventType(), SubscriptionEventType.PHASE);
assertMatches(subscription3.getEvents().get(2).getPlan(), "shotgun-monthly-[1-9]+");
assertMatches(subscription3.getEvents().get(2).getPhase(), "shotgun-monthly-[1-9]+-evergreen");
Assert.assertEquals(subscription3.getEvents().get(2).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
Assert.assertEquals(subscription3.getEvents().get(2).getProduct(), "Shotgun");
- Assert.assertEquals(subscription3.getEvents().get(3).getEventType(), SubscriptionEventType.CHANGE.name());
+ Assert.assertEquals(subscription3.getEvents().get(3).getEventType(), SubscriptionEventType.CHANGE);
Assert.assertEquals(subscription3.getEvents().get(3).getPlan(), "pistol-monthly");
Assert.assertEquals(subscription3.getEvents().get(3).getPhase(), "pistol-monthly-evergreen");
Assert.assertEquals(subscription3.getEvents().get(3).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
@@ -358,44 +358,44 @@ public class TestEntitlement extends TestJaxrsBase {
addOn2.setBillingPeriod(BillingPeriod.MONTHLY);
addOn2.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
- final List<Subscription> subscriptions = new ArrayList<Subscription>();
+ final Subscriptions subscriptions = new Subscriptions();
subscriptions.add(base);
subscriptions.add(addOn1);
subscriptions.add(addOn2);
- final Bundle bundle = killBillClient.createSubscriptionWithAddOns(subscriptions, null, 10, requestOptions);
+ final Bundle bundle = subscriptionApi.createSubscriptionWithAddOns(subscriptions, null, null, null, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(bundle);
assertEquals(bundle.getExternalKey(), "base");
assertEquals(bundle.getSubscriptions().size(), 3);
- final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, requestOptions);
+ final List<Invoice> invoices = accountApi.getInvoices(accountJson.getAccountId(), true, false, false, false, AuditLevel.NONE, requestOptions);
assertEquals(invoices.size(), 1);
assertEquals(invoices.get(0).getBalance().compareTo(BigDecimal.ZERO), 1);
- assertEquals(killBillClient.getInvoiceTags(invoices.get(0).getInvoiceId(), requestOptions).size(), 0);
+ assertEquals(invoiceApi.getTags(invoices.get(0).getInvoiceId(), requestOptions).size(), 0);
- final Bundles accountBundles = killBillClient.getAccountBundles(accountJson.getAccountId(), requestOptions);
+ final Bundles accountBundles = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
assertEquals(accountBundles.size(), 1);
for (final Subscription subscription : accountBundles.get(0).getSubscriptions()) {
assertEquals(subscription.getState(), EntitlementState.ACTIVE);
}
- killBillClient.closeAccount(accountJson.getAccountId(), true, true, false, requestOptions);
+ accountApi.closeAccount(accountJson.getAccountId(), true, true, false, requestOptions);
- final Bundles accountBundlesAfterClose = killBillClient.getAccountBundles(accountJson.getAccountId(), requestOptions);
+ final Bundles accountBundlesAfterClose = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
assertEquals(accountBundlesAfterClose.size(), 1);
for (final Subscription subscription : accountBundlesAfterClose.get(0).getSubscriptions()) {
assertEquals(subscription.getState(), EntitlementState.CANCELLED);
}
- final List<Invoice> invoicesAfterClose = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, requestOptions);
+ final List<Invoice> invoicesAfterClose = accountApi.getInvoices(accountJson.getAccountId(), requestOptions);
assertEquals(invoicesAfterClose.size(), 1);
assertEquals(invoicesAfterClose.get(0).getBalance().compareTo(BigDecimal.ZERO), 0);
- assertEquals(killBillClient.getInvoiceTags(invoicesAfterClose.get(0).getInvoiceId(), requestOptions).size(), 1);
+ assertEquals(invoiceApi.getTags(invoicesAfterClose.get(0).getInvoiceId(), requestOptions).size(), 1);
}
- // Flaky, see https://github.com/killbill/killbill/issues/860
+ // , see https://github.com/killbill/killbill/issues/860
@Test(groups = "slow", description = "Create a bulk of base entitlement and addOns under the same transaction", retryAnalyzer = FlakyRetryAnalyzer.class)
- public void testCreateEntitlementsWithAddOnsThenCloseAccountWithItemAdjustment() throws Exception {
+ public void testcreateSubscriptionsWithAddOnsThenCloseAccountWithItemAdjustment() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
@@ -427,21 +427,24 @@ public class TestEntitlement extends TestJaxrsBase {
subscriptions.add(addOn1);
subscriptions.add(addOn2);
- final List<BulkBaseSubscriptionAndAddOns> bulkList = new ArrayList<BulkBaseSubscriptionAndAddOns>();
- bulkList.add(new BulkBaseSubscriptionAndAddOns(subscriptions));
- bulkList.add(new BulkBaseSubscriptionAndAddOns(subscriptions));
+ final BulkSubscriptionsBundle bulkList = new BulkSubscriptionsBundle();
+ bulkList.setBaseEntitlementAndAddOns(subscriptions);
- final Bundles bundles = killBillClient.createSubscriptionsWithAddOns(bulkList, null, 10, requestOptions);
+ final BulkSubscriptionsBundles input = new BulkSubscriptionsBundles();
+ input.add(bulkList);
+ input.add(bulkList);
+
+ final Bundles bundles = subscriptionApi.createSubscriptionsWithAddOns(input, null, null, false, false, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(bundles);
assertEquals(bundles.size(), 2);
assertFalse(bundles.get(0).getExternalKey().equals(bundles.get(1).getExternalKey()));
- final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, requestOptions);
+ final List<Invoice> invoices = accountApi.getInvoices(accountJson.getAccountId(), requestOptions);
assertEquals(invoices.size(), 1);
assertEquals(invoices.get(0).getBalance().compareTo(BigDecimal.ZERO), 1);
- assertEquals(killBillClient.getInvoiceTags(invoices.get(0).getInvoiceId(), requestOptions).size(), 0);
+ assertEquals(invoiceApi.getTags(invoices.get(0).getInvoiceId(), requestOptions).size(), 0);
- final Bundles accountBundles = killBillClient.getAccountBundles(accountJson.getAccountId(), requestOptions);
+ final Bundles accountBundles = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
assertEquals(accountBundles.size(), 2);
for (final Bundle bundle : accountBundles) {
for (final Subscription subscription : bundle.getSubscriptions()) {
@@ -449,9 +452,9 @@ public class TestEntitlement extends TestJaxrsBase {
}
}
- killBillClient.closeAccount(accountJson.getAccountId(), true, false, true, requestOptions);
+ accountApi.closeAccount(accountJson.getAccountId(), true, false, true, requestOptions);
- final Bundles accountBundlesAfterClose = killBillClient.getAccountBundles(accountJson.getAccountId(), requestOptions);
+ final Bundles accountBundlesAfterClose = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
assertEquals(accountBundlesAfterClose.size(), 2);
for (final Bundle bundle : accountBundlesAfterClose) {
for (final Subscription subscription : bundle.getSubscriptions()) {
@@ -459,15 +462,15 @@ public class TestEntitlement extends TestJaxrsBase {
}
}
- final List<Invoice> invoicesAfterClose = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, requestOptions);
+ final List<Invoice> invoicesAfterClose = accountApi.getInvoices(accountJson.getAccountId(), true, false, false, false, AuditLevel.NONE, requestOptions);
assertEquals(invoicesAfterClose.size(), 1);
assertEquals(invoicesAfterClose.get(0).getBalance().compareTo(BigDecimal.ZERO), 0);
- assertEquals(killBillClient.getInvoiceTags(invoicesAfterClose.get(0).getInvoiceId(), requestOptions).size(), 0);
+ assertEquals(invoiceApi.getTags(invoicesAfterClose.get(0).getInvoiceId(), requestOptions).size(), 0);
}
@Test(groups = "slow", description = "Create a bulk of base entitlements and addOns under the same transaction",
expectedExceptions = KillBillClientException.class, expectedExceptionsMessageRegExp = "Missing Base Subscription for bundle 12345")
- public void testCreateEntitlementsWithoutBase() throws Exception {
+ public void testcreateSubscriptionsWithoutBase() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
@@ -489,14 +492,19 @@ public class TestEntitlement extends TestJaxrsBase {
subscriptions.add(bp);
subscriptions.add(addOn1);
- final List<BulkBaseSubscriptionAndAddOns> bulkList = new ArrayList<BulkBaseSubscriptionAndAddOns>();
- bulkList.add(new BulkBaseSubscriptionAndAddOns(subscriptions));
- bulkList.add(new BulkBaseSubscriptionAndAddOns(subscriptions));
+ final BulkSubscriptionsBundle bulkList1 = new BulkSubscriptionsBundle();
+ bulkList1.setBaseEntitlementAndAddOns(subscriptions);
+ final BulkSubscriptionsBundle bulkList2 = new BulkSubscriptionsBundle();
+ bulkList2.setBaseEntitlementAndAddOns(subscriptions);
+
+ final BulkSubscriptionsBundles input = new BulkSubscriptionsBundles();
+ input.add(bulkList1);
+ input.add(bulkList2);
- killBillClient.createSubscriptionsWithAddOns(bulkList, null, 10, requestOptions);
+ subscriptionApi.createSubscriptionsWithAddOns(input, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
}
- @Test(groups = "slow", description = "Create addOns in a bundle where BP subscrsiptions already exist")
+ @Test(groups = "slow", description = "Create addOns in a bundle where BP subscription already exist")
public void testEntitlementsWithAddOnsAndAlreadyExistingBP() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
@@ -510,7 +518,7 @@ public class TestEntitlement extends TestJaxrsBase {
input.setProductCategory(ProductCategory.BASE);
input.setBillingPeriod(BillingPeriod.MONTHLY);
input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
- final Subscription subscription = killBillClient.createSubscription(input, null, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, requestOptions);
+ final Subscription subscription = subscriptionApi.createSubscription(input, null, null, null, null, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
final Subscription base = new Subscription();
base.setAccountId(accountJson.getAccountId());
@@ -536,19 +544,23 @@ public class TestEntitlement extends TestJaxrsBase {
subscriptions.add(addOn1);
subscriptions.add(addOn2);
- final Iterable<BulkBaseSubscriptionAndAddOns> bulkBaseSubscriptionAndAddOns = ImmutableList.of(new BulkBaseSubscriptionAndAddOns(subscriptions));
+ final BulkSubscriptionsBundles bulkSubscriptionsBundles = new BulkSubscriptionsBundles();
- final Bundles bundles = killBillClient.createSubscriptionsWithAddOns(bulkBaseSubscriptionAndAddOns, null, 10, requestOptions);
+ final BulkSubscriptionsBundle bulkSubscriptionsBundle = new BulkSubscriptionsBundle();
+ bulkSubscriptionsBundle.setBaseEntitlementAndAddOns(subscriptions);
+ bulkSubscriptionsBundles.add(bulkSubscriptionsBundle);
+
+ final Bundles bundles = subscriptionApi.createSubscriptionsWithAddOns(bulkSubscriptionsBundles, null, null, false, false, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(bundles);
assertEquals(bundles.size(), 1);
assertEquals(bundles.get(0).getSubscriptions().size(), 3);
- final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, false, AuditLevel.FULL, requestOptions);
+ final List<Invoice> invoices = accountApi.getInvoices(accountJson.getAccountId(), true, false, false, false, AuditLevel.NONE, requestOptions);
assertEquals(invoices.size(), 2);
}
@Test(groups = "slow", description = "Can create an entitlement in the future")
- public void testCreateEntitlementInTheFuture() throws Exception {
+ public void testcreateSubscriptionInTheFuture() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
@@ -560,7 +572,7 @@ public class TestEntitlement extends TestJaxrsBase {
input.setProductCategory(ProductCategory.BASE);
input.setBillingPeriod(BillingPeriod.MONTHLY);
input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
- final Subscription entitlementJson = killBillClient.createSubscription(input, initialDate.toLocalDate().plusMonths(1), -1, requestOptions);
+ final Subscription entitlementJson = subscriptionApi.createSubscription(input, initialDate.toLocalDate().plusMonths(1), null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(entitlementJson.getProductName(), input.getProductName());
Assert.assertEquals(entitlementJson.getProductCategory(), input.getProductCategory());
@@ -568,7 +580,7 @@ public class TestEntitlement extends TestJaxrsBase {
Assert.assertEquals(entitlementJson.getPriceList(), input.getPriceList());
// Retrieves with GET
- final Subscription subscription = killBillClient.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
+ final Subscription subscription = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
Assert.assertTrue(subscription.equals(entitlementJson));
Assert.assertEquals(subscription.getPriceOverrides().size(), 2);
Assert.assertEquals(subscription.getPriceOverrides().get(0).getPhaseName(), "shotgun-monthly-trial");
@@ -580,17 +592,17 @@ public class TestEntitlement extends TestJaxrsBase {
}
@Test(groups = "slow", description = "Can create an entitlement with an account with autoPayOff")
- public void testCreateEntitlementWithAutoPayOff() throws Exception {
+ public void testcreateSubscriptionWithAutoPayOff() throws Exception {
final Account accountJson = createAccount();
assertNotNull(accountJson);
// assign autoPaymentOff tag to account
- Tags tags = killBillClient.createAccountTag(accountJson.getAccountId(), new UUID(0L, 1L), requestOptions);
+ Tags tags = accountApi.createTags(accountJson.getAccountId(), ImmutableList.<String>of(new UUID(0L, 1L).toString()), requestOptions);
assertEquals(tags.get(0).getTagDefinitionName(), "AUTO_PAY_OFF");
// verify that number of invoices and payments for account is still 0
- assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions).size(), 0);
- assertEquals(killBillClient.getPaymentsForAccount(accountJson.getAccountId(), requestOptions).size(), 0);
+ assertEquals(accountApi.getInvoices(accountJson.getAccountId(), requestOptions).size(), 0);
+ assertEquals(accountApi.getPayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions).size(), 0);
// create a subscription with no trial plan
final Subscription input = new Subscription();
@@ -599,14 +611,15 @@ public class TestEntitlement extends TestJaxrsBase {
input.setProductCategory(ProductCategory.BASE);
input.setBillingPeriod(BillingPeriod.MONTHLY);
input.setPriceList("notrial");
- final Subscription subscriptionJson = killBillClient.createSubscription(input, null, 10, requestOptions);
+
+ final Subscription subscriptionJson = subscriptionApi.createSubscription(input, null, null, null, null, null, true, 10L, NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(subscriptionJson);
// verify that number of invoices is now 1
- assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions).size(), 1);
+ assertEquals(accountApi.getInvoices(accountJson.getAccountId(), requestOptions).size(), 1);
// verify that number of payments is still 0 (no attempts)
- assertEquals(killBillClient.getPaymentsForAccount(accountJson.getAccountId(), requestOptions).size(), 0);
+ assertEquals(accountApi.getPayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions).size(), 0);
}
@Test(groups = "slow", description = "Verify we can move the BCD associated with the subscription")
@@ -619,7 +632,7 @@ public class TestEntitlement extends TestJaxrsBase {
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
- final Subscription entitlementJson = createEntitlement(accountJson.getAccountId(), "99999", productName,
+ final Subscription entitlementJson = createSubscription(accountJson.getAccountId(), "99999", productName,
ProductCategory.BASE, term, true);
Assert.assertEquals(entitlementJson.getBillCycleDayLocal(), new Integer(25));
@@ -627,10 +640,9 @@ public class TestEntitlement extends TestJaxrsBase {
final Subscription updatedSubscription = new Subscription();
updatedSubscription.setSubscriptionId(entitlementJson.getSubscriptionId());
updatedSubscription.setBillCycleDayLocal(9);
- killBillClient.updateSubscriptionBCD(updatedSubscription, null, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, requestOptions);
+ subscriptionApi.updateSubscriptionBCD(updatedSubscription, entitlementJson.getSubscriptionId(), null, requestOptions);
-
- final Subscription result = killBillClient.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
+ final Subscription result = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
// Still shows as the 4 (BCD did not take effect)
Assert.assertEquals(result.getBillCycleDayLocal(), new Integer(25));
@@ -638,7 +650,7 @@ public class TestEntitlement extends TestJaxrsBase {
clock.addDays(14);
crappyWaitForLackOfProperSynchonization();
- final Subscription result2 = killBillClient.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
+ final Subscription result2 = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
// Still shows as the 4 (BCD did not take effect)
Assert.assertEquals(result2.getBillCycleDayLocal(), new Integer(9));
}
@@ -655,18 +667,18 @@ public class TestEntitlement extends TestJaxrsBase {
input.setExternalKey("somethingSpecial");
input.setPlanName("shotgun-monthly");
- final Subscription entitlementJson = killBillClient.createSubscription(input, null, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, requestOptions);
+ final Subscription entitlementJson = subscriptionApi.createSubscription(input, null, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(entitlementJson.getProductName(), "Shotgun");
Assert.assertEquals(entitlementJson.getBillingPeriod(), BillingPeriod.MONTHLY);
Assert.assertEquals(entitlementJson.getPriceList(), DefaultPriceListSet.DEFAULT_PRICELIST_NAME);
Assert.assertEquals(entitlementJson.getPlanName(), "shotgun-monthly");
-
final Subscription newInput = new Subscription();
newInput.setAccountId(entitlementJson.getAccountId());
newInput.setSubscriptionId(entitlementJson.getSubscriptionId());
newInput.setPlanName("pistol-monthly");
- final Subscription newEntitlementJson = killBillClient.updateSubscription(newInput, null, null, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, requestOptions);
+ subscriptionApi.changeSubscriptionPlan(newInput, entitlementJson.getSubscriptionId(), null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
+ final Subscription newEntitlementJson = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
Assert.assertEquals(newEntitlementJson.getProductName(), "Pistol");
Assert.assertEquals(newEntitlementJson.getBillingPeriod(), BillingPeriod.MONTHLY);
Assert.assertEquals(newEntitlementJson.getPriceList(), DefaultPriceListSet.DEFAULT_PRICELIST_NAME);
@@ -683,11 +695,9 @@ public class TestEntitlement extends TestJaxrsBase {
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
- final Subscription entitlementJson = createEntitlement(accountJson.getAccountId(), "99999", productName,
+ final Subscription entitlementJson = createSubscription(accountJson.getAccountId(), "99999", productName,
ProductCategory.BASE, term, true);
-
-
// Change plan in the future
final String newProductName = "Assault-Rifle";
@@ -698,15 +708,14 @@ public class TestEntitlement extends TestJaxrsBase {
newInput.setProductCategory(ProductCategory.BASE);
newInput.setBillingPeriod(entitlementJson.getBillingPeriod());
newInput.setPriceList(entitlementJson.getPriceList());
-
- Subscription refreshedSubscription = killBillClient.updateSubscription(newInput, new LocalDate(2012, 4, 28), null, CALL_COMPLETION_TIMEOUT_SEC, requestOptions);
+ subscriptionApi.changeSubscriptionPlan(newInput, entitlementJson.getSubscriptionId(), new LocalDate(2012, 4, 28), null, NULL_PLUGIN_PROPERTIES, requestOptions);
+ Subscription refreshedSubscription = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
Assert.assertNotNull(refreshedSubscription);
-
final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(1));
clock.addDeltaFromReality(it.toDurationMillis());
- killBillClient.undoChangePlan(refreshedSubscription.getSubscriptionId(), requestOptions);
+ subscriptionApi.undoChangeSubscriptionPlan(refreshedSubscription.getSubscriptionId(), NULL_PLUGIN_PROPERTIES, requestOptions);
// MOVE AFTER TRIAL
final Interval it2 = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(30));
@@ -715,7 +724,7 @@ public class TestEntitlement extends TestJaxrsBase {
crappyWaitForLackOfProperSynchonization();
// Retrieves to check EndDate
- refreshedSubscription = killBillClient.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
+ refreshedSubscription = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
Assert.assertEquals(refreshedSubscription.getPriceOverrides().size(), 2);
Assert.assertEquals(refreshedSubscription.getPriceOverrides().get(0).getPhaseName(), "shotgun-monthly-trial");
Assert.assertEquals(refreshedSubscription.getPriceOverrides().get(0).getFixedPrice(), BigDecimal.ZERO);
@@ -726,6 +735,4 @@ public class TestEntitlement extends TestJaxrsBase {
}
-
-
}
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestInvoice.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestInvoice.java
index f105cac..8add60f 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestInvoice.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestInvoice.java
@@ -765,11 +765,11 @@ public class TestInvoice extends TestJaxrsBase {
final Account childAccount3 = createAccount(parentAccount.getAccountId());
// Add a bundle, subscription and move the clock to get the first invoice
- createEntitlement(childAccount1.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
+ createSubscription(childAccount1.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
ProductCategory.BASE, BillingPeriod.MONTHLY, true);
- createEntitlement(childAccount2.getAccountId(), UUID.randomUUID().toString(), "Pistol",
+ createSubscription(childAccount2.getAccountId(), UUID.randomUUID().toString(), "Pistol",
ProductCategory.BASE, BillingPeriod.MONTHLY, true);
- createEntitlement(childAccount3.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
+ createSubscription(childAccount3.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
ProductCategory.BASE, BillingPeriod.MONTHLY, true);
clock.addDays(32);