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 org.jdom.Document;
19 import org.junit.Test;
20 import org.kuali.rice.core.api.CoreApiServiceLocator;
21 import org.kuali.rice.coreservice.api.style.Style;
22 import org.kuali.rice.core.api.util.xml.XmlHelper;
23 import org.kuali.rice.core.api.util.xml.XmlJotter;
24 import org.kuali.rice.coreservice.impl.style.StyleBo;
25 import org.kuali.rice.coreservice.impl.style.StyleExportDataSet;
26 import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
27 import org.kuali.rice.test.BaselineTestCase;
28
29 import java.io.BufferedInputStream;
30 import java.io.ByteArrayInputStream;
31 import java.io.StringReader;
32 import java.util.Iterator;
33 import java.util.List;
34
35 import static org.junit.Assert.*;
36
37
38
39
40
41
42 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
43 public class StyleXmlExporterTest extends XmlExporterTestCase {
44
45 public void testExportActionConfig() throws Exception {
46
47 }
48
49 public void testExportEngineConfig() throws Exception {
50
51 }
52
53
54
55
56 @Test public void testExport() throws Exception {
57 loadXmlFile("StyleExportConfig.xml");
58 assertExport();
59 }
60
61 protected void assertExport() throws Exception {
62 List<String> oldStyleNames = CoreServiceApiServiceLocator.getStyleService().getAllStyleNames();
63
64 StyleExportDataSet dataSet = new StyleExportDataSet();
65 for (String oldStyleName : oldStyleNames) {
66 Style oldStyle = CoreServiceApiServiceLocator.getStyleService().getStyle(oldStyleName);
67 assertNotNull(oldStyle);
68 dataSet.getStyles().add(StyleBo.from(oldStyle));
69 }
70
71 byte[] xmlBytes = CoreApiServiceLocator.getXmlExporterService().export(dataSet.createExportDataSet());
72 assertTrue("XML should be non empty.", xmlBytes != null && xmlBytes.length > 0);
73
74
75
76 assertTrue("XML does not contain exported style", new String(xmlBytes).contains("<styles "));
77 assertTrue("XML does not contain exported style", new String(xmlBytes).contains("<style name=\"an_arbitrary_style\">"));
78
79
80 loadXmlStream(new BufferedInputStream(new ByteArrayInputStream(xmlBytes)));
81
82 List<String> newStyleNames = CoreServiceApiServiceLocator.getStyleService().getAllStyleNames();
83 assertEquals("Should have same number of old and new Styles.", oldStyleNames.size(), newStyleNames.size());
84 for (Iterator<String> iterator = oldStyleNames.iterator(); iterator.hasNext();) {
85 String oldStyleName = iterator.next();
86 Style oldStyleEntry = CoreServiceApiServiceLocator.getStyleService().getStyle(oldStyleName);
87 assertNotNull(oldStyleEntry);
88 boolean foundAttribute = false;
89 for (String newStyleName : newStyleNames) {
90 if (oldStyleEntry.getName().equals(newStyleName)) {
91 Style newStyleEntry = CoreServiceApiServiceLocator.getStyleService().getStyle(newStyleName);
92 assertNotNull(newStyleEntry);
93
94
95 assertEquals(canonicalize(oldStyleEntry.getXmlContent()),
96 canonicalize(newStyleEntry.getXmlContent()));
97 foundAttribute = true;
98 }
99 }
100 assertTrue("Could not locate the new style for name " + oldStyleEntry.getName(), foundAttribute);
101 }
102 }
103
104 private String canonicalize(String xml) throws Exception {
105 Document document = XmlHelper.buildJDocument(new StringReader(xml));
106 return XmlJotter.jotDocument(document);
107 }
108 }