01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.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: // Created on Oct 23, 2006
18: package edu.iu.uis.eden.routetemplate;
19:
20: import java.util.List;
21: import java.util.Map;
22:
23: import junit.framework.TestCase;
24:
25: import org.junit.Test;
26:
27: import edu.iu.uis.eden.routeheader.DocumentContent;
28: import edu.iu.uis.eden.routeheader.StandardDocumentContent;
29:
30: public class GenericAttributeContentTest extends TestCase {
31: private static final String ATTRIB1_CONTENT = " <boringAttribute>"
32: + " <field>"
33: + " <name>color</name>"
34: + " <value>green</value>"
35: + " </field>"
36: + " <field>"
37: + " <name>shape</name>"
38: + " <value>circle</value>"
39: + " </field>"
40: + " </boringAttribute>";
41: private static final String ATTRIB2_CONTENT = " <coolAttribute>"
42: + " <field>" + " <name>car</name>"
43: + " <value>KIT</value>" + " </field>"
44: + " <field>" + " <name>driver</name>"
45: + " <value>hasselhof</value>" + " </field>"
46: + " </coolAttribute>";
47: private static final String TEST_CONTENT = "<documentContent>"
48: + " <attributeContent>" + ATTRIB1_CONTENT
49: + ATTRIB2_CONTENT + " </attributeContent>"
50: + "</documentContent>";
51:
52: @Test
53: public void testGenerateContent() throws Exception {
54: DocumentContent dc = new StandardDocumentContent(TEST_CONTENT);
55: GenericAttributeContent gac = new GenericAttributeContent(
56: "boringAttribute");
57: List<Map<String, String>> attrs = gac.parseContent(dc
58: .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
66: .replaceAll("\\s+", ""));
67:
68: gac = new GenericAttributeContent("coolAttribute");
69: attrs = gac.parseContent(dc.getAttributeContent());
70: assertEquals(1, attrs.size());
71: properties = attrs.get(0);
72: assertEquals(2, properties.size());
73: assertEquals("hasselhof", properties.get("driver"));
74: assertEquals("KIT", properties.get("car"));
75: content = gac.generateContent(properties);
76: assertEquals(content.replaceAll("\\s+", ""), ATTRIB2_CONTENT
77: .replaceAll("\\s+", ""));
78: }
79: }
|