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.junit.Test;
25 import org.kuali.rice.kew.export.ExportDataSet;
26 import org.kuali.rice.kew.help.HelpEntry;
27 import org.kuali.rice.kew.service.KEWServiceLocator;
28
29
30
31 public class HelpEntryXmlExporterTest extends XmlExporterTestCase {
32
33 public void testExportActionConfig() throws Exception {
34
35 }
36
37 public void testExportEngineConfig() throws Exception {
38
39 }
40
41
42
43
44 @Test public void testExport() throws Exception {
45 loadXmlFile("HelpEntryExportConfig.xml");
46 assertExport();
47 }
48
49 protected void assertExport() throws Exception {
50
51 HelpEntry entry=new HelpEntry();
52 entry.setHelpKey("");
53 entry.setHelpName("");
54 entry.setHelpText("");
55 List oldHelpEntries = KEWServiceLocator.getHelpService().search(entry);
56 ExportDataSet dataSet = new ExportDataSet();
57 dataSet.getHelp().addAll(oldHelpEntries);
58 byte[] xmlBytes = KEWServiceLocator.getXmlExporterService().export(dataSet);
59 assertTrue("XML should be non empty.", xmlBytes != null && xmlBytes.length > 0);
60
61
62 loadXmlStream(new BufferedInputStream(new ByteArrayInputStream(xmlBytes)));
63
64 List newHelpEntries = KEWServiceLocator.getHelpService().search(entry);
65 assertEquals("Should have same number of old and new RuleAttributes.", oldHelpEntries.size(), newHelpEntries.size());
66 for (Iterator iterator = oldHelpEntries.iterator(); iterator.hasNext();) {
67 HelpEntry oldHelpEntry = (HelpEntry) iterator.next();
68 boolean foundAttribute = false;
69 for (Iterator iterator2 = newHelpEntries.iterator(); iterator2.hasNext();) {
70 HelpEntry newHelpEntry = (HelpEntry) iterator2.next();
71 if (oldHelpEntry.getHelpName().equals(newHelpEntry.getHelpName())) {
72 assertHelpEntryExport(oldHelpEntry, newHelpEntry);
73 foundAttribute = true;
74 }
75 }
76 assertTrue("Could not locate the new HelpEntry for name " + oldHelpEntry.getHelpName(), foundAttribute);
77 }
78 }
79
80 private void assertHelpEntryExport(HelpEntry oldHelpEntry, HelpEntry newHelpEntry) {
81
82 assertEquals("Ids should be the same.", oldHelpEntry.getHelpId(), newHelpEntry.getHelpId());
83 assertFalse("Version numbers should be different.", oldHelpEntry.getLockVerNbr().equals(newHelpEntry.getLockVerNbr()));
84 assertEquals(oldHelpEntry.getHelpName(), newHelpEntry.getHelpName());
85 assertEquals(oldHelpEntry.getHelpKey(), newHelpEntry.getHelpKey());
86 assertEquals(oldHelpEntry.getHelpText(), newHelpEntry.getHelpText());
87
88
89 }
90
91
92
93 }