1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.edl.impl;
17
18 import org.junit.Test;
19 import org.kuali.rice.core.api.CoreApiServiceLocator;
20 import org.kuali.rice.core.api.config.property.Config;
21 import org.kuali.rice.core.api.config.property.ConfigContext;
22 import org.kuali.rice.core.api.impex.xml.XmlIngestionException;
23 import org.kuali.rice.core.api.style.Style;
24 import org.kuali.rice.core.api.style.StyleService;
25 import org.kuali.rice.core.api.util.xml.XmlJotter;
26 import org.kuali.rice.edl.impl.bo.EDocLiteAssociation;
27 import org.kuali.rice.edl.impl.bo.EDocLiteDefinition;
28 import org.kuali.rice.edl.impl.service.EDocLiteService;
29 import org.kuali.rice.edl.impl.service.EdlServiceLocator;
30 import org.kuali.rice.kew.test.KEWTestCase;
31 import org.kuali.rice.kew.test.TestUtilities;
32 import org.kuali.rice.test.BaselineTestCase;
33 import org.w3c.dom.Element;
34
35 import javax.xml.transform.Templates;
36 import java.io.ByteArrayInputStream;
37 import java.io.FileNotFoundException;
38 import java.util.List;
39 import java.util.Map;
40
41 import static org.junit.Assert.*;
42
43
44
45
46
47 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
48 public class EDocLiteServiceImplTest extends KEWTestCase {
49
50 @Test public void testLoadXML() throws FileNotFoundException {
51 loadXmlFile("EDocLiteContent.xml");
52 loadXmlFile("edlstyle.xml");
53
54 EDocLiteService edls = EdlServiceLocator.getEDocLiteService();
55 StyleService styleService = CoreApiServiceLocator.getStyleService();
56
57 assertTrue("Definition not found", edls.getEDocLiteDefinitions().contains("profile"));
58 Style defaultStyle = styleService.getStyle("Default");
59 assertNotNull("Style not found", defaultStyle);
60 assertEquals(1, edls.getEDocLiteAssociations().size());
61 EDocLiteDefinition def = edls.getEDocLiteDefinition("profile");
62 assertNotNull("'profile' definition not found", def);
63 assertEquals("profile", def.getName());
64 assertNotNull(def.getActiveInd());
65 assertTrue(def.getActiveInd().booleanValue());
66 Style style = styleService.getStyle("Default");
67 assertNotNull("'Default' style not found", style);
68 assertEquals("Default", style.getName());
69 assertTrue(style.isActive());
70 assertNotNull(style.getXmlContent());
71 }
72
73 @Test public void testLoadBadDefinition() throws FileNotFoundException {
74 EDocLiteService edls = EdlServiceLocator.getEDocLiteService();
75 try {
76 edls.loadXml(TestUtilities.loadResource(getClass(), "BadDefinition.xml"), null);
77 fail("BadDefinition was successfully parsed.");
78 } catch (XmlIngestionException re) {
79
80
81 assertTrue("Wrong exception occurred", re.getMessage().contains("EDocLite definition contains references to non-existent attributes"));
82 }
83 }
84
85 @Test public void testStoreDefinition() {
86 EDocLiteService edls = EdlServiceLocator.getEDocLiteService();
87 String defXml = "<edl></edl>";
88 try {
89 edls.saveEDocLiteDefinition(new ByteArrayInputStream(defXml.getBytes()));
90 fail("Storing edl with no name succeeded");
91 } catch (XmlIngestionException wsee) {
92
93 }
94 defXml = "<edl name=\"test\"></edl>";
95 edls.saveEDocLiteDefinition(new ByteArrayInputStream(defXml.getBytes()));
96 EDocLiteDefinition def = edls.getEDocLiteDefinition("test");
97 assertNotNull(def);
98 assertEquals("test", def.getName());
99 }
100
101 @Test public void testStoreAssociation() {
102 EDocLiteService edls = EdlServiceLocator.getEDocLiteService();
103 String assocXml = "<association></association>";
104 try {
105 edls.saveEDocLiteAssociation(new ByteArrayInputStream(assocXml.getBytes()));
106 fail("Storing association with no docType succeeded");
107 } catch (XmlIngestionException wsee) {
108
109 }
110 assocXml = "<association><docType></docType></association>";
111 try {
112 edls.saveEDocLiteAssociation(new ByteArrayInputStream(assocXml.getBytes()));
113 fail("Storing association with empty docType succeeded");
114 } catch (XmlIngestionException wsee) {
115
116 }
117 assocXml = "<association><docType>foobar</docType></association>";
118 edls.saveEDocLiteAssociation(new ByteArrayInputStream(assocXml.getBytes()));
119 EDocLiteAssociation assoc = edls.getEDocLiteAssociation("foobar");
120 assertNull("Inactive Association was found", assoc);
121
122 assocXml = "<association><docType>foobar</docType><active>true</active></association>";
123 edls.saveEDocLiteAssociation(new ByteArrayInputStream(assocXml.getBytes()));
124 assoc = edls.getEDocLiteAssociation("foobar");
125 assertNotNull("Association was not found", assoc);
126 assertEquals("foobar", assoc.getEdlName());
127 assertNull(assoc.getDefinition());
128 assertNull(assoc.getStyle());
129
130 List<EDocLiteAssociation> assocs = edls.getEDocLiteAssociations();
131 assertEquals(1, assocs.size());
132 assoc = assocs.get(0);
133 assertEquals("foobar", assoc.getEdlName());
134 assertNull(assoc.getDefinition());
135 assertNull(assoc.getStyle());
136 assertNotNull(assoc.getActiveInd());
137 assertTrue(assoc.getActiveInd().booleanValue());
138
139 assocXml = "<association><style>style name</style><definition>definition name</definition><docType>foobar</docType><active>true</active></association>";
140 edls.saveEDocLiteAssociation(new ByteArrayInputStream(assocXml.getBytes()));
141 assoc = edls.getEDocLiteAssociation("foobar");
142 assertNotNull("Association was not found", assoc);
143 assertEquals("foobar", assoc.getEdlName());
144 assertEquals("definition name", assoc.getDefinition());
145 assertEquals("style name", assoc.getStyle());
146
147 assocs = edls.getEDocLiteAssociations();
148 assertEquals(1, assocs.size());
149 assoc = (EDocLiteAssociation) assocs.get(0);
150 assertNotNull("Association was not found", assoc);
151 assertEquals("foobar", assoc.getEdlName());
152 assertEquals("definition name", assoc.getDefinition());
153 assertEquals("style name", assoc.getStyle());
154 assertNotNull(assoc.getActiveInd());
155 assertTrue(assoc.getActiveInd().booleanValue());
156 }
157
158
159
160
161
162
163
164 @Test public void testStyleCaching() throws Exception {
165 ConfigContext.getCurrentContextConfig().putProperty(Config.EDL_CONFIG_LOCATION, "classpath:org/kuali/rice/kew/edl/TestEDLConfig.xml");
166
167 loadXmlFile("EDocLiteContent.xml");
168 loadXmlFile("edlstyle.xml");
169 loadXmlFile("widgets.xml");
170
171
172
173
174
175
176 EDocLiteAssociation association = EdlServiceLocator.getEDocLiteService().getEDocLiteAssociation("EDocLiteDocType");
177 assertNull("We should be using the Default style.", association.getStyle());
178 Templates templates = EdlServiceLocator.getEDocLiteService().getStyleAsTranslet(association.getStyle());
179 assertNotNull("Templates should not be null.", templates);
180
181
182
183
184
185
186
187
188
189 loadXmlFile("edlstyle.xml");
190
191
192
193
194 Templates newTemplates = EdlServiceLocator.getEDocLiteService().getStyleAsTranslet(association.getStyle());
195 assertNotNull("Templates should not be null.", templates);
196
197
198
199
200 assertFalse("Old Templates should be different from new Templates.", templates.equals(newTemplates));
201
202 }
203 }