diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PlanDetailJason.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PlanDetailJason.java
index 89acd18..391a777 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PlanDetailJason.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PlanDetailJason.java
@@ -22,19 +22,17 @@ import com.ning.billing.catalog.api.InternationalPrice;
import com.ning.billing.catalog.api.Listing;
public class PlanDetailJason {
- final String productName;
- final String planName;
- final BillingPeriod billingPeriod;
- final String priceListName;
+ final String productName;
+ final String planName;
+ final BillingPeriod billingPeriod;
+ final String priceListName;
final InternationalPrice finalPhasePrice;
- public PlanDetailJason(
- @JsonProperty("product") final String productName,
- @JsonProperty("plan") final String planName,
- @JsonProperty("final_phase_billing_period") final BillingPeriod billingPeriod,
- @JsonProperty("priceList") final String priceListName,
- @JsonProperty("final_phase_recurring_price") final InternationalPrice finalPhasePrice
- ) {
+ public PlanDetailJason(@JsonProperty("product") final String productName,
+ @JsonProperty("plan") final String planName,
+ @JsonProperty("final_phase_billing_period") final BillingPeriod billingPeriod,
+ @JsonProperty("priceList") final String priceListName,
+ @JsonProperty("final_phase_recurring_price") final InternationalPrice finalPhasePrice) {
this.productName = productName;
this.planName = planName;
this.billingPeriod = billingPeriod;
@@ -43,11 +41,8 @@ public class PlanDetailJason {
}
public PlanDetailJason(final Listing listing) {
- this.productName = listing.getPlan().getProduct().getName();
- this.planName = listing.getPlan().getName();
- this.billingPeriod = listing.getPlan().getBillingPeriod();
- this.priceListName = listing.getPriceList().getName();
- this.finalPhasePrice = listing.getPlan().getFinalPhase().getRecurringPrice();
+ this(listing.getPlan().getProduct().getName(), listing.getPlan().getName(), listing.getPlan().getBillingPeriod(),
+ listing.getPriceList().getName(), listing.getPlan().getFinalPhase().getRecurringPrice());
}
public String getProductName() {
@@ -70,5 +65,43 @@ public class PlanDetailJason {
return finalPhasePrice;
}
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final PlanDetailJason that = (PlanDetailJason) o;
+
+ if (billingPeriod != that.billingPeriod) {
+ return false;
+ }
+ if (finalPhasePrice != null ? !finalPhasePrice.equals(that.finalPhasePrice) : that.finalPhasePrice != null) {
+ return false;
+ }
+ if (planName != null ? !planName.equals(that.planName) : that.planName != null) {
+ return false;
+ }
+ if (priceListName != null ? !priceListName.equals(that.priceListName) : that.priceListName != null) {
+ return false;
+ }
+ if (productName != null ? !productName.equals(that.productName) : that.productName != null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = productName != null ? productName.hashCode() : 0;
+ result = 31 * result + (planName != null ? planName.hashCode() : 0);
+ result = 31 * result + (billingPeriod != null ? billingPeriod.hashCode() : 0);
+ result = 31 * result + (priceListName != null ? priceListName.hashCode() : 0);
+ result = 31 * result + (finalPhasePrice != null ? finalPhasePrice.hashCode() : 0);
+ return result;
+ }
}
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestPlanDetailJason.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestPlanDetailJason.java
new file mode 100644
index 0000000..ee7ba0d
--- /dev/null
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestPlanDetailJason.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2010-2012 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.jaxrs.json;
+
+import java.util.UUID;
+
+import org.mockito.Mockito;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.InternationalPrice;
+import com.ning.billing.catalog.api.Listing;
+import com.ning.billing.catalog.api.Plan;
+import com.ning.billing.catalog.api.PlanPhase;
+import com.ning.billing.catalog.api.PriceList;
+import com.ning.billing.catalog.api.Product;
+
+public class TestPlanDetailJason {
+ private static final ObjectMapper mapper = new ObjectMapper();
+
+ @Test(groups = "fast")
+ public void testJson() throws Exception {
+ final String productName = UUID.randomUUID().toString();
+ final String planName = UUID.randomUUID().toString();
+ final BillingPeriod billingPeriod = BillingPeriod.ANNUAL;
+ final String priceListName = UUID.randomUUID().toString();
+ final PlanDetailJason planDetailJason = new PlanDetailJason(productName, planName, billingPeriod, priceListName, null);
+ Assert.assertEquals(planDetailJason.getProductName(), productName);
+ Assert.assertEquals(planDetailJason.getPlanName(), planName);
+ Assert.assertEquals(planDetailJason.getBillingPeriod(), billingPeriod);
+ Assert.assertEquals(planDetailJason.getPriceListName(), priceListName);
+ Assert.assertEquals(planDetailJason.getFinalPhasePrice(), null);
+
+ final String asJson = mapper.writeValueAsString(planDetailJason);
+ Assert.assertEquals(asJson, "{\"productName\":\"" + planDetailJason.getProductName() + "\"," +
+ "\"planName\":\"" + planDetailJason.getPlanName() + "\"," +
+ "\"billingPeriod\":\"" + planDetailJason.getBillingPeriod().toString() + "\"," +
+ "\"priceListName\":\"" + planDetailJason.getPriceListName() + "\"," +
+ "\"finalPhasePrice\":null}");
+
+ final PlanDetailJason fromJson = mapper.readValue(asJson, PlanDetailJason.class);
+ Assert.assertEquals(fromJson, planDetailJason);
+ }
+
+ @Test(groups = "fast")
+ public void testFromListing() throws Exception {
+ final Product product = Mockito.mock(Product.class);
+ Mockito.when(product.getName()).thenReturn(UUID.randomUUID().toString());
+
+ final InternationalPrice price = Mockito.mock(InternationalPrice.class);
+ final PlanPhase planPhase = Mockito.mock(PlanPhase.class);
+ Mockito.when(planPhase.getRecurringPrice()).thenReturn(price);
+
+ final Plan plan = Mockito.mock(Plan.class);
+ Mockito.when(plan.getProduct()).thenReturn(product);
+ Mockito.when(plan.getName()).thenReturn(UUID.randomUUID().toString());
+ Mockito.when(plan.getBillingPeriod()).thenReturn(BillingPeriod.QUARTERLY);
+ Mockito.when(plan.getFinalPhase()).thenReturn(planPhase);
+
+ final PriceList priceList = Mockito.mock(PriceList.class);
+ Mockito.when(priceList.getName()).thenReturn(UUID.randomUUID().toString());
+
+ final Listing listing = Mockito.mock(Listing.class);
+ Mockito.when(listing.getPlan()).thenReturn(plan);
+ Mockito.when(listing.getPriceList()).thenReturn(priceList);
+
+ final PlanDetailJason planDetailJason = new PlanDetailJason(listing);
+ Assert.assertEquals(planDetailJason.getProductName(), plan.getProduct().getName());
+ Assert.assertEquals(planDetailJason.getPlanName(), plan.getName());
+ Assert.assertEquals(planDetailJason.getBillingPeriod(), plan.getBillingPeriod());
+ Assert.assertEquals(planDetailJason.getPriceListName(), priceList.getName());
+ Assert.assertEquals(planDetailJason.getFinalPhasePrice(), plan.getFinalPhase().getRecurringPrice());
+ }
+}