killbill-memoizeit
Changes
pom.xml 2(+1 -1)
Details
diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/PhasePriceOverrideJson.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/PhasePriceOverrideJson.java
index d83acaa..06de8a8 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/PhasePriceOverrideJson.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/PhasePriceOverrideJson.java
@@ -37,22 +37,30 @@ import com.google.common.collect.Iterables;
public class PhasePriceOverrideJson {
+
+ private final String planName;
private final String phaseName;
private final String phaseType;
private final BigDecimal fixedPrice;
private final BigDecimal recurringPrice;
@JsonCreator
- public PhasePriceOverrideJson(@JsonProperty("phaseName") final String phaseName,
+ public PhasePriceOverrideJson(@JsonProperty("planName") final String planName,
+ @JsonProperty("phaseName") final String phaseName,
@JsonProperty("phaseType") final String phaseType,
@Nullable @JsonProperty("fixedPrice") final BigDecimal fixedPrice,
@Nullable @JsonProperty("recurringPrice") final BigDecimal recurringPrice) {
+ this.planName = planName;
this.phaseName = phaseName;
this.phaseType = phaseType;
this.fixedPrice = fixedPrice;
this.recurringPrice = recurringPrice;
}
+ public String getPlanName() {
+ return planName;
+ }
+
public BigDecimal getFixedPrice() {
return fixedPrice;
}
@@ -72,6 +80,7 @@ public class PhasePriceOverrideJson {
@Override
public String toString() {
return "PhasePriceOverrideJson{" +
+ "planName='" + planName + '\'' +
"phaseName='" + phaseName + '\'' +
"phaseType='" + phaseType + '\'' +
", fixedPrice=" + fixedPrice +
@@ -94,6 +103,9 @@ public class PhasePriceOverrideJson {
if (fixedPrice != null ? fixedPrice.compareTo(that.fixedPrice) != 0 : that.fixedPrice != null) {
return false;
}
+ if (planName != null ? !planName.equals(that.planName) : that.planName != null) {
+ return false;
+ }
if (phaseName != null ? !phaseName.equals(that.phaseName) : that.phaseName != null) {
return false;
}
@@ -108,7 +120,8 @@ public class PhasePriceOverrideJson {
@Override
public int hashCode() {
- int result = phaseName != null ? phaseName.hashCode() : 0;
+ int result = planName != null ? planName.hashCode() : 0;
+ result = 31 * result + (phaseName != null ? phaseName.hashCode() : 0);
result = 31 * result + (recurringPrice != null ? recurringPrice.hashCode() : 0);
result = 31 * result + (phaseType != null ? phaseType.hashCode() : 0);
result = 31 * result + (recurringPrice != null ? recurringPrice.hashCode() : 0);
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 5629546..491815d 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
@@ -30,6 +30,7 @@ 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.Plan;
import org.killbill.billing.catalog.api.PlanPhase;
import org.killbill.billing.catalog.api.PriceList;
import org.killbill.billing.catalog.api.Product;
@@ -83,20 +84,22 @@ public class SubscriptionJson extends JsonBase {
private final String eventId;
private final String 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 Boolean isBlockedBilling;
private final Boolean isBlockedEntitlement;
private final String serviceName;
private final String serviceStateName;
- private final String phase;
@JsonCreator
public EventSubscriptionJson(@JsonProperty("eventId") final String eventId,
@JsonProperty("billingPeriod") final String billingPeriod,
@JsonProperty("effectiveDt") final LocalDate effectiveDate,
+ @JsonProperty("plan") final String plan,
@JsonProperty("product") final String product,
@JsonProperty("priceList") final String priceList,
@JsonProperty("eventType") final String eventType,
@@ -110,6 +113,7 @@ public class SubscriptionJson extends JsonBase {
this.eventId = eventId;
this.billingPeriod = billingPeriod;
this.effectiveDate = effectiveDate;
+ this.plan = plan;
this.product = product;
this.priceList = priceList;
this.eventType = eventType;
@@ -124,12 +128,14 @@ public class SubscriptionJson extends JsonBase {
super(toAuditLogJson(getAuditLogsForSubscriptionEvent(subscriptionEvent, accountAuditLogs)));
final BillingPeriod billingPeriod = subscriptionEvent.getNextBillingPeriod() != null ? subscriptionEvent.getNextBillingPeriod() : subscriptionEvent.getPrevBillingPeriod();
+ final Plan plan = subscriptionEvent.getNextPlan() != null ? subscriptionEvent.getNextPlan() : subscriptionEvent.getPrevPlan();
final Product product = subscriptionEvent.getNextProduct() != null ? subscriptionEvent.getNextProduct() : subscriptionEvent.getPrevProduct();
final PriceList priceList = subscriptionEvent.getNextPriceList() != null ? subscriptionEvent.getNextPriceList() : subscriptionEvent.getPrevPriceList();
final PlanPhase phase = subscriptionEvent.getNextPhase() != null ? subscriptionEvent.getNextPhase() : subscriptionEvent.getPrevPhase();
this.eventId = subscriptionEvent.getId().toString();
this.billingPeriod = billingPeriod != null ? billingPeriod.toString() : null;
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();
@@ -166,6 +172,10 @@ public class SubscriptionJson extends JsonBase {
return effectiveDate;
}
+ public String getPlan() {
+ return plan;
+ }
+
public String getProduct() {
return product;
}
@@ -204,6 +214,7 @@ public class SubscriptionJson extends JsonBase {
sb.append("eventId='").append(eventId).append('\'');
sb.append(", billingPeriod='").append(billingPeriod).append('\'');
sb.append(", effectiveDate=").append(effectiveDate);
+ sb.append(", plan='").append(plan).append('\'');
sb.append(", product='").append(product).append('\'');
sb.append(", priceList='").append(priceList).append('\'');
sb.append(", eventType='").append(eventType).append('\'');
@@ -251,6 +262,9 @@ public class SubscriptionJson extends JsonBase {
if (priceList != null ? !priceList.equals(that.priceList) : that.priceList != null) {
return false;
}
+ if (plan != null ? !plan.equals(that.plan) : that.plan != null) {
+ return false;
+ }
if (product != null ? !product.equals(that.product) : that.product != null) {
return false;
}
@@ -269,6 +283,7 @@ public class SubscriptionJson extends JsonBase {
int result = eventId != null ? eventId.hashCode() : 0;
result = 31 * result + (billingPeriod != null ? billingPeriod.hashCode() : 0);
result = 31 * result + (effectiveDate != null ? effectiveDate.hashCode() : 0);
+ result = 31 * result + (plan != null ? plan.hashCode() : 0);
result = 31 * result + (product != null ? product.hashCode() : 0);
result = 31 * result + (priceList != null ? priceList.hashCode() : 0);
result = 31 * result + (eventType != null ? eventType.hashCode() : 0);
@@ -378,20 +393,21 @@ public class SubscriptionJson extends JsonBase {
this.events = new LinkedList<EventSubscriptionJson>();
// We fill the catalog info every time we get the currency from the account (even if this is not overridden Plan)
this.priceOverrides = new ArrayList<PhasePriceOverrideJson>();
+
String currentPhaseName = null;
for (final SubscriptionEvent subscriptionEvent : subscription.getSubscriptionEvents()) {
this.events.add(new EventSubscriptionJson(subscriptionEvent, accountAuditLogs));
if (currency != null) {
- final PlanPhase cur = subscriptionEvent.getNextPhase();
- if (cur == null || cur.getName().equals(currentPhaseName)) {
+ final PlanPhase curPlanPhase = subscriptionEvent.getNextPhase();
+ if (curPlanPhase == null || curPlanPhase.getName().equals(currentPhaseName)) {
continue;
}
- currentPhaseName = cur.getName();
+ currentPhaseName = curPlanPhase.getName();
- final BigDecimal fixedPrice = cur.getFixed() != null ? cur.getFixed().getPrice().getPrice(currency) : null;
- final BigDecimal recurringPrice = cur.getRecurring() != null ? cur.getRecurring().getRecurringPrice().getPrice(currency) : null;
- final PhasePriceOverrideJson phase = new PhasePriceOverrideJson(cur.getName(), cur.getPhaseType().toString(), fixedPrice, recurringPrice);
+ final BigDecimal fixedPrice = curPlanPhase.getFixed() != null ? curPlanPhase.getFixed().getPrice().getPrice(currency) : null;
+ final BigDecimal recurringPrice = curPlanPhase.getRecurring() != null ? curPlanPhase.getRecurring().getRecurringPrice().getPrice(currency) : null;
+ final PhasePriceOverrideJson phase = new PhasePriceOverrideJson(subscriptionEvent.getNextPlan().getName(), curPlanPhase.getName(), curPlanPhase.getPhaseType().toString(), fixedPrice, recurringPrice);
priceOverrides.add(phase);
}
}
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 3dcd46f..7087b4f 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
@@ -48,6 +48,7 @@ public class TestBundleJsonWithSubscriptions extends JaxrsTestSuiteNoDB {
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
+ UUID.randomUUID().toString(),
true,
false,
UUID.randomUUID().toString(),
@@ -55,7 +56,7 @@ public class TestBundleJsonWithSubscriptions extends JaxrsTestSuiteNoDB {
UUID.randomUUID().toString(),
null);
- final PhasePriceOverrideJson priceOverride = new PhasePriceOverrideJson(null, "somePhaseType", BigDecimal.ONE, null);
+ final PhasePriceOverrideJson priceOverride = new PhasePriceOverrideJson(null, null, "somePhaseType", BigDecimal.ONE, null);
final SubscriptionJson subscription = new SubscriptionJson(UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
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 5749e61..114d0fc 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
@@ -39,6 +39,7 @@ public class TestBundleTimelineJson extends JaxrsTestSuiteNoDB {
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
+ UUID.randomUUID().toString(),
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 f9e58bb..cee508d 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
@@ -54,6 +54,7 @@ public class TestEntitlementJsonWithEvents extends JaxrsTestSuiteNoDB {
effectiveDate.toLocalDate(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
+ UUID.randomUUID().toString(),
SubscriptionBaseTransitionType.CREATE.toString(),
false,
true,
@@ -62,7 +63,7 @@ public class TestEntitlementJsonWithEvents extends JaxrsTestSuiteNoDB {
PhaseType.DISCOUNT.toString(),
auditLogs);
- final PhasePriceOverrideJson priceOverride = new PhasePriceOverrideJson("bar", null, BigDecimal.TEN, BigDecimal.ONE);
+ final PhasePriceOverrideJson priceOverride = new PhasePriceOverrideJson("foo", "bar", null, BigDecimal.TEN, BigDecimal.ONE);
final SubscriptionJson entitlementJsonWithEvents = new SubscriptionJson(accountId,
bundleId,
pom.xml 2(+1 -1)
diff --git a/pom.xml b/pom.xml
index 7e6042e..c2cdcb7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,7 @@
<parent>
<artifactId>killbill-oss-parent</artifactId>
<groupId>org.kill-bill.billing</groupId>
- <version>0.140.6</version>
+ <version>0.140.7</version>
</parent>
<artifactId>killbill</artifactId>
<version>0.18.2-SNAPSHOT</version>
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 1927323..da4a391 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
@@ -41,7 +41,9 @@ 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.Tags;
+import org.killbill.billing.entitlement.EntitlementTransitionType;
import org.killbill.billing.entitlement.api.Entitlement.EntitlementActionPolicy;
+import org.killbill.billing.entitlement.api.SubscriptionEventType;
import org.killbill.billing.util.api.AuditLevel;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -246,21 +248,75 @@ public class TestEntitlement extends TestJaxrsBase {
input.setBillingPeriod(BillingPeriod.MONTHLY);
input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
final List<PhasePriceOverride> overrides = new ArrayList<PhasePriceOverride>();
- overrides.add(new PhasePriceOverride(null, PhaseType.TRIAL.toString(), BigDecimal.TEN, null));
+ overrides.add(new PhasePriceOverride(null, null, PhaseType.TRIAL.toString(), BigDecimal.TEN, null));
input.setPriceOverrides(overrides);
final Subscription subscription = killBillClient.createSubscription(input, null, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, requestOptions);
Assert.assertEquals(subscription.getPriceOverrides().size(), 2);
- Assert.assertEquals(subscription.getPriceOverrides().get(0).getPhaseName(), "shotgun-monthly-1-trial");
- Assert.assertEquals(subscription.getPriceOverrides().get(0).getFixedPrice().compareTo(BigDecimal.TEN), 0);
- Assert.assertNull(subscription.getPriceOverrides().get(0).getRecurringPrice());
- Assert.assertEquals(subscription.getPriceOverrides().get(1).getPhaseName(), "shotgun-monthly-1-evergreen");
- Assert.assertNull(subscription.getPriceOverrides().get(1).getFixedPrice());
- Assert.assertEquals(subscription.getPriceOverrides().get(1).getRecurringPrice(), new BigDecimal("249.95"));
+
+ Assert.assertEquals(subscription.getEvents().size(), 3);
+ Assert.assertEquals(subscription.getEvents().get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT.name());
+ Assert.assertEquals(subscription.getEvents().get(0).getPlan(), "shotgun-monthly-1");
+ Assert.assertEquals(subscription.getEvents().get(0).getPhase(), "shotgun-monthly-1-trial");
+ Assert.assertEquals(subscription.getEvents().get(0).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
+ 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).getPlan(), "shotgun-monthly-1");
+ Assert.assertEquals(subscription.getEvents().get(1).getPhase(), "shotgun-monthly-1-trial");
+ Assert.assertEquals(subscription.getEvents().get(1).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
+ Assert.assertEquals(subscription.getEvents().get(1).getProduct(), "Shotgun");
+
+ Assert.assertEquals(subscription.getEvents().get(2).getEventType(), SubscriptionEventType.PHASE.name());
+ Assert.assertEquals(subscription.getEvents().get(2).getPlan(), "shotgun-monthly-1");
+ Assert.assertEquals(subscription.getEvents().get(2).getPhase(), "shotgun-monthly-1-evergreen");
+ Assert.assertEquals(subscription.getEvents().get(2).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
+ Assert.assertEquals(subscription.getEvents().get(2).getProduct(), "Shotgun");
+
final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 1);
assertEquals(invoices.get(0).getAmount().compareTo(BigDecimal.TEN), 0);
+
+ // Move clock after phase
+ clock.addDays(30);
+ crappyWaitForLackOfProperSynchonization();
+
+ final Subscription subscription2 = killBillClient.getSubscription(subscription.getSubscriptionId(), requestOptions);
+ Assert.assertEquals(subscription2.getEvents().size(), 3);
+
+ clock.addDays(3);
+
+ // Change Plan
+ 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, basicRequestOptions());
+
+ Assert.assertEquals(subscription3.getEvents().size(), 4);
+ Assert.assertEquals(subscription3.getEvents().get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT.name());
+ Assert.assertEquals(subscription3.getEvents().get(0).getPlan(), "shotgun-monthly-1");
+ Assert.assertEquals(subscription3.getEvents().get(0).getPhase(), "shotgun-monthly-1-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).getPlan(), "shotgun-monthly-1");
+ Assert.assertEquals(subscription3.getEvents().get(1).getPhase(), "shotgun-monthly-1-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).getPlan(), "shotgun-monthly-1");
+ Assert.assertEquals(subscription3.getEvents().get(2).getPhase(), "shotgun-monthly-1-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).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());
+ Assert.assertEquals(subscription3.getEvents().get(3).getProduct(), "Pistol");
}
@Test(groups = "slow", description = "Create a base entitlement and also addOns entitlements under the same bundle")