1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.xml.export;
18
19 import java.io.BufferedInputStream;
20 import java.io.ByteArrayInputStream;
21 import java.util.Iterator;
22 import java.util.List;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.junit.Test;
26 import org.kuali.rice.kew.export.ExportDataSet;
27 import org.kuali.rice.kew.rule.bo.RuleAttribute;
28 import org.kuali.rice.kew.rule.bo.RuleTemplateAttribute;
29 import org.kuali.rice.kew.service.KEWServiceLocator;
30
31
32 public class RuleAttributeXmlExporterTest extends XmlExporterTestCase {
33
34
35
36
37 @Test public void testExport() throws Exception {
38 loadXmlFile("RuleAttributeExportConfig.xml");
39 assertExport();
40 }
41
42 protected void assertExport() throws Exception {
43
44 List oldRuleAttributes = KEWServiceLocator.getRuleAttributeService().findAll();
45 ExportDataSet dataSet = new ExportDataSet();
46 dataSet.getRuleAttributes().addAll(oldRuleAttributes);
47 byte[] xmlBytes = KEWServiceLocator.getXmlExporterService().export(dataSet);
48 assertTrue("XML should be non empty.", xmlBytes != null && xmlBytes.length > 0);
49
50
51 loadXmlStream(new BufferedInputStream(new ByteArrayInputStream(xmlBytes)));
52
53 List newRuleAttributes = KEWServiceLocator.getRuleAttributeService().findAll();
54 assertEquals("Should have same number of old and new RuleAttributes.", oldRuleAttributes.size(), newRuleAttributes.size());
55 for (Iterator iterator = oldRuleAttributes.iterator(); iterator.hasNext();) {
56 RuleAttribute oldRuleAttribute = (RuleAttribute) iterator.next();
57 boolean foundAttribute = false;
58 for (Iterator iterator2 = newRuleAttributes.iterator(); iterator2.hasNext();) {
59 RuleAttribute newRuleAttribute = (RuleAttribute) iterator2.next();
60 if (oldRuleAttribute.getName().equals(newRuleAttribute.getName())) {
61 assertRuleAttributeExport(oldRuleAttribute, newRuleAttribute);
62 foundAttribute = true;
63 }
64 }
65 assertTrue("Could not locate the new rule attribute for name " + oldRuleAttribute.getName(), foundAttribute);
66 }
67 }
68
69 private void assertRuleAttributeExport(RuleAttribute oldRuleAttribute, RuleAttribute newRuleAttribute) {
70
71 assertEquals("Ids should be the same.", oldRuleAttribute.getRuleAttributeId(), newRuleAttribute.getRuleAttributeId());
72 assertFalse("Version numbers should be different.", oldRuleAttribute.getVersionNumber().equals(newRuleAttribute.getVersionNumber()));
73 assertEquals(oldRuleAttribute.getDescription(), newRuleAttribute.getDescription());
74 assertEquals(oldRuleAttribute.getName(), newRuleAttribute.getName());
75 assertEquals(oldRuleAttribute.getLabel(), newRuleAttribute.getLabel());
76 assertEquals(oldRuleAttribute.getType(), newRuleAttribute.getType());
77 assertEquals(StringUtils.deleteWhitespace(oldRuleAttribute.getXmlConfigData()), StringUtils.deleteWhitespace(newRuleAttribute.getXmlConfigData()));
78 assertRuleTemplateAttributes(oldRuleAttribute.getRuleTemplateAttributes(), newRuleAttribute.getRuleTemplateAttributes());
79 }
80
81 private void assertRuleTemplateAttributes(List oldRuleTemplateAttributes, List newRuleTemplateAttributes) {
82 assertEquals(oldRuleTemplateAttributes.size(), newRuleTemplateAttributes.size());
83 for (Iterator iterator = oldRuleTemplateAttributes.iterator(); iterator.hasNext();) {
84 RuleTemplateAttribute oldAttribute = (RuleTemplateAttribute) iterator.next();
85 boolean foundAttribute = false;
86 for (Iterator iterator2 = oldRuleTemplateAttributes.iterator(); iterator2.hasNext();) {
87 RuleTemplateAttribute newAttribute = (RuleTemplateAttribute) iterator2.next();
88 if (oldAttribute.getRuleAttribute().getName().equals(newAttribute.getRuleAttribute().getName())) {
89 assertEquals(oldAttribute.getRequired(), newAttribute.getRequired());
90 foundAttribute = true;
91 }
92 }
93 assertTrue("Could not locate new attribute.", foundAttribute);
94 }
95 }
96
97 }