001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.purap.rules;
017:
018: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
019: import static org.kuali.test.fixtures.UserNameFixture.PARKE;
020:
021: import java.util.ArrayList;
022: import java.util.List;
023:
024: import org.kuali.module.purap.bo.PurchaseOrderItem;
025: import org.kuali.module.purap.bo.PurchaseOrderVendorStipulation;
026: import org.kuali.module.purap.document.PurchaseOrderDocument;
027: import org.kuali.module.purap.fixtures.AmountsLimitsFixture;
028: import org.kuali.module.purap.fixtures.ItemAccountsFixture;
029: import org.kuali.module.purap.fixtures.ItemTypesFixture;
030: import org.kuali.test.ConfigureContext;
031:
032: @ConfigureContext(session=KHUNTLEY)
033: public class PurchaseOrderDocumentRuleTest extends PurapRuleTestBase {
034:
035: PurchaseOrderDocumentRule rule;
036: PurchaseOrderDocument po;
037:
038: protected void setUp() throws Exception {
039: super .setUp();
040: po = new PurchaseOrderDocument();
041: rule = new PurchaseOrderDocumentRule();
042: }
043:
044: protected void tearDown() throws Exception {
045: rule = null;
046: po = null;
047: super .tearDown();
048: }
049:
050: /*
051: * Tests of validateEmptyItemWithAccounts
052: */
053: @ConfigureContext(session=PARKE)
054: public void testValidateEmptyItemWithAccounts_NullItemWithAccount() {
055: PurchaseOrderItem poItem = ItemAccountsFixture.NULL_ITEM_WITH_ACCOUNT
056: .populateItem();
057: assertFalse(rule.validateEmptyItemWithAccounts(poItem, "Item "
058: + poItem.getItemLineNumber().toString()));
059: }
060:
061: @ConfigureContext(session=PARKE)
062: public void testValidateEmptyItemWithAccounts_WithItemWithAccount() {
063: PurchaseOrderItem poItem = ItemAccountsFixture.WITH_QUANTITY_WITH_PRICE_WITH_ACCOUNT
064: .populateItem();
065: assertTrue(rule.validateEmptyItemWithAccounts(poItem, "Item "
066: + poItem.getItemLineNumber().toString()));
067: }
068:
069: @ConfigureContext(session=PARKE)
070: public void testValidateEmptyItemWithAccounts_WithItemWithoutAccount() {
071: PurchaseOrderItem poItem = ItemAccountsFixture.WITH_QUANTITY_WITH_PRICE_NULL_ACCOUNT
072: .populateItem();
073: assertTrue(rule.validateEmptyItemWithAccounts(poItem, "Item "
074: + poItem.getItemLineNumber().toString()));
075: }
076:
077: /*
078: * Tests of validateTotalDollarAmountIsLessThanPurchaseOrderTotalLimit
079: */
080: public void testValidateTotalDollarAmountIsLessThanPurchaseOrderTotalLimit_ZeroAmountSmallLimit() {
081: po = AmountsLimitsFixture.ZERO_AMOUNT_SMALL_LIMIT
082: .populatePurchaseOrder();
083: assertTrue(rule
084: .validateTotalDollarAmountIsLessThanPurchaseOrderTotalLimit(po));
085: }
086:
087: public void testValidateTotalDollarAmountIsLessThanPurchaseOrderTotalLimit_SmallAmountSmallLimit() {
088: po = AmountsLimitsFixture.SMALL_AMOUNT_SMALL_LIMIT
089: .populatePurchaseOrder();
090: assertTrue(rule
091: .validateTotalDollarAmountIsLessThanPurchaseOrderTotalLimit(po));
092: }
093:
094: public void testValidateTotalDollarAmountIsLessThanPurchaseOrderTotalLimit_LargeAmountSmallLimit() {
095: po = AmountsLimitsFixture.LARGE_AMOUNT_SMALL_LIMIT
096: .populatePurchaseOrder();
097: assertFalse(rule
098: .validateTotalDollarAmountIsLessThanPurchaseOrderTotalLimit(po));
099: }
100:
101: /*
102: * Tests of validateTradeInAndDiscountCoexistence
103: */
104: public void testValidateTradeInAndDiscountCoexistence_WithTradeInWithDiscount() {
105: po = ItemTypesFixture.WITH_TRADEIN_WITH_DISCOUNT.populate();
106: assertFalse(rule.validateTradeInAndDiscountCoexistence(po));
107: }
108:
109: public void testValidateTradeInAndDiscountCoexistence_WithTradeInWithMisc() {
110: po = ItemTypesFixture.WITH_TRADEIN_WITH_MISC.populate();
111: assertTrue(rule.validateTradeInAndDiscountCoexistence(po));
112: }
113:
114: public void testValidateTradeInAndDiscountCoexistence_WithDiscountWithMisc() {
115: po = ItemTypesFixture.WITH_MISC_WITH_DISCOUNT.populate();
116: assertTrue(rule.validateTradeInAndDiscountCoexistence(po));
117: }
118:
119: /*
120: * Tests of processVendorStipulationValidation
121: */
122: public void testProcessVendorStipulationValidation_NotBlank() {
123: po = new PurchaseOrderDocument();
124: PurchaseOrderVendorStipulation stip = new PurchaseOrderVendorStipulation();
125: stip.setVendorStipulationDescription("test");
126: List<PurchaseOrderVendorStipulation> stipulations = new ArrayList();
127: stipulations.add(stip);
128: po.setPurchaseOrderVendorStipulations(stipulations);
129: assertTrue(rule.processVendorStipulationValidation(po));
130: }
131:
132: public void testProcessVendorStipulationValidation_Blank() {
133: po = new PurchaseOrderDocument();
134: PurchaseOrderVendorStipulation stip = new PurchaseOrderVendorStipulation();
135: stip.setVendorStipulationDescription("");
136: List<PurchaseOrderVendorStipulation> stipulations = new ArrayList();
137: stipulations.add(stip);
138: po.setPurchaseOrderVendorStipulations(stipulations);
139: assertFalse(rule.processVendorStipulationValidation(po));
140: }
141: }
|