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.module.chart.service;
017:
018: import java.util.Collections;
019: import java.util.List;
020:
021: import org.kuali.kfs.context.KualiTestBase;
022: import org.kuali.module.chart.bo.Org;
023: import org.kuali.module.chart.dao.OrganizationDao;
024: import org.kuali.module.chart.service.impl.OrganizationServiceImpl;
025:
026: /**
027: * This class tests the Organization service.
028: */
029: public class OrganizationServiceTest extends KualiTestBase {
030: private OrganizationServiceImpl organizationService;
031: private FakeOrganizationDao organizationDao;
032:
033: @Override
034: protected void setUp() throws Exception {
035: super .setUp();
036:
037: organizationDao = new FakeOrganizationDao();
038: organizationService = new OrganizationServiceImpl();
039: organizationService.setOrganizationDao(organizationDao);
040: }
041:
042: public void testSave() throws Exception {
043: Org o = new Org();
044: o.setChartOfAccountsCode("XX");
045: o.setOrganizationCode("ZZZZ");
046: o.setOrganizationName("Sleep Org");
047:
048: organizationService.save(o);
049: assertNotNull("Didn't save", organizationDao.saved);
050: assertEquals("Wrong chart", "XX", organizationDao.saved
051: .getChartOfAccountsCode());
052: assertEquals("Wrong code", "ZZZZ", organizationDao.saved
053: .getOrganizationCode());
054: assertEquals("Wrong name", "Sleep Org", organizationDao.saved
055: .getOrganizationName());
056: }
057:
058: public void testGetByPrimaryId() throws Exception {
059: Org o = new Org();
060: o.setChartOfAccountsCode("XX");
061: o.setOrganizationCode("ZZZZ");
062: o.setOrganizationName("Sleep Org");
063:
064: organizationDao.retrieved = o;
065: Org retrieved = organizationService.getByPrimaryId("X", "Y");
066: assertNotNull("Didn't save", retrieved);
067: assertEquals("Wrong chart", "XX", retrieved
068: .getChartOfAccountsCode());
069: assertEquals("Wrong code", "ZZZZ", retrieved
070: .getOrganizationCode());
071: assertEquals("Wrong name", "Sleep Org", retrieved
072: .getOrganizationName());
073:
074: organizationDao.retrieved = null;
075: retrieved = organizationService.getByPrimaryId("X", "Y");
076: assertNull("Retrieved org that shouldn't have existed",
077: retrieved);
078: }
079:
080: class FakeOrganizationDao implements OrganizationDao {
081: public Org saved;
082: public Org retrieved;
083:
084: public Org getByPrimaryId(String chartOfAccountsCode,
085: String organizationCode) {
086: return retrieved;
087: }
088:
089: public void save(Org organization) {
090: saved = organization;
091: }
092:
093: public List getActiveAccountsByOrg(String chartOfAccountsCode,
094: String organizationCode) {
095: return Collections.EMPTY_LIST;
096: }
097:
098: public List getActiveChildOrgs(String chartOfAccountsCode,
099: String organizationCode) {
100: return Collections.EMPTY_LIST;
101: }
102:
103: public List<Org> getActiveOrgsByType(String organizationTypeCode) {
104: return Collections.EMPTY_LIST;
105: }
106:
107: public String[] getRootOrganizationCode(String rootChart,
108: String selfReportsORgType) {
109: String[] returnValues = { null, null };
110: return returnValues;
111: }
112:
113: }
114: }
|