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:
017: package org.kuali.core.xml;
018:
019: import org.kuali.core.document.MaintenanceDocumentBase;
020: import org.kuali.core.maintenance.KualiMaintainableImpl;
021: import org.kuali.core.service.XmlObjectSerializerService;
022: import org.kuali.kfs.KFSConstants;
023: import org.kuali.kfs.context.KualiTestBase;
024: import org.kuali.kfs.context.SpringContext;
025: import org.kuali.module.chart.bo.ProjectCode;
026: import org.kuali.test.ConfigureContext;
027:
028: /**
029: * This class tests the Xml representation of objects.
030: */
031: @ConfigureContext
032: public class XmlTest extends KualiTestBase {
033:
034: private static final String PROJECT_CODE_MAINTENANCE_DOCUMENT_TYPENAME = "ProjectCodeMaintenanceDocument";
035:
036: private String PROJECT1_EDIT_XML;
037: private String PROJECT1_NEW_XML;
038: private String BAD_PROJECT_XML;
039:
040: private ProjectCode project1;
041:
042: @Override
043: protected void setUp() throws Exception {
044: super .setUp();
045:
046: // userSession is set by superclass
047:
048: project1 = new ProjectCode();
049: project1.setActive(true);
050: project1.setCode("BOB");
051: project1.setChartOfAccountsCode("UA");
052: project1.setProjectDescription("test");
053: project1.setName("test");
054: project1.setOrganizationCode("FMOP");
055: project1.setProjectManagerUniversalId("111111111");
056: project1.setVersionNumber(new Long(1));
057:
058: PROJECT1_EDIT_XML = SpringContext.getBean(
059: XmlObjectSerializerService.class).toXml(project1);
060: }
061:
062: public void testCreateXmlFromProjectAndBack() throws Exception {
063: ProjectCode project2 = (ProjectCode) SpringContext.getBean(
064: XmlObjectSerializerService.class).fromXml(
065: PROJECT1_EDIT_XML);
066:
067: assertEquals(project2.isActive(), project1.isActive());
068: assertEquals(project2.getCode(), project1.getCode());
069: assertEquals(project2.getChartOfAccountsCode(), project1
070: .getChartOfAccountsCode());
071: assertEquals(project2.getProjectDescription(), project1
072: .getProjectDescription());
073: assertEquals(project2.getName(), project1.getName());
074: assertEquals(project2.getProjectManagerUniversalId(), project1
075: .getProjectManagerUniversalId());
076: assertEquals(project2.getVersionNumber(), project1
077: .getVersionNumber());
078: assertEquals(project2.getOrganizationCode(), project1
079: .getOrganizationCode());
080: assertEquals(project2.getChartOfAccountsCode(), project1
081: .getChartOfAccountsCode());
082: }
083:
084: public void testMaintDocEditDissemination() throws Exception {
085: MaintenanceDocumentBase doc = new MaintenanceDocumentBase(
086: PROJECT_CODE_MAINTENANCE_DOCUMENT_TYPENAME);
087: doc.getOldMaintainableObject().setBusinessObject(project1);
088: doc.getNewMaintainableObject().setBusinessObject(project1);
089: doc.getNewMaintainableObject().setMaintenanceAction(
090: KFSConstants.MAINTENANCE_EDIT_ACTION);
091:
092: String projectXml = doc.getXmlDocumentContents();
093: doc.setXmlDocumentContents(projectXml);
094: doc.populateMaintainablesFromXmlDocumentContents();
095:
096: assertEquals(((ProjectCode) doc.getNewMaintainableObject()
097: .getBusinessObject()).getChartOfAccountsCode(), "UA");
098: assertEquals(((ProjectCode) doc.getOldMaintainableObject()
099: .getBusinessObject()).getChartOfAccountsCode(), "UA");
100: assertEquals(KFSConstants.MAINTENANCE_EDIT_ACTION, doc
101: .getNewMaintainableObject().getMaintenanceAction());
102: }
103:
104: public void testMaintDocNewDissemination() throws Exception {
105: MaintenanceDocumentBase doc = new MaintenanceDocumentBase(
106: PROJECT_CODE_MAINTENANCE_DOCUMENT_TYPENAME);
107: doc.getNewMaintainableObject().setBusinessObject(project1);
108: doc.getNewMaintainableObject().setMaintenanceAction(
109: KFSConstants.MAINTENANCE_NEW_ACTION);
110:
111: String projectXml = doc.getXmlDocumentContents();
112: doc.setXmlDocumentContents(projectXml);
113: doc.populateMaintainablesFromXmlDocumentContents();
114:
115: assertEquals(((ProjectCode) doc.getNewMaintainableObject()
116: .getBusinessObject()).getChartOfAccountsCode(), "UA");
117: assertEquals(KFSConstants.MAINTENANCE_NEW_ACTION, doc
118: .getNewMaintainableObject().getMaintenanceAction());
119: }
120:
121: public void testMaintDocEditInsemination() throws Exception {
122: MaintenanceDocumentBase doc = new MaintenanceDocumentBase();
123: doc
124: .setNewMaintainableObject(new KualiMaintainableImpl(
125: project1));
126: doc
127: .setOldMaintainableObject(new KualiMaintainableImpl(
128: project1));
129: doc.populateXmlDocumentContentsFromMaintainables();
130: assertNotNull(doc.getXmlDocumentContents());
131: assertTrue(doc
132: .getXmlDocumentContents()
133: .startsWith(
134: "<maintainableDocumentContents maintainableImplClass=\"org.kuali.core.maintenance.KualiMaintainableImpl\">"));
135: assertTrue(doc.getXmlDocumentContents().indexOf(
136: "<oldMaintainableObject>") > 0);
137: assertTrue(doc.getXmlDocumentContents().indexOf(
138: "<newMaintainableObject>") > 0);
139: }
140:
141: public void testMaintDocNewInsemination() throws Exception {
142: MaintenanceDocumentBase doc = new MaintenanceDocumentBase();
143: doc
144: .setNewMaintainableObject(new KualiMaintainableImpl(
145: project1));
146: doc.populateXmlDocumentContentsFromMaintainables();
147: assertNotNull(doc.getXmlDocumentContents());
148: assertTrue(doc
149: .getXmlDocumentContents()
150: .startsWith(
151: "<maintainableDocumentContents maintainableImplClass=\"org.kuali.core.maintenance.KualiMaintainableImpl\">"));
152: assertFalse(doc.getXmlDocumentContents().indexOf(
153: "<oldMaintainableObject>") > 0);
154: assertTrue(doc.getXmlDocumentContents().indexOf(
155: "<newMaintainableObject>") > 0);
156: }
157:
158: public void testMaintDocEditXmlRoundTrip() {
159:
160: // create a new maint doc, set the old & new, set the action to EDIT
161: MaintenanceDocumentBase doc1 = new MaintenanceDocumentBase(
162: PROJECT_CODE_MAINTENANCE_DOCUMENT_TYPENAME);
163: doc1.getOldMaintainableObject().setBusinessObject(project1);
164: doc1.getNewMaintainableObject().setBusinessObject(project1);
165: doc1.getNewMaintainableObject().setMaintenanceAction(
166: KFSConstants.MAINTENANCE_EDIT_ACTION);
167:
168: // have the object generate XML, and get that XML
169: doc1.populateXmlDocumentContentsFromMaintainables();
170: String projectXml = doc1.getXmlDocumentContents();
171:
172: // create a new object
173: MaintenanceDocumentBase doc2 = new MaintenanceDocumentBase(
174: PROJECT_CODE_MAINTENANCE_DOCUMENT_TYPENAME);
175:
176: // insert the XML, and try to re-constitute the maintainables from the XML
177: doc2.setXmlDocumentContents(projectXml);
178: doc2.populateMaintainablesFromXmlDocumentContents();
179:
180: assertEquals(((ProjectCode) doc1.getNewMaintainableObject()
181: .getBusinessObject()).getChartOfAccountsCode(),
182: ((ProjectCode) doc2.getNewMaintainableObject()
183: .getBusinessObject()).getChartOfAccountsCode());
184: assertEquals(((ProjectCode) doc1.getOldMaintainableObject()
185: .getBusinessObject()).getChartOfAccountsCode(),
186: ((ProjectCode) doc2.getOldMaintainableObject()
187: .getBusinessObject()).getChartOfAccountsCode());
188: assertEquals(doc1.getNewMaintainableObject()
189: .getMaintenanceAction(), doc2
190: .getNewMaintainableObject().getMaintenanceAction());
191: }
192: }
|