killbill-uncached

Merge branch 'irs-integration' of github.com:ning/killbill

11/16/2011 7:53:59 PM

Changes

catalog/src/main/java/com/ning/billing/catalog/rules/PlanPolicyChangeRule.java 98(+0 -98)

catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanChangeRules.java 257(+0 -257)

Details

diff --git a/api/src/main/java/com/ning/billing/catalog/api/CatalogApiException.java b/api/src/main/java/com/ning/billing/catalog/api/CatalogApiException.java
index 6099e23..3de9eb8 100644
--- a/api/src/main/java/com/ning/billing/catalog/api/CatalogApiException.java
+++ b/api/src/main/java/com/ning/billing/catalog/api/CatalogApiException.java
@@ -22,12 +22,12 @@ import com.ning.billing.ErrorCode;
 public class CatalogApiException extends BillingExceptionBase {
 	private static final long serialVersionUID = 1L;
 
-	public CatalogApiException(Throwable cause, Object... args) {
-		super(cause, ErrorCode.CAT_ILLEGAL_CHANGE_REQUEST, args);
+	public CatalogApiException(Throwable cause, ErrorCode code, Object... args) {
+		super(cause, code, args);
 	}
 
-	public CatalogApiException(Object... args) {
-		super(ErrorCode.CAT_ILLEGAL_CHANGE_REQUEST, args);
+	public CatalogApiException(ErrorCode code, Object... args) {
+		super(code, args);
 	}
 
 }
diff --git a/api/src/main/java/com/ning/billing/catalog/api/IllegalPlanChange.java b/api/src/main/java/com/ning/billing/catalog/api/IllegalPlanChange.java
index 6255383..21bd513 100644
--- a/api/src/main/java/com/ning/billing/catalog/api/IllegalPlanChange.java
+++ b/api/src/main/java/com/ning/billing/catalog/api/IllegalPlanChange.java
@@ -21,14 +21,14 @@ import com.ning.billing.ErrorCode;
 public class IllegalPlanChange extends CatalogApiException {
 	private static final long serialVersionUID = 1L;
 
-	public IllegalPlanChange(Throwable cause, ErrorCode code, PlanPhaseSpecifier from,
+	public IllegalPlanChange(Throwable cause, PlanPhaseSpecifier from,
 			PlanSpecifier to) {
-		super(cause, code, from.getProductName(), from.getBillingPeriod(), from.getPriceListName(), to.getProductName(), to.getBillingPeriod(), to.getPriceListName());
+		super(cause, ErrorCode.CAT_ILLEGAL_CHANGE_REQUEST, from.getProductName(), from.getBillingPeriod(), from.getPriceListName(), to.getProductName(), to.getBillingPeriod(), to.getPriceListName());
 	}
 
-	public IllegalPlanChange(ErrorCode code, PlanPhaseSpecifier from,
+	public IllegalPlanChange(PlanPhaseSpecifier from,
 			PlanSpecifier to) {
-		super(code, from.getProductName(), from.getBillingPeriod(), from.getPriceListName(), to.getProductName(), to.getBillingPeriod(), to.getPriceListName());
+		super(ErrorCode.CAT_ILLEGAL_CHANGE_REQUEST, from.getProductName(), from.getBillingPeriod(), from.getPriceListName(), to.getProductName(), to.getBillingPeriod(), to.getPriceListName());
 	}
 
 
diff --git a/api/src/main/java/com/ning/billing/catalog/api/PlanChangeResult.java b/api/src/main/java/com/ning/billing/catalog/api/PlanChangeResult.java
index bbb8e39..c0be482 100644
--- a/api/src/main/java/com/ning/billing/catalog/api/PlanChangeResult.java
+++ b/api/src/main/java/com/ning/billing/catalog/api/PlanChangeResult.java
@@ -35,6 +35,11 @@ public class PlanChangeResult {
 
 	public ActionPolicy getPolicy() {
 		return policy;
+	}
+
+	public PlanAlignmentChange getAlignment() {
+		return alignment;
 	}	
+	 
 	
 }
diff --git a/api/src/main/java/com/ning/billing/catalog/api/PlanPhaseSpecifier.java b/api/src/main/java/com/ning/billing/catalog/api/PlanPhaseSpecifier.java
index 7dadda0..18c864a 100644
--- a/api/src/main/java/com/ning/billing/catalog/api/PlanPhaseSpecifier.java
+++ b/api/src/main/java/com/ning/billing/catalog/api/PlanPhaseSpecifier.java
@@ -50,4 +50,7 @@ public class PlanPhaseSpecifier  {
 		return phaseType;
 	}
 
+	public PlanSpecifier toPlanSpecifier() {
+		return new PlanSpecifier(productName, productCategory, billingPeriod, priceListName);
+	}
 }
diff --git a/catalog/src/main/java/com/ning/billing/catalog/Catalog.java b/catalog/src/main/java/com/ning/billing/catalog/Catalog.java
index 9f5d1f0..fa24752 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/Catalog.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/Catalog.java
@@ -284,7 +284,7 @@ public class Catalog extends ValidatingConfig<Catalog> implements ICatalog {
 	@Override
 	public PlanChangeResult planChange(PlanPhaseSpecifier from, PlanSpecifier to)
 			throws IllegalPlanChange {
-		return planRules.planChange(from, to);
+		return planRules.planChange(from, to, this);
 	}
 	
 	//TODO: MDW validation - only allow one default pricelist
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 d63cc2e..67f7bae 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,9 +16,6 @@
 
 package com.ning.billing.catalog.rules;
 
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlIDREF;
-
 import com.ning.billing.catalog.Catalog;
 import com.ning.billing.catalog.PriceList;
 import com.ning.billing.catalog.Product;
@@ -36,22 +33,6 @@ public abstract class Case<T> extends ValidatingConfig<Catalog> {
 	protected PriceList priceList;
 
 	protected abstract T getResult();
-	
-	public Case() {}
-	
-	protected Case (
-			Product product, 
-			ProductCategory productCategory, 
-			BillingPeriod billingPeriod, 
-			PriceList priceList, 
-			T result
-			) {
-		this.product = product;
-		this.productCategory = productCategory;
-		this.billingPeriod = billingPeriod;
-		this.priceList = priceList;
-	}
-
 
 	public T getResult(PlanSpecifier planPhase, Catalog c) {
 		if (satisfiesCase(planPhase, c)	) {
@@ -69,8 +50,8 @@ public abstract class Case<T> extends ValidatingConfig<Catalog> {
 
 	public static <K> K getResult(Case<K>[] cases, PlanSpecifier planSpec, Catalog catalog) {
     	if(cases != null) {
-    		for(int i = cases.length - 1; i >=0; i --) {
-    			K result = cases[i].getResult(planSpec, catalog);
+    		for(Case<K> c : cases) {
+    			K result = c.getResult(planSpec, catalog);
     			if(result != null) { 
     				return result; 
     			}        					
@@ -82,8 +63,29 @@ public abstract class Case<T> extends ValidatingConfig<Catalog> {
 	
 	@Override
 	public ValidationErrors validate(Catalog catalog, ValidationErrors errors) {
-		// TODO Auto-generated method stub
-		return null;
+		return errors;
+	}
+
+	protected Case<T> setProduct(Product product) {
+		this.product = product;
+		return this;
+	}
+
+	protected Case<T> setProductCategory(ProductCategory productCategory) {
+		this.productCategory = productCategory;
+		return this;
+	}
+
+	protected Case<T> setBillingPeriod(BillingPeriod billingPeriod) {
+		this.billingPeriod = billingPeriod;
+		return this;
+	}
+
+	protected Case<T> setPriceList(PriceList priceList) {
+		this.priceList = priceList;
+		return this;
 	}
 
+	
+	
 }
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseBillingAlignment.java b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseBillingAlignment.java
index 2744431..8b8c9ab 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseBillingAlignment.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseBillingAlignment.java
@@ -18,29 +18,22 @@ package com.ning.billing.catalog.rules;
 
 import javax.xml.bind.annotation.XmlElement;
 
-import com.ning.billing.catalog.PriceList;
-import com.ning.billing.catalog.Product;
 import com.ning.billing.catalog.api.BillingAlignment;
-import com.ning.billing.catalog.api.BillingPeriod;
-import com.ning.billing.catalog.api.PhaseType;
-import com.ning.billing.catalog.api.ProductCategory;
 
 public class CaseBillingAlignment extends CasePhase<BillingAlignment> {
 
-
 	@XmlElement(required=true)
 	private BillingAlignment alignment;
 
-	public CaseBillingAlignment() {}
-
-	public CaseBillingAlignment(Product product, ProductCategory productCategory, BillingPeriod billingPeriod,
-			PriceList priceList, PhaseType phaseType, BillingAlignment alignment) {
-		super(product, productCategory, billingPeriod, priceList, phaseType, alignment);
-		this.alignment = alignment;
-	}
-
 	@Override
 	protected BillingAlignment getResult() {
 		return alignment;
 	}
+
+	protected CaseBillingAlignment setAlignment(BillingAlignment alignment) {
+		this.alignment = alignment;
+		return this;
+	}
+	
+	
 }
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseCancelPolicy.java b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseCancelPolicy.java
index 0405077..eb49803 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseCancelPolicy.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseCancelPolicy.java
@@ -18,31 +18,21 @@ package com.ning.billing.catalog.rules;
 
 import javax.xml.bind.annotation.XmlElement;
 
-import com.ning.billing.catalog.PriceList;
-import com.ning.billing.catalog.Product;
 import com.ning.billing.catalog.api.ActionPolicy;
-import com.ning.billing.catalog.api.BillingPeriod;
-import com.ning.billing.catalog.api.PhaseType;
-import com.ning.billing.catalog.api.ProductCategory;
 
 public class CaseCancelPolicy extends CasePhase<ActionPolicy>{
 
 	@XmlElement(required=true)
 	private ActionPolicy policy;
 
-	public CaseCancelPolicy() {}
-
-	public CaseCancelPolicy(Product product, ProductCategory productCategory, BillingPeriod billingPeriod, PriceList priceList,
-			PhaseType phaseType, ActionPolicy policy) {
-		super(product, productCategory, billingPeriod, priceList, phaseType, policy);
-		this.policy = policy;
-	}
-
-
-
 	@Override
 	protected ActionPolicy getResult() {
 		return policy;
 	}
 
+	protected CaseCancelPolicy setPolicy(ActionPolicy policy) {
+		this.policy = policy;
+		return this;
+	}
+
 }
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChange.java b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChange.java
index 1251487..e0095f8 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChange.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChange.java
@@ -65,26 +65,6 @@ public abstract class CaseChange<T>  extends ValidatingConfig<Catalog> {
 	@XmlElement(required=false)
 	@XmlIDREF
 	private PriceList toPriceList;
-	
-	public CaseChange(){}
-	
-	protected CaseChange (
-			Product from, Product to, 
-			ProductCategory fromProductCategory, ProductCategory toProductCategory, 
-			BillingPeriod fromBP, BillingPeriod toBP, 
-			PriceList fromPriceList, PriceList toPriceList,
-			PhaseType fromType,
-			T result) {
-		this.fromProduct = from;
-		this.toProduct = to;
-		this.fromProductCategory = fromProductCategory;
-		this.toProductCategory = toProductCategory;
-		this.fromBillingPeriod = fromBP;
-		this.toBillingPeriod = toBP;
-		this.phaseType = fromType;
-		this.fromPriceList = fromPriceList;
-		this.toPriceList = toPriceList;
-	}
 
 	protected abstract T getResult();
 	
@@ -109,8 +89,8 @@ public abstract class CaseChange<T>  extends ValidatingConfig<Catalog> {
 	static public <K> K getResult(CaseChange<K>[] cases, PlanPhaseSpecifier from,
 			PlanSpecifier to, Catalog catalog) {
     	if(cases != null) {
-    		for(int i = cases.length - 1; i >=0; i --) {
-    			K result = cases[i].getResult(from, to, catalog);
+    		for(CaseChange<K> cc : cases) {
+    			K result = cc.getResult(from, to, catalog);
     			if(result != null) { 
     				return result; 
     			}        					
@@ -119,12 +99,55 @@ public abstract class CaseChange<T>  extends ValidatingConfig<Catalog> {
         return null;
         
     }
+	
 	@Override
 	public ValidationErrors validate(Catalog catalog, ValidationErrors errors) {
-		// TODO Auto-generated method stub
 		return errors;
 	}
 
+	protected CaseChange<T> setPhaseType(PhaseType phaseType) {
+		this.phaseType = phaseType;
+		return this;
+	}
+
+	protected CaseChange<T> setFromProduct(Product fromProduct) {
+		this.fromProduct = fromProduct;
+		return this;
+	}
+
+	protected CaseChange<T> setFromProductCategory(ProductCategory fromProductCategory) {
+		this.fromProductCategory = fromProductCategory;
+		return this;
+	}
+
+	protected CaseChange<T> setFromBillingPeriod(BillingPeriod fromBillingPeriod) {
+		this.fromBillingPeriod = fromBillingPeriod;
+		return this;
+	}
+
+	protected CaseChange<T> setFromPriceList(PriceList fromPriceList) {
+		this.fromPriceList = fromPriceList;
+		return this;
+	}
+
+	protected CaseChange<T> setToProduct(Product toProduct) {
+		this.toProduct = toProduct;
+		return this;
+	}
+
+	protected CaseChange<T> setToProductCategory(ProductCategory toProductCategory) {
+		this.toProductCategory = toProductCategory;
+		return this;
+	}
 
+	protected CaseChange<T> setToBillingPeriod(BillingPeriod toBillingPeriod) {
+		this.toBillingPeriod = toBillingPeriod;
+		return this;
+	}
+
+	protected CaseChange<T> setToPriceList(PriceList toPriceList) {
+		this.toPriceList = toPriceList;
+		return this;
+	}
 
 }
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChangePlanAlignment.java b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChangePlanAlignment.java
index 8b8276d..3186288 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChangePlanAlignment.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChangePlanAlignment.java
@@ -18,39 +18,21 @@ package com.ning.billing.catalog.rules;
 
 import javax.xml.bind.annotation.XmlElement;
 
-import com.ning.billing.catalog.PriceList;
-import com.ning.billing.catalog.Product;
-import com.ning.billing.catalog.api.BillingPeriod;
-import com.ning.billing.catalog.api.PhaseType;
 import com.ning.billing.catalog.api.PlanAlignmentChange;
-import com.ning.billing.catalog.api.ProductCategory;
 
 public class CaseChangePlanAlignment extends CaseChange<PlanAlignmentChange> {
 
 	@XmlElement(required=true)
 	private PlanAlignmentChange alignment;
-	
-	public CaseChangePlanAlignment() {}
-
-	protected CaseChangePlanAlignment(
-			Product from, Product to, 
-			ProductCategory fromProductCategory, ProductCategory toProductCategory, 
-			BillingPeriod fromBP,BillingPeriod toBP, 
-			PriceList fromPriceList, PriceList toPriceList,
-			PhaseType fromType, 
-			PlanAlignmentChange result) {
-		super(from, to, 
-				fromProductCategory, toProductCategory, 
-				fromBP, toBP, 
-				fromPriceList, toPriceList,  
-				fromType,
-				result);
-		alignment = result;
-	}
 
 	@Override
 	protected PlanAlignmentChange getResult() {
 		return alignment;
 	}
 
+	protected CaseChangePlanAlignment setAlignment(PlanAlignmentChange alignment) {
+		this.alignment = alignment;
+		return this;
+	}
+	
 }
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChangePlanPolicy.java b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChangePlanPolicy.java
index 0a894ce..f6862f9 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChangePlanPolicy.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChangePlanPolicy.java
@@ -19,42 +19,22 @@ package com.ning.billing.catalog.rules;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlSeeAlso;
 
-import com.ning.billing.catalog.PriceList;
-import com.ning.billing.catalog.Product;
 import com.ning.billing.catalog.api.ActionPolicy;
-import com.ning.billing.catalog.api.BillingPeriod;
-import com.ning.billing.catalog.api.PhaseType;
-import com.ning.billing.catalog.api.ProductCategory;
 
 @XmlSeeAlso(CaseChange.class)
 public class CaseChangePlanPolicy extends CaseChange<ActionPolicy> {
 	
 	@XmlElement(required=true)
 	private ActionPolicy policy;
-	
-	public CaseChangePlanPolicy() {}
-
-	protected CaseChangePlanPolicy(
-			Product from, Product to, 
-			ProductCategory fromProductCategory, ProductCategory toProductCategory, 
-			BillingPeriod fromBP,BillingPeriod toBP, 
-			PriceList fromPriceList, PriceList toPriceList,
-			PhaseType fromType,
-			ActionPolicy result) {
-		super(from, to, 
-				fromProductCategory, toProductCategory,
-				fromBP, toBP, 
-				fromPriceList, toPriceList, 
-				fromType, 
-				result);
-		policy = result;
-	}
-
-
 
 	@Override
 	protected ActionPolicy getResult() {
 		return policy;
 	}
 
+	protected CaseChangePlanPolicy setPolicy(ActionPolicy policy) {
+		this.policy = policy;
+		return this;
+	}
+	
 }
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseCreateAlignment.java b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseCreateAlignment.java
index 1f25773..39f6607 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseCreateAlignment.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseCreateAlignment.java
@@ -18,28 +18,21 @@ package com.ning.billing.catalog.rules;
 
 import javax.xml.bind.annotation.XmlElement;
 
-import com.ning.billing.catalog.PriceList;
-import com.ning.billing.catalog.Product;
-import com.ning.billing.catalog.api.BillingPeriod;
 import com.ning.billing.catalog.api.PlanAlignmentCreate;
-import com.ning.billing.catalog.api.ProductCategory;
 
 public class CaseCreateAlignment extends CaseStandardNaming<PlanAlignmentCreate>{
 
 	@XmlElement(required=true)
 	private PlanAlignmentCreate alignment;
 
-	public CaseCreateAlignment() {}
-
-	public CaseCreateAlignment(Product product, ProductCategory productCategory,  BillingPeriod billingPeriod,
-			PriceList priceList, PlanAlignmentCreate alignment) {
-		super(product, productCategory, billingPeriod, priceList, alignment);
-		this.alignment = alignment;
-	}
-
 	@Override
 	protected PlanAlignmentCreate getResult() {
 		return alignment;
 	}
 
+	protected CaseCreateAlignment setAlignment(PlanAlignmentCreate alignment) {
+		this.alignment = alignment;
+		return this;
+	}
+	
 }
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/CasePhase.java b/catalog/src/main/java/com/ning/billing/catalog/rules/CasePhase.java
index 122ed7a..afd6d4b 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/CasePhase.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/CasePhase.java
@@ -31,17 +31,7 @@ import com.ning.billing.util.config.ValidationErrors;
 public abstract class CasePhase<T> extends CaseStandardNaming<T> {
 
 	@XmlElement(required=false)
-	private PhaseType phaseType;
-
-	public CasePhase() {}
-
-	public CasePhase(Product product, ProductCategory productCategory,
-			BillingPeriod billingPeriod, PriceList priceList,
-			PhaseType phaseType, T result) {
-		super(product, productCategory, billingPeriod, priceList, result);
-		this.phaseType = phaseType;
-	}
-	
+	private PhaseType phaseType;	
 	
 	public T getResult(PlanPhaseSpecifier specifier, Catalog c) {
 		if (	
@@ -55,8 +45,8 @@ public abstract class CasePhase<T> extends CaseStandardNaming<T> {
 	
 	public static <K> K getResult(CasePhase<K>[] cases, PlanPhaseSpecifier planSpec, Catalog catalog) {
     	if(cases != null) {
-    		for(int i = cases.length - 1; i >=0; i --) {
-    			K result = cases[i].getResult(planSpec, catalog);
+    		for(CasePhase<K> cp : cases) {
+    			K result = cp.getResult(planSpec, catalog);
     			if(result != null) { 
     				return result; 
     			}        					
@@ -68,7 +58,13 @@ public abstract class CasePhase<T> extends CaseStandardNaming<T> {
 
 	@Override
 	public ValidationErrors validate(Catalog catalog, ValidationErrors errors) {
-		// TODO Auto-generated method stub
-		return null;
+		return errors;
 	}
+
+	protected CasePhase<T> setPhaseType(PhaseType phaseType) {
+		this.phaseType = phaseType;
+		return this;
+	}
+	
+	
 }
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 ccd0f87..2e155f8 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
@@ -56,4 +56,11 @@ public class CasePriceList extends Case<PriceList> {
 	protected PriceList getResult() {
 		return toPriceList;
 	}
+
+	protected CasePriceList setToPriceList(PriceList toPriceList) {
+		this.toPriceList = toPriceList;
+		return this;
+	}
+	
+	
 }
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 3b20634..f74a48d 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
@@ -26,13 +26,6 @@ import com.ning.billing.catalog.api.ProductCategory;
 
 public abstract class CaseStandardNaming<T> extends Case<T> {
 
-	public CaseStandardNaming() {}
-	
-	public CaseStandardNaming(Product product, ProductCategory productCategory,
-			BillingPeriod billingPeriod, PriceList priceList, T result) {
-		super(product, productCategory, billingPeriod, priceList, result);
-	}
-	
 	@XmlElement(required=false, name="product")
 	@XmlIDREF
 	public Product getProduct(){
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/PlanRules.java b/catalog/src/main/java/com/ning/billing/catalog/rules/PlanRules.java
index ba6dee8..787dbaf 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/PlanRules.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/PlanRules.java
@@ -22,69 +22,46 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 
 import com.ning.billing.catalog.Catalog;
+import com.ning.billing.catalog.PriceList;
 import com.ning.billing.catalog.api.ActionPolicy;
 import com.ning.billing.catalog.api.BillingAlignment;
-import com.ning.billing.catalog.api.BillingPeriod;
-import com.ning.billing.catalog.api.IProduct;
+import com.ning.billing.catalog.api.IllegalPlanChange;
 import com.ning.billing.catalog.api.PlanAlignmentChange;
 import com.ning.billing.catalog.api.PlanAlignmentCreate;
 import com.ning.billing.catalog.api.PlanChangeResult;
 import com.ning.billing.catalog.api.PlanPhaseSpecifier;
 import com.ning.billing.catalog.api.PlanSpecifier;
+import com.ning.billing.catalog.api.ProductCategory;
 import com.ning.billing.util.config.ValidatingConfig;
 import com.ning.billing.util.config.ValidationErrors;
 
 @XmlAccessorType(XmlAccessType.NONE)
 public class PlanRules extends ValidatingConfig<Catalog>  {
 
-	@XmlElementWrapper(name="tiers", required=true)
-	@XmlElement(name="tier", required=false) // may not have tiers in some catalogs
-	private ProductTier[] productTiers;
-
-	@XmlElement(name="changePolicyRule", required=true)
-	private PlanPolicyChangeRule[] rules;
-
+	@XmlElementWrapper(name="changePolicy")
 	@XmlElement(name="changePolicyCase", required=false)
 	private CaseChangePlanPolicy[] changeCase;
 	
+	@XmlElementWrapper(name="changeAlignment")
 	@XmlElement(name="changeAlignmentCase", required=false)
 	private CaseChangePlanAlignment[] changeAlignmentCase;
 
+	@XmlElementWrapper(name="cancelPolicy")
 	@XmlElement(name="cancelPolicyCase", required=false)
 	private CaseCancelPolicy[] cancelCase;
 
+	@XmlElementWrapper(name="createAlignment")
 	@XmlElement(name="createAlignmentCase", required=false)
 	private CaseCreateAlignment[] createAlignmentCase;
 	
+	@XmlElementWrapper(name="billingAlignment")
 	@XmlElement(name="billingAlignmentCase", required=false)
 	private CaseBillingAlignment[] billingAlignmentCase;
 
+	@XmlElementWrapper(name="priceList")
 	@XmlElement(name="priceListCase", required=false)
 	private CasePriceList[] priceListCase;
 
-	@Override
-	public ValidationErrors validate(Catalog catalog, ValidationErrors errors) {
-		return errors;
-
-	}
-	
-	public PlanRules(){}
-
-	//For test
-	protected PlanRules(ProductTier[] productTiers, PlanPolicyChangeRule[] rules,
-			CaseChangePlanPolicy[] changeCase, CaseCancelPolicy[] cancelCase,
-			CaseChangePlanAlignment[] changeAlignmentCase,
-			CaseCreateAlignment[] createAlignmentCase) {
-		super();
-		this.productTiers = productTiers;
-		this.rules = rules;
-		this.changeCase = changeCase;
-		this.cancelCase = cancelCase;
-		this.changeAlignmentCase = changeAlignmentCase;
-		this.createAlignmentCase = createAlignmentCase;
-	}
-
-
 	public PlanAlignmentCreate getPlanCreateAlignment(PlanSpecifier specifier, Catalog catalog) {
 		return Case.getResult(createAlignmentCase, specifier, catalog);      
     }
@@ -97,18 +74,21 @@ public class PlanRules extends ValidatingConfig<Catalog>  {
 		return CasePhase.getResult(billingAlignmentCase, planPhase, catalog);      
 	}
 
-	private int getBillingPeriodIndex(BillingPeriod src) {
-		return src.ordinal();
-	}
-
-
-	public void setProductTiers(ProductTier[] productTiers) {
-		this.productTiers = productTiers;
-	}
-
-	public PlanChangeResult planChange(PlanPhaseSpecifier from, PlanSpecifier to) {
-		//TODO disallow transitions to the same thing you came from
-		return null;
+	public PlanChangeResult planChange(PlanPhaseSpecifier from, PlanSpecifier to, Catalog catalog) throws IllegalPlanChange {
+		PriceList priceList = catalog.getPriceListFromName(to.getPriceListName());
+		if( priceList== null ) {
+			priceList = findPriceList(from.toPlanSpecifier(), catalog);
+			to = new PlanSpecifier(to.getProductName(), to.getProductCategory(), to.getBillingPeriod(), priceList.getName());
+		} 
+		
+		ActionPolicy policy = getPlanChangePolicy(from, to, catalog);
+		if(policy == ActionPolicy.ILLEGAL) {
+			throw new IllegalPlanChange(from, to);
+		}
+		
+		PlanAlignmentChange alignment = getPlanChangeAlignment(from, to, catalog);
+		
+		return new PlanChangeResult(priceList, policy, alignment);
 	}
 	
 	public PlanAlignmentChange getPlanChangeAlignment(PlanPhaseSpecifier from,
@@ -118,43 +98,69 @@ public class PlanRules extends ValidatingConfig<Catalog>  {
 
 	public ActionPolicy getPlanChangePolicy(PlanPhaseSpecifier from,
 			PlanSpecifier to, Catalog catalog) {
-		
-		ActionPolicy policy = CaseChange.getResult(changeCase, from, to, catalog); 
-		if (policy != null) {
-			return policy;
+		if(from.getProductName().equals(to.getProductName()) &&
+				from.getBillingPeriod() == to.getBillingPeriod() &&
+				from.getPriceListName().equals(to.getPriceListName())) {
+			return ActionPolicy.ILLEGAL;
 		}
-
-    	
-        for(int i = rules.length - 1; i >=0; i --) {
-        	int fromProductIndex       = getProductIndex(catalog.getProductFromName(from.getProductName()));
-        	int fromBillingPeriodIndex = getBillingPeriodIndex(from.getBillingPeriod());
-			int toProductIndex         = getProductIndex(catalog.getProductFromName(to.getProductName()));
-			int toBillingPeriodIndex   = getBillingPeriodIndex(to.getBillingPeriod());
-			
-			policy = rules[i].getPlanChangePolicy(
-        		fromProductIndex, fromBillingPeriodIndex,
-        		toProductIndex, toBillingPeriodIndex,
-        		from.getPhaseType());
-        	if (policy != null) { return policy; }        
-        }
-        return null;
-        
-    }
+		
+		return CaseChange.getResult(changeCase, from, to, catalog); 
+	}
 	
-	private int getProductIndex(IProduct src) {
-		for(ProductTier tier : productTiers) {
-			for(int i = 0; i < tier.getProducts().length; i++ ){
-				if (src.equals(tier.getProducts()[i])) {
-					return i;
-				}
-			}
+	private PriceList findPriceList(PlanSpecifier specifier, Catalog catalog) {
+		PriceList result = Case.getResult(priceListCase, specifier, catalog);
+		if (result == null) {
+			result = catalog.getPriceListFromName(specifier.getPriceListName());
 		}
-		return 0;
+		return result;
 	}
 	
-    //TODO: MDW - Validation: check that the plan change special case pairs are unique!
-    //TODO: MDW - Validation: check that the each product appears in at most one tier.
-	//TODO: MDW - Unit tests for rules
-	//TODO: MDW - validate that there is a default policy for change AND cancel
+	
+	@Override
+	public ValidationErrors validate(Catalog catalog, ValidationErrors errors) {
+	    //TODO: MDW - Validation: check that the plan change special case pairs are unique!
+	    //TODO: MDW - Validation: check that the each product appears in at most one tier.
+		//TODO: MDW - Unit tests for rules
+		//TODO: MDW - validate that there is a default policy for change AND cancel
+
+		return errors;
+	}
+
+	
+	/////////////////////////////////////////////////////////////////////////////////////
+	// Setters for testing
+	/////////////////////////////////////////////////////////////////////////////////////
+	
+	protected PlanRules setChangeCase(CaseChangePlanPolicy[] changeCase) {
+		this.changeCase = changeCase;
+		return this;
+	}
+
+	protected PlanRules setChangeAlignmentCase(
+			CaseChangePlanAlignment[] changeAlignmentCase) {
+		this.changeAlignmentCase = changeAlignmentCase;
+		return this;
+	}
+
+	protected PlanRules setCancelCase(CaseCancelPolicy[] cancelCase) {
+		this.cancelCase = cancelCase;
+		return this;
+	}
+
+	protected PlanRules setCreateAlignmentCase(CaseCreateAlignment[] createAlignmentCase) {
+		this.createAlignmentCase = createAlignmentCase;
+		return this;
+	}
+
+	protected PlanRules setBillingAlignmentCase(
+			CaseBillingAlignment[] billingAlignmentCase) {
+		this.billingAlignmentCase = billingAlignmentCase;
+		return this;
+	}
+
+	protected PlanRules setPriceListCase(CasePriceList[] priceListCase) {
+		this.priceListCase = priceListCase;
+		return this;
+	}
 
 }
diff --git a/catalog/src/test/java/com/ning/billing/catalog/MockCatalog.java b/catalog/src/test/java/com/ning/billing/catalog/MockCatalog.java
index 89e2739..c561457 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/MockCatalog.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/MockCatalog.java
@@ -16,25 +16,12 @@
 
 package com.ning.billing.catalog;
 
-import com.ning.billing.catalog.Catalog;
-import com.ning.billing.catalog.Duration;
-import com.ning.billing.catalog.Plan;
-import com.ning.billing.catalog.PlanPhase;
-import com.ning.billing.catalog.PriceList;
-import com.ning.billing.catalog.PriceListDefault;
-import com.ning.billing.catalog.PriceListSet;
-import com.ning.billing.catalog.Product;
-import com.ning.billing.catalog.api.BillingPeriod;
-import com.ning.billing.catalog.api.PhaseType;
 import com.ning.billing.catalog.api.ProductCategory;
-import com.ning.billing.catalog.api.TimeUnit;
 import com.ning.billing.catalog.rules.CaseCancelPolicy;
 import com.ning.billing.catalog.rules.CaseChangePlanAlignment;
 import com.ning.billing.catalog.rules.CaseChangePlanPolicy;
 import com.ning.billing.catalog.rules.CaseCreateAlignment;
-import com.ning.billing.catalog.rules.PlanPolicyChangeRule;
 import com.ning.billing.catalog.rules.PlanRules;
-import com.ning.billing.catalog.rules.ProductTier;
 
 public class MockCatalog extends Catalog {
 	private static final String[] PRODUCT_NAMES = new String[]{ "TestProduct1", "TestProduct2", "TestProduct3"};
@@ -42,7 +29,6 @@ public class MockCatalog extends Catalog {
 	public MockCatalog() {
 		populateProducts();
 		populateRules();
-		populateProductTiers();
 		populatePlans();
 		populatePriceLists();
 	}
@@ -51,7 +37,7 @@ public class MockCatalog extends Catalog {
 		setPlanRules(new PlanRules());
 	}
 
-	public void setRules(PlanPolicyChangeRule[] rules,
+	public void setRules( 
 			CaseChangePlanPolicy[] caseChangePlanPolicy,
 			CaseChangePlanAlignment[] caseChangePlanAlignment,
 			CaseCancelPolicy[] caseCancelPolicy,
@@ -68,13 +54,6 @@ public class MockCatalog extends Catalog {
 		}
 		setProducts(products);
 	}
-
-	public void populateProductTiers() {
-		//default to having a single tier with all products in it
-		ProductTier tier = new ProductTier();
-		tier.setProducts(getProducts());
-		getPlanRules().setProductTiers(new ProductTier[]{tier});
-	}
 	
 	public void populatePlans() {
 		Product[] products = getProducts();
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/MockPlanRules.java b/catalog/src/test/java/com/ning/billing/catalog/rules/MockPlanRules.java
index 6961ffc..1c2eb1c 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/MockPlanRules.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/MockPlanRules.java
@@ -18,4 +18,16 @@ package com.ning.billing.catalog.rules;
 
 public class MockPlanRules extends PlanRules {
 
+	//For test
+	public MockPlanRules(
+			CaseChangePlanPolicy[] changeCase, CaseCancelPolicy[] cancelCase,
+			CaseChangePlanAlignment[] changeAlignmentCase,
+			CaseCreateAlignment[] createAlignmentCase) {
+		super();
+		setChangeCase(changeCase);
+		setCancelCase(cancelCase);
+		setChangeAlignmentCase(changeAlignmentCase);
+		setCreateAlignmentCase(createAlignmentCase);
+	}
+
 }
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 756b8ea..3cd031b 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
@@ -34,9 +34,7 @@ import com.ning.billing.catalog.api.ProductCategory;
 import com.ning.billing.catalog.rules.Case;
 
 public class TestCase {
-	protected enum Result {
-		FOO, BAR, WIBBLE
-	}
+
 	protected class CaseResult extends Case<Result>  {
 
 		@XmlElement(required=true)
@@ -44,7 +42,10 @@ public class TestCase {
 
 		public CaseResult(Product product, ProductCategory productCategory, BillingPeriod billingPeriod, PriceList priceList,
 				 Result policy) {
-			super(product, productCategory, billingPeriod, priceList,  policy);
+			setProduct(product);
+			setProductCategory(productCategory);
+			setBillingPeriod(billingPeriod);
+			setPriceList(priceList);
 			this.policy = policy;
 		}
 
@@ -167,6 +168,54 @@ public class TestCase {
 		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() {
+		MockCatalog cat = new MockCatalog();
+
+		Product product = cat.getProducts()[0];
+		PriceList priceList = cat.getPriceListFromName(IPriceListSet.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, Catalog cat){
 		assertNull(cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat));
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCaseChange.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCaseChange.java
index 49f80e3..34f055d 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCaseChange.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCaseChange.java
@@ -35,11 +35,7 @@ import com.ning.billing.catalog.api.PlanSpecifier;
 import com.ning.billing.catalog.api.ProductCategory;
 
 public class TestCaseChange {
-	protected enum Result {
-		FOO, BAR, WIBBLE
-	}
-	
-	protected class CaseChangeResult extends CaseChange<Result>  {
+	protected static class CaseChangeResult extends CaseChange<Result>  {
 
 		@XmlElement(required=true)
 		private Result result;
@@ -50,12 +46,16 @@ public class TestCaseChange {
 				PriceList fromPriceList, PriceList toPriceList,
 				PhaseType fromType, 
 				Result result) {
-			super(from, to, 
-					fromProductCategory, toProductCategory,
-					fromBP, toBP, 
-					fromPriceList, toPriceList,
-					fromType, 
-					result);
+			setFromProduct(from);
+			setToProduct(to);
+			setFromProductCategory(fromProductCategory);
+			setToProductCategory(toProductCategory);
+			setFromPriceList(fromPriceList);
+			setToPriceList(toPriceList);
+			setFromBillingPeriod(fromBP);
+			setToBillingPeriod(toBP);
+			setPhaseType(fromType);
+			
 			this.result = result;
 		}
 
@@ -959,6 +959,72 @@ public class TestCaseChange {
 	}
 	
 	
+	@Test(enabled=true)
+	public void testOrder(){
+		MockCatalog cat = new MockCatalog();
+
+		Product product1 = cat.getProducts()[0];
+		PriceList priceList1 = cat.getPriceListFromName(IPriceListSet.DEFAULT_PRICELIST_NAME);
+
+		Product product2 = cat.getProducts()[2];
+		PriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
+
+
+		CaseChangeResult cr0 = new CaseChangeResult(
+				product1, product2,
+				ProductCategory.BASE, ProductCategory.BASE,
+				BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, 
+				priceList1,priceList2,
+				PhaseType.EVERGREEN,
+				Result.FOO);
+
+		CaseChangeResult cr1 = new CaseChangeResult(
+				product1, product2,
+				ProductCategory.BASE, ProductCategory.BASE,
+				BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, 
+				priceList1,priceList2,
+				PhaseType.EVERGREEN,
+				Result.BAR);
+
+		CaseChangeResult cr2 = new CaseChangeResult(
+				product1, product2,
+				ProductCategory.BASE, ProductCategory.BASE,
+				BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, 
+				priceList1,priceList2,
+				PhaseType.EVERGREEN,
+				Result.TINKYWINKY);
+
+		CaseChangeResult cr3 = new CaseChangeResult(
+				product1, product2,
+				ProductCategory.BASE, ProductCategory.BASE,
+				BillingPeriod.MONTHLY, BillingPeriod.ANNUAL, 
+				priceList1,priceList2,
+				PhaseType.EVERGREEN,
+				Result.DIPSY);
+
+		CaseChangeResult cr4 = new CaseChangeResult(
+				product1, product2,
+				ProductCategory.BASE, ProductCategory.BASE,
+				BillingPeriod.MONTHLY, BillingPeriod.ANNUAL, 
+				priceList1,priceList2,
+				PhaseType.EVERGREEN,
+				Result.LALA);
+		
+		Result r1 = CaseChange.getResult(new CaseChangeResult[]{ cr0, cr1, cr2, cr3, cr4 }, 
+				new PlanPhaseSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN), 
+				new PlanSpecifier(product2.getName(), product2.getCategory(), BillingPeriod.MONTHLY, priceList2.getName()), cat);
+
+		assertEquals(Result.FOO,r1);
+		
+		Result r2 = CaseChange.getResult(new CaseChangeResult[]{ cr0, cr1, cr2, cr3, cr4 }, 
+				new PlanPhaseSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN), 
+				new PlanSpecifier(product2.getName(), product2.getCategory(), BillingPeriod.ANNUAL, priceList2.getName()), cat);
+
+		assertEquals(Result.DIPSY,r2);
+		
+	}
+	
+	
 	protected void assertionNull(CaseChangeResult cr, 
 			String fromProductName, String toProductName,
 			ProductCategory fromProductCategory, ProductCategory toProductCategory, 
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCasePhase.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCasePhase.java
index 676d460..32c8354 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCasePhase.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCasePhase.java
@@ -34,9 +34,6 @@ import com.ning.billing.catalog.api.ProductCategory;
 import com.ning.billing.catalog.rules.CasePhase;
 
 public class TestCasePhase {
-	protected enum Result {
-		FOO, BAR, WIBBLE
-	}
 	protected class CaseResult extends CasePhase<Result>  {
 
 		@XmlElement(required=true)
@@ -44,7 +41,12 @@ public class TestCasePhase {
 
 		public CaseResult(Product product, ProductCategory productCategory, BillingPeriod billingPeriod, PriceList priceList,
 				PhaseType phaseType, Result policy) {
-			super(product, productCategory, billingPeriod, priceList, phaseType, policy);
+			setProduct(product);
+			setProductCategory(productCategory);
+			setBillingPeriod(billingPeriod);
+			setPriceList(priceList);
+			setPhaseType(phaseType);
+			
 			this.policy = policy;
 		}
 
@@ -197,6 +199,67 @@ public class TestCasePhase {
 		assertionNull(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);
 	}
+	
+	@Test(enabled=true)
+	public void testOrder(){
+		MockCatalog cat = new MockCatalog();
+
+		Product product = cat.getProducts()[0];
+		PriceList priceList = cat.getPriceLists().getDefaultPricelist();
+
+
+		CaseResult cr0 = new CaseResult(
+				product, 
+				ProductCategory.BASE,
+				BillingPeriod.MONTHLY, 
+				priceList,
+				PhaseType.EVERGREEN, 
+				Result.FOO);
+
+		CaseResult cr1 = new CaseResult(
+				product, 
+				ProductCategory.BASE,
+				BillingPeriod.MONTHLY, 
+				priceList,
+				PhaseType.EVERGREEN, 
+				Result.BAR);
+
+		CaseResult cr2 = new CaseResult(
+				product, 
+				ProductCategory.BASE,
+				BillingPeriod.MONTHLY, 
+				priceList,
+				PhaseType.EVERGREEN, 
+				Result.TINKYWINKY);
+
+		CaseResult cr3 = new CaseResult(
+				product, 
+				ProductCategory.BASE,
+				BillingPeriod.ANNUAL, 
+				priceList,
+				PhaseType.EVERGREEN, 
+				Result.DIPSY);
+
+		CaseResult cr4 = new CaseResult(
+				product, 
+				ProductCategory.BASE,
+				BillingPeriod.ANNUAL, 
+				priceList,
+				PhaseType.EVERGREEN, 
+				Result.LALA);
+		
+		Result r1 = CasePhase.getResult(new CaseResult[]{cr0, cr1, cr2,cr3,cr4}, 
+				new PlanPhaseSpecifier(product.getName(), product.getCategory(), BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN), cat);
+		
+		assertEquals(Result.FOO, r1);
+
+		Result r2 = CasePhase.getResult(new CaseResult[]{cr0, cr1, cr2,cr3,cr4}, 
+				new PlanPhaseSpecifier(product.getName(), product.getCategory(), BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN), cat);
+		
+		assertEquals(Result.DIPSY, r2);
+
+	}
+
 
 	protected void assertionNull(CaseResult cr, String productName, ProductCategory productCategory, BillingPeriod bp, String priceListName, PhaseType phaseType, Catalog cat){
 		assertNull(cr.getResult(new PlanPhaseSpecifier(productName, productCategory, bp, priceListName, phaseType), cat));
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanRules.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanRules.java
index 6fb2fbc..fac41a2 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanRules.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanRules.java
@@ -13,67 +13,114 @@
  * License for the specific language governing permissions and limitations
  * under the License.
  */
+
 package com.ning.billing.catalog.rules;
 
-import com.ning.billing.catalog.Catalog;
-import com.ning.billing.catalog.Plan;
+import junit.framework.Assert;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import com.ning.billing.catalog.MockCatalog;
 import com.ning.billing.catalog.PriceList;
 import com.ning.billing.catalog.Product;
-import com.ning.billing.catalog.api.ProductCategory;
-
+import com.ning.billing.catalog.api.ActionPolicy;
+import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.IPriceListSet;
+import com.ning.billing.catalog.api.IllegalPlanChange;
+import com.ning.billing.catalog.api.PhaseType;
+import com.ning.billing.catalog.api.PlanAlignmentChange;
+import com.ning.billing.catalog.api.PlanChangeResult;
+import com.ning.billing.catalog.api.PlanPhaseSpecifier;
+import com.ning.billing.catalog.api.PlanSpecifier;
 
 public class TestPlanRules {
+	Logger log = LoggerFactory.getLogger(TestPlanRules.class);
 
-	public Catalog createCatalog(PlanPolicyChangeRule[] generalRules, 
-			CaseChangePlanPolicy[] specialCaseRules,
-			CaseCancelPolicy[] cancelCaseRules,
-					Product fromP,
-					Product toP) {
-		Catalog c = new Catalog();
-		PlanRules pcr = new PlanRules(
-				new ProductTier[] {new ProductTier(new Product[]{ fromP, toP })},
-				generalRules,
-				specialCaseRules,
-				cancelCaseRules,
-				null,
-				null
-		);
-		c.setPlanChangeRules(pcr);
-		c.setProducts(new Product[] { fromP, toP });
-		return c;
-	}
-	
-	public Catalog createCatalog(PlanPolicyChangeRule[] generalRules, 
-			CaseChangePlanPolicy[] specialCaseRules,
-			CaseCancelPolicy[] cancelCaseRules,
-			CaseChangePlanAlignment[] alignmentChangeCases,
-					Product fromP,
-					Product toP) {
-		Catalog c = new Catalog();
-		PlanRules pcr = new PlanRules(
-				new ProductTier[] {new ProductTier(new Product[]{ fromP, toP })},
-				generalRules,
-				specialCaseRules,
-				cancelCaseRules,
-				alignmentChangeCases,
-				null
-		);
-
-		c.setPlanChangeRules(pcr);
-		c.setProducts(new Product[] { fromP, toP });
-		return c;
+	private MockCatalog cat = null;
+
+	@BeforeTest
+	public void setup() {
+		cat = new MockCatalog();
+
+		PriceList priceList2 = cat.getPriceLists().getChildPriceLists()[0];
+
+		CaseChangePlanPolicy casePolicy = new CaseChangePlanPolicy().setPolicy(ActionPolicy.END_OF_TERM);
+		CaseChangePlanAlignment caseAlignment = new CaseChangePlanAlignment().setAlignment(PlanAlignmentChange.START_OF_SUBSCRIPTION);
+		CasePriceList casePriceList = new CasePriceList().setToPriceList(priceList2);
+
+		cat.getPlanRules().
+		setChangeCase(new CaseChangePlanPolicy[]{casePolicy}).
+		setChangeAlignmentCase(new CaseChangePlanAlignment[]{caseAlignment}).
+		setPriceListCase(new CasePriceList[]{casePriceList});
 	}
 
-	
-	public Product createProduct(String name) {
-		return new Product(name, ProductCategory.BASE);
+	@Test
+	public void testCannotChangeToSamePlan() {
+		Product product1 = cat.getProducts()[0];
+		PriceList priceList1 = cat.getPriceListFromName(IPriceListSet.DEFAULT_PRICELIST_NAME);
+		
+		PlanPhaseSpecifier from = new PlanPhaseSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN);
+		PlanSpecifier to = new PlanSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName());
+
+		try {
+			cat.getPlanRules().planChange(from, to, cat);
+			Assert.fail("We did not see an exception when  trying to change plan to the same plan");
+		} catch (IllegalPlanChange e) {
+			log.info("Correct - cannot change to the same plan:", e);
+		}
+
 	}
 	
+	@Test
+	public void testExistingPriceListIsKept() {
+		Product product1 = cat.getProducts()[0];
+		PriceList priceList1 = cat.getPriceListFromName(IPriceListSet.DEFAULT_PRICELIST_NAME);
+		
+		PlanPhaseSpecifier from = new PlanPhaseSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN);
+		PlanSpecifier to = new PlanSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.ANNUAL, priceList1.getName());
+
+		PlanChangeResult result = null;
+		try {
+			result = cat.getPlanRules().planChange(from, to, cat);		
+		} catch (IllegalPlanChange e) {
+			log.info("Correct - cannot change to the same plan:", e);
+			Assert.fail("We should not have triggered this error");
+		}
+		
+		Assert.assertEquals(result.getPolicy(), ActionPolicy.END_OF_TERM);
+		Assert.assertEquals(result.getAlignment(), PlanAlignmentChange.START_OF_SUBSCRIPTION);
+		Assert.assertEquals(result.getNewPriceList(), priceList1);
 
-	protected PriceList createPriceList(String name) {
-		PriceList result = new PriceList(new Plan[]{},name);
-		return result;
 	}
+	
+	
+	@Test
+	public void testBaseCase() {
+		Product product1 = cat.getProducts()[0];
+		Product product2 = cat.getProducts()[1];
+		PriceList priceList1 = cat.getPriceListFromName(IPriceListSet.DEFAULT_PRICELIST_NAME);
+		PriceList priceList2 = cat.getPriceLists().getChildPriceLists()[0];
+		
+		PlanPhaseSpecifier from = new PlanPhaseSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN);
+		PlanSpecifier to = new PlanSpecifier(product2.getName(), product2.getCategory(), BillingPeriod.MONTHLY, null);
 
+		PlanChangeResult result = null;
+		try {
+			result = cat.getPlanRules().planChange(from, to, cat);		
+		} catch (IllegalPlanChange e) {
+			log.info("Correct - cannot change to the same plan:", e);
+			Assert.fail("We should not have triggered this error");
+		}
+		
+		Assert.assertEquals(result.getPolicy(), ActionPolicy.END_OF_TERM);
+		Assert.assertEquals(result.getAlignment(), PlanAlignmentChange.START_OF_SUBSCRIPTION);
+		Assert.assertEquals(result.getNewPriceList(), priceList2);
 
+	}
+	
+	
+	
 }
diff --git a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-1.xml b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-1.xml
index dacf37c..a29e929 100644
--- a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-1.xml
+++ b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-1.xml
@@ -40,43 +40,26 @@
 	</products>
 	 
 	<rules>
-		<tiers>
-			<tier>
-				<product>Pistol</product>
-				<product>Shotgun</product>
-			</tier>
-		</tiers>
-		<changePolicyRule>
-			<qualifier>DEFAULT</qualifier>
-			<policy>END_OF_TERM</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>TERM_FROM_SHORT_TO_LONG</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>PRODUCT_FROM_LOW_TO_HIGH</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>PRODUCT_FROM_LOW_TO_HIGH</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyCase> 
-			<fromBillingPeriod>MONTHLY</fromBillingPeriod>
-			<toProduct>Shotgun</toProduct>
-			<toBillingPeriod>MONTHLY</toBillingPeriod>
-			<policy>END_OF_TERM</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<phaseType>TRIAL</phaseType>
-			<policy>IMMEDIATE</policy>
-		</changePolicyCase>	
-		<changeAlignmentCase>
-			<alignment>START_OF_SUBSCRIPTION</alignment>
-		</changeAlignmentCase>
+		<changePolicy>
+			<changePolicyCase> 
+				<fromBillingPeriod>MONTHLY</fromBillingPeriod>
+				<toProduct>Shotgun</toProduct>
+				<toBillingPeriod>MONTHLY</toBillingPeriod>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<phaseType>TRIAL</phaseType>
+				<policy>IMMEDIATE</policy>
+			</changePolicyCase>	
+		</changePolicy>
+		<changeAlignment>
+			<changeAlignmentCase>
+				<alignment>START_OF_SUBSCRIPTION</alignment>
+			</changeAlignmentCase>
+		</changeAlignment>
 	</rules>
 
+
 	<plans>
 		<plan name="pistol-monthly">
 			<product>Pistol</product>
diff --git a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-2.xml b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-2.xml
index 5e42c30..135a89e 100644
--- a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-2.xml
+++ b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-2.xml
@@ -40,41 +40,23 @@
 	</products>
 	 
 	<rules>
-		<tiers>
-			<tier>
-				<product>Pistol</product>
-				<product>Shotgun</product>
-			</tier>
-		</tiers>
-		<changePolicyRule>
-			<qualifier>DEFAULT</qualifier>
-			<policy>END_OF_TERM</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>TERM_FROM_SHORT_TO_LONG</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>PRODUCT_FROM_LOW_TO_HIGH</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>PRODUCT_FROM_LOW_TO_HIGH</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyCase> 
-			<fromBillingPeriod>MONTHLY</fromBillingPeriod>
-			<toProduct>Shotgun</toProduct>
-			<toBillingPeriod>MONTHLY</toBillingPeriod>
-			<policy>END_OF_TERM</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<phaseType>TRIAL</phaseType>
-			<policy>IMMEDIATE</policy>
-		</changePolicyCase>	
-		<changeAlignmentCase>
-			<alignment>START_OF_SUBSCRIPTION</alignment>
-		</changeAlignmentCase>
+		<changePolicy>
+			<changePolicyCase> 
+				<fromBillingPeriod>MONTHLY</fromBillingPeriod>
+				<toProduct>Shotgun</toProduct>
+				<toBillingPeriod>MONTHLY</toBillingPeriod>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<phaseType>TRIAL</phaseType>
+				<policy>IMMEDIATE</policy>
+			</changePolicyCase>	
+		</changePolicy>
+		<changeAlignment>
+			<changeAlignmentCase>
+				<alignment>START_OF_SUBSCRIPTION</alignment>
+			</changeAlignmentCase>
+		</changeAlignment>
 	</rules>
 
 	<plans>
diff --git a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-3.xml b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-3.xml
index cb2a91a..747f54b 100644
--- a/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-3.xml
+++ b/catalog/src/test/resources/versionedCatalog/WeaponsHireSmall-3.xml
@@ -40,43 +40,26 @@
 	</products>
 	 
 	<rules>
-		<tiers>
-			<tier>
-				<product>Pistol</product>
-				<product>Shotgun</product>
-			</tier>
-		</tiers>
-		<changePolicyRule>
-			<qualifier>DEFAULT</qualifier>
-			<policy>END_OF_TERM</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>TERM_FROM_SHORT_TO_LONG</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>PRODUCT_FROM_LOW_TO_HIGH</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>PRODUCT_FROM_LOW_TO_HIGH</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyCase> 
-			<fromBillingPeriod>MONTHLY</fromBillingPeriod>
-			<toProduct>Shotgun</toProduct>
-			<toBillingPeriod>MONTHLY</toBillingPeriod>
-			<policy>END_OF_TERM</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<phaseType>TRIAL</phaseType>
-			<policy>IMMEDIATE</policy>
-		</changePolicyCase>	
-		<changeAlignmentCase>
-			<alignment>START_OF_SUBSCRIPTION</alignment>
-		</changeAlignmentCase>
+		<changePolicy>
+			<changePolicyCase> 
+				<fromBillingPeriod>MONTHLY</fromBillingPeriod>
+				<toProduct>Shotgun</toProduct>
+				<toBillingPeriod>MONTHLY</toBillingPeriod>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<phaseType>TRIAL</phaseType>
+				<policy>IMMEDIATE</policy>
+			</changePolicyCase>	
+		</changePolicy>
+		<changeAlignment>
+			<changeAlignmentCase>
+				<alignment>START_OF_SUBSCRIPTION</alignment>
+			</changeAlignmentCase>
+		</changeAlignment>
 	</rules>
 
+
 	<plans>
 		<plan name="pistol-monthly">
 			<product>Pistol</product>
diff --git a/catalog/src/test/resources/WeaponsHire.xml b/catalog/src/test/resources/WeaponsHire.xml
index 29b89d2..740a903 100644
--- a/catalog/src/test/resources/WeaponsHire.xml
+++ b/catalog/src/test/resources/WeaponsHire.xml
@@ -86,107 +86,100 @@ Use Cases to do:
 	</products>
 	 
 	<rules>
-		<tiers>
-			<tier>
-				<product>Pistol</product>
-				<product>Shotgun</product>
-				<product>Assault-Rifle</product>
-			</tier>
-		</tiers>
-		<changePolicyRule>
-			<qualifier>DEFAULT</qualifier>
-			<policy>END_OF_TERM</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>TERM_FROM_SHORT_TO_LONG</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>PRODUCT_FROM_LOW_TO_HIGH</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyCase> 
-			<policy>END_OF_TERM</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<toProduct>Assault-Rifle</toProduct>
-			<policy>IMMEDIATE</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<toProduct>Pistol</toProduct>
-			<policy>END_OF_TERM</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<fromProduct>Pistol</fromProduct>
-			<toProduct>Shotgun</toProduct>
-			<policy>IMMEDIATE</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<fromProduct>Assault-Rifle</fromProduct>
-			<toProduct>Shotgun</toProduct>
-			<policy>END_OF_TERM</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<fromBillingPeriod>MONTHLY</fromBillingPeriod>
-			<toBillingPeriod>ANNUAL</toBillingPeriod>
-			<policy>IMMEDIATE</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<fromBillingPeriod>ANNUAL</fromBillingPeriod>
-			<toBillingPeriod>MONTHLY</toBillingPeriod>
-			<policy>END_OF_TERM</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<fromBillingPeriod>MONTHLY</fromBillingPeriod>
-			<toProduct>Assault-Rifle</toProduct>
-			<toBillingPeriod>MONTHLY</toBillingPeriod>
-			<policy>END_OF_TERM</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<toPriceList>rescue</toPriceList>
-			<policy>END_OF_TERM</policy>
-		</changePolicyCase>		
-		<changePolicyCase> 
-			<phaseType>TRIAL</phaseType>
-			<policy>IMMEDIATE</policy>
-		</changePolicyCase>
-		<changeAlignmentCase>
-			<alignment>START_OF_SUBSCRIPTION</alignment>
-		</changeAlignmentCase>
-		<changeAlignmentCase>
-			<toPriceList>rescue</toPriceList>
-			<alignment>CHANGE_OF_PLAN</alignment>
-		</changeAlignmentCase>
-		<changeAlignmentCase>
-			<fromPriceList>rescue</fromPriceList>
-			<toPriceList>rescue</toPriceList>
-			<alignment>CHANGE_OF_PRICELIST</alignment>
-		</changeAlignmentCase>
-		<cancelPolicyCase>
-			<policy>END_OF_TERM</policy>
-		</cancelPolicyCase>
-		<cancelPolicyCase>
-			<phaseType>TRIAL</phaseType>
-			<policy>IMMEDIATE</policy>
-		</cancelPolicyCase>
-		<createAlignmentCase>
-			<alignment>START_OF_BUNDLE</alignment>
-		</createAlignmentCase>
+		<changePolicy>
+			<changePolicyCase> 
+				<phaseType>TRIAL</phaseType>
+				<policy>IMMEDIATE</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<toProduct>Pistol</toProduct>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<toPriceList>rescue</toPriceList>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>		
+			<changePolicyCase> 
+				<fromProduct>Pistol</fromProduct>
+				<toProduct>Shotgun</toProduct>
+				<policy>IMMEDIATE</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<fromProduct>Assault-Rifle</fromProduct>
+				<toProduct>Shotgun</toProduct>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<fromBillingPeriod>MONTHLY</fromBillingPeriod>
+				<toProduct>Assault-Rifle</toProduct>
+				<toBillingPeriod>MONTHLY</toBillingPeriod>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<toProduct>Assault-Rifle</toProduct>
+				<policy>IMMEDIATE</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<fromBillingPeriod>MONTHLY</fromBillingPeriod>
+				<toBillingPeriod>ANNUAL</toBillingPeriod>
+				<policy>IMMEDIATE</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<fromBillingPeriod>ANNUAL</fromBillingPeriod>
+				<toBillingPeriod>MONTHLY</toBillingPeriod>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+		</changePolicy>
+		<changeAlignment>
+			<changeAlignmentCase>
+				<alignment>START_OF_SUBSCRIPTION</alignment>
+			</changeAlignmentCase>
+			<changeAlignmentCase>
+				<toPriceList>rescue</toPriceList>
+				<alignment>CHANGE_OF_PLAN</alignment>
+			</changeAlignmentCase>
+			<changeAlignmentCase>
+				<fromPriceList>rescue</fromPriceList>
+				<toPriceList>rescue</toPriceList>
+				<alignment>CHANGE_OF_PRICELIST</alignment>
+			</changeAlignmentCase>
+		</changeAlignment>
+		<cancelPolicy>
+			<cancelPolicyCase>
+				<policy>END_OF_TERM</policy>
+			</cancelPolicyCase>
+			<cancelPolicyCase>
+				<phaseType>TRIAL</phaseType>
+				<policy>IMMEDIATE</policy>
+			</cancelPolicyCase>
+		</cancelPolicy>
+		<createAlignment>
+			<createAlignmentCase>
+				<alignment>START_OF_BUNDLE</alignment>
+			</createAlignmentCase>
+		</createAlignment>
+		<billingAlignment>
 		<billingAlignmentCase>
 			<alignment>ACCOUNT</alignment>
 		</billingAlignmentCase>
-		<billingAlignmentCase>
-			<billingPeriod>ANNUAL</billingPeriod>
-			<alignment>SUBSCRIPTION</alignment>
-		</billingAlignmentCase>
-		<billingAlignmentCase>
-			<productCategory>ADD_ON</productCategory>
-			<alignment>BUNDLE</alignment>
-		</billingAlignmentCase>
-		<priceListCase>
-			<fromPriceList>rescue</fromPriceList>
-			<toPriceList>DEFAULT</toPriceList>
-		</priceListCase>
+			<billingAlignmentCase>
+				<billingPeriod>ANNUAL</billingPeriod>
+				<alignment>SUBSCRIPTION</alignment>
+			</billingAlignmentCase>
+			<billingAlignmentCase>
+				<productCategory>ADD_ON</productCategory>
+				<alignment>BUNDLE</alignment>
+			</billingAlignmentCase>
+		</billingAlignment>
+		<priceList>
+			<priceListCase>
+				<fromPriceList>rescue</fromPriceList>
+				<toPriceList>DEFAULT</toPriceList>
+			</priceListCase>
+		</priceList>
 	</rules>
 
 	<plans>
diff --git a/catalog/src/test/resources/WeaponsHireSmall.xml b/catalog/src/test/resources/WeaponsHireSmall.xml
index e8150c0..0a3ed52 100644
--- a/catalog/src/test/resources/WeaponsHireSmall.xml
+++ b/catalog/src/test/resources/WeaponsHireSmall.xml
@@ -40,41 +40,23 @@
 	</products>
 	 
 	<rules>
-		<tiers>
-			<tier>
-				<product>Pistol</product>
-				<product>Shotgun</product>
-			</tier>
-		</tiers>
-		<changePolicyRule>
-			<qualifier>DEFAULT</qualifier>
-			<policy>END_OF_TERM</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>TERM_FROM_SHORT_TO_LONG</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>PRODUCT_FROM_LOW_TO_HIGH</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>PRODUCT_FROM_LOW_TO_HIGH</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyCase> 
-			<fromBillingPeriod>MONTHLY</fromBillingPeriod>
-			<toProduct>Shotgun</toProduct>
-			<toBillingPeriod>MONTHLY</toBillingPeriod>
-			<policy>END_OF_TERM</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<phaseType>TRIAL</phaseType>
-			<policy>IMMEDIATE</policy>
-		</changePolicyCase>	
-		<changeAlignmentCase>
-			<alignment>START_OF_SUBSCRIPTION</alignment>
-		</changeAlignmentCase>
+		<changePolicy>
+			<changePolicyCase> 
+				<fromBillingPeriod>MONTHLY</fromBillingPeriod>
+				<toProduct>Shotgun</toProduct>
+				<toBillingPeriod>MONTHLY</toBillingPeriod>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<phaseType>TRIAL</phaseType>
+				<policy>IMMEDIATE</policy>
+			</changePolicyCase>	
+		</changePolicy>
+		<changeAlignment>
+			<changeAlignmentCase>
+				<alignment>START_OF_SUBSCRIPTION</alignment>
+			</changeAlignmentCase>
+		</changeAlignment>
 	</rules>
 
 	<plans>
diff --git a/entitlement/src/test/resources/testInput.xml b/entitlement/src/test/resources/testInput.xml
index 9ded8fa..740a903 100644
--- a/entitlement/src/test/resources/testInput.xml
+++ b/entitlement/src/test/resources/testInput.xml
@@ -86,76 +86,100 @@ Use Cases to do:
 	</products>
 	 
 	<rules>
-		<tiers>
-			<tier>
-				<product>Pistol</product>
-				<product>Shotgun</product>
-				<product>Assault-Rifle</product>
-			</tier>
-		</tiers>
-		<changePolicyRule>
-			<qualifier>DEFAULT</qualifier>
-			<policy>END_OF_TERM</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>TERM_FROM_SHORT_TO_LONG</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyRule>
-			<qualifier>PRODUCT_FROM_LOW_TO_HIGH</qualifier>
-			<policy>IMMEDIATE</policy>
-		</changePolicyRule>
-		<changePolicyCase> 
-			<fromBillingPeriod>MONTHLY</fromBillingPeriod>
-			<toProduct>Assault-Rifle</toProduct>
-			<toBillingPeriod>MONTHLY</toBillingPeriod>
-			<policy>END_OF_TERM</policy>
-		</changePolicyCase>
-		<changePolicyCase> 
-			<toPriceList>rescue</toPriceList>
-			<policy>END_OF_TERM</policy>
-		</changePolicyCase>		
-		<changePolicyCase> 
-			<phaseType>TRIAL</phaseType>
-			<policy>IMMEDIATE</policy>
-		</changePolicyCase>
-		<changeAlignmentCase>
-			<alignment>START_OF_SUBSCRIPTION</alignment>
-		</changeAlignmentCase>
-		<changeAlignmentCase>
-			<toPriceList>rescue</toPriceList>
-			<alignment>CHANGE_OF_PLAN</alignment>
-		</changeAlignmentCase>
-		<changeAlignmentCase>
-			<fromPriceList>rescue</fromPriceList>
-			<toPriceList>rescue</toPriceList>
-			<alignment>CHANGE_OF_PRICELIST</alignment>
-		</changeAlignmentCase>
-		<cancelPolicyCase>
-			<policy>END_OF_TERM</policy>
-		</cancelPolicyCase>
-		<cancelPolicyCase>
-			<phaseType>TRIAL</phaseType>
-			<policy>IMMEDIATE</policy>
-		</cancelPolicyCase>
-		<createAlignmentCase>
-			<alignment>START_OF_BUNDLE</alignment>
-		</createAlignmentCase>
+		<changePolicy>
+			<changePolicyCase> 
+				<phaseType>TRIAL</phaseType>
+				<policy>IMMEDIATE</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<toProduct>Pistol</toProduct>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<toPriceList>rescue</toPriceList>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>		
+			<changePolicyCase> 
+				<fromProduct>Pistol</fromProduct>
+				<toProduct>Shotgun</toProduct>
+				<policy>IMMEDIATE</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<fromProduct>Assault-Rifle</fromProduct>
+				<toProduct>Shotgun</toProduct>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<fromBillingPeriod>MONTHLY</fromBillingPeriod>
+				<toProduct>Assault-Rifle</toProduct>
+				<toBillingPeriod>MONTHLY</toBillingPeriod>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<toProduct>Assault-Rifle</toProduct>
+				<policy>IMMEDIATE</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<fromBillingPeriod>MONTHLY</fromBillingPeriod>
+				<toBillingPeriod>ANNUAL</toBillingPeriod>
+				<policy>IMMEDIATE</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<fromBillingPeriod>ANNUAL</fromBillingPeriod>
+				<toBillingPeriod>MONTHLY</toBillingPeriod>
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+			<changePolicyCase> 
+				<policy>END_OF_TERM</policy>
+			</changePolicyCase>
+		</changePolicy>
+		<changeAlignment>
+			<changeAlignmentCase>
+				<alignment>START_OF_SUBSCRIPTION</alignment>
+			</changeAlignmentCase>
+			<changeAlignmentCase>
+				<toPriceList>rescue</toPriceList>
+				<alignment>CHANGE_OF_PLAN</alignment>
+			</changeAlignmentCase>
+			<changeAlignmentCase>
+				<fromPriceList>rescue</fromPriceList>
+				<toPriceList>rescue</toPriceList>
+				<alignment>CHANGE_OF_PRICELIST</alignment>
+			</changeAlignmentCase>
+		</changeAlignment>
+		<cancelPolicy>
+			<cancelPolicyCase>
+				<policy>END_OF_TERM</policy>
+			</cancelPolicyCase>
+			<cancelPolicyCase>
+				<phaseType>TRIAL</phaseType>
+				<policy>IMMEDIATE</policy>
+			</cancelPolicyCase>
+		</cancelPolicy>
+		<createAlignment>
+			<createAlignmentCase>
+				<alignment>START_OF_BUNDLE</alignment>
+			</createAlignmentCase>
+		</createAlignment>
+		<billingAlignment>
 		<billingAlignmentCase>
 			<alignment>ACCOUNT</alignment>
 		</billingAlignmentCase>
-		<billingAlignmentCase>
-			<billingPeriod>ANNUAL</billingPeriod>
-			<alignment>SUBSCRIPTION</alignment>
-		</billingAlignmentCase>
-		<billingAlignmentCase>
-			<productCategory>ADD_ON</productCategory>
-			<alignment>BUNDLE</alignment>
-		</billingAlignmentCase>
-		<priceListCase>
-			<fromPriceList>rescue</fromPriceList>
-			<toPriceList>DEFAULT</toPriceList>
-		</priceListCase>
+			<billingAlignmentCase>
+				<billingPeriod>ANNUAL</billingPeriod>
+				<alignment>SUBSCRIPTION</alignment>
+			</billingAlignmentCase>
+			<billingAlignmentCase>
+				<productCategory>ADD_ON</productCategory>
+				<alignment>BUNDLE</alignment>
+			</billingAlignmentCase>
+		</billingAlignment>
+		<priceList>
+			<priceListCase>
+				<fromPriceList>rescue</fromPriceList>
+				<toPriceList>DEFAULT</toPriceList>
+			</priceListCase>
+		</priceList>
 	</rules>
 
 	<plans>