View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }