001: /*
002: * Copyright 2006-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.maintenance;
017:
018: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
019:
020: import java.util.Iterator;
021:
022: import org.kuali.core.document.MaintenanceDocumentBase;
023: import org.kuali.core.service.DocumentService;
024: import org.kuali.core.web.ui.Field;
025: import org.kuali.core.web.ui.Row;
026: import org.kuali.core.web.ui.Section;
027: import org.kuali.kfs.context.KualiTestBase;
028: import org.kuali.kfs.context.SpringContext;
029: import org.kuali.test.ConfigureContext;
030:
031: /**
032: * This class test the maintenance framework.
033: */
034: @ConfigureContext(session=KHUNTLEY)
035: public class KualiMaintenanceTest extends KualiTestBase {
036: private MaintenanceDocumentBase document;
037:
038: private static final String DOCTYPE = "ProjectCodeMaintenanceDocument";
039: private static final String DOCTYPE2 = "ObjectCodeMaintenanceDocument";
040:
041: @Override
042: protected void setUp() throws Exception {
043: super .setUp();
044: document = (MaintenanceDocumentBase) SpringContext.getBean(
045: DocumentService.class).getNewDocument(DOCTYPE);
046: }
047:
048: public void testDocumentCreation() throws Exception {
049: assertNotNull(document.getDocumentNumber());
050: assertNotNull(document.getDocumentHeader());
051: assertNotNull(document.getDocumentHeader().getDocumentNumber());
052: }
053:
054: public void testObjectCodeActiveByDefault() throws Exception {
055: MaintenanceDocumentBase doc2 = (MaintenanceDocumentBase) SpringContext
056: .getBean(DocumentService.class)
057: .getNewDocument(DOCTYPE2);
058:
059: doc2.getNewMaintainableObject().setGenerateDefaultValues(true);
060: Section section = (Section) doc2.getNewMaintainableObject()
061: .getSections(doc2.getOldMaintainableObject()).get(0);
062: for (Iterator iter = section.getRows().iterator(); iter
063: .hasNext();) {
064: Row row = (Row) iter.next();
065: for (Iterator iterator = row.getFields().iterator(); iterator
066: .hasNext();) {
067: Field field = (Field) iterator.next();
068: if ("financialObjectActiveCode".equals(field
069: .getPropertyName())) {
070: assertEquals("default value for active not set",
071: "Yes", field.getPropertyValue());
072: }
073: }
074: }
075: }
076:
077: public void testGenerateDefaultValues() throws Exception {
078: document.getNewMaintainableObject().setGenerateDefaultValues(
079: true);
080: Section section = (Section) document.getNewMaintainableObject()
081: .getSections(document.getOldMaintainableObject())
082: .get(0);
083: for (Iterator iter = section.getRows().iterator(); iter
084: .hasNext();) {
085: Row row = (Row) iter.next();
086: for (Iterator iterator = row.getFields().iterator(); iterator
087: .hasNext();) {
088: Field field = (Field) iterator.next();
089: if ("code".equals(field.getPropertyName())) {
090: assertEquals("code not cleared", "", field
091: .getPropertyValue());
092: } else if ("projectDescription".equals(field
093: .getPropertyName())) {
094: assertEquals("description not cleared", "", field
095: .getPropertyValue());
096: } else if ("active".equals(field.getPropertyName())) {
097: assertEquals("default value for active not set",
098: "Yes", field.getPropertyValue());
099: } else if ("chartOfAccountsCode".equals(field
100: .getPropertyName())) {
101: assertEquals("chart not cleared", "", field
102: .getPropertyValue());
103: } else if ("organization".equals(field
104: .getPropertyName())) {
105: assertEquals("organization not cleared", "", field
106: .getPropertyValue());
107: } else if ("projectManagerUniversalId".equals(field
108: .getPropertyName())) {
109: assertEquals("manager id not cleared", "", field
110: .getPropertyValue());
111: }
112: }
113: }
114: }
115:
116: }
|