001: /*
002: * Copyright 2005-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.core.service;
017:
018: import java.util.Collection;
019: import java.util.HashMap;
020: import java.util.Iterator;
021:
022: import org.kuali.kfs.context.KualiTestBase;
023: import org.kuali.kfs.context.SpringContext;
024: import org.kuali.module.chart.bo.Account;
025: import org.kuali.module.chart.bo.Chart;
026: import org.kuali.module.chart.bo.ObjectType;
027: import org.kuali.module.chart.bo.Org;
028: import org.kuali.module.financial.bo.InternalBillingItem;
029: import org.kuali.test.ConfigureContext;
030: import org.kuali.test.suite.AnnotationTestSuite;
031: import org.kuali.test.suite.LookupRefactoringSuite;
032:
033: /**
034: * This class tests the Lookup service.
035: */
036: @ConfigureContext
037: @AnnotationTestSuite(LookupRefactoringSuite.class)
038: public class LookupServiceTest extends KualiTestBase {
039: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
040: .getLogger(LookupServiceTest.class);
041:
042: public void testAssummedLike() {
043: ObjectType otc = new ObjectType();
044: // test correct with like and wildcard
045: HashMap map = new HashMap();
046: map.put("name", "ASS%");
047: Collection collection = SpringContext.getBean(
048: LookupService.class).findCollectionBySearch(
049: otc.getClass(), map);
050:
051: assertEquals(1, collection.size());
052:
053: Iterator iter = collection.iterator();
054: ObjectType otcRetreived = (ObjectType) iter.next();
055: assertEquals(otcRetreived.getCode(), "AS");
056: // test incorrect value w like and wildcard
057: map = new HashMap();
058: map.put("name", "BASS%");
059: collection = SpringContext.getBean(LookupService.class)
060: .findCollectionBySearch(otc.getClass(), map);
061:
062: assertEquals(0, collection.size());
063: }
064:
065: public void testDateWithOps() {
066: // test date with >,<,>=,<=,..
067: Org org = new Org();
068:
069: // test the following date formats for one record
070: String[] dates = { "<1994-07-16", ">1991-07-16",
071: "<=1994-07-16", ">=1991-07-16",
072: "1991-07-16..2000-07-16" };
073: for (int i = 0; i < dates.length; i++) {
074: HashMap map = new HashMap();
075: map.put("organizationCode", "FMOP");
076: map.put("chartOfAccountsCode", "UA");
077: map.put("organizationBeginDate", dates[i]);
078:
079: Collection collection = SpringContext.getBean(
080: LookupService.class).findCollectionBySearch(
081: org.getClass(), map);
082: assertTrue(collection.size() >= 1);
083: }
084:
085: }
086:
087: public void testNumber() {
088: // test number without ops
089: HashMap map = new HashMap();
090: map.put("financialCashObjectCode", "8000");
091: Collection collection = SpringContext.getBean(
092: LookupService.class).findCollectionBySearch(
093: Chart.class, map);
094: assertTrue(collection.size() > 0);
095:
096: Iterator iter = collection.iterator();
097: Chart chart2 = (Chart) iter.next();
098:
099: assertEquals("8000", chart2.getFinancialCashObject()
100: .getFinancialObjectCode());
101: }
102:
103: public void testNumber2() {
104: // test incorrect number
105: HashMap map = new HashMap();
106: map.put("financialCashObjectCode", "6666");
107: Collection collection = SpringContext.getBean(
108: LookupService.class).findCollectionBySearch(
109: Chart.class, map);
110:
111: assertEquals(0, collection.size());
112:
113: }
114:
115: public void testNumberWithOps_lessThan() {
116: // test number (as string) with <
117: HashMap map = new HashMap();
118: map.put("itemUnitAmount", "<0");
119: Collection collection = SpringContext.getBean(
120: LookupService.class).findCollectionBySearch(
121: InternalBillingItem.class, map);
122:
123: // need better verification here
124: assertTrue(collection.size() == 0);
125: }
126:
127: public void testNumberWithOps_greaterThan() {
128: // test number with >
129: HashMap map = new HashMap();
130: map.put("itemSequenceId", ">1000000");
131: Collection collection = SpringContext.getBean(
132: LookupService.class).findCollectionBySearch(
133: InternalBillingItem.class, map);
134:
135: // need better verification here
136: assertTrue(collection.size() == 0);
137: }
138:
139: public void testBoolean() { // KULCOA-371
140: HashMap map = new HashMap();
141: map.put("accountNumber", "9*");
142: map.put("accountClosedIndicator", "Y");
143: Iterator iter = SpringContext.getBean(LookupService.class)
144: .findCollectionBySearch(Account.class, map).iterator();
145: assertTrue(iter.hasNext());
146: while (iter.hasNext()) {
147: Account account = (Account) iter.next();
148: LOG.debug(account);
149: assertTrue(account.isAccountClosedIndicator());
150: }
151: }
152:
153: }
|