01: /*
02: * Copyright 2006-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.module.chart.bo;
17:
18: import java.util.ArrayList;
19: import java.util.Collection;
20: import java.util.HashMap;
21: import java.util.List;
22: import java.util.Map;
23:
24: import org.kuali.core.service.BusinessObjectService;
25: import org.kuali.kfs.KFSConstants;
26: import org.kuali.kfs.context.KualiTestBase;
27: import org.kuali.kfs.context.SpringContext;
28: import org.kuali.test.ConfigureContext;
29:
30: @ConfigureContext
31: public class OrganizationRoutingModelTest extends KualiTestBase {
32:
33: OrganizationRoutingModel model;
34:
35: @Override
36: protected void setUp() throws Exception {
37: super .setUp();
38: Map<String, String> fieldValues = new HashMap<String, String>();
39: fieldValues
40: .put(KFSConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME,
41: "BL");
42: fieldValues.put(KFSConstants.ORGANIZATION_CODE_PROPERTY_NAME,
43: "CLAS");
44: List<OrganizationRoutingModel> results = (List<OrganizationRoutingModel>) SpringContext
45: .getBean(BusinessObjectService.class).findMatching(
46: OrganizationRoutingModel.class, fieldValues);
47: assertFalse("no models found", results.isEmpty());
48:
49: model = results.get(0);
50: }
51:
52: public void testSaveModel() {
53: String name = model.getOrganizationRoutingModelName();
54: OrganizationRoutingModel routingModel = new OrganizationRoutingModel();
55: routingModel.setOrganizationRoutingModelName(name);
56: routingModel.setChartOfAccountsCode(model
57: .getChartOfAccountsCode());
58: routingModel.setOrganizationCode(model.getOrganizationCode());
59: routingModel.setAccountDelegateUniversalId(model
60: .getAccountDelegateUniversalId());
61: routingModel.setFinancialDocumentTypeCode("xx");
62: SpringContext.getBean(BusinessObjectService.class).save(
63: routingModel);
64:
65: assertTrue(loadModel(name, model.getClass()));
66: }
67:
68: private boolean loadModel(String name, Class clazz) {
69:
70: Map<String, String> fieldValues = new HashMap<String, String>();
71: fieldValues.put("ORG_RTNG_MDL_NM", name);
72:
73: Collection<OrganizationRoutingModel> foundModel = SpringContext
74: .getBean(BusinessObjectService.class).findMatching(
75: clazz, fieldValues);
76:
77: List<DelegateGlobalDetail> delegateGlobals = new ArrayList<DelegateGlobalDetail>();
78:
79: for (OrganizationRoutingModel model : foundModel) {
80: delegateGlobals.add(new DelegateGlobalDetail(model));
81: }
82:
83: return (foundModel != null && !foundModel.isEmpty());
84:
85: }
86:
87: }
|