killbill-uncached

Fix NPE in entitlement when getting timeline Fix toString

8/23/2013 12:44:32 AM

Details

diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/DefaultEntitlement.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/DefaultEntitlement.java
index f02d9a2..d1249a0 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/DefaultEntitlement.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/DefaultEntitlement.java
@@ -165,7 +165,7 @@ public class DefaultEntitlement extends EntityBase implements Entitlement {
 
     @Override
     public Product getProduct() {
-        return subscriptionBase.getCurrentPlan().getProduct();
+        return subscriptionBase.getCurrentPlan() != null ? subscriptionBase.getCurrentPlan().getProduct() : null;
     }
 
     @Override
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/DefaultEntitlementApi.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/DefaultEntitlementApi.java
index 72ceed6..7812f48 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/DefaultEntitlementApi.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/DefaultEntitlementApi.java
@@ -274,13 +274,13 @@ public class DefaultEntitlementApi implements EntitlementApi {
         final BlockingState bundleEntitlementState = blockingStateDao.getBlockingStateForService(subscriptionBase.getBundleId(), EntitlementService.ENTITLEMENT_SERVICE_NAME, context);
         if (bundleEntitlementState != null && ENT_STATE_CANCELLED.equals(bundleEntitlementState.getStateName())) {
             final LocalDate localDate = new LocalDate(bundleEntitlementState.getEffectiveDate(), accountTimeZone);
-            result = (result == null) || (result.compareTo(localDate) < 0) ? result : localDate;
+            result = ((result == null) || (localDate.compareTo(result) < 0)) ? localDate : result;
         }
 
         final BlockingState accountEntitlementState = blockingStateDao.getBlockingStateForService(accountId, EntitlementService.ENTITLEMENT_SERVICE_NAME, context);
         if (accountEntitlementState != null && ENT_STATE_CANCELLED.equals(accountEntitlementState.getStateName())) {
             final LocalDate localDate = new LocalDate(accountEntitlementState.getEffectiveDate(), accountTimeZone);
-            result = (result == null) || (result.compareTo(localDate) < 0) ? result : localDate;
+            result = ((result == null) || (localDate.compareTo(result) < 0)) ? localDate : result;
         }
         return result;
     }
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/DefaultSubscriptionBundleTimeline.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/DefaultSubscriptionBundleTimeline.java
index ecfa16f..40a73ec 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/DefaultSubscriptionBundleTimeline.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/DefaultSubscriptionBundleTimeline.java
@@ -135,6 +135,7 @@ public class DefaultSubscriptionBundleTimeline implements SubscriptionBundleTime
 
         int index = -1;
         final Iterator<SubscriptionEvent> it = result.iterator();
+        // Where we need to insert in that stream
         DefaultSubscriptionEvent cur = null;
         while (it.hasNext()) {
             cur = (DefaultSubscriptionEvent) it.next();
@@ -167,15 +168,16 @@ public class DefaultSubscriptionBundleTimeline implements SubscriptionBundleTime
         }
 
 
-        final DefaultSubscriptionEvent next = it.hasNext() ? (DefaultSubscriptionEvent) it.next() : null;
-
         final List<UUID> targetEntitlementIds = bs.getType() == BlockingStateType.SUBSCRIPTION ? ImmutableList.<UUID>of(bs.getBlockedId()) :
                                                 ImmutableList.<UUID>copyOf(allEntitlementUUIDs);
         for (UUID target : targetEntitlementIds) {
 
+
+            final SubscriptionEvent[] prevNext = findPrevNext(result, target, cur, bs);
+
             // If the blocking state is ENT_STATE_CANCELLED there is nothing else to look at, just insert the event
             if (bs.getStateName().equals(DefaultEntitlementApi.ENT_STATE_CANCELLED)) {
-                newEvents.add(toSubscriptionEvent(cur, next, target, bs, SubscriptionEventType.STOP_ENTITLEMENT, accountTimeZone));
+                newEvents.add(toSubscriptionEvent(prevNext[0], prevNext[1], target, bs, SubscriptionEventType.STOP_ENTITLEMENT, accountTimeZone));
                 continue;
             }
 
@@ -187,22 +189,49 @@ public class DefaultSubscriptionBundleTimeline implements SubscriptionBundleTime
             final Boolean isServiceStateChange = !(isResumeEntitlement || isPauseEntitlement || isResumeBilling || isPauseBilling);
 
             if (isResumeEntitlement) {
-                newEvents.add(toSubscriptionEvent(cur, next, target, bs, SubscriptionEventType.RESUME_ENTITLEMENT, accountTimeZone));
+                newEvents.add(toSubscriptionEvent(prevNext[0], prevNext[1], target, bs, SubscriptionEventType.RESUME_ENTITLEMENT, accountTimeZone));
             } else if (isPauseEntitlement) {
-                newEvents.add(toSubscriptionEvent(cur, next, target, bs, SubscriptionEventType.PAUSE_ENTITLEMENT, accountTimeZone));
+                newEvents.add(toSubscriptionEvent(prevNext[0], prevNext[1], target, bs, SubscriptionEventType.PAUSE_ENTITLEMENT, accountTimeZone));
             }
             if (isResumeBilling) {
-                newEvents.add(toSubscriptionEvent(cur, next, target, bs, SubscriptionEventType.RESUME_BILLING, accountTimeZone));
+                newEvents.add(toSubscriptionEvent(prevNext[0], prevNext[1], target, bs, SubscriptionEventType.RESUME_BILLING, accountTimeZone));
             } else if (isPauseBilling) {
-                newEvents.add(toSubscriptionEvent(cur, next, target, bs, SubscriptionEventType.PAUSE_BILLING, accountTimeZone));
+                newEvents.add(toSubscriptionEvent(prevNext[0], prevNext[1], target, bs, SubscriptionEventType.PAUSE_BILLING, accountTimeZone));
             }
             if (isServiceStateChange) {
-                newEvents.add(toSubscriptionEvent(cur, next, target, bs, SubscriptionEventType.SERVICE_STATE_CHANGE, accountTimeZone));
+                newEvents.add(toSubscriptionEvent(prevNext[0], prevNext[1], target, bs, SubscriptionEventType.SERVICE_STATE_CHANGE, accountTimeZone));
             }
         }
         return index;
     }
 
