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 org.kuali.kfs.context.KualiTestBase;
019: import org.kuali.module.chart.bo.ProjectCode;
020: import org.kuali.module.chart.dao.ProjectCodeDao;
021: import org.kuali.module.chart.service.impl.ProjectCodeServiceImpl;
022:
023: /**
024: * This class tests the ProjectCode service.
025: */
026: public class ProjectCodeServiceTest extends KualiTestBase {
027: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
028: .getLogger(ProjectCodeServiceTest.class);
029:
030: private FakeProjectCodeDao projectCodeDao;
031: private ProjectCodeServiceImpl projectCodeService;
032:
033: @Override
034: protected void setUp() throws Exception {
035: super .setUp();
036:
037: projectCodeDao = new FakeProjectCodeDao();
038: projectCodeService = new ProjectCodeServiceImpl();
039: projectCodeService.setProjectCodeDao(projectCodeDao);
040: }
041:
042: public void testGetByPrimaryId() throws Exception {
043: ProjectCode pc = new ProjectCode();
044: pc.setCode("PROJ");
045: pc.setName("PROJ Name");
046:
047: projectCodeDao.retrieved = pc;
048: ProjectCode retrieved = projectCodeService
049: .getByPrimaryId("XXX");
050: assertNotNull("Didn't retrieve", retrieved);
051: assertEquals("Code is wrong", "PROJ", retrieved.getCode());
052: assertEquals("Name is wrong", "PROJ Name", retrieved.getName());
053:
054: projectCodeDao.retrieved = null;
055: retrieved = projectCodeService.getByPrimaryId("XXX");
056: assertNull("Didn't retrieve", retrieved);
057: }
058:
059: public void testGetByName() throws Exception {
060: ProjectCode pc = new ProjectCode();
061: pc.setCode("PROJ");
062: pc.setName("PROJ Name");
063:
064: projectCodeDao.retrieved = pc;
065: ProjectCode retrieved = projectCodeService
066: .getByPrimaryId("XXX");
067: assertNotNull("Didn't retrieve", retrieved);
068: assertEquals("Code is wrong", "PROJ", retrieved.getCode());
069: assertEquals("Name is wrong", "PROJ Name", retrieved.getName());
070:
071: projectCodeDao.retrieved = null;
072: retrieved = projectCodeService.getByPrimaryId("XXX");
073: assertNull("Didn't retrieve", retrieved);
074: }
075:
076: public void testSave() throws Exception {
077: ProjectCode pc = new ProjectCode();
078: pc.setCode("PROJ");
079: pc.setName("PROJ Name");
080:
081: projectCodeService.save(pc);
082: assertNotNull("Didn't save", projectCodeDao.saved);
083: assertEquals("Code is wrong", "PROJ", projectCodeDao.saved
084: .getCode());
085: assertEquals("Name is wrong", "PROJ Name", projectCodeDao.saved
086: .getName());
087: }
088:
089: class FakeProjectCodeDao implements ProjectCodeDao {
090: public ProjectCode retrieved = null;
091: public ProjectCode saved = null;
092:
093: public ProjectCode getByName(String name) {
094: return retrieved;
095: }
096:
097: public ProjectCode getByPrimaryId(String projectCode) {
098: return retrieved;
099: }
100:
101: public void save(ProjectCode projectCode) {
102: saved = projectCode;
103: }
104: }
105: }
|