1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.xml.export;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertTrue;
21
22 import java.io.BufferedInputStream;
23 import java.io.ByteArrayInputStream;
24 import java.util.Iterator;
25 import java.util.List;
26
27 import org.junit.Test;
28 import org.kuali.rice.core.api.CoreApiServiceLocator;
29 import org.kuali.rice.kew.export.KewExportDataSet;
30 import org.kuali.rice.kew.help.HelpEntry;
31 import org.kuali.rice.kew.service.KEWServiceLocator;
32 import org.kuali.rice.test.BaselineTestCase;
33
34 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
35 public class HelpEntryXmlExporterTest extends XmlExporterTestCase {
36
37 public void testExportActionConfig() throws Exception {
38
39 }
40
41 public void testExportEngineConfig() throws Exception {
42
43 }
44
45
46
47
48 @Test public void testExport() throws Exception {
49 loadXmlFile("HelpEntryExportConfig.xml");
50 assertExport();
51 }
52
53 protected void assertExport() throws Exception {
54
55 HelpEntry entry=new HelpEntry();
56 entry.setHelpKey("");
57 entry.setHelpName("");
58 entry.setHelpText("");
59 List oldHelpEntries = KEWServiceLocator.getHelpService().search(entry);
60 KewExportDataSet dataSet = new KewExportDataSet();
61 dataSet.getHelp().addAll(oldHelpEntries);
62 byte[] xmlBytes = CoreApiServiceLocator.getXmlExporterService().export(dataSet.createExportDataSet());
63 assertTrue("XML should be non empty.", xmlBytes != null && xmlBytes.length > 0);
64
65
66 loadXmlStream(new BufferedInputStream(new ByteArrayInputStream(xmlBytes)));
67
68 List newHelpEntries = KEWServiceLocator.getHelpService().search(entry);
69 assertEquals("Should have same number of old and new RuleAttributes.", oldHelpEntries.size(), newHelpEntries.size());
70 for (Iterator iterator = oldHelpEntries.iterator(); iterator.hasNext();) {
71 HelpEntry oldHelpEntry = (HelpEntry) iterator.next();
72 boolean foundAttribute = false;
73 for (Iterator iterator2 = newHelpEntries.iterator(); iterator2.hasNext();) {
74 HelpEntry newHelpEntry = (HelpEntry) iterator2.next();
75 if (oldHelpEntry.getHelpName().equals(newHelpEntry.getHelpName())) {
76 assertHelpEntryExport(oldHelpEntry, newHelpEntry);
77 foundAttribute = true;
78 }
79 }
80 assertTrue("Could not locate the new HelpEntry for name " + oldHelpEntry.getHelpName(), foundAttribute);
81 }
82 }
83
84 private void assertHelpEntryExport(HelpEntry oldHelpEntry, HelpEntry newHelpEntry) {
85
86 assertEquals("Ids should be the same.", oldHelpEntry.getHelpId(), newHelpEntry.getHelpId());
87 assertFalse("Version numbers should be different.", oldHelpEntry.getLockVerNbr().equals(newHelpEntry.getLockVerNbr()));
88 assertEquals(oldHelpEntry.getHelpName(), newHelpEntry.getHelpName());
89 assertEquals(oldHelpEntry.getHelpKey(), newHelpEntry.getHelpKey());
90 assertEquals(oldHelpEntry.getHelpText(), newHelpEntry.getHelpText());
91
92
93 }
94
95
96
97 }