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