killbill-uncached

Details

diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/Case.java b/catalog/src/main/java/com/ning/billing/catalog/rules/Case.java
index 737373e..00bc275 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/Case.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/Case.java
@@ -16,6 +16,7 @@
 
 package com.ning.billing.catalog.rules;
 
+
 import com.ning.billing.catalog.DefaultPriceList;
 import com.ning.billing.catalog.DefaultProduct;
 import com.ning.billing.catalog.StandaloneCatalog;
@@ -28,12 +29,15 @@ import com.ning.billing.util.config.ValidationErrors;
 
 public abstract class Case<T> extends ValidatingConfig<StandaloneCatalog> {
 
-	protected DefaultProduct product;
-	protected ProductCategory productCategory;
-	protected BillingPeriod billingPeriod;
-	protected DefaultPriceList priceList;
-
 	protected abstract T getResult();
+	
+	public abstract DefaultProduct getProduct();
+
+	public abstract ProductCategory getProductCategory();
+
+	public abstract BillingPeriod getBillingPeriod();
+	    
+	public abstract DefaultPriceList getPriceList();
 
 	public T getResult(PlanSpecifier planPhase, StandaloneCatalog c) throws CatalogApiException {
 		if (satisfiesCase(planPhase, c)	) {
@@ -43,10 +47,10 @@ public abstract class Case<T> extends ValidatingConfig<StandaloneCatalog> {
 	}
 	
 	protected boolean satisfiesCase(PlanSpecifier planPhase, StandaloneCatalog c) throws CatalogApiException {
-		return (product         == null || product.equals(c.findProduct(planPhase.getProductName()))) &&
-		(productCategory == null || productCategory.equals(planPhase.getProductCategory())) &&
-		(billingPeriod   == null || billingPeriod.equals(planPhase.getBillingPeriod())) &&
-		(priceList       == null || priceList.equals(c.getPriceListFromName(planPhase.getPriceListName())));
+		return (getProduct()         == null || getProduct().equals(c.findProduct(planPhase.getProductName()))) &&
+		(getProductCategory() == null || getProductCategory().equals(planPhase.getProductCategory())) &&
+		(getBillingPeriod()   == null || getBillingPeriod().equals(planPhase.getBillingPeriod())) &&
+		(getPriceList()       == null || getPriceList().equals(c.getPriceListFromName(planPhase.getPriceListName())));
 	}
 
 	public static <K> K getResult(Case<K>[] cases, PlanSpecifier planSpec, StandaloneCatalog catalog) throws CatalogApiException {
@@ -67,26 +71,11 @@ public abstract class Case<T> extends ValidatingConfig<StandaloneCatalog> {
 		return errors;
 	}
 
-	protected Case<T> setProduct(DefaultProduct product) {
-		this.product = product;
-		return this;
-	}
-
-	protected Case<T> setProductCategory(ProductCategory productCategory) {
-		this.productCategory = productCategory;
-		return this;
-	}
+	protected abstract Case<T> setProduct(DefaultProduct product);
 
-	protected Case<T> setBillingPeriod(BillingPeriod billingPeriod) {
-		this.billingPeriod = billingPeriod;
-		return this;
-	}
+	protected abstract  Case<T> setProductCategory(ProductCategory productCategory);
 
-	protected Case<T> setPriceList(DefaultPriceList priceList) {
-		this.priceList = priceList;
-		return this;
-	}
+	protected abstract  Case<T> setBillingPeriod(BillingPeriod billingPeriod);
 
-	
-	
+	protected abstract  Case<T> setPriceList(DefaultPriceList priceList);
 }
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/CasePriceList.java b/catalog/src/main/java/com/ning/billing/catalog/rules/CasePriceList.java
index fbb9cab..5063131 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/CasePriceList.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/CasePriceList.java
@@ -25,37 +25,66 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlIDREF;
 
 public class CasePriceList extends Case<DefaultPriceList> {
+    @XmlElement(required=false, name="fromProduct")
+    @XmlIDREF
+    private DefaultProduct fromProduct;
+    
+    @XmlElement(required=false, name="fromProductCategory")
+    private ProductCategory fromProductCategory;
+    
+    @XmlElement(required=false, name="fromBillingPeriod")
+    private BillingPeriod fromBillingPeriod;
+    
+    @XmlElement(required=false, name="fromPriceList")
+    @XmlIDREF
+    private DefaultPriceList fromPriceList;
 
-	private DefaultPriceList toPriceList;
+    @XmlElement(required=true, name="toPriceList")
+    @XmlIDREF
+    private DefaultPriceList toPriceList;
 
-	@XmlElement(required=false, name="fromProduct")
-	@XmlIDREF
-	public DefaultProduct getProduct(){
-		return product;
-	}
+    public DefaultProduct getProduct(){
+        return fromProduct;
+    }
 
-	@XmlElement(required=false, name="fromProductCategory")
-	public ProductCategory getProductCategory() {
-		return productCategory;
-	}
+    public ProductCategory getProductCategory() {
+        return fromProductCategory;
+    }
 
-	@XmlElement(required=false, name="fromBillingPeriod")
-	public BillingPeriod getBillingPeriod() {
-		return billingPeriod;
-	}
-	
-	@XmlElement(required=false, name="fromPriceList")
-	@XmlIDREF
-	public DefaultPriceList getPriceList() {
-		return priceList;
-	}
+    public BillingPeriod getBillingPeriod() {
+        return fromBillingPeriod;
+    }
+    
+    public DefaultPriceList getPriceList() {
+        return fromPriceList;
+    }
+
+    protected DefaultPriceList getResult() {
+        return toPriceList;
+    }
+
+    protected CasePriceList setProduct(DefaultProduct product) {
+        this.fromProduct = product;
+        return this;
+    }
+
+    protected CasePriceList setProductCategory(ProductCategory productCategory) {
+        this.fromProductCategory = productCategory;
+        return this;
+    }
+
+    protected CasePriceList setBillingPeriod(BillingPeriod billingPeriod) {
+        this.fromBillingPeriod = billingPeriod;
+        return this;
+    }
+
+    protected CasePriceList setPriceList(DefaultPriceList priceList) {
+        this.fromPriceList = priceList;
+        return this;
+    }
+    
+    
 
-	@Override
-	@XmlElement(required=true, name="toPriceList")
-	@XmlIDREF
-	protected DefaultPriceList getResult() {
-		return toPriceList;
-	}
 
 	protected CasePriceList setToPriceList(DefaultPriceList toPriceList) {
 		this.toPriceList = toPriceList;
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseStandardNaming.java b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseStandardNaming.java
index cf61fcd..8e161ce 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseStandardNaming.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseStandardNaming.java
@@ -25,27 +25,53 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlIDREF;
 
 public abstract class CaseStandardNaming<T> extends Case<T> {
+    @XmlElement(required=false, name="product")
+    @XmlIDREF
+    private DefaultProduct product;
+    @XmlElement(required=false, name="productCategory")
+    private ProductCategory productCategory;
+    
+    @XmlElement(required=false, name="billingPeriod")
+    private BillingPeriod billingPeriod;
+    
+    @XmlElement(required=false, name="priceList")
+    @XmlIDREF
+    private DefaultPriceList priceList;
 
-	@XmlElement(required=false, name="product")
-	@XmlIDREF
 	public DefaultProduct getProduct(){
 		return product;
 	}
 
-	@XmlElement(required=false, name="productCategory")
 	public ProductCategory getProductCategory() {
 		return productCategory;
 	}
 
-	@XmlElement(required=false, name="billingPeriod")
 	public BillingPeriod getBillingPeriod() {
 		return billingPeriod;
 	}
 	
-	@XmlElement(required=false, name="priceList")
-	@XmlIDREF
 	public DefaultPriceList getPriceList() {
 		return priceList;
 	}
 
+    protected CaseStandardNaming<T> setProduct(DefaultProduct product) {
+        this.product = product;
+        return this;
+    }
+
+    protected CaseStandardNaming<T> setProductCategory(ProductCategory productCategory) {
+        this.productCategory = productCategory;
+        return this;
+    }
+
+    protected CaseStandardNaming<T> setBillingPeriod(BillingPeriod billingPeriod) {
+        this.billingPeriod = billingPeriod;
+        return this;
+    }
+
+    protected CaseStandardNaming<T> setPriceList(DefaultPriceList priceList) {
+        this.priceList = priceList;
+        return this;
+    }
+
 }
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCase.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCase.java
index c00f1c4..0c2f3b0 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCase.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCase.java
@@ -24,201 +24,251 @@ import com.ning.billing.catalog.api.*;
 import org.testng.annotations.Test;
 
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlIDREF;
 
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertNull;
 
 public class TestCase {
 
-	protected class CaseResult extends Case<Result>  {
-
-		@XmlElement(required=true)
-		private Result policy;
-
-		public CaseResult(DefaultProduct product, ProductCategory productCategory, BillingPeriod billingPeriod, DefaultPriceList priceList,
-				 Result policy) {
-			setProduct(product);
-			setProductCategory(productCategory);
-			setBillingPeriod(billingPeriod);
-			setPriceList(priceList);
-			this.policy = policy;
-		}
-
-		@Override
-		protected Result getResult() {
-			return policy;
-		}
-	}
-
-	@Test(enabled=true)
-	public void testBasic() throws CatalogApiException{
-		MockCatalog cat = new MockCatalog();
-
-		DefaultProduct product = cat.getProducts()[0];
-		DefaultPriceList priceList = cat.getPriceListFromName(PriceListSet.DEFAULT_PRICELIST_NAME);
-
-
-		CaseResult cr = new CaseResult(
-				product, 
-				ProductCategory.BASE,
-				BillingPeriod.MONTHLY, 
-				priceList,
-				Result.FOO);
-
-		assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat);
-		assertionNull(cr, cat.getProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat);
-		assertionNull(cr, product.getName(), ProductCategory.ADD_ON,BillingPeriod.MONTHLY, priceList.getName(), cat);
-		assertionNull(cr, product.getName(), ProductCategory.BASE,BillingPeriod.ANNUAL, priceList.getName(), cat);
-		assertionNull(cr, product.getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, "dipsy", cat);
-	}
-
-	@Test(enabled=true)
-	public void testWildCardProduct() throws CatalogApiException{
-		MockCatalog cat = new MockCatalog();
-
-		DefaultProduct product = cat.getProducts()[0];
-		DefaultPriceList priceList = cat.getPriceListFromName(PriceListSet.DEFAULT_PRICELIST_NAME);
-
-
-		CaseResult cr = new CaseResult(
-				null, 
-				ProductCategory.BASE,
-				BillingPeriod.MONTHLY, 
-				priceList,
-
-				Result.FOO);
-
-		assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, priceList.getName(), cat);
-		assertion(Result.FOO, cr, cat.getProducts()[1].getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, priceList.getName(), cat);
-		assertionNull(cr, product.getName(), ProductCategory.ADD_ON,BillingPeriod.MONTHLY, priceList.getName(), cat);
-		assertionNull(cr, product.getName(), ProductCategory.BASE,BillingPeriod.ANNUAL, priceList.getName(), cat);
-		assertionNull(cr, product.getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, "dipsy", cat);
-	}
-	
-	@Test(enabled=true)
-	public void testWildCardProductCategory() throws CatalogApiException{
-		MockCatalog cat = new MockCatalog();
-
-		DefaultProduct product = cat.getProducts()[0];
-		DefaultPriceList priceList = cat.getPriceListFromName(PriceListSet.DEFAULT_PRICELIST_NAME);
-
-
-		CaseResult cr = new CaseResult(
-				product, 
-				null,
-				BillingPeriod.MONTHLY, 
-				priceList,
-
-				Result.FOO);
-
-		assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat);
-		assertionNull(cr,  cat.getProducts()[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);
-		assertionNull(cr, product.getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, "dipsy", cat);
-	}
-	
-	@Test(enabled=true)
-	public void testWildCardBillingPeriod() throws CatalogApiException{
-		MockCatalog cat = new MockCatalog();
-
-		DefaultProduct product = cat.getProducts()[0];
-		DefaultPriceList priceList = cat.getPriceListFromName(PriceListSet.DEFAULT_PRICELIST_NAME);
-
-
-		CaseResult cr = new CaseResult(
-				product, 
-				ProductCategory.BASE,
-				null, 
-				priceList,
-
-				Result.FOO);
-
-		assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat);
-		assertionNull(cr,  cat.getProducts()[1].getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, priceList.getName(), cat);
-		assertionNull(cr, product.getName(), ProductCategory.ADD_ON,BillingPeriod.MONTHLY, priceList.getName(), cat);
-		assertion(Result.FOO,cr, product.getName(), ProductCategory.BASE,BillingPeriod.ANNUAL, priceList.getName(), cat);
-		assertionNull(cr, product.getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, "dipsy", cat);
-	}
-
-	@Test(enabled=true)
-	public void testWildCardPriceList() throws CatalogApiException{
-		MockCatalog cat = new MockCatalog();
-
-		DefaultProduct product = cat.getProducts()[0];
-		DefaultPriceList priceList = cat.getPriceListFromName(PriceListSet.DEFAULT_PRICELIST_NAME);
-
-
-		CaseResult cr = new CaseResult(
-				product, 
-				ProductCategory.BASE,
-				BillingPeriod.MONTHLY, 
-				null,
-
-				Result.FOO);
-
-		assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, priceList.getName(), cat);
-		assertionNull(cr,  cat.getProducts()[1].getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, priceList.getName(), cat);
-		assertionNull(cr, product.getName(), ProductCategory.ADD_ON,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);
-	}
-	
-	@Test
-	public void testCaseOrder() throws CatalogApiException {
-		MockCatalog cat = new MockCatalog();
-
-		DefaultProduct product = cat.getProducts()[0];
-		DefaultPriceList priceList = cat.getPriceListFromName(PriceListSet.DEFAULT_PRICELIST_NAME);
-
-
-		CaseResult cr0 = new CaseResult(
-				product, 
-				ProductCategory.BASE,
-				BillingPeriod.MONTHLY, 
-				priceList,
-				Result.FOO);
-
-		CaseResult cr1 = new CaseResult(
-				product, 
-				ProductCategory.BASE,
-				BillingPeriod.MONTHLY, 
-				priceList,
-				Result.BAR);
-
-		CaseResult cr2 = new CaseResult(
-				product, 
-				ProductCategory.BASE,
-				BillingPeriod.ANNUAL, 
-				priceList,
-				Result.DIPSY);
-
-		CaseResult cr3 = new CaseResult(
-				product, 
-				ProductCategory.BASE,
-				BillingPeriod.ANNUAL, 
-				priceList,
-				Result.LALA);
-
-		Result r1 = Case.getResult(new CaseResult[]{cr0, cr1, cr2,cr3}, 
-				new PlanSpecifier(product.getName(), product.getCategory(), BillingPeriod.MONTHLY, priceList.getName()), cat);
-		assertEquals(Result.FOO, r1);
-		
-		Result r2 = Case.getResult(new CaseResult[]{cr0, cr1, cr2}, 
-				new PlanSpecifier(product.getName(), product.getCategory(), BillingPeriod.ANNUAL, priceList.getName()), cat);
-		assertEquals(Result.DIPSY, r2);
-	}
-
-	
-
-
-	protected void assertionNull(CaseResult cr, String productName, ProductCategory productCategory, BillingPeriod bp, String priceListName, StandaloneCatalog cat) throws CatalogApiException{
-		assertNull(cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat));
-	}
-
-	protected void assertion(Result result, CaseResult cr, String productName, ProductCategory productCategory, BillingPeriod bp, String priceListName,StandaloneCatalog cat) throws CatalogApiException{
-		assertEquals(result, cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat));
-	}
+    protected class CaseResult extends Case<Result>  {
+
+        @XmlElement(required=true)
+        private Result policy;
+
+        public CaseResult(DefaultProduct product, ProductCategory productCategory, BillingPeriod billingPeriod, DefaultPriceList priceList,
+                Result policy) {
+            setProduct(product);
+            setProductCategory(productCategory);
+            setBillingPeriod(billingPeriod);
+            setPriceList(priceList);
+            this.policy = policy;
+        }
+
+        @Override
+        protected Result getResult() {
+            return policy;
+        }
+
+        @XmlElement(required=false, name="product")
+        @XmlIDREF
+        protected DefaultProduct product;
+        @XmlElement(required=false, name="productCategory")
+        protected ProductCategory productCategory;
+
+        @XmlElement(required=false, name="billingPeriod")
+        protected BillingPeriod billingPeriod;
+
+        @XmlElement(required=false, name="priceList")
+        @XmlIDREF
+        protected DefaultPriceList priceList;
+
+        public DefaultProduct getProduct(){
+            return product;
+        }
+
+        public ProductCategory getProductCategory() {
+            return productCategory;
+        }
+
+        public BillingPeriod getBillingPeriod() {
+            return billingPeriod;
+        }
+
+        public DefaultPriceList getPriceList() {
+            return priceList;
+        }
+
+        protected CaseResult setProduct(DefaultProduct product) {
+            this.product = product;
+            return this;
+        }
+
+        protected CaseResult setProductCategory(ProductCategory productCategory) {
+            this.productCategory = productCategory;
+            return this;
+        }
+
+        protected CaseResult setBillingPeriod(BillingPeriod billingPeriod) {
+            this.billingPeriod = billingPeriod;
+            return this;
+        }
+
+        protected CaseResult setPriceList(DefaultPriceList priceList) {
+            this.priceList = priceList;
+            return this;
+        }
+    }
+
+    @Test(enabled=true)
+    public void testBasic() throws CatalogApiException{
+        MockCatalog cat = new MockCatalog();
+
+        DefaultProduct product = cat.getProducts()[0];
+        DefaultPriceList priceList = cat.getPriceListFromName(PriceListSet.DEFAULT_PRICELIST_NAME);
+
+
+        CaseResult cr = new CaseResult(
+                product, 
+                ProductCategory.BASE,
+                BillingPeriod.MONTHLY, 
+                priceList,
+                Result.FOO);
+
+        assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat);
+        assertionNull(cr, cat.getProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat);
+        assertionNull(cr, product.getName(), ProductCategory.ADD_ON,BillingPeriod.MONTHLY, priceList.getName(), cat);
+        assertionNull(cr, product.getName(), ProductCategory.BASE,BillingPeriod.ANNUAL, priceList.getName(), cat);
+        assertionNull(cr, product.getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, "dipsy", cat);
+    }
+
+    @Test(enabled=true)
+    public void testWildCardProduct() throws CatalogApiException{
+        MockCatalog cat = new MockCatalog();
+
+        DefaultProduct product = cat.getProducts()[0];
+        DefaultPriceList priceList = cat.getPriceListFromName(PriceListSet.DEFAULT_PRICELIST_NAME);
+
+
+        CaseResult cr = new CaseResult(
+                null, 
+                ProductCategory.BASE,
+                BillingPeriod.MONTHLY, 
+                priceList,
+
+                Result.FOO);
+
+        assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, priceList.getName(), cat);
+        assertion(Result.FOO, cr, cat.getProducts()[1].getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, priceList.getName(), cat);
+        assertionNull(cr, product.getName(), ProductCategory.ADD_ON,BillingPeriod.MONTHLY, priceList.getName(), cat);
+        assertionNull(cr, product.getName(), ProductCategory.BASE,BillingPeriod.ANNUAL, priceList.getName(), cat);
+        assertionNull(cr, product.getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, "dipsy", cat);
+    }
+
+    @Test(enabled=true)
+    public void testWildCardProductCategory() throws CatalogApiException{
+        MockCatalog cat = new MockCatalog();
+
+        DefaultProduct product = cat.getProducts()[0];
+        DefaultPriceList priceList = cat.getPriceListFromName(PriceListSet.DEFAULT_PRICELIST_NAME);
+
+
+        CaseResult cr = new CaseResult(
+                product, 
+                null,
+                BillingPeriod.MONTHLY, 
+                priceList,
+
+                Result.FOO);
+
+        assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat);
+        assertionNull(cr,  cat.getProducts()[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);
+        assertionNull(cr, product.getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, "dipsy", cat);
+    }
+
+    @Test(enabled=true)
+    public void testWildCardBillingPeriod() throws CatalogApiException{
+        MockCatalog cat = new MockCatalog();
+
+        DefaultProduct product = cat.getProducts()[0];
+        DefaultPriceList priceList = cat.getPriceListFromName(PriceListSet.DEFAULT_PRICELIST_NAME);
+
+
+        CaseResult cr = new CaseResult(
+                product, 
+                ProductCategory.BASE,
+                null, 
+                priceList,
+
+                Result.FOO);
+
+        assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat);
+        assertionNull(cr,  cat.getProducts()[1].getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, priceList.getName(), cat);
+        assertionNull(cr, product.getName(), ProductCategory.ADD_ON,BillingPeriod.MONTHLY, priceList.getName(), cat);
+        assertion(Result.FOO,cr, product.getName(), ProductCategory.BASE,BillingPeriod.ANNUAL, priceList.getName(), cat);
+        assertionNull(cr, product.getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, "dipsy", cat);
+    }
+
+    @Test(enabled=true)
+    public void testWildCardPriceList() throws CatalogApiException{
+        MockCatalog cat = new MockCatalog();
+
+        DefaultProduct product = cat.getProducts()[0];
+        DefaultPriceList priceList = cat.getPriceListFromName(PriceListSet.DEFAULT_PRICELIST_NAME);
+
+
+        CaseResult cr = new CaseResult(
+                product, 
+                ProductCategory.BASE,
+                BillingPeriod.MONTHLY, 
+                null,
+
+                Result.FOO);
+
+        assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, priceList.getName(), cat);
+        assertionNull(cr,  cat.getProducts()[1].getName(), ProductCategory.BASE,BillingPeriod.MONTHLY, priceList.getName(), cat);
+        assertionNull(cr, product.getName(), ProductCategory.ADD_ON,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);
+    }
+
+    @Test
+    public void testCaseOrder() throws CatalogApiException {
+        MockCatalog cat = new MockCatalog();
+
+        DefaultProduct product = cat.getProducts()[0];
+        DefaultPriceList priceList = cat.getPriceListFromName(PriceListSet.DEFAULT_PRICELIST_NAME);
+
+
+        CaseResult cr0 = new CaseResult(
+                product, 
+                ProductCategory.BASE,
+                BillingPeriod.MONTHLY, 
+                priceList,
+                Result.FOO);
+
+        CaseResult cr1 = new CaseResult(
+                product, 
+                ProductCategory.BASE,
+                BillingPeriod.MONTHLY, 
+                priceList,
+                Result.BAR);
+
+        CaseResult cr2 = new CaseResult(
+                product, 
+                ProductCategory.BASE,
+                BillingPeriod.ANNUAL, 
+                priceList,
+                Result.DIPSY);
+
+        CaseResult cr3 = new CaseResult(
+                product, 
+                ProductCategory.BASE,
+                BillingPeriod.ANNUAL, 
+                priceList,
+                Result.LALA);
+
+        Result r1 = Case.getResult(new CaseResult[]{cr0, cr1, cr2,cr3}, 
+                new PlanSpecifier(product.getName(), product.getCategory(), BillingPeriod.MONTHLY, priceList.getName()), cat);
+        assertEquals(Result.FOO, r1);
+
+        Result r2 = Case.getResult(new CaseResult[]{cr0, cr1, cr2}, 
+                new PlanSpecifier(product.getName(), product.getCategory(), BillingPeriod.ANNUAL, priceList.getName()), cat);
+        assertEquals(Result.DIPSY, r2);
+    }
+
+
+
+
+    protected void assertionNull(CaseResult cr, String productName, ProductCategory productCategory, BillingPeriod bp, String priceListName, StandaloneCatalog cat) throws CatalogApiException{
+        assertNull(cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat));
+    }
+
+    protected void assertion(Result result, CaseResult cr, String productName, ProductCategory productCategory, BillingPeriod bp, String priceListName,StandaloneCatalog cat) throws CatalogApiException{
+        assertEquals(result, cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat));
+    }
 
 
 }
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestLoadRules.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestLoadRules.java
new file mode 100644
index 0000000..6f1d9e2
--- /dev/null
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestLoadRules.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.catalog.rules;
+
+import java.io.File;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.ning.billing.catalog.StandaloneCatalog;
+import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.Plan;
+import com.ning.billing.catalog.api.PlanAlignmentCreate;
+import com.ning.billing.catalog.api.PlanSpecifier;
+import com.ning.billing.catalog.api.ProductCategory;
+import com.ning.billing.util.config.XMLLoader;
+
+public class TestLoadRules {
+
+    @Test
+    public void test() throws Exception {
+        StandaloneCatalog catalog = XMLLoader.getObjectFromUri(new File("src/test/resources/WeaponsHireSmall.xml").toURI(), StandaloneCatalog.class);
+        Assert.assertNotNull(catalog);
+        PlanRules rules = catalog.getPlanRules();
+        
+        PlanSpecifier specifier = new PlanSpecifier("Laser-Scope", ProductCategory.ADD_ON , BillingPeriod.MONTHLY,
+                "DEFAULT");
+        
+        PlanAlignmentCreate alignment=  rules.getPlanCreateAlignment(specifier, catalog);
+        Assert.assertEquals(alignment, PlanAlignmentCreate.START_OF_SUBSCRIPTION);
+        
+        PlanSpecifier specifier2 = new PlanSpecifier("Extra-Ammo", ProductCategory.ADD_ON , BillingPeriod.MONTHLY,
+                "DEFAULT");
+        
+        PlanAlignmentCreate alignment2 = rules.getPlanCreateAlignment(specifier2, catalog);
+        Assert.assertEquals(alignment2, PlanAlignmentCreate.START_OF_BUNDLE);
+    }
+}
diff --git a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-1.xml b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-1.xml
index a29e929..fe66528 100644
--- a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-1.xml
+++ b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-1.xml
@@ -57,6 +57,15 @@
 				<alignment>START_OF_SUBSCRIPTION</alignment>
 			</changeAlignmentCase>
 		</changeAlignment>
