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.tools.xml;
018:
019: import java.io.File;
020: import java.util.List;
021:
022: import org.apache.commons.io.FileUtils;
023: import org.junit.Assert;
024: import org.junit.Test;
025:
026: /**
027: *
028: * @author ewestfal
029: */
030: public class XmlGenTest extends Assert {
031:
032: @Test
033: public void testIndexing() throws Exception {
034: String outputPath = System.getProperty("java.io.tmpdir")
035: + "/xmlgentest";
036: File outputFile = new File(outputPath);
037: if (outputFile.exists()) {
038: FileUtils.deleteDirectory(outputFile);
039: }
040:
041: XmlGen xmlGen = new XmlGen();
042: xmlGen.setInputDirectoryPath("tools/test/input");
043: xmlGen.setOutputDirectoryPath(outputPath);
044: xmlGen.setXmlGenHelper(new TestXmlGenHelper());
045: xmlGen.run();
046:
047: // verify everything was indexed correctly
048:
049: assertEquals("Should be 2 document types.", 2, xmlGen
050: .getDocumentTypes().size());
051: assertEquals("Should be 2 attributes.", 2, xmlGen
052: .getAttributes().size());
053: assertEquals("Should be 5 templates.", 5, xmlGen.getTemplates()
054: .size());
055:
056: boolean foundInitiatorAttribute = false;
057: boolean foundSchoolAttribute = false;
058: for (Attribute attribute : xmlGen.getAttributes().values()) {
059: if (attribute.getName().equals("InitiatorAttribute")) {
060: foundInitiatorAttribute = true;
061: List<String> fieldNames = attribute.getFieldNames();
062: assertEquals(
063: "Field names for the initiator attribute should be empty.",
064: 0, fieldNames.size());
065: } else if (attribute.getName().equals("EDLSchoolAttribute")) {
066: foundSchoolAttribute = true;
067: List<String> fieldNames = attribute.getFieldNames();
068: assertEquals("School attribute should have 1 field.",
069: 1, fieldNames.size());
070: assertEquals("school", fieldNames.get(0));
071: }
072: }
073: assertTrue(foundInitiatorAttribute);
074: assertTrue(foundSchoolAttribute);
075:
076: // check the SpreadsheetOutput
077: SpreadsheetOutput output = xmlGen.getOutput();
078:
079: // verify the output
080: assertEquals("Should be 3 rules.", 3, output.getRules().size());
081:
082: // rule1
083: Rule rule1 = output.getRules().get(0);
084: assertEquals("OfferRequest", rule1.getDocumentType().getName());
085: assertEquals("OfficeOfAffirmativeAction-SchoolRouting", rule1
086: .getTemplate().getName());
087: assertFalse(rule1.getIgnorePrevious());
088: assertEquals("School/RC of Bl-BUS for OAA eDoc Lite", rule1
089: .getDescription());
090: assertEquals(1, rule1.getRuleExtensions().size());
091: RuleExtension rule1Ext1 = rule1.getRuleExtensions().get(0);
092: assertEquals(1, rule1Ext1.getExtensionValues().size());
093: RuleExtensionValue rule1ExtVal1 = rule1Ext1
094: .getExtensionValues().get(0);
095: assertEquals("school", rule1ExtVal1.getKey());
096: assertEquals("BUS", rule1ExtVal1.getValue());
097: assertEquals(1, rule1.getResponsibilities().size());
098: Responsibility rule1Resp1 = rule1.getResponsibilities().get(0);
099: assertEquals("A", rule1Resp1.getActionRequested());
100: assertNotNull(rule1Resp1.getWorkgroup());
101: assertEquals("OAA_BL-BUS", rule1Resp1.getWorkgroup().getName());
102: Workgroup rule1Wg1 = rule1Resp1.getWorkgroup();
103: assertEquals(3, rule1Wg1.getMembers().size());
104: assertTrue(rule1Wg1.getMembers().contains("user1"));
105: assertTrue(rule1Wg1.getMembers().contains("user2"));
106: assertTrue(rule1Wg1.getMembers().contains("user3"));
107:
108: // rule2
109: Rule rule2 = output.getRules().get(1);
110: assertEquals("OfferRequest", rule2.getDocumentType().getName());
111: assertEquals("OfficeOfAffirmativeAction-SchoolRouting", rule2
112: .getTemplate().getName());
113: assertFalse(rule2.getIgnorePrevious());
114: assertEquals("EDUC Description", rule2.getDescription());
115: assertEquals(1, rule2.getRuleExtensions().size());
116: RuleExtension rule2Ext1 = rule2.getRuleExtensions().get(0);
117: assertEquals(1, rule2Ext1.getExtensionValues().size());
118: RuleExtensionValue rule2ExtVal1 = rule2Ext1
119: .getExtensionValues().get(0);
120: assertEquals("school", rule2ExtVal1.getKey());
121: assertEquals("EDUC", rule2ExtVal1.getValue());
122: assertEquals(1, rule2.getResponsibilities().size());
123: Responsibility rule2Resp1 = rule2.getResponsibilities().get(0);
124: assertEquals("K", rule2Resp1.getActionRequested());
125: assertNotNull(rule2Resp1.getWorkgroup());
126: assertEquals("MyEducWG", rule2Resp1.getWorkgroup().getName());
127: assertEquals("user5", rule2Resp1.getWorkgroup().getMembers()
128: .get(0));
129:
130: // rule3
131: Rule rule3 = output.getRules().get(2);
132: assertEquals("OfferRequest", rule3.getDocumentType().getName());
133: assertEquals("OfficeOfAffirmativeAction-SchoolRouting", rule3
134: .getTemplate().getName());
135: assertTrue(rule3.getIgnorePrevious());
136: assertTrue(rule3.getDescription().contains("MUS"));
137: assertTrue(rule3.getDescription().contains("OfferRequest"));
138: assertTrue(rule3.getDescription().contains("school"));
139: assertEquals(1, rule3.getRuleExtensions().size());
140: RuleExtension rule3Ext1 = rule3.getRuleExtensions().get(0);
141: assertEquals(1, rule3Ext1.getExtensionValues().size());
142: RuleExtensionValue rule3ExtVal1 = rule3Ext1
143: .getExtensionValues().get(0);
144: assertEquals("school", rule3ExtVal1.getKey());
145: assertEquals("MUS", rule3ExtVal1.getValue());
146: assertEquals(2, rule3.getResponsibilities().size());
147: Responsibility rule3Resp1 = rule3.getResponsibilities().get(0);
148: assertEquals("F", rule3Resp1.getActionRequested());
149: assertNull(rule3Resp1.getWorkgroup());
150: assertEquals("user3", rule3Resp1.getUser());
151: Responsibility rule3Resp2 = rule3.getResponsibilities().get(1);
152: assertEquals("F", rule3Resp2.getActionRequested());
153: assertNull(rule3Resp2.getWorkgroup());
154: assertEquals("user2", rule3Resp2.getUser());
155:
156: if (outputFile.exists()) {
157: FileUtils.deleteDirectory(outputFile);
158: }
159: }
160:
161: private class TestXmlGenHelper extends XmlGenHelper {
162:
163: @Override
164: public String generateRuleDescription(Rule rule) {
165: if (rule.getResponsibilities().size() > 0
166: && rule.getResponsibilities().get(0).getWorkgroup() != null
167: && rule.getResponsibilities().get(0).getWorkgroup()
168: .getName().equals("MyEducWG")) {
169: return "EDUC Description";
170: }
171: return null;
172: }
173:
174: @Override
175: public List<String> resolveFieldNames(Attribute attribute) {
176: // TODO Auto-generated method stub
177: return null;
178: }
179:
180: }
181:
182: }
|