+    private SubscriptionEvent[] findPrevNext(final List<SubscriptionEvent> events, final UUID targetEntitlementId, final SubscriptionEvent insertionEvent, final BlockingState bs) {
+
+        // Find prev/next event for the same entitlement
+        final SubscriptionEvent[] result =  new DefaultSubscriptionEvent[2];
+        final Iterator<SubscriptionEvent> it = events.iterator();
+        DefaultSubscriptionEvent prev = null;
+        DefaultSubscriptionEvent next = null;
+        boolean foundCur = false;
+        while (it.hasNext()) {
+            final DefaultSubscriptionEvent tmp = (DefaultSubscriptionEvent) it.next();
+            if (tmp.getEntitlementId().equals(targetEntitlementId)) {
+                if (!foundCur) {
+                    prev = tmp;
+                } else {
+                    next = tmp;
+                    break;
+                }
+            }
+            if (tmp.getId().equals(insertionEvent.getId())) {
+                foundCur = true;
+            }
+        }
+        result[0] = prev;
+        result[1] = next;
+        return result;
+    }
+
 
     private LinkedList<SubscriptionEvent> computeSubscriptionBaseEvents(final List<Entitlement> entitlements, final DateTimeZone accountTimeZone) {
 
@@ -293,11 +322,12 @@ public class DefaultSubscriptionBundleTimeline implements SubscriptionBundleTime
                                             in.isBlockBilling(),
                                             in.getService(),
                                             in.getStateName(),
-                                            prev != null ? prev.getNextProduct() : null,
-                                            prev != null ? prev.getNextPlan() : null,
-                                            prev != null ? prev.getNextPhase() : null,
-                                            prev != null ? prev.getNextPriceList() : null,
-                                            prev != null ? prev.getNextBillingPeriod() : null,
+                                            // We look for the next for the 'prev' meaning we we are headed to, but if this is null -- for example on cancellation we get the prev which gives the correct state.
+                                            prev != null ? (prev.getNextProduct() != null ? prev.getNextProduct() : prev.getPrevProduct()) : null,
+                                            prev != null ? (prev.getNextPlan() != null ? prev.getNextPlan() : prev.getPrevPlan()) : null,
+                                            prev != null ? (prev.getNextPhase() != null ? prev.getNextPhase() : prev.getPrevPhase()) : null,
+                                            prev != null ? (prev.getNextPriceList() != null ? prev.getNextPriceList() : prev.getPrevPriceList()) : null,
+                                            prev != null ? (prev.getNextBillingPeriod() != null ? prev.getNextBillingPeriod() : prev.getPrevBillingPeriod())  : null,
                                             next != null ? next.getPrevProduct() : null,
                                             next != null ? next.getPrevPlan() : null,
                                             next != null ? next.getPrevPhase() : null,
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/EntitlementDateHelper.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/EntitlementDateHelper.java
index 1a619c4..7cfd9ba 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/EntitlementDateHelper.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/EntitlementDateHelper.java
@@ -68,16 +68,16 @@ public class EntitlementDateHelper {
         final DateTime t2 = new DateTime(t1, DateTimeZone.UTC);
 
         //
-        // Ok, in the case of a LocalDate of today we expect any chnage to be immediate, so we check that DateTime returned is not in the future
+        // Ok, in the case of a LocalDate of today we expect any change to be immediate, so we check that DateTime returned is not in the future
         // (which means that reference time might not be honored, but this is not very important).
         //
-        return adjustDateTimeToNotBeInFutureIfLocaDateIsToday(t2);
+        return adjustDateTimeToNotBeInFutureIfLocaDateIsToday(t2, accountTimeZone);
     }
 
-    private final DateTime adjustDateTimeToNotBeInFutureIfLocaDateIsToday(final DateTime inputUtc) {
+    private final DateTime adjustDateTimeToNotBeInFutureIfLocaDateIsToday(final DateTime inputUtc, final DateTimeZone accountTimeZone) {
         // If the LocalDate is TODAY but after adding the reference time we end up in the future, we correct it to be NOW,
         // so change occurs immediately
-        if (isBeforeOrEqualsToday(inputUtc, DateTimeZone.UTC) && inputUtc.compareTo(clock.getUTCNow()) > 0) {
+        if (isBeforeOrEqualsToday(inputUtc, accountTimeZone) && inputUtc.compareTo(clock.getUTCNow()) > 0) {
             return clock.getUTCNow();
         } else {
             return inputUtc;
@@ -87,7 +87,7 @@ public class EntitlementDateHelper {
     /**
      *
      * @param inputDate       the fully qualified DateTime
-     * @param accountTimeZone the acount timezone
+     * @param accountTimeZone the account timezone
      * @return true if the inputDate, once converted into a LocalDate using account timezone is less or equals than today
      */
     public boolean isBeforeOrEqualsToday(final DateTime inputDate, final DateTimeZone accountTimeZone) {
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/TestEntitlementDateHelper.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/TestEntitlementDateHelper.java
index fbb1aea..3237e80 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/TestEntitlementDateHelper.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/TestEntitlementDateHelper.java
@@ -43,13 +43,14 @@ public class TestEntitlementDateHelper extends EntitlementTestSuiteNoDB {
         account = Mockito.mock(Account.class);
         Mockito.when(accountInternalApi.getAccountByRecordId(Mockito.anyLong(), Mockito.<InternalTenantContext>any())).thenReturn(account);
         dateHelper = new EntitlementDateHelper(accountInternalApi, clock);
+        clock.resetDeltaFromReality();;
     }
 
     @Test(groups = "fast")
     public void testWithAccountInUtc() throws EntitlementApiException {
 
         final LocalDate initialDate = new LocalDate(2013, 8, 7);
-        //clock.setDay(initialDate.plusDays(1));
+        clock.setDay(initialDate.plusDays(1));
 
         Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC);
 
@@ -64,7 +65,7 @@ public class TestEntitlementDateHelper extends EntitlementTestSuiteNoDB {
     public void testWithAccountInUtcMinus8() throws EntitlementApiException {
 
         final LocalDate inputDate = new LocalDate(2013, 8, 7);
-        //.setDay(inputDate.plusDays(3));
+        clock.setDay(inputDate.plusDays(3));
 
         final DateTimeZone timeZoneUtcMinus8 = DateTimeZone.forOffsetHours(-8);
         Mockito.when(account.getTimeZone()).thenReturn(timeZoneUtcMinus8);
@@ -79,12 +80,38 @@ public class TestEntitlementDateHelper extends EntitlementTestSuiteNoDB {
     }
 
 
+    @Test(groups = "fast")
+    public void test2WithAccountInUtcMinus8() throws EntitlementApiException {
+
+        final DateTime initialNow = new DateTime(2013, 8, 22,22, 07, 01, 0, DateTimeZone.UTC);
+        clock.setTime(initialNow);
+
+        final LocalDate inputDate = new LocalDate(2013, 8, 22);
+
+        final DateTimeZone timeZoneUtcMinus8 = DateTimeZone.forOffsetHours(-8);
+        Mockito.when(account.getTimeZone()).thenReturn(timeZoneUtcMinus8);
+
+        // We also use a reference time of 16, 48, 0 -> DateTime in UTC will be (2013, 8, 23, 00, 48, 0) which:
+        // * is greater than now
+        // * with a inputLocalDate in the account timezone which is today
+        //
+        // => Code will round to now to not end up in the future
+        //
+        final DateTime refererenceDateTime = new DateTime(2013, 8, 22, 16, 48, 0, DateTimeZone.UTC);
+        final DateTime targetDate = dateHelper.fromLocalDateAndReferenceTime(inputDate, refererenceDateTime, internalCallContext);
+
+        final DateTime now = clock.getUTCNow();
+        Assert.assertTrue(initialNow.compareTo(targetDate) <= 0);
+        Assert.assertTrue(targetDate.compareTo(now) <= 0);
+    }
+
+
 
     @Test(groups = "fast")
     public void testWithAccountInUtcPlus5() throws EntitlementApiException {
 
         final LocalDate inputDate = new LocalDate(2013, 8, 7);
-        //clock.setDay(inputDate.plusDays(1));
+        clock.setDay(inputDate.plusDays(1));
 
         final DateTimeZone timeZoneUtcPlus5 = DateTimeZone.forOffsetHours(+5);
         Mockito.when(account.getTimeZone()).thenReturn(timeZoneUtcPlus5);
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/EntitlementJsonNoEvents.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/EntitlementJsonNoEvents.java
index d613bfb..e159644 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/EntitlementJsonNoEvents.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/EntitlementJsonNoEvents.java
@@ -41,7 +41,7 @@ public class EntitlementJsonNoEvents extends EntitlementJsonSimple {
     @JsonCreator
     public EntitlementJsonNoEvents(@JsonProperty("accountId") @Nullable final String accountId,
                                    @JsonProperty("bundleId") @Nullable final String bundleId,
-                                   @JsonProperty("entitlementId") @Nullable final String entitlementId,
+                                   @JsonProperty("subscriptionId") @Nullable final String subscriptionId,
                                    @JsonProperty("externalKey") @Nullable final String externalKey,
                                    @JsonProperty("startDate") @Nullable final LocalDate startDate,
                                    @JsonProperty("productName") @Nullable final String productName,
@@ -50,7 +50,7 @@ public class EntitlementJsonNoEvents extends EntitlementJsonSimple {
                                    @JsonProperty("priceList") @Nullable final String priceList,
                                    @JsonProperty("cancelledDate") @Nullable final LocalDate cancelledDate,
                                    @JsonProperty("auditLogs") @Nullable final List<AuditLogJson> auditLogs) {
-        super(accountId, bundleId, entitlementId, externalKey, auditLogs);
+        super(accountId, bundleId, subscriptionId, externalKey, auditLogs);
         this.startDate = startDate;
         this.productName = productName;
         this.productCategory = productCategory;
@@ -99,7 +99,7 @@ public class EntitlementJsonNoEvents extends EntitlementJsonSimple {
 
     @Override
     public String toString() {
-        return "SubscriptionJson [subscriptionId=" + entitlementId
+        return "SubscriptionJson [subscriptionId=" + subscriptionId
                + ", productName=" + productName
                + ", productCategory=" + productCategory + ", billingPeriod="
                + billingPeriod + ", priceList=" + priceList + "]";
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/EntitlementJsonSimple.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/EntitlementJsonSimple.java
index 9606d9f..08aca3b 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/EntitlementJsonSimple.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/EntitlementJsonSimple.java
@@ -27,24 +27,24 @@ public class EntitlementJsonSimple extends JsonBase {
 
     protected final String accountId;
     protected final String bundleId;
-    protected final String entitlementId;
+    protected final String subscriptionId;
     protected final String externalKey;
 
     @JsonCreator
     public EntitlementJsonSimple(@JsonProperty("accountId") @Nullable final String accountId,
                                  @JsonProperty("bundleId") @Nullable final String bundleId,
-                                 @JsonProperty("entitlementId") @Nullable final String entitlementId,
+                                 @JsonProperty("subscriptionId") @Nullable final String entitlementId,
                                  @JsonProperty("externalKey") @Nullable final String externalKey,
                                  @JsonProperty("auditLogs") @Nullable final List<AuditLogJson> auditLogs) {
         super(auditLogs);
         this.accountId = accountId;
         this.bundleId = bundleId;
-        this.entitlementId = entitlementId;
+        this.subscriptionId = entitlementId;
         this.externalKey = externalKey;
     }
 
-    public String getEntitlementId() {
-        return entitlementId;
+    public String getSubscriptionId() {
+        return subscriptionId;
     }
 
     public String getAccountId() {
@@ -63,7 +63,7 @@ public class EntitlementJsonSimple extends JsonBase {
     public String toString() {
         final StringBuilder sb = new StringBuilder();
         sb.append("EntitlementJsonSimple");
-        sb.append("{subscriptionId='").append(entitlementId).append('\'');
+        sb.append("{subscriptionId='").append(subscriptionId).append('\'');
         sb.append('}');
         return sb.toString();
     }
@@ -85,7 +85,7 @@ public class EntitlementJsonSimple extends JsonBase {
         if (bundleId != null ? !bundleId.equals(that.bundleId) : that.bundleId != null) {
             return false;
         }
-        if (entitlementId != null ? !entitlementId.equals(that.entitlementId) : that.entitlementId != null) {
+        if (subscriptionId != null ? !subscriptionId.equals(that.subscriptionId) : that.subscriptionId != null) {
             return false;
         }
         return true;
@@ -95,7 +95,7 @@ public class EntitlementJsonSimple extends JsonBase {
     public int hashCode() {
         int result = accountId != null ? accountId.hashCode() : 0;
         result = 31 * result + (bundleId != null ? bundleId.hashCode() : 0);
-        result = 31 * result + (entitlementId != null ? entitlementId.hashCode() : 0);
+        result = 31 * result + (subscriptionId != null ? subscriptionId.hashCode() : 0);
         return result;
     }
 }
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonNoEvents.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonNoEvents.java
index b131ace..5a76edd 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonNoEvents.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonNoEvents.java
@@ -41,7 +41,7 @@ public class SubscriptionJsonNoEvents extends EntitlementJsonNoEvents {
     @JsonCreator
     public SubscriptionJsonNoEvents(@JsonProperty("accountId") @Nullable final String accountId,
                                     @JsonProperty("bundleId") @Nullable final String bundleId,
-                                    @JsonProperty("entitlementId") @Nullable final String entitlementId,
+                                    @JsonProperty("subscriptionId") @Nullable final String subscriptionId,
                                     @JsonProperty("externalKey") @Nullable final String externalKey,
                                     @JsonProperty("startDate") @Nullable final LocalDate startDate,
                                     @JsonProperty("productName") @Nullable final String productName,
@@ -53,7 +53,7 @@ public class SubscriptionJsonNoEvents extends EntitlementJsonNoEvents {
                                     @JsonProperty("chargedThroughDate") @Nullable final LocalDate chargedThroughDate,
                                     @JsonProperty("billingStartDate") @Nullable final LocalDate billingStartDate,
                                     @JsonProperty("billingEndDate") @Nullable final LocalDate billingEndDate) {
-        super(accountId, bundleId, entitlementId, externalKey, startDate, productName, productCategory, billingPeriod, priceList, cancelledDate, auditLogs);
+        super(accountId, bundleId, subscriptionId, externalKey, startDate, productName, productCategory, billingPeriod, priceList, cancelledDate, auditLogs);
         this.chargedThroughDate = chargedThroughDate;
         this.billingStartDate = billingStartDate;
         this.billingEndDate = billingEndDate;
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonWithEvents.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonWithEvents.java
index eca2d97..ec91d6f 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonWithEvents.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonWithEvents.java
@@ -300,7 +300,7 @@ public class SubscriptionJsonWithEvents extends EntitlementJsonSimple {
                                                           billingPeriod != null ? billingPeriod.toString() : null,
                                                           cur.getRequestedDate(),
                                                           cur.getEffectiveDate(),
-                                                          product != null ? product.toString() : null,
+                                                          product != null ? product.getName() : null,
                                                           priceList != null ? priceList.getName() : null,
                                                           cur.getSubscriptionEventType().toString(),
                                                           phase != null ? phase.getName() : null,
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestEntitlementJsonSimple.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestEntitlementJsonSimple.java
index 4c9913d..d64274a 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestEntitlementJsonSimple.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestEntitlementJsonSimple.java
@@ -38,7 +38,7 @@ public class TestEntitlementJsonSimple extends JaxrsTestSuiteNoDB {
         final EntitlementJsonSimple entitlementJsonSimple = new EntitlementJsonSimple(accountId, bundleId, entitlementId, externalKey, auditLogs);
         Assert.assertEquals(entitlementJsonSimple.getAccountId(), accountId);
         Assert.assertEquals(entitlementJsonSimple.getBundleId(), bundleId);
-        Assert.assertEquals(entitlementJsonSimple.getEntitlementId(), entitlementId);
+        Assert.assertEquals(entitlementJsonSimple.getSubscriptionId(), entitlementId);
         Assert.assertEquals(entitlementJsonSimple.getExternalKey(), externalKey);
         Assert.assertEquals(entitlementJsonSimple.getAuditLogs(), auditLogs);
 
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonNoEvents.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonNoEvents.java
index aa5404d..4721fd0 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonNoEvents.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonNoEvents.java
@@ -61,7 +61,7 @@ public class TestSubscriptionJsonNoEvents extends JaxrsTestSuiteNoDB {
                                                                                                productCategory, billingPeriod, priceList, cancelDate, auditLogs, chargedThroughDate,
                                                                                                billingStartDate, billingEndDate);
 
-        Assert.assertEquals(subscriptionJsonNoEvents.getEntitlementId(), entitlementId);
+        Assert.assertEquals(subscriptionJsonNoEvents.getSubscriptionId(), entitlementId);
         Assert.assertEquals(subscriptionJsonNoEvents.getBundleId(), bundleId);
         Assert.assertEquals(subscriptionJsonNoEvents.getStartDate(), startDate);
         Assert.assertEquals(subscriptionJsonNoEvents.getProductName(), productName);
diff --git a/server/src/main/resources/killbill-server.properties b/server/src/main/resources/killbill-server.properties
index 7401da5..a51c99d 100644
--- a/server/src/main/resources/killbill-server.properties
+++ b/server/src/main/resources/killbill-server.properties
@@ -14,11 +14,18 @@
 # under the License.
 #
 
-# Use skeleton properties for server and configure killbill database
-com.ning.jetty.jdbi.url=jdbc:mysql://127.0.0.1:3306/killbill
-com.ning.jetty.jdbi.user=root
-com.ning.jetty.jdbi.password=root
+killbill.catalog.uri=file:///Users/stephanebrossier/Work/Src/Killbill/killbill/server/src/main/resources/NingCatalog.xml
+killbill.overdue.uri=file:///Users/stephanebrossier/Work/Src/Killbill/killbill/server/src/main/resources/OverdueConfig.xml
+
+com.ning.jetty.jdbi.url=jdbc:mysql://127.0.0.1:13306/irs_xna
+com.ning.jetty.jdbi.user=irs_xna
+com.ning.jetty.jdbi.password=irs_xna
 
 user.timezone=UTC
 
 ANTLR_USE_DIRECT_CLASS_LOADING=true
+
+killbill.billing.util.notificationq.notification.off=true
+killbill.billing.util.persistent.bus.off=true
+killbill.server.multitenant=false
+com.ning.billing.osgi.bundles.jruby.conf.dir=/Users/stephanebrossier/Work/Src/Killbill/killbill/server/src/main/resources
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestEntitlement.java b/server/src/test/java/com/ning/billing/jaxrs/TestEntitlement.java
index 399a92f..dea71a1 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestEntitlement.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestEntitlement.java
@@ -56,7 +56,7 @@ public class TestEntitlement extends TestJaxrsBase {
 
         final EntitlementJsonNoEvents entitlementJson = createEntitlement(accountJson.getAccountId(), "99999", productName, ProductCategory.BASE.toString(), term.toString(), true);
 
-        String uri = JaxrsResource.ENTITLEMENTS_PATH + "/" + entitlementJson.getEntitlementId();
+        String uri = JaxrsResource.ENTITLEMENTS_PATH + "/" + entitlementJson.getSubscriptionId();
 
         // Retrieves with GET
         Response response = doGet(uri, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
@@ -70,7 +70,7 @@ public class TestEntitlement extends TestJaxrsBase {
 
         final EntitlementJsonNoEvents newInput = new EntitlementJsonNoEvents(null,
                                                                              null,
-                                                                             entitlementJson.getEntitlementId(),
+                                                                             entitlementJson.getSubscriptionId(),
                                                                              null,
                                                                              null,
                                                                              newProductName,
@@ -95,12 +95,12 @@ public class TestEntitlement extends TestJaxrsBase {
         crappyWaitForLackOfProperSynchonization();
 
         // Cancel EOT
-        uri = JaxrsResource.ENTITLEMENTS_PATH + "/" + entitlementJson.getEntitlementId();
+        uri = JaxrsResource.ENTITLEMENTS_PATH + "/" + entitlementJson.getSubscriptionId();
         response = doDelete(uri, queryParams, DEFAULT_HTTP_TIMEOUT_SEC);
         assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
 
         // Retrieves to check EndDate
-        uri = JaxrsResource.ENTITLEMENTS_PATH + "/" + entitlementJson.getEntitlementId();
+        uri = JaxrsResource.ENTITLEMENTS_PATH + "/" + entitlementJson.getSubscriptionId();
         response = doGet(uri, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
 
         assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
@@ -111,7 +111,7 @@ public class TestEntitlement extends TestJaxrsBase {
 
         // Uncancel
         // STEPH_ENT uncancel not implemented yet
-        uri = JaxrsResource.ENTITLEMENTS_PATH + "/" + entitlementJson.getEntitlementId() + "/uncancel";
+        uri = JaxrsResource.ENTITLEMENTS_PATH + "/" + entitlementJson.getSubscriptionId() + "/uncancel";
         response = doPut(uri, baseJson, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
         Assert.assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
     }
@@ -144,7 +144,7 @@ public class TestEntitlement extends TestJaxrsBase {
         final BillingPeriod term = BillingPeriod.ANNUAL;
 
         final EntitlementJsonNoEvents entitlementJsonNoEvents = createEntitlement(accountJson.getAccountId(), "99999", productName, ProductCategory.BASE.toString(), term.toString(), true);
-        final String uri = JaxrsResource.ENTITLEMENTS_PATH + "/" + entitlementJsonNoEvents.getEntitlementId();
+        final String uri = JaxrsResource.ENTITLEMENTS_PATH + "/" + entitlementJsonNoEvents.getSubscriptionId();
 
         // Retrieves with GET
         Response response = doGet(uri, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
@@ -157,7 +157,7 @@ public class TestEntitlement extends TestJaxrsBase {
         // Change billing period immediately
         final EntitlementJsonNoEvents newInput = new EntitlementJsonNoEvents(null,
                                                                              null,
-                                                                             entitlementJsonNoEvents.getEntitlementId(),
+                                                                             entitlementJsonNoEvents.getSubscriptionId(),
                                                                              null,
                                                                              null,
                                                                              entitlementJsonNoEvents.getProductName(),
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestSubscription.java b/server/src/test/java/com/ning/billing/jaxrs/TestSubscription.java
index 99229c6..657c170 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestSubscription.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestSubscription.java
@@ -50,7 +50,7 @@ public class TestSubscription extends TestJaxrsBase {
 
         final EntitlementJsonNoEvents entitlementJson = createEntitlement(accountJson.getAccountId(), "99999", productName, ProductCategory.BASE.toString(), term.toString(), true);
 
-        String uri = JaxrsResource.SUBSCRIPTIONS_PATH + "/" + entitlementJson.getEntitlementId();
+        String uri = JaxrsResource.SUBSCRIPTIONS_PATH + "/" + entitlementJson.getSubscriptionId();
 
         // Retrieves with GET
         Response response = doGet(uri, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);