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.vendor.service;
017:
018: import static org.kuali.module.vendor.fixtures.VendorAddressFixture.address1;
019: import static org.kuali.module.vendor.fixtures.VendorAddressFixture.address2;
020: import static org.kuali.module.vendor.fixtures.VendorAddressFixture.address3;
021: import static org.kuali.module.vendor.fixtures.VendorAddressFixture.address4;
022: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
023:
024: import java.util.ArrayList;
025: import java.util.List;
026:
027: import org.kuali.kfs.context.KualiTestBase;
028: import org.kuali.kfs.context.SpringContext;
029: import org.kuali.module.vendor.bo.VendorAddress;
030: import org.kuali.module.vendor.bo.VendorDetail;
031: import org.kuali.module.vendor.bo.VendorHeader;
032: import org.kuali.module.vendor.fixtures.VendorAddressFixture;
033: import org.kuali.module.vendor.fixtures.VendorRoutingChangesFixture;
034: import org.kuali.test.ConfigureContext;
035:
036: @ConfigureContext(session=KHUNTLEY)
037: public class VendorServiceTest extends KualiTestBase {
038:
039: public VendorDetail oldVDtl;
040: public VendorHeader oldVHdr;
041: public VendorDetail newVDtl;
042: public VendorHeader newVHdr;
043:
044: @Override
045: protected void setUp() throws Exception {
046: super .setUp();
047: oldVDtl = new VendorDetail();
048: oldVHdr = new VendorHeader();
049: newVDtl = new VendorDetail();
050: newVHdr = new VendorHeader();
051: }
052:
053: @Override
054: protected void tearDown() throws Exception {
055: oldVDtl = null;
056: oldVHdr = null;
057: newVDtl = null;
058: newVHdr = null;
059: super .tearDown();
060: }
061:
062: private List addresses;
063:
064: private void testGetVendorDefaultAddress(Integer expectedDefaultId,
065: List addresses, String addressType, String campus) {
066: VendorAddress address = SpringContext.getBean(
067: VendorService.class).getVendorDefaultAddress(addresses,
068: addressType, campus);
069: Integer resultDefaultId = null;
070: if (address != null) {
071: resultDefaultId = address
072: .getVendorAddressGeneratedIdentifier();
073: }
074: assertEquals("Did not get expected default", expectedDefaultId,
075: resultDefaultId);
076: }
077:
078: public void testGetVendorDefaultAddress_test1() {
079: addresses = setupAddresses(new VendorAddressFixture[] {
080: address1, address2 });
081: testGetVendorDefaultAddress(
082: address2.vendorAddressGeneratedIdentifier, addresses,
083: "PO", "IN");
084: }
085:
086: public void testGetVendorDefaultAddress_test2() {
087: addresses = setupAddresses(new VendorAddressFixture[] {
088: address1, address2 });
089: testGetVendorDefaultAddress(
090: address1.vendorAddressGeneratedIdentifier, addresses,
091: "PO", "BL");
092: }
093:
094: public void testGetVendorDefaultAddress_test3() {
095: addresses = setupAddresses(new VendorAddressFixture[] {
096: address1, address2 });
097: testGetVendorDefaultAddress(
098: address1.vendorAddressGeneratedIdentifier, addresses,
099: "PO", "");
100: }
101:
102: public void testGetVendorDefaultAddress_test4() {
103: addresses = setupAddresses(new VendorAddressFixture[] {
104: address1, address2 });
105: testGetVendorDefaultAddress(null, addresses, "RM", "BL");
106: }
107:
108: public void testGetVendorDefaultAddress_test5() {
109: addresses = setupAddresses(new VendorAddressFixture[] {
110: address1, address2, address3, address4 });
111: testGetVendorDefaultAddress(
112: address3.vendorAddressGeneratedIdentifier, addresses,
113: "RM", "BL");
114: }
115:
116: public void testGetVendorDefaultAddress_test6() {
117: addresses = setupAddresses(new VendorAddressFixture[] {
118: address1, address2, address3, address4 });
119: testGetVendorDefaultAddress(
120: address4.vendorAddressGeneratedIdentifier, addresses,
121: "RM", "SB");
122: }
123:
124: private List setupAddresses(VendorAddressFixture[] fixtures) {
125: addresses = new ArrayList();
126: for (VendorAddressFixture fixture : fixtures) {
127: addresses.add(fixture.createAddress());
128: }
129: return addresses;
130: }
131:
132: public void testNoRouteSignificantChangeOccurred_Complete_No_Changes() {
133: VendorRoutingChangesFixture fixture = VendorRoutingChangesFixture.COMPLETE_NO_CHANGES;
134: fixture.populate(oldVDtl, oldVHdr, newVDtl, newVHdr);
135: assertTrue(SpringContext.getBean(VendorService.class)
136: .noRouteSignificantChangeOccurred(oldVDtl, oldVHdr,
137: newVDtl, newVHdr));
138: }
139:
140: public void testNoRouteSignificantChangeOccurred_Complete_VH_Change() {
141: VendorRoutingChangesFixture fixture = VendorRoutingChangesFixture.COMPLETE_VH_CHANGE;
142: fixture.populate(oldVDtl, oldVHdr, newVDtl, newVHdr);
143: assertFalse(SpringContext.getBean(VendorService.class)
144: .noRouteSignificantChangeOccurred(oldVDtl, oldVHdr,
145: newVDtl, newVHdr));
146: }
147:
148: public void testNoRouteSignificantChangeOccurred_Complete_VSD1_Change() {
149: VendorRoutingChangesFixture fixture = VendorRoutingChangesFixture.COMPLETE_VSD1_CHANGE;
150: fixture.populate(oldVDtl, oldVHdr, newVDtl, newVHdr);
151: assertFalse(SpringContext.getBean(VendorService.class)
152: .noRouteSignificantChangeOccurred(oldVDtl, oldVHdr,
153: newVDtl, newVHdr));
154: }
155:
156: public void testNoRouteSignificantChangeOccurred_Complete_VSSC1_Change() {
157: VendorRoutingChangesFixture fixture = VendorRoutingChangesFixture.COMPLETE_VSSC1_CHANGE;
158: fixture.populate(oldVDtl, oldVHdr, newVDtl, newVHdr);
159: assertFalse(SpringContext.getBean(VendorService.class)
160: .noRouteSignificantChangeOccurred(oldVDtl, oldVHdr,
161: newVDtl, newVHdr));
162: }
163:
164: public void testNoRouteSignificantChangeOccurred_Complete_VA2_Change() {
165: VendorRoutingChangesFixture fixture = VendorRoutingChangesFixture.COMPLETE_VA2_CHANGE;
166: fixture.populate(oldVDtl, oldVHdr, newVDtl, newVHdr);
167: assertFalse(SpringContext.getBean(VendorService.class)
168: .noRouteSignificantChangeOccurred(oldVDtl, oldVHdr,
169: newVDtl, newVHdr));
170: }
171:
172: public void testNoRouteSignificantChangeOccurred_Null_Olds() {
173: VendorRoutingChangesFixture fixture = VendorRoutingChangesFixture.NULL_OLDS;
174: fixture.populate(oldVDtl, oldVHdr, newVDtl, newVHdr);
175: assertFalse(SpringContext.getBean(VendorService.class)
176: .noRouteSignificantChangeOccurred(oldVDtl, oldVHdr,
177: newVDtl, newVHdr));
178: }
179:
180: public void testNoRouteSignificantChangeOccurred_Null_News() {
181: VendorRoutingChangesFixture fixture = VendorRoutingChangesFixture.NULL_NEWS;
182: fixture.populate(oldVDtl, oldVHdr, newVDtl, newVHdr);
183: assertFalse(SpringContext.getBean(VendorService.class)
184: .noRouteSignificantChangeOccurred(oldVDtl, oldVHdr,
185: newVDtl, newVHdr));
186: }
187:
188: public void testNoRouteSignificantChangeOccurred_Null_All() {
189: VendorRoutingChangesFixture fixture = VendorRoutingChangesFixture.NULL_ALL;
190: fixture.populate(oldVDtl, oldVHdr, newVDtl, newVHdr);
191: assertTrue(SpringContext.getBean(VendorService.class)
192: .noRouteSignificantChangeOccurred(oldVDtl, oldVHdr,
193: newVDtl, newVHdr));
194: }
195: }
|