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.ArrayList;
019: import java.util.Collection;
020:
021: import org.kuali.core.bo.KualiCode;
022: import org.kuali.kfs.context.KualiTestBase;
023: import org.kuali.kfs.dao.KualiCodeDao;
024: import org.kuali.kfs.service.impl.KualiCodeServiceImpl;
025: import org.springframework.dao.DataAccessException;
026:
027: /**
028: * This class tests the BudgetAggregationCode service.
029: */
030: public class KualiCodeServiceTest extends KualiTestBase {
031: KualiCodeServiceImpl kualiCodeService;
032: FakeKualiCodeDao kualiCodeDao;
033:
034: @Override
035: protected void setUp() throws Exception {
036: super .setUp();
037: kualiCodeDao = new FakeKualiCodeDao();
038: kualiCodeService = new KualiCodeServiceImpl();
039: kualiCodeService.setKualiCodeDao(kualiCodeDao);
040: }
041:
042: public void testGetByCode() throws Exception {
043: KualiCode code = kualiCodeService.getByCode(
044: FakeKualiCode.class, "XXX");
045: assertEquals("Wrong code", "CODE1", code.getCode());
046: assertEquals("Wrong name", "Name1", code.getName());
047: assertTrue("Wrong active code", code.isActive());
048: }
049:
050: public void testGetSystemCode() throws Exception {
051: KualiCode code = kualiCodeService.getSystemCode(
052: FakeKualiCode.class, "XXX");
053: assertEquals("Wrong code", "CODE1", code.getCode());
054: assertEquals("Wrong name", "Name1", code.getName());
055: assertTrue("Wrong active code", code.isActive());
056: }
057:
058: public void testGetByName() throws Exception {
059: KualiCode code = kualiCodeService.getByName(
060: FakeKualiCode.class, "XXX");
061: assertEquals("Wrong code", "CODE1", code.getCode());
062: assertEquals("Wrong name", "Name1", code.getName());
063: assertTrue("Wrong active code", code.isActive());
064: }
065:
066: public void testSave() throws Exception {
067: KualiCode code = new FakeKualiCode("CODE", "Name", true);
068: kualiCodeService.save(code);
069: assertNotNull("Didn't save", kualiCodeDao.saved);
070: assertEquals("Wrong code", "CODE", kualiCodeDao.saved.getCode());
071: assertEquals("Wrong name", "Name", kualiCodeDao.saved.getName());
072: assertTrue("Wrong active code", kualiCodeDao.saved.isActive());
073: }
074:
075: public void testGetAll() throws Exception {
076: Collection codes = kualiCodeService.getAll(FakeKualiCode.class);
077: assertNotNull("Null collection", codes);
078: assertEquals("Wrong collection size", 2, codes.size());
079: }
080:
081: class FakeKualiCode implements KualiCode {
082: private String code;
083: private boolean active;
084: private String name;
085:
086: public FakeKualiCode(String code, String name, boolean active) {
087: this .code = code;
088: this .active = active;
089: this .name = name;
090: }
091:
092: public String getCode() {
093: return code;
094: }
095:
096: public String getName() {
097: return name;
098: }
099:
100: public boolean isActive() {
101: return active;
102: }
103:
104: public void setActive(boolean a) {
105: active = a;
106: }
107:
108: public void setCode(String code) {
109: this .code = code;
110: }
111:
112: public void setName(String name) {
113: this .name = name;
114: }
115: }
116:
117: class FakeKualiCodeDao implements KualiCodeDao {
118: public boolean deleted = false;
119: public KualiCode saved = null;
120:
121: public void delete(KualiCode kualiCode) {
122: deleted = true;
123: }
124:
125: public Collection getAll(Class queryClass) {
126: Collection junk = new ArrayList();
127: junk.add(new FakeKualiCode("CODE1", "Name1", true));
128: junk.add(new FakeKualiCode("CODE2", "Name2", true));
129: return junk;
130: }
131:
132: public Collection getAllActive(Class queryClass) {
133: Collection junk = new ArrayList();
134: junk.add(new FakeKualiCode("CODE1", "Name1", true));
135: junk.add(new FakeKualiCode("CODE2", "Name2", true));
136: return junk;
137: }
138:
139: public KualiCode getByCode(Class queryClass, String code) {
140: return new FakeKualiCode("CODE1", "Name1", true);
141: }
142:
143: public KualiCode getByName(Class queryClass, String name) {
144: return new FakeKualiCode("CODE1", "Name1", true);
145: }
146:
147: public KualiCode getSystemCode(Class clazz, String code) {
148: return new FakeKualiCode("CODE1", "Name1", true);
149: }
150:
151: public void save(KualiCode kualiCode)
152: throws DataAccessException {
153: saved = kualiCode;
154: }
155: }
156: }
|