killbill-memoizeit
Changes
account/pom.xml 2(+1 -1)
analytics/pom.xml 2(+1 -1)
api/pom.xml 2(+1 -1)
beatrix/pom.xml 2(+1 -1)
catalog/pom.xml 2(+1 -1)
entitlement/pom.xml 2(+1 -1)
entitlement/src/main/java/com/ning/billing/entitlement/api/billing/EntitlementBillingApi.java 16(+4 -12)
entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionBuilder.java 124(+124 -0)
entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionTransition.java 35(+22 -13)
entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/ISubscriptionSqlDao.java 15(+12 -3)
entitlement/src/main/java/com/ning/billing/entitlement/events/phase/PhaseEventBuilder.java 41(+41 -0)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateMemory.java 5(+5 -0)
entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/EntitlementDaoMemoryMock.java 4(+2 -2)
entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/TestEntitlementDao.java 131(+0 -131)
invoice/pom.xml 2(+1 -1)
payment/pom.xml 2(+1 -1)
pom.xml 2(+1 -1)
util/pom.xml 2(+1 -1)
Details
account/pom.xml 2(+1 -1)
diff --git a/account/pom.xml b/account/pom.xml
index 11823a4..3443aac 100644
--- a/account/pom.xml
+++ b/account/pom.xml
@@ -13,7 +13,7 @@
<parent>
<groupId>com.ning.billing</groupId>
<artifactId>killbill</artifactId>
- <version>0.0.15-SNAPSHOT</version>
+ <version>0.0.16-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>killbill-account</artifactId>
analytics/pom.xml 2(+1 -1)
diff --git a/analytics/pom.xml b/analytics/pom.xml
index f5cc263..498b3c0 100644
--- a/analytics/pom.xml
+++ b/analytics/pom.xml
@@ -13,7 +13,7 @@
<parent>
<groupId>com.ning.billing</groupId>
<artifactId>killbill</artifactId>
- <version>0.0.15-SNAPSHOT</version>
+ <version>0.0.16-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>killbill-analytics</artifactId>
diff --git a/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java b/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
index 1bf2682..12b6ab9 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
@@ -117,6 +117,7 @@ public class TestAnalyticsService
final DateTime requestedTransitionTime = new DateTime(DateTimeZone.UTC);
final String priceList = "something";
transition = new SubscriptionTransition(
+ UUID.randomUUID(),
subscriptionId,
bundle.getId(),
IEvent.EventType.API_USER,
diff --git a/analytics/src/test/java/com/ning/billing/analytics/TestAnalyticsListener.java b/analytics/src/test/java/com/ning/billing/analytics/TestAnalyticsListener.java
index c4612fd..c0c93aa 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/TestAnalyticsListener.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/TestAnalyticsListener.java
@@ -156,6 +156,7 @@ public class TestAnalyticsListener
final ApiEventType eventType = ApiEventType.CREATE;
final ISubscription.SubscriptionState nextState = ISubscription.SubscriptionState.ACTIVE;
return new SubscriptionTransition(
+ UUID.randomUUID(),
subscriptionId,
bundleUUID,
IEvent.EventType.API_USER,
@@ -203,6 +204,7 @@ public class TestAnalyticsListener
)
{
return new SubscriptionTransition(
+ UUID.randomUUID(),
subscriptionId,
bundleUUID,
IEvent.EventType.API_USER,
api/pom.xml 2(+1 -1)
diff --git a/api/pom.xml b/api/pom.xml
index 6e07c7b..5a01c5b 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -13,7 +13,7 @@
<parent>
<groupId>com.ning.billing</groupId>
<artifactId>killbill</artifactId>
- <version>0.0.15-SNAPSHOT</version>
+ <version>0.0.16-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>killbill-api</artifactId>
diff --git a/api/src/main/java/com/ning/billing/entitlement/api/user/ISubscriptionTransition.java b/api/src/main/java/com/ning/billing/entitlement/api/user/ISubscriptionTransition.java
index 718c28a..e968aa4 100644
--- a/api/src/main/java/com/ning/billing/entitlement/api/user/ISubscriptionTransition.java
+++ b/api/src/main/java/com/ning/billing/entitlement/api/user/ISubscriptionTransition.java
@@ -37,6 +37,8 @@ public interface ISubscriptionTransition extends IEventBusType {
PHASE
}
+ UUID getId();
+
SubscriptionTransitionType getTransitionType();
UUID getBundleId();
beatrix/pom.xml 2(+1 -1)
diff --git a/beatrix/pom.xml b/beatrix/pom.xml
index 7c90e56..3867975 100644
--- a/beatrix/pom.xml
+++ b/beatrix/pom.xml
@@ -13,7 +13,7 @@
<parent>
<groupId>com.ning.billing</groupId>
<artifactId>killbill</artifactId>
- <version>0.0.15-SNAPSHOT</version>
+ <version>0.0.16-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>killbill-beatrix</artifactId>
catalog/pom.xml 2(+1 -1)
diff --git a/catalog/pom.xml b/catalog/pom.xml
index 125ebdb..fb48f3d 100644
--- a/catalog/pom.xml
+++ b/catalog/pom.xml
@@ -13,7 +13,7 @@
<parent>
<groupId>com.ning.billing</groupId>
<artifactId>killbill</artifactId>
- <version>0.0.15-SNAPSHOT</version>
+ <version>0.0.16-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>killbill-catalog</artifactId>
entitlement/pom.xml 2(+1 -1)
diff --git a/entitlement/pom.xml b/entitlement/pom.xml
index b73fb04..65c4d26 100644
--- a/entitlement/pom.xml
+++ b/entitlement/pom.xml
@@ -13,7 +13,7 @@
<parent>
<groupId>com.ning.billing</groupId>
<artifactId>killbill</artifactId>
- <version>0.0.15-SNAPSHOT</version>
+ <version>0.0.16-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>killbill-entitlement</artifactId>
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/billing/EntitlementBillingApi.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/billing/EntitlementBillingApi.java
index d3e3c6e..c37c79d 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/billing/EntitlementBillingApi.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/billing/EntitlementBillingApi.java
@@ -27,7 +27,7 @@ import com.ning.billing.account.api.IAccount;
import com.ning.billing.catalog.api.ICatalog;
import com.ning.billing.entitlement.api.user.ISubscription;
import com.ning.billing.entitlement.api.user.Subscription;
-import com.ning.billing.entitlement.api.user.Subscription.SubscriptionBuilder;
+import com.ning.billing.entitlement.api.user.SubscriptionBuilder;
import com.ning.billing.entitlement.engine.core.Engine;
import com.ning.billing.entitlement.engine.dao.IEntitlementDao;
import com.ning.billing.util.clock.IClock;
@@ -62,18 +62,10 @@ public class EntitlementBillingApi implements IEntitlementBillingApi {
new EntitlementBillingApiException(String.format("Unknwon subscription %s", subscriptionId));
}
- Subscription updatedSubscription = new SubscriptionBuilder()
- .setId(subscription.getId())
- .setBundleId(subscription.getBundleId())
- .setStartDate(subscription.getStartDate())
- .setBundleStartDate(subscription.getBundleStartDate())
+ SubscriptionBuilder builder = new SubscriptionBuilder(subscription)
.setChargedThroughDate(ctd)
- .setPaidThroughDate(subscription.getPaidThroughDate())
- .setActiveVersion(subscription.getActiveVersion())
- .setCategory(subscription.getCategory())
- .build();
-
- dao.updateSubscription(updatedSubscription);
+ .setPaidThroughDate(subscription.getPaidThroughDate());
+ dao.updateSubscription(new Subscription(builder, false));
}
}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/EntitlementUserApi.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/EntitlementUserApi.java
index decc852..0a2715f 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/EntitlementUserApi.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/EntitlementUserApi.java
@@ -30,6 +30,7 @@ import com.ning.billing.catalog.api.ICatalogService;
import com.ning.billing.catalog.api.IPlan;
import com.ning.billing.catalog.api.IPlanPhase;
import com.ning.billing.catalog.api.IPriceListSet;
+import com.ning.billing.catalog.api.PlanAlignmentChange;
import com.ning.billing.entitlement.alignment.IPlanAligner;
import com.ning.billing.entitlement.alignment.IPlanAligner.TimedPhase;
import com.ning.billing.entitlement.api.user.ISubscription;
@@ -39,6 +40,7 @@ import com.ning.billing.entitlement.engine.dao.IEntitlementDao;
import com.ning.billing.entitlement.events.IEvent;
import com.ning.billing.entitlement.events.phase.IPhaseEvent;
import com.ning.billing.entitlement.events.phase.PhaseEvent;
+import com.ning.billing.entitlement.events.user.ApiEventBuilder;
import com.ning.billing.entitlement.events.user.ApiEventCreate;
import com.ning.billing.entitlement.exceptions.EntitlementError;
import com.ning.billing.util.clock.Clock;
@@ -100,13 +102,11 @@ public class EntitlementUserApi implements IEntitlementUserApi {
String realPriceList = (priceList == null) ? IPriceListSet.DEFAULT_PRICELIST_NAME : priceList;
DateTime now = clock.getUTCNow();
- requestedDate = (requestedDate != null) ? Clock.truncateMs(requestedDate) : null;
+ requestedDate = (requestedDate != null) ? Clock.truncateMs(requestedDate) : now;
if (requestedDate != null && requestedDate.isAfter(now)) {
throw new EntitlementUserApiException(ErrorCode.ENT_INVALID_REQUESTED_DATE, requestedDate.toString());
}
- requestedDate = (requestedDate == null) ? now : requestedDate;
-
IPlan plan = catalogService.getCatalog().getPlan(productName, term, realPriceList);
if (plan == null) {
throw new EntitlementUserApiException(ErrorCode.ENT_CREATE_BAD_CATALOG, productName, term, realPriceList);
@@ -146,13 +146,24 @@ public class EntitlementUserApi implements IEntitlementUserApi {
}
DateTime effectiveDate = requestedDate;
- Subscription subscription = new Subscription(bundleId, plan.getProduct().getCategory(), bundleStartDate, effectiveDate);
+ Subscription subscription = new Subscription(new SubscriptionBuilder()
+ .setId(UUID.randomUUID())
+ .setBundleId(bundleId)
+ .setCategory(plan.getProduct().getCategory())
+ .setBundleStartDate(bundleStartDate)
+ .setStartDate(effectiveDate),
+ false);
TimedPhase currentTimedPhase = planAligner.getCurrentTimedPhaseOnCreate(subscription, plan, realPriceList, effectiveDate);
- ApiEventCreate creationEvent =
- new ApiEventCreate(subscription.getId(), bundleStartDate, now, plan.getName(), currentTimedPhase.getPhase().getName(), realPriceList,
- requestedDate, effectiveDate, subscription.getActiveVersion());
-
+ ApiEventCreate creationEvent = new ApiEventCreate(new ApiEventBuilder()
+ .setSubscriptionId(subscription.getId())
+ .setEventPlan(plan.getName())
+ .setEventPlanPhase(currentTimedPhase.getPhase().getName())
+ .setEventPriceList(realPriceList)
+ .setActiveVersion(subscription.getActiveVersion())
+ .setProcessedDate(now)
+ .setEffectiveDate(effectiveDate)
+ .setRequestedDate(requestedDate));
TimedPhase nextTimedPhase = planAligner.getNextTimedPhaseOnCreate(subscription, plan, realPriceList, effectiveDate);
IPhaseEvent nextPhaseEvent = PhaseEvent.getNextPhaseEvent(nextTimedPhase, subscription, now);
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/Subscription.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/Subscription.java
index b1c0b82..a87e73c 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/Subscription.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/Subscription.java
@@ -16,17 +16,17 @@
package com.ning.billing.entitlement.api.user;
-import java.lang.reflect.Field;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
-import com.ning.billing.ErrorCode;
-import com.ning.billing.account.api.IAccount;
import org.joda.time.DateTime;
+import com.ning.billing.ErrorCode;
+
import com.ning.billing.catalog.api.ActionPolicy;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.catalog.api.CatalogApiException;
@@ -47,8 +47,10 @@ import com.ning.billing.entitlement.events.IEvent;
import com.ning.billing.entitlement.events.IEvent.EventType;
import com.ning.billing.entitlement.events.phase.IPhaseEvent;
import com.ning.billing.entitlement.events.phase.PhaseEvent;
+import com.ning.billing.entitlement.events.user.ApiEventBuilder;
import com.ning.billing.entitlement.events.user.ApiEventCancel;
import com.ning.billing.entitlement.events.user.ApiEventChange;
+import com.ning.billing.entitlement.events.user.ApiEventCreate;
import com.ning.billing.entitlement.events.user.ApiEventType;
import com.ning.billing.entitlement.events.user.ApiEventUncancel;
import com.ning.billing.entitlement.events.user.IApiEvent;
@@ -59,118 +61,55 @@ import com.ning.billing.util.clock.IClock;
public class Subscription extends PrivateFields implements ISubscription {
+ //
+ // Singletons used to perform API changes
+ private final IClock clock;
+ private final IEntitlementDao dao;
+ private final ICatalog catalog;
+ private final IPlanAligner planAligner;
+
+ //
+ // Final subscription fields
+ //
private final UUID id;
private final UUID bundleId;
private final DateTime startDate;
private final DateTime bundleStartDate;
- private final long activeVersion;
private final ProductCategory category;
- private final IClock clock;
- private final IEntitlementDao dao;
- private final ICatalog catalog;
- private final IPlanAligner planAligner;
-
- // STEPH interaction with billing /payment system
+ //
+ // Those can be modified through non User APIs, and a new Subscription object would be created
+ //
+ private final long activeVersion;
private final DateTime chargedThroughDate;
private final DateTime paidThroughDate;
- // STEPH non final because of change/ cancel API at the object level
+ //
+ // User APIs (createm chnage, cancel,...) will recompute those each time,
+ // so the user holding that subscription object get the correct state when
+ // the call completes
+ //
private List<SubscriptionTransition> transitions;
-
- public static class SubscriptionBuilder {
- private UUID id;
- private UUID bundleId;
- private DateTime startDate;
- private DateTime bundleStartDate;
- private Long activeVersion;
- private ProductCategory category;
- private DateTime chargedThroughDate;
- private DateTime paidThroughDate;
-
- public SubscriptionBuilder setId(UUID id) {
- this.id = id;
- return this;
- }
- public SubscriptionBuilder setBundleId(UUID bundleId) {
- this.bundleId = bundleId;
- return this;
- }
- public SubscriptionBuilder setStartDate(DateTime startDate) {
- this.startDate = startDate;
- return this;
- }
- public SubscriptionBuilder setBundleStartDate(DateTime bundleStartDate) {
- this.bundleStartDate = bundleStartDate;
- return this;
- }
- public SubscriptionBuilder setActiveVersion(long activeVersion) {
- this.activeVersion = activeVersion;
- return this;
- }
- public SubscriptionBuilder setChargedThroughDate(DateTime chargedThroughDate) {
- this.chargedThroughDate = chargedThroughDate;
- return this;
- }
- public SubscriptionBuilder setPaidThroughDate(DateTime paidThroughDate) {
- this.paidThroughDate = paidThroughDate;
- return this;
- }
- public SubscriptionBuilder setCategory(ProductCategory category) {
- this.category = category;
- return this;
- }
-
- private void checkAllFieldsSet() {
- for (Field cur : SubscriptionBuilder.class.getDeclaredFields()) {
- try {
- Object value = cur.get(this);
- if (value == null) {
- throw new EntitlementError(String.format("Field %s has not been set for Subscription",
- cur.getName()));
- }
- } catch (IllegalAccessException e) {
- throw new EntitlementError(String.format("Failed to access value for field %s for Subscription",
- cur.getName()), e);
- }
- }
- }
-
- public Subscription build() {
- //checkAllFieldsSet();
- return new Subscription(id, bundleId, category, bundleStartDate, startDate, chargedThroughDate, paidThroughDate, activeVersion);
- }
-
- }
-
- public Subscription(UUID bundleId, ProductCategory category, DateTime bundleStartDate, DateTime startDate) {
- this(UUID.randomUUID(), bundleId, category, bundleStartDate, startDate, null, null, SubscriptionEvents.INITIAL_VERSION);
- }
-
-
- public Subscription(UUID id, UUID bundleId, ProductCategory category, DateTime bundleStartDate, DateTime startDate, DateTime ctd, DateTime ptd, long activeVersion) {
-
+ public Subscription(SubscriptionBuilder builder, boolean rebuildTransition) {
super();
this.clock = InjectorMagic.getClock();
this.dao = InjectorMagic.getEntitlementDao();
this.catalog = InjectorMagic.getCatlog();
this.planAligner = InjectorMagic.getPlanAligner();
- this.id = id;
- this.bundleId = bundleId;
- this.startDate = startDate;
- this.bundleStartDate = bundleStartDate;
- this.category = category;
-
- this.activeVersion = activeVersion;
-
- this.chargedThroughDate = ctd;
- this.paidThroughDate = ptd;
-
- rebuildTransitions();
+ this.id = builder.getId();
+ this.bundleId = builder.getBundleId();
+ this.startDate = builder.getStartDate();
+ this.bundleStartDate = builder.getBundleStartDate();
+ this.category = builder.getCategory();
+ this.activeVersion = builder.getActiveVersion();
+ this.chargedThroughDate = builder.getChargedThroughDate();
+ this.paidThroughDate = builder.getPaidThroughDate();
+ if (rebuildTransition) {
+ rebuildTransitions();
+ }
}
-
@Override
public UUID getId() {
return id;
@@ -243,7 +182,14 @@ public class Subscription extends PrivateFields implements ISubscription {
ActionPolicy policy = catalog.getPlanCancelPolicy(planPhase);
DateTime effectiveDate = getPlanChangeEffectiveDate(policy, now);
- IEvent cancelEvent = new ApiEventCancel(id, bundleStartDate, now, now, effectiveDate, activeVersion);
+
+ IEvent cancelEvent = new ApiEventCancel(new ApiEventBuilder()
+ .setSubscriptionId(id)
+ .setActiveVersion(activeVersion)
+ .setProcessedDate(now)
+ .setEffectiveDate(effectiveDate)
+ .setRequestedDate(now));
+
dao.cancelSubscription(id, cancelEvent);
rebuildTransitions();
}
@@ -254,7 +200,13 @@ public class Subscription extends PrivateFields implements ISubscription {
throw new EntitlementUserApiException(ErrorCode.ENT_UNCANCEL_BAD_STATE, id.toString());
}
DateTime now = clock.getUTCNow();
- IEvent uncancelEvent = new ApiEventUncancel(id, bundleStartDate, now, now, now, activeVersion);
+ IEvent uncancelEvent = new ApiEventUncancel(new ApiEventBuilder()
+ .setSubscriptionId(id)
+ .setActiveVersion(activeVersion)
+ .setProcessedDate(now)
+ .setRequestedDate(now)
+ .setEffectiveDate(now));
+
List<IEvent> uncancelEvents = new ArrayList<IEvent>();
uncancelEvents.add(uncancelEvent);
@@ -322,8 +274,16 @@ public class Subscription extends PrivateFields implements ISubscription {
DateTime effectiveDate = getPlanChangeEffectiveDate(policy, now);
TimedPhase currentTimedPhase = planAligner.getCurrentTimedPhaseOnChange(this, newPlan, newPriceList.getName(), effectiveDate);
- IEvent changeEvent = new ApiEventChange(id, bundleStartDate, now, newPlan.getName(), currentTimedPhase.getPhase().getName(),
- newPriceList.getName(), now, effectiveDate, activeVersion);
+
+ IEvent changeEvent = new ApiEventChange(new ApiEventBuilder()
+ .setSubscriptionId(id)
+ .setEventPlan(newPlan.getName())
+ .setEventPlanPhase(currentTimedPhase.getPhase().getName())
+ .setEventPriceList(newPriceList.getName())
+ .setActiveVersion(activeVersion)
+ .setProcessedDate(now)
+ .setEffectiveDate(effectiveDate)
+ .setRequestedDate(now));
TimedPhase nextTimedPhase = planAligner.getNextTimedPhaseOnChange(this, newPlan, newPriceList.getName(), effectiveDate);
IPhaseEvent nextPhaseEvent = PhaseEvent.getNextPhaseEvent(nextTimedPhase, this, now);
@@ -363,6 +323,19 @@ public class Subscription extends PrivateFields implements ISubscription {
return latestSubscription;
}
+ public ISubscriptionTransition getTransitionFromEvent(IEvent event) {
+ if (transitions == null || event == null) {
+ return null;
+ }
+
+ for (ISubscriptionTransition cur : transitions) {
+ if (cur.getId().equals(event.getId())) {
+ return cur;
+ }
+ }
+ return null;
+ }
+
public long getActiveVersion() {
return activeVersion;
}
@@ -407,7 +380,7 @@ public class Subscription extends PrivateFields implements ISubscription {
public List<ISubscriptionTransition> getActiveTransitions() {
if (transitions == null) {
- return null;
+ return Collections.emptyList();
}
List<ISubscriptionTransition> activeTransitions = new ArrayList<ISubscriptionTransition>();
@@ -556,7 +529,7 @@ public class Subscription extends PrivateFields implements ISubscription {
IPlanPhase nextPhase = catalog.getPhaseFromName(nextPhaseName);
SubscriptionTransition transition =
- new SubscriptionTransition(id, bundleId, cur.getType(), apiEventType,
+ new SubscriptionTransition(cur.getId(), id, bundleId, cur.getType(), apiEventType,
cur.getRequestedDate(), cur.getEffectiveDate(),
previousState, previousPlan, previousPhase, previousPriceList,
nextState, nextPlan, nextPhase, nextPriceList);
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionBuilder.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionBuilder.java
new file mode 100644
index 0000000..d14b754
--- /dev/null
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionBuilder.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.entitlement.api.user;
+
+import java.lang.reflect.Field;
+import java.util.UUID;
+
+import org.joda.time.DateTime;
+
+import com.ning.billing.catalog.api.ProductCategory;
+import com.ning.billing.entitlement.exceptions.EntitlementError;
+
+public class SubscriptionBuilder {
+
+ private UUID id;
+ private UUID bundleId;
+ private DateTime startDate;
+ private DateTime bundleStartDate;
+ private Long activeVersion;
+ private ProductCategory category;
+ private DateTime chargedThroughDate;
+ private DateTime paidThroughDate;
+
+ public SubscriptionBuilder() {
+ this.activeVersion = SubscriptionEvents.INITIAL_VERSION;
+ }
+
+ public SubscriptionBuilder(Subscription original) {
+ this.id = original.getId();
+ this.bundleId = original.getBundleId();
+ this.startDate = original.getStartDate();
+ this.bundleStartDate = original.getBundleStartDate();
+ this.category = original.getCategory();
+ this.activeVersion = original.getActiveVersion();
+ this.chargedThroughDate = original.getChargedThroughDate();
+ this.paidThroughDate = original.getPaidThroughDate();
+ }
+
+ public SubscriptionBuilder setId(UUID id) {
+ this.id = id;
+ return this;
+ }
+ public SubscriptionBuilder setBundleId(UUID bundleId) {
+ this.bundleId = bundleId;
+ return this;
+ }
+ public SubscriptionBuilder setStartDate(DateTime startDate) {
+ this.startDate = startDate;
+ return this;
+ }
+ public SubscriptionBuilder setBundleStartDate(DateTime bundleStartDate) {
+ this.bundleStartDate = bundleStartDate;
+ return this;
+ }
+ public SubscriptionBuilder setActiveVersion(long activeVersion) {
+ this.activeVersion = activeVersion;
+ return this;
+ }
+ public SubscriptionBuilder setChargedThroughDate(DateTime chargedThroughDate) {
+ this.chargedThroughDate = chargedThroughDate;
+ return this;
+ }
+ public SubscriptionBuilder setPaidThroughDate(DateTime paidThroughDate) {
+ this.paidThroughDate = paidThroughDate;
+ return this;
+ }
+ public SubscriptionBuilder setCategory(ProductCategory category) {
+ this.category = category;
+ return this;
+ }
+
+ public UUID getId() {
+ return id;
+ }
+ public UUID getBundleId() {
+ return bundleId;
+ }
+ public DateTime getStartDate() {
+ return startDate;
+ }
+ public DateTime getBundleStartDate() {
+ return bundleStartDate;
+ }
+ public Long getActiveVersion() {
+ return activeVersion;
+ }
+ public ProductCategory getCategory() {
+ return category;
+ }
+ public DateTime getChargedThroughDate() {
+ return chargedThroughDate;
+ }
+ public DateTime getPaidThroughDate() {
+ return paidThroughDate;
+ }
+ private void checkAllFieldsSet() {
+ for (Field cur : SubscriptionBuilder.class.getDeclaredFields()) {
+ try {
+ Object value = cur.get(this);
+ if (value == null) {
+ throw new EntitlementError(String.format("Field %s has not been set for Subscription",
+ cur.getName()));
+ }
+ } catch (IllegalAccessException e) {
+ throw new EntitlementError(String.format("Failed to access value for field %s for Subscription",
+ cur.getName()), e);
+ }
+ }
+ }
+}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionTransition.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionTransition.java
index 616e871..7f8bc8c 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionTransition.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionTransition.java
@@ -32,6 +32,7 @@ public class SubscriptionTransition implements ISubscriptionTransition {
private final UUID subscriptionId;
private final UUID bundleId;
+ private final UUID eventId;
private final EventType eventType;
private final ApiEventType apiEventType;
private final DateTime requestedTransitionTime;
@@ -45,11 +46,12 @@ public class SubscriptionTransition implements ISubscriptionTransition {
private final IPlan nextPlan;
private final IPlanPhase nextPhase;
- public SubscriptionTransition(UUID subscriptionId, UUID bundleId, EventType eventType,
+ public SubscriptionTransition(UUID eventId, UUID subscriptionId, UUID bundleId, EventType eventType,
ApiEventType apiEventType, DateTime requestedTransitionTime, DateTime effectiveTransitionTime,
SubscriptionState previousState, IPlan previousPlan, IPlanPhase previousPhase, String previousPriceList,
SubscriptionState nextState, IPlan nextPlan, IPlanPhase nextPhase, String nextPriceList) {
super();
+ this.eventId = eventId;
this.subscriptionId = subscriptionId;
this.bundleId = bundleId;
this.eventType = eventType;
@@ -67,6 +69,11 @@ public class SubscriptionTransition implements ISubscriptionTransition {
}
@Override
+ public UUID getId() {
+ return eventId;
+ }
+
+ @Override
public UUID getSubscriptionId() {
return subscriptionId;
}
@@ -151,17 +158,19 @@ public class SubscriptionTransition implements ISubscriptionTransition {
@Override
public String toString() {
- return "SubscriptionTransition [subscriptionId=" + subscriptionId
- + ", eventType=" + eventType + ", apiEventType="
- + apiEventType + ", requestedTransitionTime=" + requestedTransitionTime
- + ", effectiveTransitionTime=" + effectiveTransitionTime
- + ", previousState=" + previousState + ", previousPlan="
- + ((previousPlan != null) ? previousPlan.getName() : null)
- + ", previousPhase=" + ((previousPhase != null) ? previousPhase.getName() : null)
- + ", previousPriceList " + previousPriceList
- + ", nextState=" + nextState
- + ", nextPlan=" + ((nextPlan != null) ? nextPlan.getName() : null)
- + ", nextPriceList " + nextPriceList
- + ", nextPhase=" + ((nextPhase != null) ? nextPhase.getName() : null) + "]";
+ return "SubscriptionTransition [eventId=" + eventId
+ + ", subscriptionId=" + subscriptionId
+ + ", eventType=" + eventType + ", apiEventType="
+ + apiEventType + ", requestedTransitionTime=" + requestedTransitionTime
+ + ", effectiveTransitionTime=" + effectiveTransitionTime
+ + ", previousState=" + previousState + ", previousPlan="
+ + ((previousPlan != null) ? previousPlan.getName() : null)
+ + ", previousPhase=" + ((previousPhase != null) ? previousPhase.getName() : null)
+ + ", previousPriceList " + previousPriceList
+ + ", nextState=" + nextState
+ + ", nextPlan=" + ((nextPlan != null) ? nextPlan.getName() : null)
+ + ", nextPriceList " + nextPriceList
+ + ", nextPhase=" + ((nextPhase != null) ? nextPhase.getName() : null) + "]";
}
+
}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java b/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java
index 2587baa..2b47f9c 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java
@@ -132,7 +132,7 @@ public class Engine implements IEventListener, IEntitlementService {
insertNextPhaseEvent(subscription);
}
try {
- eventBus.post(subscription.getLatestTranstion());
+ eventBus.post(subscription.getTransitionFromEvent(event));
} catch (EventBusException e) {
log.warn("Failed to post entitlement event " + event, e);
}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/EntitlementDao.java b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/EntitlementDao.java
index b490fcd..943a0dc 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/EntitlementDao.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/EntitlementDao.java
@@ -37,6 +37,7 @@ import com.ning.billing.config.IEntitlementConfig;
import com.ning.billing.entitlement.api.user.ISubscription;
import com.ning.billing.entitlement.api.user.ISubscriptionBundle;
import com.ning.billing.entitlement.api.user.Subscription;
+import com.ning.billing.entitlement.api.user.SubscriptionBuilder;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.entitlement.events.IEvent;
import com.ning.billing.entitlement.events.IEvent.EventType;
@@ -225,8 +226,7 @@ public class EntitlementDao implements IEntitlementDao {
return null;
}
});
- return new Subscription(subscription.getId(), subscription.getBundleId(),subscription.getCategory(), subscription.getBundleStartDate(),
- subscription.getStartDate(), subscription.getChargedThroughDate(), subscription.getPaidThroughDate(), subscription.getActiveVersion());
+ return new Subscription(new SubscriptionBuilder(subscription), true);
}
@Override
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/IEventSqlDao.java b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/IEventSqlDao.java
index 3c2180d..ff53ef2 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/IEventSqlDao.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/IEventSqlDao.java
@@ -38,11 +38,14 @@ import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
import org.skife.jdbi.v2.sqlobject.stringtemplate.ExternalizedSqlViaStringTemplate3;
import org.skife.jdbi.v2.tweak.ResultSetMapper;
+import com.ning.billing.entitlement.events.EventBaseBuilder;
import com.ning.billing.entitlement.events.IEvent;
import com.ning.billing.entitlement.events.IEvent.EventType;
import com.ning.billing.entitlement.events.IEventLyfecycle.IEventLyfecycleState;
import com.ning.billing.entitlement.events.phase.IPhaseEvent;
import com.ning.billing.entitlement.events.phase.PhaseEvent;
+import com.ning.billing.entitlement.events.phase.PhaseEventBuilder;
+import com.ning.billing.entitlement.events.user.ApiEventBuilder;
import com.ning.billing.entitlement.events.user.ApiEventCancel;
import com.ning.billing.entitlement.events.user.ApiEventChange;
import com.ning.billing.entitlement.events.user.ApiEventCreate;
@@ -125,7 +128,7 @@ public interface IEventSqlDao extends Transactional<IEventSqlDao>, CloseMe, Tran
@Override
public IEvent map(int index, ResultSet r, StatementContext ctx)
- throws SQLException {
+ throws SQLException {
UUID id = UUID.fromString(r.getString("event_id"));
EventType eventType = EventType.valueOf(r.getString("event_type"));
@@ -143,28 +146,47 @@ public interface IEventSqlDao extends Transactional<IEventSqlDao>, CloseMe, Tran
UUID processingOwner = (r.getString("processing_owner") != null) ? UUID.fromString(r.getString("processing_owner")) : null;
IEventLyfecycleState processingState = IEventLyfecycleState.valueOf(r.getString("processing_state"));
+ EventBaseBuilder<?> base = ((eventType == EventType.PHASE) ?
+ new PhaseEventBuilder() :
+ new ApiEventBuilder())
+ .setUuid(id)
+ .setSubscriptionId(subscriptionId)
+ .setRequestedDate(requestedDate)
+ .setEffectiveDate(effectiveDate)
+ .setProcessedDate(createdDate)
+ .setActiveVersion(currentVersion)
+ .setActive(isActive)
+ .setProcessingOwner(processingOwner)
+ .setNextAvailableProcessingTime(nextAvailableDate)
+ .setProcessingState(processingState);
+
+
IEvent result = null;
if (eventType == EventType.PHASE) {
- result = new PhaseEvent(id, subscriptionId, phaseName, requestedDate, effectiveDate, createdDate,
- currentVersion, isActive, processingOwner, nextAvailableDate, processingState);
- } else if (userType == ApiEventType.CREATE) {
- result = new ApiEventCreate(id, subscriptionId, createdDate, planName, phaseName, priceListName, requestedDate, effectiveDate,
- currentVersion, isActive, processingOwner, nextAvailableDate, processingState);
- } else if (userType == ApiEventType.CHANGE) {
- result = new ApiEventChange(id, subscriptionId, createdDate, planName, phaseName, priceListName, requestedDate, effectiveDate,
- currentVersion, isActive, processingOwner, nextAvailableDate, processingState);
- } else if (userType == ApiEventType.CANCEL) {
- result = new ApiEventCancel(id, subscriptionId, createdDate, planName, phaseName, priceListName, requestedDate, effectiveDate,
- currentVersion, isActive, processingOwner, nextAvailableDate, processingState);
- } else if (userType == ApiEventType.PAUSE) {
- result = new ApiEventPause(id, subscriptionId, createdDate, planName, phaseName, priceListName, requestedDate, effectiveDate,
- currentVersion, isActive, processingOwner, nextAvailableDate, processingState);
- } else if (userType == ApiEventType.RESUME) {
- result = new ApiEventResume(id, subscriptionId, createdDate, planName, phaseName, priceListName, requestedDate, effectiveDate,
- currentVersion, isActive, processingOwner, nextAvailableDate, processingState);
- } else if (userType == ApiEventType.UNCANCEL) {
- result = new ApiEventUncancel(id, subscriptionId, createdDate, planName, phaseName, priceListName, requestedDate, effectiveDate,
- currentVersion, isActive, processingOwner, nextAvailableDate, processingState);
+ EventBaseBuilder<PhaseEventBuilder> realBase = (EventBaseBuilder<PhaseEventBuilder>) base;
+ result = new PhaseEvent(new PhaseEventBuilder(realBase).setPhaseName(phaseName));
+ } else if (eventType == EventType.API_USER) {
+
+ EventBaseBuilder<ApiEventBuilder> realBase = (EventBaseBuilder<ApiEventBuilder>) base;
+ ApiEventBuilder builder = new ApiEventBuilder(realBase)
+ .setEventPlan(planName)
+ .setEventPlanPhase(phaseName)
+ .setEventPriceList(priceListName)
+ .setEventType(userType);
+
+ if (userType == ApiEventType.CREATE) {
+ result = new ApiEventCreate(builder);
+ } else if (userType == ApiEventType.CHANGE) {
+ result = new ApiEventChange(builder);
+ } else if (userType == ApiEventType.CANCEL) {
+ result = new ApiEventCancel(builder);
+ } else if (userType == ApiEventType.PAUSE) {
+ result = new ApiEventPause(builder);
+ } else if (userType == ApiEventType.RESUME) {
+ result = new ApiEventResume(builder);
+ } else if (userType == ApiEventType.UNCANCEL) {
+ result = new ApiEventUncancel(builder);
+ }
} else {
throw new EntitlementError(String.format("Can't deserialize event %s", eventType));
}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/ISubscriptionSqlDao.java b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/ISubscriptionSqlDao.java
index e1af556..f3c5c7d 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/ISubscriptionSqlDao.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/ISubscriptionSqlDao.java
@@ -41,6 +41,8 @@ import org.skife.jdbi.v2.tweak.ResultSetMapper;
import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.entitlement.api.user.ISubscription;
import com.ning.billing.entitlement.api.user.Subscription;
+import com.ning.billing.entitlement.api.user.SubscriptionBuilder;
+
@ExternalizedSqlViaStringTemplate3()
public interface ISubscriptionSqlDao extends Transactional<ISubscriptionSqlDao>, CloseMe, Transmogrifier {
@@ -98,10 +100,17 @@ public interface ISubscriptionSqlDao extends Transactional<ISubscriptionSqlDao>,
DateTime ptd = getDate(r, "ptd_dt");
long activeVersion = r.getLong("active_version");
- Subscription subscription = new Subscription(id, bundleId, category, bundleStartDate, startDate, ctd, ptd, activeVersion);
+ Subscription subscription = new Subscription(new SubscriptionBuilder()
+ .setId(id)
+ .setBundleId(bundleId)
+ .setCategory(category)
+ .setBundleStartDate(bundleStartDate)
+ .setStartDate(startDate)
+ .setActiveVersion(activeVersion)
+ .setChargedThroughDate(ctd)
+ .setPaidThroughDate(ptd),
+ true);
return subscription;
}
}
-
-
}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBase.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBase.java
index b1e9f02..84e0b50 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBase.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBase.java
@@ -40,6 +40,20 @@ public abstract class EventBase implements IEvent {
private DateTime nextAvailableProcessingTime;
private IEventLyfecycleState processingState;
+ public EventBase(EventBaseBuilder builder) {
+ this.uuid = builder.getUuid();
+ this.subscriptionId = builder.getSubscriptionId();
+ this.requestedDate = builder.getRequestedDate();
+ this.effectiveDate = builder.getEffectiveDate();
+ this.processedDate = builder.getProcessedDate();
+
+ this.activeVersion = builder.getActiveVersion();
+ this.isActive = builder.isActive();
+ this.processingOwner = builder.getProcessingOwner();
+ this.nextAvailableProcessingTime = builder.getNextAvailableProcessingTime();
+ this.processingState = builder.getProcessingState();
+ }
+
public EventBase(UUID subscriptionId, DateTime requestedDate,
DateTime effectiveDate, DateTime processedDate,
long activeVersion, boolean isActive) {
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBaseBuilder.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBaseBuilder.java
new file mode 100644
index 0000000..69980a3
--- /dev/null
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBaseBuilder.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.entitlement.events;
+
+import java.util.UUID;
+
+import org.joda.time.DateTime;
+
+import com.ning.billing.entitlement.events.IEventLyfecycle.IEventLyfecycleState;
+
+@SuppressWarnings("unchecked")
+public class EventBaseBuilder<T extends EventBaseBuilder<T>> {
+
+ private UUID uuid;
+ private UUID subscriptionId;
+ private DateTime requestedDate;
+ private DateTime effectiveDate;
+ private DateTime processedDate;
+
+ private long activeVersion;
+ private boolean isActive;
+ private UUID processingOwner;
+ private DateTime nextAvailableProcessingTime;
+ private IEventLyfecycleState processingState;
+
+
+ public EventBaseBuilder() {
+ this.uuid = UUID.randomUUID();
+ this.isActive = true;
+ this.processingState = IEventLyfecycleState.AVAILABLE;
+ }
+
+ public EventBaseBuilder(EventBaseBuilder<?> copy) {
+ this.uuid = copy.uuid;
+ this.subscriptionId = copy.subscriptionId;
+ this.requestedDate = copy.requestedDate;
+ this.effectiveDate = copy.effectiveDate;
+ this.processedDate = copy.processedDate;
+
+ this.activeVersion = copy.activeVersion;
+ this.isActive = copy.isActive;
+ this.processingOwner = copy.processingOwner;
+ this.nextAvailableProcessingTime = copy.nextAvailableProcessingTime;
+ this.processingState = copy.processingState;
+ }
+
+ public T setUuid(UUID uuid) {
+ this.uuid = uuid;
+ return (T) this;
+ }
+
+ public T setSubscriptionId(UUID subscriptionId) {
+ this.subscriptionId = subscriptionId;
+ return (T) this;
+ }
+
+ public T setRequestedDate(DateTime requestedDate) {
+ this.requestedDate = requestedDate;
+ return (T) this;
+ }
+
+ public T setEffectiveDate(DateTime effectiveDate) {
+ this.effectiveDate = effectiveDate;
+ return (T) this;
+ }
+
+ public T setProcessedDate(DateTime processedDate) {
+ this.processedDate = processedDate;
+ return (T) this;
+ }
+
+ public T setActiveVersion(long activeVersion) {
+ this.activeVersion = activeVersion;
+ return (T) this;
+ }
+
+ public T setActive(boolean isActive) {
+ this.isActive = isActive;
+ return (T) this;
+ }
+
+ public T setProcessingOwner(UUID processingOwner) {
+ this.processingOwner = processingOwner;
+ return (T) this;
+ }
+
+ public T setNextAvailableProcessingTime(DateTime nextAvailableProcessingTime) {
+ this.nextAvailableProcessingTime = nextAvailableProcessingTime;
+ return (T) this;
+ }
+
+ public T setProcessingState(IEventLyfecycleState processingState) {
+ this.processingState = processingState;
+ return (T) this;
+ }
+
+ public UUID getUuid() {
+ return uuid;
+ }
+
+ public UUID getSubscriptionId() {
+ return subscriptionId;
+ }
+
+ public DateTime getRequestedDate() {
+ return requestedDate;
+ }
+
+ public DateTime getEffectiveDate() {
+ return effectiveDate;
+ }
+
+ public DateTime getProcessedDate() {
+ return processedDate;
+ }
+
+ public long getActiveVersion() {
+ return activeVersion;
+ }
+
+ public boolean isActive() {
+ return isActive;
+ }
+
+ public UUID getProcessingOwner() {
+ return processingOwner;
+ }
+
+ public DateTime getNextAvailableProcessingTime() {
+ return nextAvailableProcessingTime;
+ }
+
+ public IEventLyfecycleState getProcessingState() {
+ return processingState;
+ }
+}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/phase/PhaseEvent.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/phase/PhaseEvent.java
index 9c6bbba..7c2d228 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/events/phase/PhaseEvent.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/phase/PhaseEvent.java
@@ -16,39 +16,23 @@
package com.ning.billing.entitlement.events.phase;
-import java.util.UUID;
import org.joda.time.DateTime;
-import com.ning.billing.catalog.api.IPlan;
-import com.ning.billing.catalog.api.IPlanPhase;
import com.ning.billing.entitlement.alignment.IPlanAligner.TimedPhase;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.entitlement.events.EventBase;
-import com.ning.billing.entitlement.events.IEventLyfecycle.IEventLyfecycleState;
public class PhaseEvent extends EventBase implements IPhaseEvent {
private final String phaseName;
- public PhaseEvent(UUID subscriptionId, IPlanPhase phase, DateTime requestedDate,
- DateTime effectiveDate, DateTime processedDate, long activeVersion) {
- super(subscriptionId, requestedDate, effectiveDate, processedDate, activeVersion, true);
- this.phaseName = phase.getName();
+ public PhaseEvent(PhaseEventBuilder builder) {
+ super(builder);
+ this.phaseName = builder.getPhaseName();
}
-
- public PhaseEvent(UUID id, UUID subscriptionId, String phaseName, DateTime requestedDate,
- DateTime effectiveDate, DateTime processedDate,
- long activeVersion, boolean isActiveVersion,
- UUID processingOwner, DateTime nextAvailableProcessingTime,
- IEventLyfecycleState processingState) {
- super(id, subscriptionId, requestedDate, effectiveDate, processedDate, activeVersion, isActiveVersion, processingOwner, nextAvailableProcessingTime, processingState);
- this.phaseName = phaseName;
- }
-
-
@Override
public EventType getType() {
return EventType.PHASE;
@@ -76,9 +60,12 @@ public class PhaseEvent extends EventBase implements IPhaseEvent {
public static final IPhaseEvent getNextPhaseEvent(TimedPhase nextTimedPhase, Subscription subscription, DateTime now) {
return (nextTimedPhase == null) ?
null :
- new PhaseEvent(subscription.getId(), nextTimedPhase.getPhase(), now, nextTimedPhase.getStartPhase(),
- now, subscription.getActiveVersion());
-
+ new PhaseEvent(new PhaseEventBuilder()
+ .setSubscriptionId(subscription.getId())
+ .setRequestedDate(now)
+ .setEffectiveDate(nextTimedPhase.getStartPhase())
+ .setProcessedDate(now)
+ .setActiveVersion(subscription.getActiveVersion())
+ .setPhaseName(nextTimedPhase.getPhase().getName()));
}
-
}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/phase/PhaseEventBuilder.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/phase/PhaseEventBuilder.java
new file mode 100644
index 0000000..00ac8e2
--- /dev/null
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/phase/PhaseEventBuilder.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.entitlement.events.phase;
+
+import com.ning.billing.entitlement.events.EventBaseBuilder;
+
+public class PhaseEventBuilder extends EventBaseBuilder<PhaseEventBuilder> {
+
+ private String phaseName;
+
+ public PhaseEventBuilder() {
+ super();
+ }
+
+ public PhaseEventBuilder(EventBaseBuilder<PhaseEventBuilder> base) {
+ super(base);
+ }
+
+ public PhaseEventBuilder setPhaseName(String phaseName) {
+ this.phaseName = phaseName;
+ return this;
+ }
+
+ public String getPhaseName() {
+ return phaseName;
+ }
+}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventBase.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventBase.java
index e1b9177..d4012dd 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventBase.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventBase.java
@@ -36,6 +36,15 @@ public class ApiEventBase extends EventBase implements IApiEvent {
private final String eventPriceList;
+ public ApiEventBase(ApiEventBuilder builder) {
+ super(builder);
+ this.eventType = builder.getEventType();
+ this.eventPriceList = builder.getEventPriceList();
+ this.eventPlan = builder.getEventPlan();
+ this.eventPlanPhase = builder.getEventPlanPhase();
+ }
+
+
public ApiEventBase(UUID subscriptionId, DateTime bundleStartDate, DateTime processed, String planName, String phaseName,
String priceList, DateTime requestedDate, ApiEventType eventType, DateTime effectiveDate, long activeVersion) {
super(subscriptionId, requestedDate, effectiveDate, processed, activeVersion, true);
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventBuilder.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventBuilder.java
new file mode 100644
index 0000000..cd3857e
--- /dev/null
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventBuilder.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.entitlement.events.user;
+
+import com.ning.billing.entitlement.events.EventBaseBuilder;
+
+public class ApiEventBuilder extends EventBaseBuilder<ApiEventBuilder> {
+
+ private ApiEventType eventType;
+ private String eventPlan;
+ private String eventPlanPhase;
+ private String eventPriceList;
+
+ public ApiEventBuilder() {
+ super();
+ }
+
+ public ApiEventBuilder(EventBaseBuilder<ApiEventBuilder> base) {
+ super(base);
+ }
+
+ public ApiEventType getEventType() {
+ return eventType;
+ }
+
+ public String getEventPlan() {
+ return eventPlan;
+ }
+
+ public String getEventPlanPhase() {
+ return eventPlanPhase;
+ }
+
+ public String getEventPriceList() {
+ return eventPriceList;
+ }
+
+ public ApiEventBuilder setEventType(ApiEventType eventType) {
+ this.eventType = eventType;
+ return this;
+ }
+
+ public ApiEventBuilder setEventPlan(String eventPlan) {
+ this.eventPlan = eventPlan;
+ return this;
+ }
+
+ public ApiEventBuilder setEventPlanPhase(String eventPlanPhase) {
+ this.eventPlanPhase = eventPlanPhase;
+ return this;
+ }
+
+ public ApiEventBuilder setEventPriceList(String eventPriceList) {
+ this.eventPriceList = eventPriceList;
+ return this;
+ }
+}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventCancel.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventCancel.java
index a3806d2..5df11ba 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventCancel.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventCancel.java
@@ -16,23 +16,10 @@
package com.ning.billing.entitlement.events.user;
-import java.util.UUID;
-
-import org.joda.time.DateTime;
-
-import com.ning.billing.catalog.api.IPlan;
-import com.ning.billing.entitlement.events.IEventLyfecycle.IEventLyfecycleState;
-
public class ApiEventCancel extends ApiEventBase {
- public ApiEventCancel(UUID subscriptionId, DateTime bundleStartDate, DateTime now, DateTime requestedDate, DateTime effectiveDate, long version) {
- super(subscriptionId, bundleStartDate, now, requestedDate, ApiEventType.CANCEL, effectiveDate, version);
- }
- public ApiEventCancel(UUID id, UUID subscriptionId, DateTime processed, String eventPlan, String eventPhase,
- String priceList, DateTime requestedDate, DateTime effectiveDate, long activeVersion,
- boolean isActive, UUID processingOwner, DateTime nextAvailableProcessingTime,IEventLyfecycleState processingState) {
- super(id, subscriptionId, processed, eventPlan, eventPhase, priceList, requestedDate, ApiEventType.CANCEL, effectiveDate,
- activeVersion, isActive, processingOwner, nextAvailableProcessingTime, processingState);
+ public ApiEventCancel(ApiEventBuilder builder) {
+ super(builder.setEventType(ApiEventType.CANCEL));
}
}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventChange.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventChange.java
index 40584f5..3770a2f 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventChange.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventChange.java
@@ -17,25 +17,10 @@
package com.ning.billing.entitlement.events.user;
-import java.util.UUID;
-
-import org.joda.time.DateTime;
-
-import com.ning.billing.catalog.api.IPlan;
-import com.ning.billing.entitlement.events.IEventLyfecycle.IEventLyfecycleState;
-
public class ApiEventChange extends ApiEventBase {
- public ApiEventChange(UUID subscriptionId, DateTime bundleStartDate, DateTime now, String planName, String phaseName, String priceList,
- DateTime requestedDate, DateTime effectiveDate, long version) {
- super(subscriptionId, bundleStartDate, now, planName, phaseName, priceList, requestedDate, ApiEventType.CHANGE, effectiveDate, version);
- }
-
- public ApiEventChange(UUID id, UUID subscriptionId, DateTime processed, String eventPlan, String eventPhase, String priceList,
- DateTime requestedDate, DateTime effectiveDate, long activeVersion,
- boolean isActive, UUID processingOwner, DateTime nextAvailableProcessingTime,IEventLyfecycleState processingState) {
- super(id, subscriptionId, processed, eventPlan, eventPhase, priceList, requestedDate, ApiEventType.CHANGE, effectiveDate,
- activeVersion, isActive, processingOwner, nextAvailableProcessingTime, processingState);
+ public ApiEventChange(ApiEventBuilder builder) {
+ super(builder.setEventType(ApiEventType.CHANGE));
}
}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventCreate.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventCreate.java
index 2b12e7e..df1879d 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventCreate.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventCreate.java
@@ -17,26 +17,10 @@
package com.ning.billing.entitlement.events.user;
-import java.util.UUID;
-
-import org.joda.time.DateTime;
-import com.ning.billing.catalog.api.IPlan;
-import com.ning.billing.entitlement.events.IEventLyfecycle.IEventLyfecycleState;
public class ApiEventCreate extends ApiEventBase {
-
- public ApiEventCreate(UUID subscriptionId, DateTime bundleStartDate, DateTime now, String planName, String phaseName, String priceList,
- DateTime requestedDate, DateTime effectiveDate, long version) {
- super(subscriptionId, bundleStartDate, now, planName, phaseName, priceList, requestedDate, ApiEventType.CREATE, effectiveDate, version);
- }
-
-
- public ApiEventCreate(UUID id, UUID subscriptionId, DateTime processed, String eventPlan, String eventPhase, String priceList,
- DateTime requestedDate, DateTime effectiveDate, long activeVersion,
- boolean isActive, UUID processingOwner, DateTime nextAvailableProcessingTime,IEventLyfecycleState processingState) {
- super(id, subscriptionId, processed, eventPlan, eventPhase, priceList, requestedDate, ApiEventType.CREATE, effectiveDate,
- activeVersion, isActive, processingOwner, nextAvailableProcessingTime, processingState);
+ public ApiEventCreate(ApiEventBuilder builder) {
+ super(builder.setEventType(ApiEventType.CREATE));
}
-
}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventPause.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventPause.java
index a6ff4b4..8574cfc 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventPause.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventPause.java
@@ -17,23 +17,11 @@
package com.ning.billing.entitlement.events.user;
-import java.util.UUID;
-
-import org.joda.time.DateTime;
-
-import com.ning.billing.catalog.api.IPlan;
-import com.ning.billing.entitlement.events.IEventLyfecycle.IEventLyfecycleState;
public class ApiEventPause extends ApiEventBase {
- public ApiEventPause(UUID subscriptionId, DateTime now, DateTime requestedDate, DateTime effectiveDate, long version) {
- super(subscriptionId, null, now, requestedDate, ApiEventType.PAUSE, effectiveDate, version);
- }
- public ApiEventPause(UUID id, UUID subscriptionId, DateTime processed, String eventPlan, String eventPhase,
- String priceList, DateTime requestedDate, DateTime effectiveDate, long activeVersion,
- boolean isActive, UUID processingOwner, DateTime nextAvailableProcessingTime,IEventLyfecycleState processingState) {
- super(id, subscriptionId, processed, eventPlan, eventPhase, priceList, requestedDate, ApiEventType.PAUSE, effectiveDate,
- activeVersion, isActive, processingOwner, nextAvailableProcessingTime, processingState);
+ public ApiEventPause(ApiEventBuilder builder) {
+ super(builder.setEventType(ApiEventType.PAUSE));
}
}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventResume.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventResume.java
index f8bf26f..34f8f87 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventResume.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventResume.java
@@ -17,25 +17,9 @@
package com.ning.billing.entitlement.events.user;
-import java.util.UUID;
-
-import org.joda.time.DateTime;
-
-import com.ning.billing.catalog.api.IPlan;
-import com.ning.billing.entitlement.events.IEventLyfecycle.IEventLyfecycleState;
-
-
public class ApiEventResume extends ApiEventBase {
- public ApiEventResume(UUID subscriptionId, DateTime now, DateTime requestedDate, DateTime effectiveDate, long version) {
- super(subscriptionId, null, now, requestedDate, ApiEventType.RESUME, effectiveDate, version);
+ public ApiEventResume(ApiEventBuilder builder) {
+ super(builder.setEventType(ApiEventType.RESUME));
}
-
- public ApiEventResume(UUID id, UUID subscriptionId, DateTime processed, String eventPlan, String eventPhase,
- String priceList, DateTime requestedDate, DateTime effectiveDate, long activeVersion,
- boolean isActive, UUID processingOwner, DateTime nextAvailableProcessingTime,IEventLyfecycleState processingState) {
- super(id, subscriptionId, processed, eventPlan, eventPhase, priceList, requestedDate, ApiEventType.RESUME, effectiveDate,
- activeVersion, isActive, processingOwner, nextAvailableProcessingTime, processingState);
- }
-
}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventUncancel.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventUncancel.java
index b5433f1..93d8029 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventUncancel.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/user/ApiEventUncancel.java
@@ -16,21 +16,9 @@
package com.ning.billing.entitlement.events.user;
-import java.util.UUID;
-
-import org.joda.time.DateTime;
-
-
public class ApiEventUncancel extends ApiEventBase {
- public ApiEventUncancel(UUID subscriptionId, DateTime bundleStartDate, DateTime now, DateTime requestedDate, DateTime effectiveDate, long version) {
- super(subscriptionId, bundleStartDate, now, requestedDate, ApiEventType.UNCANCEL, effectiveDate, version);
- }
-
- public ApiEventUncancel(UUID id, UUID subscriptionId, DateTime processed, String eventPlan, String eventPhase,
- String priceList, DateTime requestedDate, DateTime effectiveDate, long activeVersion,
- boolean isActive, UUID processingOwner, DateTime nextAvailableProcessingTime,IEventLyfecycleState processingState) {
- super(id, subscriptionId, processed, eventPlan, eventPhase, priceList, requestedDate, ApiEventType.UNCANCEL, effectiveDate,
- activeVersion, isActive, processingOwner, nextAvailableProcessingTime, processingState);
+ public ApiEventUncancel(ApiEventBuilder builder) {
+ super(builder.setEventType(ApiEventType.UNCANCEL));
}
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/ApiTestListener.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/ApiTestListener.java
index 5b5100b..1ba79af 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/ApiTestListener.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/ApiTestListener.java
@@ -17,11 +17,16 @@
package com.ning.billing.entitlement.api;
import java.util.EmptyStackException;
+import java.util.Iterator;
+import java.util.List;
import java.util.Stack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import com.google.common.collect.Lists;
import com.google.common.eventbus.Subscribe;
import com.ning.billing.entitlement.api.user.ISubscriptionTransition;
import com.ning.billing.util.eventbus.IEventBus;
@@ -30,7 +35,7 @@ public class ApiTestListener {
private static final Logger log = LoggerFactory.getLogger(ApiTestListener.class);
- private final Stack<NextEvent> nextExpectedEvent;
+ private final List<NextEvent> nextExpectedEvent;
private volatile boolean completed;
@@ -79,7 +84,7 @@ public class ApiTestListener {
public void pushExpectedEvent(NextEvent next) {
synchronized (this) {
- nextExpectedEvent.push(next);
+ nextExpectedEvent.add(next);
completed = false;
}
}
@@ -113,17 +118,22 @@ public class ApiTestListener {
log.debug("notifyIfStackEmpty EXIT");
}
- private void assertEqualsNicely(NextEvent expected, NextEvent real) {
- if (expected != real) {
- System.err.println("Expected event " + expected + " got " + real);
- try {
- NextEvent next = nextExpectedEvent.pop();
- while (next != null) {
- System.err.println("Also got event " + next);
- next = nextExpectedEvent.pop();
- }
- } catch (EmptyStackException ignore) {
+ private void assertEqualsNicely(NextEvent expected) {
+
+ boolean foundIt = false;
+ Iterator<NextEvent> it = nextExpectedEvent.iterator();
+ while (it.hasNext()) {
+ NextEvent ev = it.next();
+ if (ev == expected) {
+ it.remove();
+ foundIt = true;
+ break;
}
+ }
+
+ if (!foundIt) {
+ Joiner joiner = Joiner.on(" ");
+ System.err.println("Expected event " + expected + " got " + joiner.join(nextExpectedEvent));
System.exit(1);
}
}
@@ -131,35 +141,35 @@ public class ApiTestListener {
public void subscriptionCreated(ISubscriptionTransition created) {
log.debug("-> Got event CREATED");
- assertEqualsNicely(nextExpectedEvent.pop(), NextEvent.CREATE);
+ assertEqualsNicely(NextEvent.CREATE);
notifyIfStackEmpty();
}
public void subscriptionCancelled(ISubscriptionTransition cancelled) {
log.debug("-> Got event CANCEL");
- assertEqualsNicely(nextExpectedEvent.pop(), NextEvent.CANCEL);
+ assertEqualsNicely(NextEvent.CANCEL);
notifyIfStackEmpty();
}
public void subscriptionChanged(ISubscriptionTransition changed) {
log.debug("-> Got event CHANGE");
- assertEqualsNicely(nextExpectedEvent.pop(), NextEvent.CHANGE);
+ assertEqualsNicely(NextEvent.CHANGE);
notifyIfStackEmpty();
}
public void subscriptionPaused(ISubscriptionTransition paused) {
log.debug("-> Got event PAUSE");
- assertEqualsNicely(nextExpectedEvent.pop(), NextEvent.PAUSE);
+ assertEqualsNicely(NextEvent.PAUSE);
notifyIfStackEmpty();
}
public void subscriptionResumed(ISubscriptionTransition resumed) {
log.debug("-> Got event RESUME");
- assertEqualsNicely(nextExpectedEvent.pop(), NextEvent.RESUME);
+ assertEqualsNicely(NextEvent.RESUME);
notifyIfStackEmpty();
}
@@ -167,7 +177,7 @@ public class ApiTestListener {
public void subscriptionPhaseChanged(
ISubscriptionTransition phaseChanged) {
log.debug("-> Got event PHASE");
- assertEqualsNicely(nextExpectedEvent.pop(), NextEvent.PHASE);
+ assertEqualsNicely(NextEvent.PHASE);
notifyIfStackEmpty();
}
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreate.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreate.java
index 64f69c3..538d5dd 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreate.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreate.java
@@ -39,6 +39,38 @@ import com.ning.billing.util.clock.Clock;
public abstract class TestUserApiCreate extends TestUserApiBase {
+
+ protected void testCreateWithRequestedDateReal() {
+ log.info("Starting testCreateWithRequestedDate");
+ try {
+
+ DateTime init = clock.getUTCNow();
+ DateTime requestedDate = init.minusYears(1);
+
+ String productName = "Shotgun";
+ BillingPeriod term = BillingPeriod.MONTHLY;
+ String planSetName = IPriceListSet.DEFAULT_PRICELIST_NAME;
+
+
+ testListener.pushExpectedEvent(NextEvent.PHASE);
+ testListener.pushExpectedEvent(NextEvent.CREATE);
+
+
+ Subscription subscription = (Subscription) entitlementApi.createSubscription(bundle.getId(), productName, term, planSetName, requestedDate);
+ assertNotNull(subscription);
+
+ assertEquals(subscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION);
+ //assertEquals(subscription.getAccount(), account.getId());
+ assertEquals(subscription.getBundleId(), bundle.getId());
+ assertEquals(subscription.getStartDate(), requestedDate);
+
+ assertTrue(testListener.isCompleted(5000));
+
+ } catch (EntitlementUserApiException e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
protected void testSimpleCreateSubscriptionReal() {
log.info("Starting testSimpleCreateSubscription");
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateMemory.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateMemory.java
index 429652c..8c1fa63 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateMemory.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateMemory.java
@@ -33,6 +33,11 @@ public class TestUserApiCreateMemory extends TestUserApiCreate {
}
@Test(enabled=true, groups={"fast"})
+ public void testCreateWithRequestedDate() {
+ invokeRealMethod(this);
+ }
+
+ @Test(enabled=true, groups={"fast"})
public void testSimpleCreateSubscription() {
invokeRealMethod(this);
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateSql.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateSql.java
index 328976f..77ee57d 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateSql.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateSql.java
@@ -32,6 +32,11 @@ public class TestUserApiCreateSql extends TestUserApiCreate {
}
@Test(enabled=true, groups={"sql"})
+ public void testCreateWithRequestedDate() {
+ invokeRealMethod(this);
+ }
+
+ @Test(enabled=true, groups={"sql"})
public void testSimpleCreateSubscription() {
invokeRealMethod(this);
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/EntitlementDaoMemoryMock.java b/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/EntitlementDaoMemoryMock.java
index c6fff2f..e4d2559 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/EntitlementDaoMemoryMock.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/EntitlementDaoMemoryMock.java
@@ -36,6 +36,7 @@ import com.ning.billing.config.IEntitlementConfig;
import com.ning.billing.entitlement.api.user.ISubscription;
import com.ning.billing.entitlement.api.user.ISubscriptionBundle;
import com.ning.billing.entitlement.api.user.Subscription;
+import com.ning.billing.entitlement.api.user.SubscriptionBuilder;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.entitlement.events.IEvent;
import com.ning.billing.entitlement.events.IEvent.EventType;
@@ -227,8 +228,7 @@ public class EntitlementDaoMemoryMock implements IEntitlementDao, IEntitlementDa
}
private ISubscription buildSubscription(Subscription in) {
- return new Subscription(in.getId(), in.getBundleId(), in.getCategory(), in.getBundleStartDate(),
- in.getStartDate(), in.getChargedThroughDate(), in.getPaidThroughDate(), in.getActiveVersion());
+ return new Subscription(new SubscriptionBuilder(in), true);
}
@Override
invoice/pom.xml 2(+1 -1)
diff --git a/invoice/pom.xml b/invoice/pom.xml
index e350a77..771b2c5 100644
--- a/invoice/pom.xml
+++ b/invoice/pom.xml
@@ -13,7 +13,7 @@
<parent>
<groupId>com.ning.billing</groupId>
<artifactId>killbill</artifactId>
- <version>0.0.15-SNAPSHOT</version>
+ <version>0.0.16-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>killbill-invoice</artifactId>
payment/pom.xml 2(+1 -1)
diff --git a/payment/pom.xml b/payment/pom.xml
index 73cf60a..6994203 100644
--- a/payment/pom.xml
+++ b/payment/pom.xml
@@ -13,7 +13,7 @@
<parent>
<groupId>com.ning.billing</groupId>
<artifactId>killbill</artifactId>
- <version>0.0.15-SNAPSHOT</version>
+ <version>0.0.16-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>killbill-payment</artifactId>
pom.xml 2(+1 -1)
diff --git a/pom.xml b/pom.xml
index be47827..bd1fb22 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,7 +17,7 @@
<groupId>com.ning.billing</groupId>
<artifactId>killbill</artifactId>
<packaging>pom</packaging>
- <version>0.0.15-SNAPSHOT</version>
+ <version>0.0.16-SNAPSHOT</version>
<name>killbill</name>
<description>Library for managing recurring subscriptions and the associated billing</description>
<url>http://github.com/ning/killbill</url>
util/pom.xml 2(+1 -1)
diff --git a/util/pom.xml b/util/pom.xml
index 8c47782..e77c581 100644
--- a/util/pom.xml
+++ b/util/pom.xml
@@ -13,7 +13,7 @@
<parent>
<groupId>com.ning.billing</groupId>
<artifactId>killbill</artifactId>
- <version>0.0.15-SNAPSHOT</version>
+ <version>0.0.16-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>killbill-util</artifactId>