001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.kuali.workflow.workgroup;
018:
019: import org.junit.Test;
020: import org.kuali.workflow.test.WorkflowTestCase;
021:
022: import edu.iu.uis.eden.KEWServiceLocator;
023: import edu.iu.uis.eden.doctype.DocumentType;
024: import edu.iu.uis.eden.doctype.DocumentTypeService;
025:
026: /**
027: *
028: * @author ewestfal
029: */
030: public class WorkgroupTypeXmlParserTest extends WorkflowTestCase {
031:
032: private WorkgroupTypeService service;
033:
034: @Override
035: protected void setUpTransaction() throws Exception {
036: super .setUpTransaction();
037: this .service = KEWServiceLocator.getWorkgroupTypeService();
038: }
039:
040: /**
041: * Tests that an existing WorkgroupType can be updated via the XML.
042: */
043: @Test
044: public void testUpdateWorkgroupType() throws Exception {
045: loadXmlFile("WorkgroupTypeDocTypeConfig.xml");
046: loadXmlFile("WorkgroupTypeConfig.xml");
047:
048: WorkgroupType wgt2 = service.findByName("WorkgroupType2");
049: assertNotNull(wgt2);
050: assertEquals(2, wgt2.getAttributes().size());
051: assertEquals(2, wgt2.getActiveAttributes().size());
052: WorkgroupTypeAttribute attribute1 = wgt2.getAttributes().get(0);
053: WorkgroupTypeAttribute attribute2 = wgt2.getAttributes().get(1);
054: assertEquals("WorkgroupTypeAttribute1", attribute1
055: .getAttribute().getName());
056: assertEquals("WorkgroupTypeAttribute2", attribute2
057: .getAttribute().getName());
058:
059: // update WorkgroupType2 to remove WorkgroupTypeAttribute1
060: loadXmlFile("WorkgroupTypeConfigUpdate1.xml");
061: wgt2 = service.findByName("WorkgroupType2");
062: assertNotNull(wgt2);
063: assertEquals(2, wgt2.getAttributes().size());
064: assertEquals(1, wgt2.getActiveAttributes().size());
065: assertEquals("attribute id should be same as before.",
066: attribute2.getWorkgroupTypeAttributeId(), wgt2
067: .getActiveAttributes().get(0)
068: .getWorkgroupTypeAttributeId());
069:
070: // now let's reactive WorkgroupTypeAttribute1 and add a new one
071: loadXmlFile("WorkgroupTypeConfigUpdate2.xml");
072: wgt2 = service.findByName("WorkgroupType2");
073: assertNotNull(wgt2);
074: assertEquals(3, wgt2.getAttributes().size());
075: assertEquals(3, wgt2.getActiveAttributes().size());
076: WorkgroupTypeAttribute attribute3New = wgt2.getAttributes()
077: .get(0);
078: WorkgroupTypeAttribute attribute1New = wgt2.getAttributes()
079: .get(1);
080: WorkgroupTypeAttribute attribute2New = wgt2.getAttributes()
081: .get(2);
082: assertEquals("WorkgroupTypeAttribute3", attribute3New
083: .getAttribute().getName());
084: assertEquals("WorkgroupTypeAttribute1", attribute1New
085: .getAttribute().getName());
086: assertEquals("WorkgroupTypeAttribute2", attribute2New
087: .getAttribute().getName());
088: assertEquals("attribute 1 id should be same as before.",
089: attribute1.getWorkgroupTypeAttributeId(), attribute1New
090: .getWorkgroupTypeAttributeId());
091: assertEquals("attribute 2 id should be same as before.",
092: attribute2.getWorkgroupTypeAttributeId(), attribute2New
093: .getWorkgroupTypeAttributeId());
094: assertEquals(0, attribute3New.getOrderIndex());
095: assertEquals(1, attribute1New.getOrderIndex());
096: assertEquals(2, attribute2New.getOrderIndex());
097:
098: // rearrange indexes and verify things are retrieved from the db correclty
099: attribute1New.setOrderIndex(2);
100: attribute2New.setOrderIndex(1);
101: service.save(wgt2);
102: wgt2 = service.findByName("WorkgroupType2");
103: assertEquals("WorkgroupTypeAttribute2", wgt2.getAttributes()
104: .get(1).getAttribute().getName());
105: assertEquals("WorkgroupTypeAttribute1", wgt2.getAttributes()
106: .get(2).getAttribute().getName());
107:
108: }
109:
110: @Test
111: public void testParseWorkgroupType() throws Exception {
112: loadXmlFile("WorkgroupTypeDocTypeConfig.xml");
113: loadXmlFile("WorkgroupTypeConfig.xml");
114:
115: // check WorkgroupType1
116: WorkgroupType workgroupType1 = service
117: .findByName("WorkgroupType1");
118: assertNotNull("WorkgroupType1 should have been found.",
119: workgroupType1);
120: assertNotNull("WorkgroupType should have an ID", workgroupType1
121: .getWorkgroupTypeId());
122: assertEquals("WorkgroupType1", workgroupType1.getName());
123: assertEquals("Should be one attribute.", 1, workgroupType1
124: .getAttributes().size());
125: WorkgroupTypeAttribute workgroupTypeAttribute1 = workgroupType1
126: .getAttributes().get(0);
127: assertEquals(workgroupType1, workgroupTypeAttribute1
128: .getWorkgroupType());
129: assertNotNull(workgroupTypeAttribute1
130: .getWorkgroupTypeAttributeId());
131: assertNotNull(workgroupTypeAttribute1.getAttribute());
132: assertEquals("Wrong attribute", "WorkgroupTypeAttribute1",
133: workgroupTypeAttribute1.getAttribute().getName());
134:
135: // check WorkgroupType2
136: WorkgroupType workgroupType2 = service
137: .findByName("WorkgroupType2");
138: assertNotNull("WorkgroupType2 should have been found.",
139: workgroupType2);
140: assertNotNull("WorkgroupType should have an ID", workgroupType2
141: .getWorkgroupTypeId());
142: assertEquals("WorkgroupType2", workgroupType2.getName());
143: assertEquals("Workgroup Type 2", workgroupType2.getLabel());
144: assertEquals("The Second Workgroup Type", workgroupType2
145: .getDescription());
146: assertEquals("Should be two attributes.", 2, workgroupType2
147: .getAttributes().size());
148: workgroupTypeAttribute1 = workgroupType2.getAttributes().get(0);
149: WorkgroupTypeAttribute workgroupTypeAttribute2 = workgroupType2
150: .getAttributes().get(1);
151: assertEquals(workgroupType2, workgroupTypeAttribute1
152: .getWorkgroupType());
153: assertEquals(workgroupType2, workgroupTypeAttribute2
154: .getWorkgroupType());
155: assertNotNull(workgroupTypeAttribute1
156: .getWorkgroupTypeAttributeId());
157: assertNotNull(workgroupTypeAttribute2
158: .getWorkgroupTypeAttributeId());
159: assertNotNull(workgroupTypeAttribute1.getAttribute());
160: assertNotNull(workgroupTypeAttribute2.getAttribute());
161: assertEquals("Wrong attribute", "WorkgroupTypeAttribute1",
162: workgroupTypeAttribute1.getAttribute().getName());
163: assertEquals("Wrong attribute", "WorkgroupTypeAttribute2",
164: workgroupTypeAttribute2.getAttribute().getName());
165:
166: // check WorkgroupType3
167: WorkgroupType workgroupType3 = service
168: .findByName("WorkgroupType3");
169: assertNotNull("WorkgroupType3 should have been found.",
170: workgroupType3);
171: assertNotNull("WorkgroupType should have an ID", workgroupType3
172: .getWorkgroupTypeId());
173: assertEquals("WorkgroupType3", workgroupType3.getName());
174: assertEquals("WorkgroupType3", workgroupType3.getLabel());
175: assertNull(workgroupType3.getDescription());
176: assertEquals("WorkgroupType3DocType", workgroupType3
177: .getDocumentTypeName());
178: DocumentType docType = getDocumentTypeService().findByName(
179: workgroupType3.getDocumentTypeName());
180: assertNotNull(docType);
181: }
182:
183: private DocumentTypeService getDocumentTypeService() {
184: return KEWServiceLocator.getDocumentTypeService();
185: }
186:
187: }
|