+		 <createAlignment>
+            <createAlignmentCase>
+                <product>Laser-Scope</product>
+                <alignment>START_OF_SUBSCRIPTION</alignment>
+            </createAlignmentCase>
+            <createAlignmentCase>
+                <alignment>START_OF_BUNDLE</alignment>
+            </createAlignmentCase>
+        </createAlignment>
 	</rules>
 
 
diff --git a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-2.xml b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-2.xml
index 135a89e..66f2cca 100644
--- a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-2.xml
+++ b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-2.xml
@@ -57,6 +57,15 @@
 				<alignment>START_OF_SUBSCRIPTION</alignment>
 			</changeAlignmentCase>
 		</changeAlignment>
+		 <createAlignment>
+            <createAlignmentCase>
+                <product>Laser-Scope</product>
+                <alignment>START_OF_SUBSCRIPTION</alignment>
+            </createAlignmentCase>
+            <createAlignmentCase>
+                <alignment>START_OF_BUNDLE</alignment>
+            </createAlignmentCase>
+        </createAlignment>
 	</rules>
 
 	<plans>
diff --git a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-3.xml b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-3.xml
index 747f54b..88caefd 100644
--- a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-3.xml
+++ b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-3.xml
@@ -57,6 +57,15 @@
 				<alignment>START_OF_SUBSCRIPTION</alignment>
 			</changeAlignmentCase>
 		</changeAlignment>
