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