1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.kuali.rice.kew.rule;
19
20 import java.util.List;
21 import java.util.Map;
22
23 import junit.framework.TestCase;
24
25 import org.junit.Test;
26 import org.kuali.rice.kew.routeheader.DocumentContent;
27 import org.kuali.rice.kew.routeheader.StandardDocumentContent;
28 import org.kuali.rice.kew.rule.GenericAttributeContent;
29
30
31 public class GenericAttributeContentTest extends TestCase {
32 private static final String ATTRIB1_CONTENT = " <boringAttribute>" +
33 " <field>" +
34 " <name>color</name>" +
35 " <value>green</value>" +
36 " </field>" +
37 " <field>" +
38 " <name>shape</name>" +
39 " <value>circle</value>" +
40 " </field>" +
41 " </boringAttribute>";
42 private static final String ATTRIB2_CONTENT = " <coolAttribute>" +
43 " <field>" +
44 " <name>car</name>" +
45 " <value>KIT</value>" +
46 " </field>" +
47 " <field>" +
48 " <name>driver</name>" +
49 " <value>hasselhof</value>" +
50 " </field>" +
51 " </coolAttribute>";
52 private static final String TEST_CONTENT = "<documentContent>" +
53 " <attributeContent>" +
54 ATTRIB1_CONTENT +
55 ATTRIB2_CONTENT +
56 " </attributeContent>" +
57 "</documentContent>";
58
59 @Test public void testGenerateContent() throws Exception {
60 DocumentContent dc = new StandardDocumentContent(TEST_CONTENT);
61 GenericAttributeContent gac = new GenericAttributeContent("boringAttribute");
62 List<Map<String, String>> attrs = gac.parseContent(dc.getAttributeContent());
63 assertEquals(1, attrs.size());
64 Map<String, String> properties = attrs.get(0);
65 assertEquals(2, properties.size());
66 assertEquals("green", properties.get("color"));
67 assertEquals("circle", properties.get("shape"));
68 String content = gac.generateContent(properties);
69 assertEquals(content.replaceAll("\\s+", ""), ATTRIB1_CONTENT.replaceAll("\\s+", ""));
70
71 gac = new GenericAttributeContent("coolAttribute");
72 attrs = gac.parseContent(dc.getAttributeContent());
73 assertEquals(1, attrs.size());
74 properties = attrs.get(0);
75 assertEquals(2, properties.size());
76 assertEquals("hasselhof", properties.get("driver"));
77 assertEquals("KIT", properties.get("car"));
78 content = gac.generateContent(properties);
79 assertEquals(content.replaceAll("\\s+", ""), ATTRIB2_CONTENT.replaceAll("\\s+", ""));
80 }
81 }