+		 <createAlignment>
+            <createAlignmentCase>
+                <product>Laser-Scope</product>
+                <alignment>START_OF_SUBSCRIPTION</alignment>
+            </createAlignmentCase>
+            <createAlignmentCase>
+                <alignment>START_OF_BUNDLE</alignment>
+            </createAlignmentCase>
+        </createAlignment>
 	</rules>
 
 
diff --git a/catalog/src/test/resources/WeaponsHireSmall.xml b/catalog/src/test/resources/WeaponsHireSmall.xml
index 0a3ed52..21a9f08 100644
--- a/catalog/src/test/resources/WeaponsHireSmall.xml
+++ b/catalog/src/test/resources/WeaponsHireSmall.xml
@@ -37,6 +37,9 @@
 		<product name="Laser-Scope">
 			<category>ADD_ON</category>
 		</product>
+        <product name="Extra-Ammo">
+            <category>ADD_ON</category>
+        </product>
 	</products>
 	 
 	<rules>
@@ -52,11 +55,20 @@
 				<policy>IMMEDIATE</policy>
 			</changePolicyCase>	
 		</changePolicy>
-		<changeAlignment>
-			<changeAlignmentCase>
-				<alignment>START_OF_SUBSCRIPTION</alignment>
-			</changeAlignmentCase>
-		</changeAlignment>
+        <changeAlignment>
+            <changeAlignmentCase>
+                <alignment>START_OF_SUBSCRIPTION</alignment>
+            </changeAlignmentCase>
+        </changeAlignment>
+        <createAlignment>
+            <createAlignmentCase>
+                <product>Laser-Scope</product>
+                <alignment>START_OF_SUBSCRIPTION</alignment>
+            </createAlignmentCase>
+            <createAlignmentCase>
+                <alignment>START_OF_BUNDLE</alignment>
+            </createAlignmentCase>
+        </createAlignment>
 	</rules>
 
 	<plans>
