View Javadoc

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