diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationWithCatalogUpdate.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationWithCatalogUpdate.java index 4635782b4c..c314ac26c9 100644 --- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationWithCatalogUpdate.java +++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationWithCatalogUpdate.java @@ -101,7 +101,7 @@ public void testBasic() throws Exception { final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.of()); catalogUserApi.addSimplePlan(desc1, init, testCallContext); StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext); - assertEquals(catalog.getCurrentPlans().length, 1); + assertEquals(catalog.getCurrentPlans().size(), 1); final Entitlement baseEntitlement = createEntitlement("foo-monthly", true); @@ -111,7 +111,7 @@ public void testBasic() throws Exception { final SimplePlanDescriptor desc2 = new DefaultSimplePlanDescriptor("superfoo-monthly", "SuperFoo", ProductCategory.BASE, account.getCurrency(), new BigDecimal("20.00"), BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.of()); catalogUserApi.addSimplePlan(desc2, init, testCallContext); catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext); - assertEquals(catalog.getCurrentPlans().length, 2); + assertEquals(catalog.getCurrentPlans().size(), 2); // Change Plan to the newly added Plan and verify correct default rules behavior (IMMEDIATE change) busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT); @@ -131,8 +131,8 @@ public void testWithMultiplePlansForOneProduct() throws CatalogApiException, Ent final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("xxx-monthly", "XXX", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.of()); catalogUserApi.addSimplePlan(desc1, init, testCallContext); StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext); - assertEquals(catalog.getCurrentProducts().length, 1); - assertEquals(catalog.getCurrentPlans().length, 1); + assertEquals(catalog.getCurrentProducts().size(), 1); + assertEquals(catalog.getCurrentPlans().size(), 1); final Entitlement baseEntitlement1 = createEntitlement("xxx-monthly", true); @@ -140,8 +140,8 @@ public void testWithMultiplePlansForOneProduct() throws CatalogApiException, Ent final SimplePlanDescriptor desc2 = new DefaultSimplePlanDescriptor("xxx-14-monthly", "XXX", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.of()); catalogUserApi.addSimplePlan(desc2, init, testCallContext); catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext); - assertEquals(catalog.getCurrentProducts().length, 1); - assertEquals(catalog.getCurrentPlans().length, 2); + assertEquals(catalog.getCurrentProducts().size(), 1); + assertEquals(catalog.getCurrentPlans().size(), 2); final Entitlement baseEntitlement2 = createEntitlement("xxx-14-monthly", false); @@ -149,8 +149,8 @@ public void testWithMultiplePlansForOneProduct() throws CatalogApiException, Ent final SimplePlanDescriptor desc3 = new DefaultSimplePlanDescriptor("xxx-30-monthly", "XXX", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.DAYS, ImmutableList.of()); catalogUserApi.addSimplePlan(desc3, init, testCallContext); catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext); - assertEquals(catalog.getCurrentProducts().length, 1); - assertEquals(catalog.getCurrentPlans().length, 3); + assertEquals(catalog.getCurrentProducts().size(), 1); + assertEquals(catalog.getCurrentPlans().size(), 3); final Entitlement baseEntitlement3 = createEntitlement("xxx-30-monthly", false); @@ -172,12 +172,12 @@ public void testError_CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST() throws Excepti final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("zoe-monthly", "Zoe", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.of()); catalogUserApi.addSimplePlan(desc1, init, testCallContext); StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext); - assertEquals(catalog.getCurrentPlans().length, 1); + assertEquals(catalog.getCurrentPlans().size(), 1); final SimplePlanDescriptor desc2 = new DefaultSimplePlanDescriptor("zoe-14-monthly", "Zoe", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.of()); catalogUserApi.addSimplePlan(desc2, init, testCallContext); catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext); - assertEquals(catalog.getCurrentPlans().length, 2); + assertEquals(catalog.getCurrentPlans().size(), 2); try { final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Zoe", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); @@ -195,9 +195,9 @@ public void testWithPriceOverride() throws Exception { final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("bar-monthly", "Bar", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.of()); catalogUserApi.addSimplePlan(desc1, init, testCallContext); StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext); - assertEquals(catalog.getCurrentPlans().length, 1); + assertEquals(catalog.getCurrentPlans().size(), 1); - final Plan plan = catalog.getCurrentPlans()[0]; + final Plan plan = catalog.getCurrentPlans().iterator().next(); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("bar-monthly", null); final List overrides = new ArrayList(); @@ -236,7 +236,7 @@ public void testWithThirtyDaysPlan() throws Exception { final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("thirty-monthly", "Thirty", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.THIRTY_DAYS, 0, TimeUnit.UNLIMITED, ImmutableList.of()); catalogUserApi.addSimplePlan(desc1, init, testCallContext); StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext); - assertEquals(catalog.getCurrentPlans().length, 1); + assertEquals(catalog.getCurrentPlans().size(), 1); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("thirty-monthly", null); diff --git a/catalog/src/main/java/org/killbill/billing/catalog/CatalogEntityCollection.java b/catalog/src/main/java/org/killbill/billing/catalog/CatalogEntityCollection.java index 78cdda02e2..b9bad426ae 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/CatalogEntityCollection.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/CatalogEntityCollection.java @@ -41,6 +41,14 @@ public CatalogEntityCollection(final T[] entities) { } } + + public CatalogEntityCollection(final Collection entities) { + this.data = new TreeMap(Ordering.natural()); + for (final T cur : entities) { + addEntry(cur); + } + } + // // Returning such entries will be log(N) // diff --git a/catalog/src/main/java/org/killbill/billing/catalog/CatalogUpdater.java b/catalog/src/main/java/org/killbill/billing/catalog/CatalogUpdater.java index fcfe43c6e3..aa1c1637bd 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/CatalogUpdater.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/CatalogUpdater.java @@ -29,9 +29,11 @@ import org.killbill.billing.catalog.api.CatalogApiException; import org.killbill.billing.catalog.api.Currency; import org.killbill.billing.catalog.api.PhaseType; +import org.killbill.billing.catalog.api.Plan; import org.killbill.billing.catalog.api.PlanAlignmentChange; import org.killbill.billing.catalog.api.PlanAlignmentCreate; import org.killbill.billing.catalog.api.PriceListSet; +import org.killbill.billing.catalog.api.Product; import org.killbill.billing.catalog.api.ProductCategory; import org.killbill.billing.catalog.api.SimplePlanDescriptor; import org.killbill.billing.catalog.api.TimeUnit; @@ -44,6 +46,8 @@ import org.killbill.billing.catalog.rules.DefaultPlanRules; import org.killbill.xmlloader.XMLWriter; +import com.google.common.collect.ImmutableList; + public class CatalogUpdater { private static URI DUMMY_URI; @@ -53,7 +57,9 @@ public class CatalogUpdater { DUMMY_URI = new URI("dummy"); } catch (URISyntaxException e) { } - }; + } + + ; private final DefaultMutableStaticCatalog catalog; @@ -68,8 +74,8 @@ public CatalogUpdater(final String catalogName, final BillingMode billingMode, f .setCatalogName(catalogName) .setEffectiveDate(effectiveDate.toDate()) .setRecurringBillingMode(billingMode) - .setProducts(new DefaultProduct[0]) - .setPlans(new DefaultPlan[0]) + .setProducts(ImmutableList.of()) + .setPlans(ImmutableList.of()) .setPriceLists(new DefaultPriceListSet(defaultPriceList, new DefaultPriceList[0])) .setPlanRules(getSaneDefaultPlanRules(defaultPriceList)); if (currencies != null && currencies.length > 0) { @@ -92,7 +98,6 @@ public String getCatalogXML() { } } - public void addSimplePlanDescriptor(final SimplePlanDescriptor desc) throws CatalogApiException { // We need at least a planId @@ -100,12 +105,12 @@ public void addSimplePlanDescriptor(final SimplePlanDescriptor desc) throws Cata throw new CatalogApiException(ErrorCode.CAT_INVALID_SIMPLE_PLAN_DESCRIPTOR, desc); } - DefaultPlan plan = getExistingPlan(desc.getPlanId()); + DefaultPlan plan = (DefaultPlan) getExistingPlan(desc.getPlanId()); if (plan == null && desc.getProductName() == null) { throw new CatalogApiException(ErrorCode.CAT_INVALID_SIMPLE_PLAN_DESCRIPTOR, desc); } - DefaultProduct product = plan != null ? (DefaultProduct) plan.getProduct() : getExistingProduct(desc.getProductName()); + DefaultProduct product = plan != null ? (DefaultProduct) plan.getProduct() : (DefaultProduct) getExistingProduct(desc.getProductName()); if (product == null) { product = new DefaultProduct(); product.setName(desc.getProductName()); @@ -171,9 +176,9 @@ public void addSimplePlanDescriptor(final SimplePlanDescriptor desc) throws Cata if (desc.getProductCategory() == ProductCategory.ADD_ON) { for (final String bp : desc.getAvailableBaseProducts()) { - final DefaultProduct targetBasePlan = getExistingProduct(bp); + final Product targetBasePlan = getExistingProduct(bp); boolean found = false; - for (DefaultProduct cur : targetBasePlan.getAvailable()) { + for (Product cur : targetBasePlan.getAvailable()) { if (cur.getName().equals(product.getName())) { found = true; break; @@ -278,8 +283,8 @@ private void validateNewPlanDescriptor(final SimplePlanDescriptor desc) throws C } } - private DefaultProduct getExistingProduct(final String productName) { - for (final DefaultProduct input : catalog.getCurrentProducts()) { + private Product getExistingProduct(final String productName) { + for (final Product input : catalog.getCurrentProducts()) { if (input.getName().equals(productName)) { return input; } @@ -287,8 +292,8 @@ private DefaultProduct getExistingProduct(final String productName) { return null; } - private DefaultPlan getExistingPlan(final String planName) { - for (final DefaultPlan input : catalog.getCurrentPlans()) { + private Plan getExistingPlan(final String planName) { + for (final Plan input : catalog.getCurrentPlans()) { if (input.getName().equals(planName)) { return input; } diff --git a/catalog/src/main/java/org/killbill/billing/catalog/DefaultMutableStaticCatalog.java b/catalog/src/main/java/org/killbill/billing/catalog/DefaultMutableStaticCatalog.java index 8e312680b1..8e83016a9a 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/DefaultMutableStaticCatalog.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/DefaultMutableStaticCatalog.java @@ -61,35 +61,16 @@ public void addCurrency(final Currency currency) throws CatalogApiException { @Override public void addProduct(final Product product) throws CatalogApiException { - final Product[] newEntries = allocateNewEntries(getCurrentProducts(), product); - setProducts((DefaultProduct[]) newEntries); + getCatalogEntityCollectionProduct().add(product); } @Override public void addPlan(final Plan plan) throws CatalogApiException { - final Plan[] newEntries = allocateNewEntries(getCurrentPlans(), plan); - setPlans((DefaultPlan[]) newEntries); - final DefaultPriceList priceList = getPriceLists().findPriceListFrom(plan.getPriceListName()); - final List newPriceListPlan = new ArrayList(); - for (Plan input : newEntries) { - if (plan.getName().equals(input.getName())) { - newPriceListPlan.add((DefaultPlan) plan); - continue; - } - if (priceList.getPlans() != null) { - for (final Plan priceListPlan : priceList.getPlans()) { - if (priceListPlan.getName().equals(input.getName())) { - newPriceListPlan.add((DefaultPlan) priceListPlan); - break; - } - } - } - } + getCatalogEntityCollectionPlan().add(plan); - final Plan[] newPriceListEntries = new DefaultPlan[newPriceListPlan.size()]; - final Plan[] bar = newPriceListPlan.toArray(newPriceListEntries); - priceList.setPlans((DefaultPlan[]) bar); + final DefaultPriceList priceList = getPriceLists().findPriceListFrom(plan.getPriceListName()); + priceList.getCatalogEntityCollectionPlan().add(plan); } @Override @@ -104,9 +85,8 @@ public void addRecurringPriceToPlan(final DefaultInternationalPrice currentPrice currentPrices.setPrices((DefaultPrice[]) newEntries); } - public void addProductAvailableAO(final DefaultProduct targetBasePlan, final DefaultProduct aoProduct) throws CatalogApiException { - final Product[] newEntries = allocateNewEntries(targetBasePlan.getAvailable(), aoProduct); - targetBasePlan.setAvailable((DefaultProduct[]) newEntries); + public void addProductAvailableAO(final Product targetBasePlan, final DefaultProduct aoProduct) throws CatalogApiException { + ((DefaultProduct) targetBasePlan).getCatalogEntityCollectionAvailable().add(aoProduct); } private T[] allocateNewEntries(final T[] existingEntries, final T newEntry) throws CatalogApiException { diff --git a/catalog/src/main/java/org/killbill/billing/catalog/DefaultPlan.java b/catalog/src/main/java/org/killbill/billing/catalog/DefaultPlan.java index 61eb0ae866..b99ec4b2ac 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/DefaultPlan.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/DefaultPlan.java @@ -218,8 +218,8 @@ public DefaultPlan setFinalPhase(final DefaultPlanPhase finalPhase) { return this; } - public DefaultPlan setProduct(final DefaultProduct product) { - this.product = product; + public DefaultPlan setProduct(final Product product) { + this.product = (DefaultProduct) product; return this; } diff --git a/catalog/src/main/java/org/killbill/billing/catalog/DefaultPriceList.java b/catalog/src/main/java/org/killbill/billing/catalog/DefaultPriceList.java index feb06e6dd6..73353545bd 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/DefaultPriceList.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/DefaultPriceList.java @@ -17,6 +17,7 @@ package org.killbill.billing.catalog; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; @@ -43,10 +44,11 @@ public class DefaultPriceList extends ValidatingConfig implem @XmlElementWrapper(name = "plans", required = false) @XmlIDREF - @XmlElement(name = "plan", required = false) - private CatalogEntityCollection plans; + @XmlElement(type=DefaultPlan.class, name = "plan", required = false) + private CatalogEntityCollection plans; public DefaultPriceList() { + this.plans = new CatalogEntityCollection(); } public DefaultPriceList(final DefaultPlan[] plans, final String name) { @@ -55,10 +57,14 @@ public DefaultPriceList(final DefaultPlan[] plans, final String name) { } @Override - public Plan[] getPlans() { - return (Plan[]) plans.toArray(new DefaultPlan[plans.size()]); + public Collection getPlans() { + return plans; } + + public CatalogEntityCollection getCatalogEntityCollectionPlan() { + return plans; + } /* (non-Javadoc) * @see org.killbill.billing.catalog.IPriceList#getName() */ @@ -71,18 +77,18 @@ public String getName() { * @see org.killbill.billing.catalog.IPriceList#findPlan(org.killbill.billing.catalog.api.IProduct, org.killbill.billing.catalog.api.BillingPeriod) */ @Override - public DefaultPlan[] findPlans(final Product product, final BillingPeriod period) { - final List result = new ArrayList(plans.size()); + public Collection findPlans(final Product product, final BillingPeriod period) { + final List result = new ArrayList(plans.size()); for (final Plan cur : getPlans()) { if (cur.getProduct().equals(product) && (cur.getRecurringBillingPeriod() != null && cur.getRecurringBillingPeriod().equals(period))) { - result.add((DefaultPlan) cur); + result.add(cur); } } - return result.toArray(new DefaultPlan[result.size()]); + return result; } - public DefaultPlan findPlan(final String planName) { + public Plan findPlan(final String planName) { return plans.findByName(planName); } @@ -96,7 +102,7 @@ public DefaultPriceList setName(final String name) { return this; } - public DefaultPriceList setPlans(final DefaultPlan[] plans) { + public DefaultPriceList setPlans(final Collection plans) { this.plans = new CatalogEntityCollection(plans); return this; } diff --git a/catalog/src/main/java/org/killbill/billing/catalog/DefaultPriceListSet.java b/catalog/src/main/java/org/killbill/billing/catalog/DefaultPriceListSet.java index 7e0f5e0edf..c159833a7e 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/DefaultPriceListSet.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/DefaultPriceListSet.java @@ -21,11 +21,13 @@ import javax.xml.bind.annotation.XmlElement; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import org.killbill.billing.ErrorCode; import org.killbill.billing.catalog.api.BillingPeriod; import org.killbill.billing.catalog.api.CatalogApiException; +import org.killbill.billing.catalog.api.Plan; import org.killbill.billing.catalog.api.PriceList; import org.killbill.billing.catalog.api.PriceListSet; import org.killbill.billing.catalog.api.Product; @@ -52,21 +54,21 @@ public DefaultPriceListSet(final DefaultPriceList defaultPricelist, final Defaul this.childPriceLists = childPriceLists != null ? childPriceLists : new DefaultPriceList[0]; } - public DefaultPlan getPlanFrom(final Product product, final BillingPeriod period, final String priceListName) throws CatalogApiException { + public Plan getPlanFrom(final Product product, final BillingPeriod period, final String priceListName) throws CatalogApiException { - DefaultPlan[] plans = null; + Collection plans = null; final DefaultPriceList pl = findPriceListFrom(priceListName); if (pl != null) { plans = pl.findPlans(product, period); } - if (plans.length == 0) { + if (plans.size() == 0) { plans = defaultPricelist.findPlans(product, period); } - switch(plans.length) { + switch(plans.size()) { case 0: return null; case 1: - return plans[0]; + return plans.iterator().next(); default: throw new CatalogApiException(ErrorCode.CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST, priceListName, product.getName(), period); diff --git a/catalog/src/main/java/org/killbill/billing/catalog/DefaultProduct.java b/catalog/src/main/java/org/killbill/billing/catalog/DefaultProduct.java index 91e4ffbd5e..ffb8e96382 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/DefaultProduct.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/DefaultProduct.java @@ -18,6 +18,7 @@ import java.net.URI; import java.util.Arrays; +import java.util.Collection; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -35,7 +36,6 @@ @XmlAccessorType(XmlAccessType.NONE) public class DefaultProduct extends ValidatingConfig implements Product { - private static final DefaultProduct[] EMPTY_PRODUCT_LIST = new DefaultProduct[0]; @XmlAttribute(required = true) @XmlID @@ -46,13 +46,13 @@ public class DefaultProduct extends ValidatingConfig implemen @XmlElementWrapper(name = "included", required = false) @XmlIDREF - @XmlElement(name = "addonProduct", required = false) - private DefaultProduct[] included; + @XmlElement(type=DefaultProduct.class, name = "addonProduct", required = false) + private CatalogEntityCollection included; @XmlElementWrapper(name = "available", required = false) @XmlIDREF - @XmlElement(name = "addonProduct", required = false) - private DefaultProduct[] available; + @XmlElement(type=DefaultProduct.class, name = "addonProduct", required = false) + private CatalogEntityCollection available; @XmlElementWrapper(name = "limits", required = false) @XmlElement(name = "limit", required = false) @@ -72,22 +72,29 @@ public ProductCategory getCategory() { } @Override - public DefaultProduct[] getIncluded() { - return included; + public Collection getIncluded() { + return included.getEntries(); } @Override - public DefaultProduct[] getAvailable() { - return available; + public Collection getAvailable() { + return available.getEntries(); } + + public CatalogEntityCollection getCatalogEntityCollectionAvailable() { + return available; + }; + public DefaultProduct() { - included = EMPTY_PRODUCT_LIST; - available = EMPTY_PRODUCT_LIST; - limits = new DefaultLimit[0]; + this.included = new CatalogEntityCollection(); + this.available = new CatalogEntityCollection(); + this.limits = new DefaultLimit[0]; } public DefaultProduct(final String name, final ProductCategory category) { + this.included = new CatalogEntityCollection(); + this.available = new CatalogEntityCollection(); this.category = category; this.name = name; } @@ -98,7 +105,7 @@ public String getName() { } public boolean isIncluded(final DefaultProduct addon) { - for (final DefaultProduct p : included) { + for (final Product p : included.getEntries()) { if (addon == p) { return true; } @@ -107,7 +114,7 @@ public boolean isIncluded(final DefaultProduct addon) { } public boolean isAvailable(final DefaultProduct addon) { - for (final DefaultProduct p : included) { + for (final Product p : included.getEntries()) { if (addon == p) { return true; } @@ -168,13 +175,13 @@ public DefaultProduct setCategory(final ProductCategory category) { return this; } - public DefaultProduct setIncluded(final DefaultProduct[] included) { - this.included = included; + public DefaultProduct setIncluded(final Collection included) { + this.included = new CatalogEntityCollection(included); return this; } - public DefaultProduct setAvailable(final DefaultProduct[] available) { - this.available = available; + public DefaultProduct setAvailable(final Collection available) { + this.available = new CatalogEntityCollection(available); return this; } @@ -185,9 +192,14 @@ public DefaultProduct setCatalogName(final String catalogName) { @Override public String toString() { - return "DefaultProduct [name=" + name + ", category=" + category + ", included=" - + Arrays.toString(included) + ", available=" + Arrays.toString(available) + ", catalogName=" - + catalogName + "]"; + return "DefaultProduct{" + + "name='" + name + '\'' + + ", category=" + category + + ", included=" + included + + ", available=" + available + + ", limits=" + Arrays.toString(limits) + + ", catalogName='" + catalogName + '\'' + + '}'; } @Override @@ -195,41 +207,40 @@ public boolean equals(final Object o) { if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { + if (!(o instanceof DefaultProduct)) { return false; } - final DefaultProduct that = (DefaultProduct) o; + final DefaultProduct product = (DefaultProduct) o; - if (!Arrays.equals(available, that.available)) { - return false; - } - if (catalogName != null ? !catalogName.equals(that.catalogName) : that.catalogName != null) { + if (name != null ? !name.equals(product.name) : product.name != null) { return false; } - if (category != that.category) { + if (category != product.category) { return false; } - if (!Arrays.equals(included, that.included)) { + if (included != null ? !included.equals(product.included) : product.included != null) { return false; } - if (!Arrays.equals(limits, that.limits)) { + if (available != null ? !available.equals(product.available) : product.available != null) { return false; } - if (name != null ? !name.equals(that.name) : that.name != null) { + // Probably incorrect - comparing Object[] arrays with Arrays.equals + if (!Arrays.equals(limits, product.limits)) { return false; } + return catalogName != null ? catalogName.equals(product.catalogName) : product.catalogName == null; - return true; } @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + (category != null ? category.hashCode() : 0); - result = 31 * result + (included != null ? Arrays.hashCode(included) : 0); - result = 31 * result + (available != null ? Arrays.hashCode(available) : 0); - result = 31 * result + (limits != null ? Arrays.hashCode(limits) : 0); + result = 31 * result + (included != null ? included.hashCode() : 0); + result = 31 * result + (available != null ? available.hashCode() : 0); + result = 31 * result + Arrays.hashCode(limits); + result = 31 * result + (catalogName != null ? catalogName.hashCode() : 0); return result; } } diff --git a/catalog/src/main/java/org/killbill/billing/catalog/StandaloneCatalog.java b/catalog/src/main/java/org/killbill/billing/catalog/StandaloneCatalog.java index e58c8ca09d..0511e71de0 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/StandaloneCatalog.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/StandaloneCatalog.java @@ -77,15 +77,15 @@ public class StandaloneCatalog extends ValidatingConfig imple private DefaultUnit[] units; @XmlElementWrapper(name = "products", required = false) - @XmlElement(name = "product", required = false) - private CatalogEntityCollection products; + @XmlElement(type=DefaultProduct.class, name = "product", required = false) + private CatalogEntityCollection products; @XmlElement(name = "rules", required = true) private DefaultPlanRules planRules; @XmlElementWrapper(name = "plans", required = false) - @XmlElement(name = "plan", required = false) - private CatalogEntityCollection plans; + @XmlElement(type=DefaultPlan.class, name = "plan", required = false) + private CatalogEntityCollection plans; @XmlElement(name = "priceLists", required = true) private DefaultPriceListSet priceLists; @@ -93,6 +93,8 @@ public class StandaloneCatalog extends ValidatingConfig imple private URI catalogURI; public StandaloneCatalog() { + this.plans = new CatalogEntityCollection(); + this.products = new CatalogEntityCollection(); } protected StandaloneCatalog(final Date effectiveDate) { @@ -121,17 +123,13 @@ public BillingMode getRecurringBillingMode() { * @see org.killbill.billing.catalog.ICatalog#getProducts() */ @Override - public DefaultProduct[] getCurrentProducts() { - return (DefaultProduct[]) products.toArray(new DefaultProduct[products.size()]); - } - - public Collection getAllProducts() { + public Collection getCurrentProducts() { return products.getEntries(); } - public Collection getAllPlans() { - return plans.getEntries(); + public CatalogEntityCollection getCatalogEntityCollectionProduct() { + return products; } /* (non-Javadoc) @@ -147,9 +145,16 @@ public Currency[] getCurrentSupportedCurrencies() { return supportedCurrencies; } + + @Override - public DefaultPlan[] getCurrentPlans() { - return (DefaultPlan[]) plans.toArray(new DefaultPlan[plans.size()]); + public Collection getCurrentPlans() { + return plans.getEntries(); + } + + + public CatalogEntityCollection getCatalogEntityCollectionPlan() { + return plans; } public boolean isTemplateCatalog() { @@ -178,8 +183,8 @@ public DefaultPriceListSet getPriceLists() { * @see org.killbill.billing.catalog.ICatalog#getPlan(java.lang.String, java.lang.String) */ @Override - public DefaultPlan createOrFindCurrentPlan(final PlanSpecifier spec, final PlanPhasePriceOverridesWithCallContext unused) throws CatalogApiException { - final DefaultPlan result; + public Plan createOrFindCurrentPlan(final PlanSpecifier spec, final PlanPhasePriceOverridesWithCallContext unused) throws CatalogApiException { + final Plan result; if (spec.getPlanName() != null) { result = findCurrentPlan(spec.getPlanName()); } else { @@ -208,7 +213,7 @@ public DefaultPlan findCurrentPlan(final String name) throws CatalogApiException if (name == null || plans == null) { throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PLAN, name); } - final DefaultPlan result = plans.findByName(name); + final DefaultPlan result = (DefaultPlan) plans.findByName(name); if (result != null) { return result; } @@ -297,11 +302,11 @@ public void initialize(final StandaloneCatalog catalog, final URI sourceURI) { super.initialize(catalog, sourceURI); planRules.initialize(catalog, sourceURI); priceLists.initialize(catalog, sourceURI); - for (final DefaultProduct p : products) { - p.initialize(catalog, sourceURI); + for (final Product p : products.getEntries()) { + ((DefaultProduct)p).initialize(catalog, sourceURI); } - for (final DefaultPlan p : plans) { - p.initialize(catalog, sourceURI); + for (final Plan p : plans.getEntries()) { + ((DefaultPlan) p).initialize(catalog, sourceURI); } } @@ -318,8 +323,8 @@ public boolean compliesWithLimits(final String phaseName, final String unit, fin return phase.compliesWithLimits(unit, value); } - public StandaloneCatalog setProducts(final DefaultProduct[] products) { - this.products = new CatalogEntityCollection(products); + public StandaloneCatalog setProducts(final Collection products) { + this.products = new CatalogEntityCollection(products); return this; } @@ -328,8 +333,8 @@ public StandaloneCatalog setSupportedCurrencies(final Currency[] supportedCurren return this; } - public StandaloneCatalog setPlans(final DefaultPlan[] plans) { - this.plans = new CatalogEntityCollection(plans); + public StandaloneCatalog setPlans(final Collection plans) { + this.plans = new CatalogEntityCollection(plans); return this; } @@ -385,7 +390,7 @@ public List getAvailableAddOnListings(final String baseProductName, @Nu for (BillingPeriod billingPeriod : BillingPeriod.values()) { for (PriceList priceList : getPriceLists().getAllPriceLists()) { if (priceListName == null || priceListName.equals(priceList.getName())) { - Plan[] addonInList = priceList.findPlans(availAddon, billingPeriod); + Collection addonInList = priceList.findPlans(availAddon, billingPeriod); for (Plan cur : addonInList) { availAddons.add(new DefaultListing(cur, priceList)); } diff --git a/catalog/src/main/java/org/killbill/billing/catalog/StandaloneCatalogWithPriceOverride.java b/catalog/src/main/java/org/killbill/billing/catalog/StandaloneCatalogWithPriceOverride.java index fbffc1f405..8a42e4beaa 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/StandaloneCatalogWithPriceOverride.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/StandaloneCatalogWithPriceOverride.java @@ -70,8 +70,8 @@ public InternalCallContextFactory getInternalCallContextFactory() { @Override - public DefaultPlan createOrFindCurrentPlan(final PlanSpecifier spec, final PlanPhasePriceOverridesWithCallContext overrides) throws CatalogApiException { - final DefaultPlan defaultPlan = super.createOrFindCurrentPlan(spec, null); + public Plan createOrFindCurrentPlan(final PlanSpecifier spec, final PlanPhasePriceOverridesWithCallContext overrides) throws CatalogApiException { + final Plan defaultPlan = super.createOrFindCurrentPlan(spec, null); if (overrides == null || overrides.getOverrides() == null || overrides.getOverrides().isEmpty()) { diff --git a/catalog/src/main/java/org/killbill/billing/catalog/VersionedCatalog.java b/catalog/src/main/java/org/killbill/billing/catalog/VersionedCatalog.java index ea97bcb0c8..fbf55914a0 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/VersionedCatalog.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/VersionedCatalog.java @@ -20,6 +20,7 @@ import java.net.URI; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -249,7 +250,7 @@ public String getCatalogName() { } @Override - public DefaultProduct[] getProducts(final DateTime requestedDate) throws CatalogApiException { + public Collection getProducts(final DateTime requestedDate) throws CatalogApiException { return versionForDate(requestedDate).getCurrentProducts(); } @@ -259,7 +260,7 @@ public Currency[] getSupportedCurrencies(final DateTime requestedDate) throws Ca } @Override - public DefaultPlan[] getPlans(final DateTime requestedDate) throws CatalogApiException { + public Collection getPlans(final DateTime requestedDate) throws CatalogApiException { return versionForDate(requestedDate).getCurrentPlans(); } @@ -435,7 +436,7 @@ public Currency[] getCurrentSupportedCurrencies() throws CatalogApiException { } @Override - public Product[] getCurrentProducts() throws CatalogApiException { + public Collection getCurrentProducts() throws CatalogApiException { return versionForDate(clock.getUTCNow()).getCurrentProducts(); } @@ -445,7 +446,7 @@ public Unit[] getCurrentUnits() throws CatalogApiException { } @Override - public Plan[] getCurrentPlans() throws CatalogApiException { + public Collection getCurrentPlans() throws CatalogApiException { return versionForDate(clock.getUTCNow()).getCurrentPlans(); } diff --git a/catalog/src/main/java/org/killbill/billing/catalog/plugin/StandaloneCatalogMapper.java b/catalog/src/main/java/org/killbill/billing/catalog/plugin/StandaloneCatalogMapper.java index 1b42d710bd..7c904427be 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/plugin/StandaloneCatalogMapper.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/plugin/StandaloneCatalogMapper.java @@ -19,6 +19,8 @@ import java.net.URI; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; import javax.annotation.Nullable; @@ -81,8 +83,8 @@ public class StandaloneCatalogMapper { private final String catalogName; private final BillingMode recurringBillingMode; - private Iterable tmpDefaultProducts; - private Iterable tmpDefaultPlans; + private Collection tmpDefaultProducts; + private Collection tmpDefaultPlans; private DefaultPriceListSet tmpDefaultPriceListSet; public StandaloneCatalogMapper(final String catalogName, final BillingMode recurringBillingMode) { @@ -105,10 +107,10 @@ public StandaloneCatalog toStandaloneCatalog(final StandalonePluginCatalog plugi result.setPlanRules(toDefaultPlanRules(pluginCatalog.getPlanRules())); for (final Product cur : pluginCatalog.getProducts()) { - for (DefaultProduct target : result.getCurrentProducts()) { + for (Product target : result.getCurrentProducts()) { if (target.getName().equals(cur.getName())) { - target.setAvailable(toFilteredDefaultProduct(ImmutableList.copyOf(cur.getAvailable()))); - target.setIncluded(toFilteredDefaultProduct(ImmutableList.copyOf(cur.getIncluded()))); + ((DefaultProduct) target).setAvailable(toFilteredDefaultProduct(ImmutableList.copyOf(cur.getAvailable()))); + ((DefaultProduct) target).setIncluded(toFilteredDefaultProduct(ImmutableList.copyOf(cur.getIncluded()))); break; } } @@ -250,22 +252,22 @@ final void populateDefaultCaseChange(final CaseChange input, final DefaultCaseCh } - private DefaultProduct[] toDefaultProducts(final Iterable input) { + private Collection toDefaultProducts(final Iterable input) { if (tmpDefaultProducts == null) { - final Function productTransformer = new Function() { + final Function productTransformer = new Function() { @Override - public DefaultProduct apply(final Product input) { + public Product apply(final Product input) { return toDefaultProduct(input); } }; - tmpDefaultProducts = ImmutableList.copyOf(Iterables.transform(input, productTransformer)); + tmpDefaultProducts = ImmutableList.copyOf(Iterables.transform(input, productTransformer)); } - return toArray(tmpDefaultProducts); + return tmpDefaultProducts; } - private DefaultProduct[] toFilteredDefaultProduct(final Iterable input) { + private Collection toFilteredDefaultProduct(final Iterable input) { if (!input.iterator().hasNext()) { - return new DefaultProduct[0]; + return Collections.emptyList(); } final List inputProductNames = ImmutableList.copyOf(Iterables.transform(input, new Function() { @Override @@ -273,33 +275,33 @@ public String apply(final Product input) { return input.getName(); } })); - final List filteredAndOrdered = new ArrayList(inputProductNames.size()); + final Collection filteredAndOrdered = new ArrayList(inputProductNames.size()); for (final String cur : inputProductNames) { - final DefaultProduct found = findOrIllegalState(tmpDefaultProducts, new Predicate() { + final Product found = findOrIllegalState(tmpDefaultProducts, new Predicate() { @Override - public boolean apply(final DefaultProduct inputPredicate) { + public boolean apply(final Product inputPredicate) { return inputPredicate.getName().equals(cur); } }, "Failed to find product " + cur); filteredAndOrdered.add(found); } - return toArray(filteredAndOrdered); + return filteredAndOrdered; } - private DefaultPlan[] toDefaultPlans(final Iterable input) { + private Collection toDefaultPlans(final Iterable input) { if (tmpDefaultPlans == null) { - final Function planTransformer = new Function() { + final Function planTransformer = new Function() { @Override - public DefaultPlan apply(final Plan input) { + public Plan apply(final Plan input) { return toDefaultPlan(input); } }; - tmpDefaultPlans = ImmutableList.copyOf(Iterables.transform(input, planTransformer)); + tmpDefaultPlans = ImmutableList.copyOf(Iterables.transform(input, planTransformer)); } - return toArray(tmpDefaultPlans); + return tmpDefaultPlans; } - private DefaultPlan[] toFilterDefaultPlans(final Iterable input) { + private Collection toFilterDefaultPlans(final Iterable input) { if (tmpDefaultPlans == null) { throw new IllegalStateException("Cannot filter on uninitialized plans"); } @@ -309,17 +311,17 @@ public String apply(final Plan input) { return input.getName(); } })); - final List filteredAndOrdered = new ArrayList(inputPlanNames.size()); + final List filteredAndOrdered = new ArrayList(inputPlanNames.size()); for (final String cur : inputPlanNames) { - final DefaultPlan found = findOrIllegalState(tmpDefaultPlans, new Predicate() { + final Plan found = findOrIllegalState(tmpDefaultPlans, new Predicate() { @Override - public boolean apply(final DefaultPlan inputPredicate) { + public boolean apply(final Plan inputPredicate) { return inputPredicate.getName().equals(cur); } }, "Failed to find plan " + cur); filteredAndOrdered.add(found); } - return toArray(filteredAndOrdered); + return filteredAndOrdered; } private DefaultPriceListSet toDefaultPriceListSet(final PriceList defaultPriceList, final Iterable childrenPriceLists) { @@ -395,14 +397,14 @@ private PriceListDefault toPriceListDefault(@Nullable final PriceList input) { return result; } - private DefaultProduct toDefaultProduct(@Nullable final Product input) { + private Product toDefaultProduct(@Nullable final Product input) { if (input == null) { return null; } if (tmpDefaultProducts != null) { - final DefaultProduct existingProduct = findOrIllegalState(tmpDefaultProducts, new Predicate() { + final Product existingProduct = findOrIllegalState(tmpDefaultProducts, new Predicate() { @Override - public boolean apply(final DefaultProduct predicateInput) { + public boolean apply(final Product predicateInput) { return predicateInput.getName().equals(input.getName()); } }, "Unknown product " + input.getName()); @@ -415,11 +417,11 @@ public boolean apply(final DefaultProduct predicateInput) { return result; } - private DefaultPlan toDefaultPlan(final Plan input) { + private Plan toDefaultPlan(final Plan input) { if (tmpDefaultPlans != null) { - final DefaultPlan existingPlan = findOrIllegalState(tmpDefaultPlans, new Predicate() { + final Plan existingPlan = findOrIllegalState(tmpDefaultPlans, new Predicate() { @Override - public boolean apply(final DefaultPlan predicateInput) { + public boolean apply(final Plan predicateInput) { return predicateInput.getName().equals(input.getName()); } }, "Unknown plan " + input.getName()); @@ -513,4 +515,4 @@ private T findOrIllegalState(final Iterable input, final Predicate pre } return result; } -} +} \ No newline at end of file diff --git a/catalog/src/main/java/org/killbill/billing/catalog/rules/DefaultCase.java b/catalog/src/main/java/org/killbill/billing/catalog/rules/DefaultCase.java index 49f5267be2..de0bef20cb 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/rules/DefaultCase.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/rules/DefaultCase.java @@ -92,7 +92,7 @@ public ValidationErrors validate(final StandaloneCatalog catalog, final Validati return errors; } - protected abstract DefaultCase setProduct(DefaultProduct product); + protected abstract DefaultCase setProduct(Product product); protected abstract DefaultCase setProductCategory(ProductCategory productCategory); diff --git a/catalog/src/main/java/org/killbill/billing/catalog/rules/DefaultCaseChange.java b/catalog/src/main/java/org/killbill/billing/catalog/rules/DefaultCaseChange.java index a0464067e1..ea441bd85a 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/rules/DefaultCaseChange.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/rules/DefaultCaseChange.java @@ -154,8 +154,8 @@ public DefaultCaseChange setPhaseType(final PhaseType phaseType) { return this; } - public DefaultCaseChange setFromProduct(final DefaultProduct fromProduct) { - this.fromProduct = fromProduct; + public DefaultCaseChange setFromProduct(final Product fromProduct) { + this.fromProduct = (DefaultProduct) fromProduct; return this; } @@ -174,8 +174,8 @@ public DefaultCaseChange setFromPriceList(final DefaultPriceList fromPriceLis return this; } - public DefaultCaseChange setToProduct(final DefaultProduct toProduct) { - this.toProduct = toProduct; + public DefaultCaseChange setToProduct(final Product toProduct) { + this.toProduct = (DefaultProduct) toProduct; return this; } diff --git a/catalog/src/main/java/org/killbill/billing/catalog/rules/DefaultCaseStandardNaming.java b/catalog/src/main/java/org/killbill/billing/catalog/rules/DefaultCaseStandardNaming.java index e922b0e12a..79c73aa76b 100644 --- a/catalog/src/main/java/org/killbill/billing/catalog/rules/DefaultCaseStandardNaming.java +++ b/catalog/src/main/java/org/killbill/billing/catalog/rules/DefaultCaseStandardNaming.java @@ -22,6 +22,7 @@ import org.killbill.billing.catalog.DefaultPriceList; import org.killbill.billing.catalog.DefaultProduct; import org.killbill.billing.catalog.api.BillingPeriod; +import org.killbill.billing.catalog.api.Product; import org.killbill.billing.catalog.api.ProductCategory; import org.killbill.billing.catalog.api.rules.Case; @@ -59,8 +60,8 @@ public DefaultPriceList getPriceList() { return priceList; } - public DefaultCaseStandardNaming setProduct(final DefaultProduct product) { - this.product = product; + public DefaultCaseStandardNaming setProduct(final Product product) { + this.product = (DefaultProduct) product; return this; } diff --git a/catalog/src/test/java/org/killbill/billing/catalog/MockCatalog.java b/catalog/src/test/java/org/killbill/billing/catalog/MockCatalog.java index ed7bf4e28f..5c788a03cd 100644 --- a/catalog/src/test/java/org/killbill/billing/catalog/MockCatalog.java +++ b/catalog/src/test/java/org/killbill/billing/catalog/MockCatalog.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.Iterator; import java.util.LinkedList; import org.joda.time.DateTime; @@ -46,6 +47,8 @@ import org.killbill.billing.catalog.rules.DefaultCaseCreateAlignment; import org.killbill.billing.catalog.rules.DefaultPlanRules; +import com.google.common.collect.ImmutableList; + public class MockCatalog extends StandaloneCatalog implements Catalog { private static final String[] PRODUCT_NAMES = new String[]{"TestProduct1", "TestProduct2", "TestProduct3"}; @@ -57,7 +60,7 @@ public class MockCatalog extends StandaloneCatalog implements Catalog { public MockCatalog() { setEffectiveDate(new Date()); setProducts(MockProduct.createAll()); - setPlans((DefaultPlan[]) MockPlan.createAll()); + setPlans(MockPlan.createAll()); populateRules(); populatePriceLists(); } @@ -76,14 +79,19 @@ public void setRules( } public void populatePriceLists() { - final DefaultPlan[] plans = getCurrentPlans(); - - final DefaultPriceList[] priceList = new DefaultPriceList[plans.length - 1]; - for (int i = 1; i < plans.length; i++) { - priceList[i - 1] = new DefaultPriceList(new DefaultPlan[]{plans[i]}, plans[i].getName() + "-pl"); + final Collection plans = getCurrentPlans(); + + final DefaultPriceList[] priceList = new DefaultPriceList[plans.size() - 1]; + int i = 1; + final Iterator it = plans.iterator(); + final Plan initialPlan = it.next(); + while (it.hasNext()) { + final Plan plan = it.next(); + priceList[i - 1] = new DefaultPriceList(new DefaultPlan[] { (DefaultPlan) plan}, plan.getName() + "-pl"); + i++; } - final DefaultPriceListSet set = new DefaultPriceListSet(new PriceListDefault(new DefaultPlan[]{plans[0]}), priceList); + final DefaultPriceListSet set = new DefaultPriceListSet(new PriceListDefault(new DefaultPlan[]{(DefaultPlan) initialPlan}), priceList); setPriceLists(set); } @@ -102,12 +110,12 @@ public Currency[] getSupportedCurrencies(final DateTime requestedDate) throws Ca } @Override - public Product[] getProducts(final DateTime requestedDate) throws CatalogApiException { + public Collection getProducts(final DateTime requestedDate) throws CatalogApiException { return getCurrentProducts(); } @Override - public Plan[] getPlans(final DateTime requestedDate) throws CatalogApiException { + public Collection getPlans(final DateTime requestedDate) throws CatalogApiException { return getCurrentPlans(); } @@ -237,24 +245,11 @@ public boolean canCreatePlan(final PlanSpecifier specifier) throws CatalogApiExc return canCreatePlan; } - @Override - public DefaultProduct[] getCurrentProducts() { - final Collection unordered = super.getAllProducts(); - final DefaultProduct[] result = new DefaultProduct[unordered.size()]; - convertCurrentEntries(unordered, result); - return result; - } - - @Override - public DefaultPlan[] getCurrentPlans() { - final Collection unordered = super.getAllPlans(); - final DefaultPlan[] result = new DefaultPlan[unordered.size()]; - convertCurrentEntries(unordered, result); - return result; + public DefaultProduct getCurrentProduct(int idx) { + return (DefaultProduct) getCurrentProducts().toArray()[idx]; } - private void convertCurrentEntries(final Collection unordered, final T [] result) { // Tests are not so well written and make assumption on how such entries are ordered final LinkedList list = new LinkedList(unordered); diff --git a/catalog/src/test/java/org/killbill/billing/catalog/MockPlan.java b/catalog/src/test/java/org/killbill/billing/catalog/MockPlan.java index 1781de85ab..54a95ba49c 100644 --- a/catalog/src/test/java/org/killbill/billing/catalog/MockPlan.java +++ b/catalog/src/test/java/org/killbill/billing/catalog/MockPlan.java @@ -16,6 +16,12 @@ package org.killbill.billing.catalog; +import java.util.Collection; + +import org.killbill.billing.catalog.api.Plan; + +import com.google.common.collect.ImmutableList; + public class MockPlan extends DefaultPlan { public static MockPlan createBicycleTrialEvergreen1USD(final int trialDurationInDays) { @@ -119,16 +125,14 @@ public MockPlan(final String planName) { setPlansAllowedInBundle(1); } - public static DefaultPlan[] createAll() { - return new DefaultPlan[]{ - createBicycleTrialEvergreen1USD(), - createBicycleNoTrialEvergreen1USD(), - createPickupTrialEvergreen10USD(), - createSportsCarTrialEvergreen100USD(), - createJetTrialEvergreen1000USD(), - createJetTrialFixedTermEvergreen1000USD(), - createHornMonthlyNoTrial1USD() - }; + public static Collection createAll() { + return ImmutableList.of(createBicycleTrialEvergreen1USD(), + createBicycleNoTrialEvergreen1USD(), + createPickupTrialEvergreen10USD(), + createSportsCarTrialEvergreen100USD(), + createJetTrialEvergreen1000USD(), + createJetTrialFixedTermEvergreen1000USD(), + createHornMonthlyNoTrial1USD()); } diff --git a/catalog/src/test/java/org/killbill/billing/catalog/MockProduct.java b/catalog/src/test/java/org/killbill/billing/catalog/MockProduct.java index 6014d4366c..569300407c 100644 --- a/catalog/src/test/java/org/killbill/billing/catalog/MockProduct.java +++ b/catalog/src/test/java/org/killbill/billing/catalog/MockProduct.java @@ -16,8 +16,13 @@ package org.killbill.billing.catalog; +import java.util.Collection; + +import org.killbill.billing.catalog.api.Product; import org.killbill.billing.catalog.api.ProductCategory; +import com.google.common.collect.ImmutableList; + public class MockProduct extends DefaultProduct { public MockProduct() { @@ -60,15 +65,14 @@ public static MockProduct createRedPaintJob() { return new MockProduct("6-RedPaintJob", ProductCategory.ADD_ON, "Vehcles"); } - public static DefaultProduct[] createAll() { - return new MockProduct[]{ + public static Collection createAll() { + return ImmutableList.of( createBicycle(), createPickup(), createSportsCar(), createJet(), createHorn(), - createRedPaintJob() - }; + createRedPaintJob()); } diff --git a/catalog/src/test/java/org/killbill/billing/catalog/TestCatalogUpdater.java b/catalog/src/test/java/org/killbill/billing/catalog/TestCatalogUpdater.java index 8b98de58c9..a973ad12d2 100644 --- a/catalog/src/test/java/org/killbill/billing/catalog/TestCatalogUpdater.java +++ b/catalog/src/test/java/org/killbill/billing/catalog/TestCatalogUpdater.java @@ -58,7 +58,7 @@ public void testEmptyDefaultCatalog() throws Exception { final CatalogUpdater catalogUpdater = new CatalogUpdater("dummy", BillingMode.IN_ADVANCE, now, null); final String catalogXML = catalogUpdater.getCatalogXML(); final StandaloneCatalog catalog = XMLLoader.getObjectFromStream(new URI("dummy"), new ByteArrayInputStream(catalogXML.getBytes(Charset.forName("UTF-8"))), StandaloneCatalog.class); - assertEquals(catalog.getCurrentPlans().length, 0); + assertEquals(catalog.getCurrentPlans().size(), 0); } @Test(groups = "fast") @@ -73,13 +73,13 @@ public void testAddNoTrialPlanOnFirstCatalog() throws CatalogApiException { final StandaloneCatalog catalog = catalogUpdater.getCatalog(); - assertEquals(catalog.getCurrentProducts().length, 1); + assertEquals(catalog.getCurrentProducts().size(), 1); - final Product product = catalog.getCurrentProducts()[0]; + final Product product = catalog.getCurrentProducts().iterator().next(); assertEquals(product.getName(), "Foo"); assertEquals(product.getCategory(), ProductCategory.BASE); - assertEquals(catalog.getCurrentPlans().length, 1); + assertEquals(catalog.getCurrentPlans().size(), 1); final Plan plan = catalog.findCurrentPlan("foo-monthly"); assertEquals(plan.getName(), "foo-monthly"); @@ -97,8 +97,8 @@ public void testAddNoTrialPlanOnFirstCatalog() throws CatalogApiException { assertEquals(catalog.getPriceLists().getAllPriceLists().size(), 1); final PriceList priceList = catalog.getPriceLists().getAllPriceLists().get(0); assertEquals(priceList.getName(), new PriceListDefault().getName()); - assertEquals(priceList.getPlans().length, 1); - assertEquals(priceList.getPlans()[0].getName(), "foo-monthly"); + assertEquals(priceList.getPlans().size(), 1); + assertEquals(priceList.getPlans().iterator().next().getName(), "foo-monthly"); } @@ -114,13 +114,13 @@ public void testAddTrialPlanOnFirstCatalog() throws CatalogApiException { final StandaloneCatalog catalog = catalogUpdater.getCatalog(); - assertEquals(catalog.getCurrentProducts().length, 1); + assertEquals(catalog.getCurrentProducts().size(), 1); - final Product product = catalog.getCurrentProducts()[0]; + final Product product = catalog.getCurrentProducts().iterator().next(); assertEquals(product.getName(), "Foo"); assertEquals(product.getCategory(), ProductCategory.BASE); - assertEquals(catalog.getCurrentPlans().length, 1); + assertEquals(catalog.getCurrentPlans().size(), 1); final Plan plan = catalog.findCurrentPlan("foo-monthly"); assertEquals(plan.getName(), "foo-monthly"); @@ -144,8 +144,8 @@ public void testAddTrialPlanOnFirstCatalog() throws CatalogApiException { assertEquals(catalog.getPriceLists().getAllPriceLists().size(), 1); final PriceList priceList = catalog.getPriceLists().getAllPriceLists().get(0); assertEquals(priceList.getName(), new PriceListDefault().getName()); - assertEquals(priceList.getPlans().length, 1); - assertEquals(priceList.getPlans()[0].getName(), "foo-monthly"); + assertEquals(priceList.getPlans().size(), 1); + assertEquals(priceList.getPlans().iterator().next().getName(), "foo-monthly"); } @@ -156,7 +156,7 @@ public void testAddPlanOnExistingCatalog() throws Exception { final StandaloneCatalog originalCatalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarBasic.xml").toExternalForm(), StandaloneCatalog.class); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName()); - assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().length, 3); + assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 3); final CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog); @@ -181,7 +181,7 @@ public void testAddPlanOnExistingCatalog() throws Exception { assertEquals(catalog.getPriceLists().getAllPriceLists().size(), 1); final PriceList priceList = catalog.getPriceLists().getAllPriceLists().get(0); assertEquals(priceList.getName(), new PriceListDefault().getName()); - assertEquals(priceList.getPlans().length, 4); + assertEquals(priceList.getPlans().size(), 4); } @@ -191,7 +191,7 @@ public void testAddExistingPlanWithNewCurrency() throws Exception { final StandaloneCatalog originalCatalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarBasic.xml").toExternalForm(), StandaloneCatalog.class); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName()); - assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().length, 3); + assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 3); final CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog); @@ -222,7 +222,7 @@ public void testInvalidPlanDescriptors() throws Exception { final StandaloneCatalog originalCatalog = enhanceOriginalCatalogForInvalidTestCases("SpyCarBasic.xml"); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName()); - assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().length, 5); + assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 5); CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog); @@ -263,7 +263,7 @@ public void testVerifyXML() throws Exception { final StandaloneCatalog originalCatalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarBasic.xml").toExternalForm(), StandaloneCatalog.class); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName()); - assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().length, 3); + assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 3); final CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog); diff --git a/catalog/src/test/java/org/killbill/billing/catalog/TestInternationalPrice.java b/catalog/src/test/java/org/killbill/billing/catalog/TestInternationalPrice.java index a3803e2ebc..12cc090b0b 100644 --- a/catalog/src/test/java/org/killbill/billing/catalog/TestInternationalPrice.java +++ b/catalog/src/test/java/org/killbill/billing/catalog/TestInternationalPrice.java @@ -63,9 +63,9 @@ public void testZeroValue() throws URISyntaxException, CatalogApiException { public void testPriceInitialization() throws URISyntaxException, CatalogApiException { final StandaloneCatalog c = new MockCatalog(); c.setSupportedCurrencies(new Currency[]{Currency.GBP, Currency.EUR, Currency.USD, Currency.BRL, Currency.MXN}); - ((DefaultInternationalPrice) c.getCurrentPlans()[0].getFinalPhase().getRecurring().getRecurringPrice()).setPrices(null); + ((DefaultInternationalPrice) c.getCurrentPlans().iterator().next().getFinalPhase().getRecurring().getRecurringPrice()).setPrices(null); c.initialize(c, new URI("foo://bar")); - Assert.assertEquals(c.getCurrentPlans()[0].getFinalPhase().getRecurring().getRecurringPrice().getPrice(Currency.GBP), new BigDecimal(0)); + Assert.assertEquals(c.getCurrentPlans().iterator().next().getFinalPhase().getRecurring().getRecurringPrice().getPrice(Currency.GBP), new BigDecimal(0)); } @Test(groups = "fast") diff --git a/catalog/src/test/java/org/killbill/billing/catalog/TestStandaloneCatalog.java b/catalog/src/test/java/org/killbill/billing/catalog/TestStandaloneCatalog.java index 93b491e2a3..78b45545a8 100644 --- a/catalog/src/test/java/org/killbill/billing/catalog/TestStandaloneCatalog.java +++ b/catalog/src/test/java/org/killbill/billing/catalog/TestStandaloneCatalog.java @@ -16,12 +16,15 @@ package org.killbill.billing.catalog; +import org.killbill.billing.catalog.api.Plan; import org.testng.Assert; import org.testng.annotations.Test; import org.killbill.billing.catalog.api.CatalogApiException; import org.killbill.billing.catalog.api.PhaseType; +import com.google.common.collect.ImmutableList; + public class TestStandaloneCatalog extends CatalogTestSuiteNoDB { @Test(groups = "fast") @@ -38,7 +41,7 @@ public void testFindPhase() throws CatalogApiException { phaseDiscount1.setPlan(plan1); phaseDiscount2.setPlan(plan2); - final StandaloneCatalog cat = new MockCatalog().setPlans(new DefaultPlan[]{plan1, plan2}); + final StandaloneCatalog cat = new MockCatalog().setPlans(ImmutableList.of(plan1, plan2)); Assert.assertEquals(cat.findCurrentPhase("TestPlan1-discount"), phaseDiscount1); Assert.assertEquals(cat.findCurrentPhase("TestPlan2-discount"), phaseDiscount2); diff --git a/catalog/src/test/java/org/killbill/billing/catalog/caching/TestEhCacheCatalogCache.java b/catalog/src/test/java/org/killbill/billing/catalog/caching/TestEhCacheCatalogCache.java index a5e675bc71..dca394689f 100644 --- a/catalog/src/test/java/org/killbill/billing/catalog/caching/TestEhCacheCatalogCache.java +++ b/catalog/src/test/java/org/killbill/billing/catalog/caching/TestEhCacheCatalogCache.java @@ -22,6 +22,7 @@ import java.io.InputStreamReader; import java.net.URI; import java.net.URISyntaxException; +import java.util.Collection; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -33,6 +34,7 @@ import org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride; import org.killbill.billing.catalog.VersionedCatalog; import org.killbill.billing.catalog.api.CatalogApiException; +import org.killbill.billing.catalog.api.Product; import org.killbill.xmlloader.UriAccessor; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -83,8 +85,8 @@ public void testDefaultCatalog() throws CatalogApiException { final VersionedCatalog result = catalogCache.getCatalog(true, true, internalCallContext); Assert.assertNotNull(result); - final DefaultProduct[] products = result.getProducts(clock.getUTCNow()); - Assert.assertEquals(products.length, 3); + final Collection products = result.getProducts(clock.getUTCNow()); + Assert.assertEquals(products.size(), 3); // Verify the lookup with other contexts final VersionedCatalog resultForMultiTenantContext = new VersionedCatalog(result.getClock()); @@ -155,14 +157,14 @@ public List answer(final InvocationOnMock invocation) throws Throwable { // Verify the lookup for this tenant final VersionedCatalog result = catalogCache.getCatalog(true, true, multiTenantContext); Assert.assertNotNull(result); - final DefaultProduct[] products = result.getProducts(clock.getUTCNow()); - Assert.assertEquals(products.length, 6); + final Collection products = result.getProducts(clock.getUTCNow()); + Assert.assertEquals(products.size(), 6); // Verify the lookup for another tenant final VersionedCatalog otherResult = catalogCache.getCatalog(true, true, otherMultiTenantContext); Assert.assertNotNull(otherResult); - final DefaultProduct[] otherProducts = otherResult.getProducts(clock.getUTCNow()); - Assert.assertEquals(otherProducts.length, 3); + final Collection otherProducts = otherResult.getProducts(clock.getUTCNow()); + Assert.assertEquals(otherProducts.size(), 3); shouldThrow.set(true); diff --git a/catalog/src/test/java/org/killbill/billing/catalog/io/TestXMLWriter.java b/catalog/src/test/java/org/killbill/billing/catalog/io/TestXMLWriter.java index 5d7966fb25..b431e9adc6 100644 --- a/catalog/src/test/java/org/killbill/billing/catalog/io/TestXMLWriter.java +++ b/catalog/src/test/java/org/killbill/billing/catalog/io/TestXMLWriter.java @@ -117,7 +117,7 @@ public void testAddPlan() throws Exception { final String newCatalogStr = XMLWriter.writeXML((StandaloneCatalog) mutableCatalog, StandaloneCatalog.class); final StandaloneCatalog newCatalog = XMLLoader.getObjectFromStream(new URI("dummy"), new ByteArrayInputStream(newCatalogStr.getBytes(Charset.forName("UTF-8"))), StandaloneCatalog.class); - assertEquals(newCatalog.getCurrentPlans().length, catalog.getCurrentPlans().length + 1); + assertEquals(newCatalog.getCurrentPlans().size(), catalog.getCurrentPlans().size() + 1); final Plan plan = newCatalog.findCurrentPlan("dynamic-monthly"); assertEquals(plan.getName(), "dynamic-monthly"); diff --git a/catalog/src/test/java/org/killbill/billing/catalog/rules/TestCase.java b/catalog/src/test/java/org/killbill/billing/catalog/rules/TestCase.java index 93774c400c..6f55bcb522 100644 --- a/catalog/src/test/java/org/killbill/billing/catalog/rules/TestCase.java +++ b/catalog/src/test/java/org/killbill/billing/catalog/rules/TestCase.java @@ -19,6 +19,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlIDREF; +import org.killbill.billing.catalog.api.Product; import org.testng.Assert; import org.testng.annotations.Test; @@ -84,8 +85,8 @@ public DefaultPriceList getPriceList() { return priceList; } - protected DefaultCaseResult setProduct(final DefaultProduct product) { - this.product = product; + protected DefaultCaseResult setProduct(final Product product) { + this.product = (DefaultProduct) product; return this; } @@ -109,7 +110,7 @@ protected DefaultCaseResult setPriceList(final DefaultPriceList priceList) { public void testBasic() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final DefaultCaseResult cr = new DefaultCaseResult( @@ -120,7 +121,7 @@ public void testBasic() throws CatalogApiException { Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); - assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); + assertionNull(cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), cat); assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", cat); } @@ -129,7 +130,7 @@ public void testBasic() throws CatalogApiException { public void testWildCardProduct() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final DefaultCaseResult cr = new DefaultCaseResult( @@ -141,7 +142,7 @@ public void testWildCardProduct() throws CatalogApiException { Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); - assertion(Result.FOO, cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); + assertion(Result.FOO, cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), cat); assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", cat); } @@ -150,7 +151,7 @@ public void testWildCardProduct() throws CatalogApiException { public void testWildCardProductCategory() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final DefaultCaseResult cr = new DefaultCaseResult( @@ -162,7 +163,7 @@ public void testWildCardProductCategory() throws CatalogApiException { Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); - assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); + assertionNull(cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); assertion(Result.FOO, cr, product.getName(), ProductCategory.ADD_ON, BillingPeriod.MONTHLY, priceList.getName(), cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), cat); assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", cat); @@ -172,7 +173,7 @@ public void testWildCardProductCategory() throws CatalogApiException { public void testWildCardBillingPeriod() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final DefaultCaseResult cr = new DefaultCaseResult( @@ -184,7 +185,7 @@ public void testWildCardBillingPeriod() throws CatalogApiException { Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); - assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); + assertionNull(cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), cat); assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", cat); } @@ -193,7 +194,7 @@ public void testWildCardBillingPeriod() throws CatalogApiException { public void testWildCardPriceList() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final DefaultCaseResult cr = new DefaultCaseResult( @@ -205,7 +206,7 @@ public void testWildCardPriceList() throws CatalogApiException { Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); - assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); + assertionNull(cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), cat); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", cat); } @@ -214,7 +215,7 @@ public void testWildCardPriceList() throws CatalogApiException { public void testCaseOrder() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final DefaultCaseResult cr0 = new DefaultCaseResult( diff --git a/catalog/src/test/java/org/killbill/billing/catalog/rules/TestCaseChange.java b/catalog/src/test/java/org/killbill/billing/catalog/rules/TestCaseChange.java index e207fffd2a..6528a3f7a8 100644 --- a/catalog/src/test/java/org/killbill/billing/catalog/rules/TestCaseChange.java +++ b/catalog/src/test/java/org/killbill/billing/catalog/rules/TestCaseChange.java @@ -71,10 +71,10 @@ protected Result getResult() { public void testBasic() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product1 = cat.getCurrentProducts()[0]; + final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); - final DefaultProduct product2 = cat.getCurrentProducts()[2]; + final DefaultProduct product2 = cat.getCurrentProduct(2); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1]; final DefaultCaseChangeResult cr = new DefaultCaseChangeResult( @@ -92,14 +92,14 @@ public void testBasic() throws CatalogApiException { PhaseType.EVERGREEN, cat); assertionNull(cr, - cat.getCurrentProducts()[1].getName(), product2.getName(), + cat.getCurrentProduct(1).getName(), product2.getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, - product1.getName(), cat.getCurrentProducts()[1].getName(), + product1.getName(), cat.getCurrentProduct(1).getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -122,13 +122,13 @@ public void testBasic() throws CatalogApiException { assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - cat.getCurrentProducts()[1].getName(), priceList2.getName(), + cat.getCurrentProduct(1).getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - priceList1.getName(), cat.getCurrentProducts()[1].getName(), + priceList1.getName(), cat.getCurrentProduct(1).getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, @@ -143,10 +143,10 @@ public void testBasic() throws CatalogApiException { public void testWildcardFromProduct() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product1 = cat.getCurrentProducts()[0]; + final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); - final DefaultProduct product2 = cat.getCurrentProducts()[2]; + final DefaultProduct product2 = cat.getCurrentProduct(2); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1]; final DefaultCaseChangeResult cr = new DefaultCaseChangeResult( @@ -164,14 +164,14 @@ public void testWildcardFromProduct() throws CatalogApiException { PhaseType.EVERGREEN, cat); assertion(Result.FOO, cr, - cat.getCurrentProducts()[1].getName(), product2.getName(), + cat.getCurrentProduct(1).getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, - product1.getName(), cat.getCurrentProducts()[1].getName(), + product1.getName(), cat.getCurrentProduct(1).getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.ANNUAL, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -187,13 +187,13 @@ public void testWildcardFromProduct() throws CatalogApiException { assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - cat.getCurrentProducts()[1].getName(), priceList2.getName(), + cat.getCurrentProduct(1).getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - priceList1.getName(), cat.getCurrentProducts()[1].getName(), + priceList1.getName(), cat.getCurrentProduct(1).getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, @@ -208,10 +208,10 @@ public void testWildcardFromProduct() throws CatalogApiException { public void testWildcardToProduct() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product1 = cat.getCurrentProducts()[0]; + final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); - final DefaultProduct product2 = cat.getCurrentProducts()[2]; + final DefaultProduct product2 = cat.getCurrentProduct(2); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1]; final DefaultCaseChangeResult cr = new DefaultCaseChangeResult( @@ -229,7 +229,7 @@ public void testWildcardToProduct() throws CatalogApiException { PhaseType.EVERGREEN, cat); assertionNull(cr, - cat.getCurrentProducts()[1].getName(), product2.getName(), + cat.getCurrentProduct(1).getName(), product2.getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -237,7 +237,7 @@ public void testWildcardToProduct() throws CatalogApiException { assertion(Result.FOO, cr, - product1.getName(), cat.getCurrentProducts()[1].getName(), + product1.getName(), cat.getCurrentProduct(1).getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); @@ -259,13 +259,13 @@ public void testWildcardToProduct() throws CatalogApiException { assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - cat.getCurrentProducts()[1].getName(), priceList2.getName(), + cat.getCurrentProduct(1).getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - priceList1.getName(), cat.getCurrentProducts()[1].getName(), + priceList1.getName(), cat.getCurrentProduct(1).getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, @@ -280,10 +280,10 @@ public void testWildcardToProduct() throws CatalogApiException { public void testWildcardFromProductCategory() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product1 = cat.getCurrentProducts()[0]; + final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); - final DefaultProduct product2 = cat.getCurrentProducts()[2]; + final DefaultProduct product2 = cat.getCurrentProduct(2); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1]; final DefaultCaseChangeResult cr = new DefaultCaseChangeResult( @@ -301,14 +301,14 @@ public void testWildcardFromProductCategory() throws CatalogApiException { PhaseType.EVERGREEN, cat); assertionNull(cr, - cat.getCurrentProducts()[1].getName(), product2.getName(), + cat.getCurrentProduct(1).getName(), product2.getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, - product1.getName(), cat.getCurrentProducts()[1].getName(), + product1.getName(), cat.getCurrentProduct(1).getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -337,13 +337,13 @@ public void testWildcardFromProductCategory() throws CatalogApiException { assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - cat.getCurrentProducts()[1].getName(), priceList2.getName(), + cat.getCurrentProduct(1).getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - priceList1.getName(), cat.getCurrentProducts()[1].getName(), + priceList1.getName(), cat.getCurrentProduct(1).getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, @@ -358,10 +358,10 @@ public void testWildcardFromProductCategory() throws CatalogApiException { public void testWildcardToProductCategory() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product1 = cat.getCurrentProducts()[0]; + final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); - final DefaultProduct product2 = cat.getCurrentProducts()[2]; + final DefaultProduct product2 = cat.getCurrentProduct(2); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1]; final DefaultCaseChangeResult cr = new DefaultCaseChangeResult( @@ -379,14 +379,14 @@ public void testWildcardToProductCategory() throws CatalogApiException { PhaseType.EVERGREEN, cat); assertionNull(cr, - cat.getCurrentProducts()[1].getName(), product2.getName(), + cat.getCurrentProduct(1).getName(), product2.getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, - product1.getName(), cat.getCurrentProducts()[1].getName(), + product1.getName(), cat.getCurrentProduct(1).getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -416,13 +416,13 @@ public void testWildcardToProductCategory() throws CatalogApiException { assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - cat.getCurrentProducts()[1].getName(), priceList2.getName(), + cat.getCurrentProduct(1).getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - priceList1.getName(), cat.getCurrentProducts()[1].getName(), + priceList1.getName(), cat.getCurrentProduct(1).getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, @@ -437,10 +437,10 @@ public void testWildcardToProductCategory() throws CatalogApiException { public void testWildcardFromBillingPeriod() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product1 = cat.getCurrentProducts()[0]; + final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); - final DefaultProduct product2 = cat.getCurrentProducts()[2]; + final DefaultProduct product2 = cat.getCurrentProduct(2); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1]; final DefaultCaseChangeResult cr = new DefaultCaseChangeResult( @@ -458,14 +458,14 @@ public void testWildcardFromBillingPeriod() throws CatalogApiException { PhaseType.EVERGREEN, cat); assertionNull(cr, - cat.getCurrentProducts()[1].getName(), product2.getName(), + cat.getCurrentProduct(1).getName(), product2.getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, - product1.getName(), cat.getCurrentProducts()[1].getName(), + product1.getName(), cat.getCurrentProduct(1).getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -487,13 +487,13 @@ public void testWildcardFromBillingPeriod() throws CatalogApiException { assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - cat.getCurrentProducts()[1].getName(), priceList2.getName(), + cat.getCurrentProduct(1).getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - priceList1.getName(), cat.getCurrentProducts()[1].getName(), + priceList1.getName(), cat.getCurrentProduct(1).getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, @@ -508,10 +508,10 @@ public void testWildcardFromBillingPeriod() throws CatalogApiException { public void testWildCardToBillingPeriod() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product1 = cat.getCurrentProducts()[0]; + final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); - final DefaultProduct product2 = cat.getCurrentProducts()[2]; + final DefaultProduct product2 = cat.getCurrentProduct(2); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1]; final DefaultCaseChangeResult cr = new DefaultCaseChangeResult( @@ -529,7 +529,7 @@ public void testWildCardToBillingPeriod() throws CatalogApiException { PhaseType.EVERGREEN, cat); assertionNull(cr, - cat.getCurrentProducts()[1].getName(), product2.getName(), + cat.getCurrentProduct(1).getName(), product2.getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -537,7 +537,7 @@ public void testWildCardToBillingPeriod() throws CatalogApiException { assertionNull(cr, - product1.getName(), cat.getCurrentProducts()[1].getName(), + product1.getName(), cat.getCurrentProduct(1).getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -559,13 +559,13 @@ public void testWildCardToBillingPeriod() throws CatalogApiException { assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - cat.getCurrentProducts()[1].getName(), priceList2.getName(), + cat.getCurrentProduct(1).getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - priceList1.getName(), cat.getCurrentProducts()[1].getName(), + priceList1.getName(), cat.getCurrentProduct(1).getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, @@ -580,10 +580,10 @@ public void testWildCardToBillingPeriod() throws CatalogApiException { public void testWildCardFromPriceList() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product1 = cat.getCurrentProducts()[0]; + final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); - final DefaultProduct product2 = cat.getCurrentProducts()[2]; + final DefaultProduct product2 = cat.getCurrentProduct(2); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1]; final DefaultCaseChangeResult cr = new DefaultCaseChangeResult( @@ -601,7 +601,7 @@ public void testWildCardFromPriceList() throws CatalogApiException { PhaseType.EVERGREEN, cat); assertionNull(cr, - cat.getCurrentProducts()[1].getName(), product2.getName(), + cat.getCurrentProduct(1).getName(), product2.getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -609,7 +609,7 @@ public void testWildCardFromPriceList() throws CatalogApiException { assertionNull(cr, - product1.getName(), cat.getCurrentProducts()[1].getName(), + product1.getName(), cat.getCurrentProduct(1).getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -638,7 +638,7 @@ public void testWildCardFromPriceList() throws CatalogApiException { assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - priceList1.getName(), cat.getCurrentProducts()[1].getName(), + priceList1.getName(), cat.getCurrentProduct(1).getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, @@ -653,10 +653,10 @@ public void testWildCardFromPriceList() throws CatalogApiException { public void testWildcardToPriceList() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product1 = cat.getCurrentProducts()[0]; + final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); - final DefaultProduct product2 = cat.getCurrentProducts()[2]; + final DefaultProduct product2 = cat.getCurrentProduct(2); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1]; final DefaultCaseChangeResult cr = new DefaultCaseChangeResult( @@ -674,7 +674,7 @@ public void testWildcardToPriceList() throws CatalogApiException { PhaseType.EVERGREEN, cat); assertionNull(cr, - cat.getCurrentProducts()[1].getName(), product2.getName(), + cat.getCurrentProduct(1).getName(), product2.getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -682,7 +682,7 @@ public void testWildcardToPriceList() throws CatalogApiException { assertionNull(cr, - product1.getName(), cat.getCurrentProducts()[1].getName(), + product1.getName(), cat.getCurrentProduct(1).getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -705,7 +705,7 @@ public void testWildcardToPriceList() throws CatalogApiException { assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - cat.getCurrentProducts()[1].getName(), priceList2.getName(), + cat.getCurrentProduct(1).getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertion(Result.FOO, cr, @@ -726,10 +726,10 @@ public void testWildcardToPriceList() throws CatalogApiException { public void testWildcardPlanPhase() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product1 = cat.getCurrentProducts()[0]; + final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); - final DefaultProduct product2 = cat.getCurrentProducts()[2]; + final DefaultProduct product2 = cat.getCurrentProduct(2); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1]; final DefaultCaseChangeResult cr = new DefaultCaseChangeResult( @@ -747,7 +747,7 @@ public void testWildcardPlanPhase() throws CatalogApiException { PhaseType.EVERGREEN, cat); assertionNull(cr, - cat.getCurrentProducts()[1].getName(), product2.getName(), + cat.getCurrentProduct(1).getName(), product2.getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -755,7 +755,7 @@ public void testWildcardPlanPhase() throws CatalogApiException { assertionNull(cr, - product1.getName(), cat.getCurrentProducts()[1].getName(), + product1.getName(), cat.getCurrentProduct(1).getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), priceList2.getName(), @@ -778,13 +778,13 @@ public void testWildcardPlanPhase() throws CatalogApiException { assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - cat.getCurrentProducts()[1].getName(), priceList2.getName(), + cat.getCurrentProduct(1).getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product1.getName(), product2.getName(), BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, - priceList1.getName(), cat.getCurrentProducts()[1].getName(), + priceList1.getName(), cat.getCurrentProduct(1).getName(), PhaseType.EVERGREEN, cat); assertion(Result.FOO, cr, @@ -798,10 +798,10 @@ public void testWildcardPlanPhase() throws CatalogApiException { public void testOrder() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product1 = cat.getCurrentProducts()[0]; + final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); - final DefaultProduct product2 = cat.getCurrentProducts()[2]; + final DefaultProduct product2 = cat.getCurrentProduct(2); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1]; final DefaultCaseChangeResult cr0 = new DefaultCaseChangeResult( diff --git a/catalog/src/test/java/org/killbill/billing/catalog/rules/TestCasePhase.java b/catalog/src/test/java/org/killbill/billing/catalog/rules/TestCasePhase.java index 22ecc52829..2db00d3c49 100644 --- a/catalog/src/test/java/org/killbill/billing/catalog/rules/TestCasePhase.java +++ b/catalog/src/test/java/org/killbill/billing/catalog/rules/TestCasePhase.java @@ -61,7 +61,7 @@ protected Result getResult() { public void testBasic() { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist(); final DefaultCaseResult cr = new DefaultCaseResult( @@ -73,7 +73,7 @@ public void testBasic() { Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); - assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); + assertionNull(cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat); @@ -83,7 +83,7 @@ public void testBasic() { public void testWildCardProduct() { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist(); final DefaultCaseResult cr = new DefaultCaseResult( @@ -95,7 +95,7 @@ public void testWildCardProduct() { Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); - assertion(Result.FOO, cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); + assertion(Result.FOO, cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat); @@ -105,7 +105,7 @@ public void testWildCardProduct() { public void testWildCardProductCategory() { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist(); final DefaultCaseResult cr = new DefaultCaseResult( @@ -117,7 +117,7 @@ public void testWildCardProductCategory() { Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); - assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); + assertionNull(cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertion(Result.FOO, cr, product.getName(), ProductCategory.ADD_ON, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", PhaseType.EVERGREEN, cat); @@ -128,7 +128,7 @@ public void testWildCardProductCategory() { public void testWildCardBillingPeriod() { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist(); final DefaultCaseResult cr = new DefaultCaseResult( @@ -140,7 +140,7 @@ public void testWildCardBillingPeriod() { Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); - assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); + assertionNull(cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat); @@ -150,7 +150,7 @@ public void testWildCardBillingPeriod() { public void testWildCardPriceList() { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist(); final DefaultCaseResult cr = new DefaultCaseResult( @@ -162,7 +162,7 @@ public void testWildCardPriceList() { Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); - assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); + assertionNull(cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN, cat); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat); @@ -172,7 +172,7 @@ public void testWildCardPriceList() { public void testWildCardPhaseType() { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist(); final DefaultCaseResult cr = new DefaultCaseResult( @@ -184,7 +184,7 @@ public void testWildCardPhaseType() { Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); - assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); + assertionNull(cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", PhaseType.EVERGREEN, cat); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat); @@ -194,7 +194,7 @@ public void testWildCardPhaseType() { public void testOrder() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); - final DefaultProduct product = cat.getCurrentProducts()[0]; + final DefaultProduct product = cat.getCurrentProduct(0); final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist(); final DefaultCaseResult cr0 = new DefaultCaseResult( diff --git a/catalog/src/test/java/org/killbill/billing/catalog/rules/TestPlanRules.java b/catalog/src/test/java/org/killbill/billing/catalog/rules/TestPlanRules.java index 66fa6bf16e..950ea45027 100644 --- a/catalog/src/test/java/org/killbill/billing/catalog/rules/TestPlanRules.java +++ b/catalog/src/test/java/org/killbill/billing/catalog/rules/TestPlanRules.java @@ -57,7 +57,7 @@ public void beforeMethod() { @Test(groups = "fast") public void testExistingPriceListIsKept() throws CatalogApiException { - final DefaultProduct product1 = cat.getCurrentProducts()[0]; + final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final PlanPhaseSpecifier from = new PlanPhaseSpecifier(product1.getName(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN); @@ -79,8 +79,8 @@ public void testExistingPriceListIsKept() throws CatalogApiException { @Test(groups = "fast") public void testBaseCase() throws CatalogApiException { - final DefaultProduct product1 = cat.getCurrentProducts()[0]; - final DefaultProduct product2 = cat.getCurrentProducts()[1]; + final DefaultProduct product1 = cat.getCurrentProduct(0); + final DefaultProduct product2 = cat.getCurrentProduct(1); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[0]; diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/CatalogJson.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/CatalogJson.java index 79a2b8b9dc..1f44b5d8fe 100644 --- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/CatalogJson.java +++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/CatalogJson.java @@ -20,6 +20,7 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.LinkedList; @@ -80,7 +81,7 @@ public CatalogJson(final Catalog catalog, final DateTime requestedDate) throws C currencies = Arrays.asList(catalog.getSupportedCurrencies(requestedDate)); priceLists = new ArrayList(); - final Plan[] plans = catalog.getPlans(requestedDate); + final Collection plans = catalog.getPlans(requestedDate); final Map productMap = new HashMap(); for (final Plan plan : plans) { // Build the product associated with this plan @@ -190,7 +191,7 @@ private List buildPrices(final InternationalPrice internationalPrice) return pricesJson; } - private List toProductNames(final Product[] in) { + private List toProductNames(final Collection in) { return Lists.transform(ImmutableList.copyOf(in), new Function() { @Override diff --git a/subscription/src/main/java/org/killbill/billing/subscription/engine/addon/AddonUtils.java b/subscription/src/main/java/org/killbill/billing/subscription/engine/addon/AddonUtils.java index 7098709196..8fd9da70f2 100644 --- a/subscription/src/main/java/org/killbill/billing/subscription/engine/addon/AddonUtils.java +++ b/subscription/src/main/java/org/killbill/billing/subscription/engine/addon/AddonUtils.java @@ -16,6 +16,7 @@ package org.killbill.billing.subscription.engine.addon; +import java.util.Collection; import java.util.List; import org.joda.time.DateTime; @@ -105,7 +106,7 @@ public boolean isAddonIncludedFromPlanName(final String basePlanName, final Plan private boolean isAddonAvailable(final Product baseProduct, final Plan targetAddOnPlan) { final Product targetAddonProduct = targetAddOnPlan.getProduct(); - final Product[] availableAddOns = baseProduct.getAvailable(); + final Collection availableAddOns = baseProduct.getAvailable(); for (final Product curAv : availableAddOns) { if (curAv.getName().equals(targetAddonProduct.getName())) { @@ -117,7 +118,7 @@ private boolean isAddonAvailable(final Product baseProduct, final Plan targetAdd private boolean isAddonIncluded(final Product baseProduct, final Plan targetAddOnPlan) { final Product targetAddonProduct = targetAddOnPlan.getProduct(); - final Product[] includedAddOns = baseProduct.getIncluded(); + final Collection includedAddOns = baseProduct.getIncluded(); for (final Product curAv : includedAddOns) { if (curAv.getName().equals(targetAddonProduct.getName())) { return true; diff --git a/util/src/test/java/org/killbill/billing/mock/MockPriceList.java b/util/src/test/java/org/killbill/billing/mock/MockPriceList.java index 0d22447ba3..9722cb28af 100644 --- a/util/src/test/java/org/killbill/billing/mock/MockPriceList.java +++ b/util/src/test/java/org/killbill/billing/mock/MockPriceList.java @@ -16,6 +16,7 @@ package org.killbill.billing.mock; +import java.util.Collection; import java.util.UUID; import org.killbill.billing.catalog.api.BillingPeriod; @@ -23,6 +24,8 @@ import org.killbill.billing.catalog.api.PriceList; import org.killbill.billing.catalog.api.Product; +import com.google.common.collect.ImmutableList; + public class MockPriceList implements PriceList { private final String name; private final Plan plan; @@ -42,10 +45,8 @@ public String getName() { } @Override - public Plan[] findPlans(final Product product, final BillingPeriod period) { - final Plan[] result = new Plan[1]; - result[0] = plan; - return result; + public Collection findPlans(final Product product, final BillingPeriod period) { + return ImmutableList.of(plan); } public Plan getPlan() { @@ -53,7 +54,8 @@ public Plan getPlan() { } @Override - public Plan[] getPlans() { - return new Plan[] { plan }; + public Collection getPlans() { + return ImmutableList.of(plan); } + } diff --git a/util/src/test/java/org/killbill/billing/mock/MockProduct.java b/util/src/test/java/org/killbill/billing/mock/MockProduct.java index 046c18a678..3e3ad3e262 100644 --- a/util/src/test/java/org/killbill/billing/mock/MockProduct.java +++ b/util/src/test/java/org/killbill/billing/mock/MockProduct.java @@ -16,17 +16,21 @@ package org.killbill.billing.mock; +import java.util.Collection; + import org.killbill.billing.catalog.api.Limit; import org.killbill.billing.catalog.api.Product; import org.killbill.billing.catalog.api.ProductCategory; +import com.google.common.collect.ImmutableList; + public class MockProduct implements Product { private final String name; private final ProductCategory category; private final String catalogName; - private final Product[] included; - private final Product[] available; + private final Collection included; + private final Collection available; public MockProduct() { this("TestProduct", ProductCategory.BASE, "Vehicules"); @@ -40,8 +44,8 @@ public MockProduct(final String name, final ProductCategory category, final Stri this.name = name; this.category = category; this.catalogName = catalogName; - this.included = included; - this.available = available; + this.included = ImmutableList.copyOf(included); + this.available = ImmutableList.copyOf(available); } @Override @@ -60,12 +64,12 @@ public String getName() { } @Override - public Product[] getAvailable() { + public Collection getAvailable() { return available; } @Override - public Product[] getIncluded() { + public Collection getIncluded() { return included; }