@@ -136,6 +148,34 @@
 				</recurringPrice>
 			</finalPhase>
 		</plan>
+		<plan name="laser-scope-monthly">
+        <product>Laser-Scope</product>
+            <finalPhase type="EVERGREEN">
+                <duration>
+                    <unit>UNLIMITED</unit>
+                </duration>
+                <billingPeriod>MONTHLY</billingPeriod>
+                <recurringPrice>
+                    <price><currency>USD</currency><value>1999.95</value></price>                               
+                    <price><currency>EUR</currency><value>1499.95</value></price>
+                    <price><currency>GBP</currency><value>1999.95</value></price>
+                </recurringPrice>
+            </finalPhase>
+        </plan>
+        <plan name="extra-ammo-monthly">
+        <product>Extra-Ammo</product>
+            <finalPhase type="EVERGREEN">
+                <duration>
+                    <unit>UNLIMITED</unit>
+                </duration>
+                <billingPeriod>MONTHLY</billingPeriod>
+                <recurringPrice>
+                    <price><currency>USD</currency><value>1999.95</value></price>                               
+                    <price><currency>EUR</currency><value>1499.95</value></price>
+                    <price><currency>GBP</currency><value>1999.95</value></price>
+                </recurringPrice>
+            </finalPhase>
+        </plan>
 	</plans>
 	<priceLists>
 		<defaultPriceList name="DEFAULT">