KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > jsp > decorator > TestDecorator


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/jsp/decorator/TestDecorator.java,v $
3  * Date : $Date: 2006/09/19 14:29:08 $
4  * Version: $Revision: 1.3 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.jsp.decorator;
33
34 import org.opencms.i18n.CmsEncoder;
35 import org.opencms.test.OpenCmsTestCase;
36 import org.opencms.test.OpenCmsTestProperties;
37
38 import java.util.Locale JavaDoc;
39
40 import junit.extensions.TestSetup;
41 import junit.framework.Test;
42 import junit.framework.TestSuite;
43
44 /**
45  * Tests for the decoration postprocessor.<p>
46  *
47  * @author Michael Emmerich
48  *
49  * @version $Revision: 1.3 $
50  *
51  * @since 6.1.3
52  */

53 public class TestDecorator extends OpenCmsTestCase {
54
55     /**
56      * Default JUnit constructor.<p>
57      *
58      * @param arg0 JUnit parameters
59      */

60     public TestDecorator(String JavaDoc arg0) {
61
62         super(arg0);
63     }
64
65     /**
66      * Test suite for this test class.<p>
67      *
68      * @return the test suite
69      */

70     public static Test suite() {
71
72         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
73
74         TestSuite suite = new TestSuite();
75         suite.setName(TestDecorator.class.getName());
76
77         suite.addTest(new TestDecorator("testDecoratorBasics"));
78         suite.addTest(new TestDecorator("testDecoratorConfiguration"));
79
80         TestSetup wrapper = new TestSetup(suite) {
81
82             protected void setUp() {
83
84                 setupOpenCms("decoration", "/sites/default/");
85             }
86
87             protected void tearDown() {
88
89                 removeOpenCms();
90             }
91         };
92
93         return wrapper;
94     }
95
96     /**
97      * Tests the decoration postprocessor.<p>
98      *
99      * @throws Exception if something goes wrong
100      */

101     public void testDecoratorBasics() throws Exception JavaDoc {
102
103         // define test values and results
104
String JavaDoc inputText1 = "The CMS stores its data in the VFS and exports some of it to the RFS./r/n To export files form the VFS to the RFS you must configure your CMS correctly.";
105         String JavaDoc resultText1 ="The <abbr title=\"Content Management System\">CMS</abbr> stores its data in the <abbr title=\"Virtual File System\">VFS</abbr> and exports some of it to the <abbr title=\"Real File System\">RFS</abbr>./r/n To export files form the <abbr>VFS</abbr> to the <abbr>RFS</abbr> you must configure your <abbr>CMS</abbr> correctly.";
106         
107         String JavaDoc inputText2 = "<h1>The CMS</h1>The CMS stores its data in the <a HREF=\"#\">VFS</a> and exports some of it to the RFS./r/n To export files form the VFS to the RFS you must configure your CMS correctly.";
108         String JavaDoc resultText2 ="<h1>The <abbr title=\"Content Management System\">CMS</abbr></h1>The <abbr>CMS</abbr> stores its data in the <a HREF=\"#\"><abbr title=\"Virtual File System\">VFS</abbr></a> and exports some of it to the <abbr title=\"Real File System\">RFS</abbr>./r/n To export files form the <abbr>VFS</abbr> to the <abbr>RFS</abbr> you must configure your <abbr>CMS</abbr> correctly.";
109         
110         String JavaDoc inputText3 = "This is a test for VFS&nbsp;RFS and VFS.";
111         String JavaDoc resultText3 = "This is a test for <abbr>VFS</abbr>&nbsp;<abbr>RFS</abbr> and <abbr>VFS</abbr>.";
112         
113         String JavaDoc inputText4 = "This is a test German Umlaute: TÜV is fine, but does T&UumlV work as well?";
114         String JavaDoc resultText4 = "This is a test German Umlaute: <abbr title=\"Technischer Überwachungsverein\">TÜV</abbr> is fine, but does <abbr>TÜV</abbr> work as well?";
115         
116         String JavaDoc inputText5 = "The CMS has a nice user interface, the so called CMS-UI. This must not be mixed up with the CMS-IU!";
117         String JavaDoc resultText5 = "The <abbr>CMS</abbr> has a nice user interface, the so called <abbr title=\"Content Management System User Interface\">CMS-UI</abbr>. This must not be mixed up with the <abbr>CMS</abbr>-IU!";
118   
119         String JavaDoc inputText6 = "Does it work to use a '?' as a delimiter for the CMS?";
120         String JavaDoc resultText6 = "Does it work to use a '?' as a delimiter for the <abbr>CMS</abbr>?";
121  
122         String JavaDoc inputText6a = "This is VFS@CMS.";
123         String JavaDoc resultText6a = "This is <abbr>VFS</abbr>@<abbr>CMS</abbr>.";
124         
125         String JavaDoc inputText6b = "This is ABC@DEF.";
126         String JavaDoc resultText6b = "This is <abbr title=\"A strange thing with a @ in it\">ABC@DEF</abbr>.";
127
128         String JavaDoc inputText7 = "<Strong>CMS</strong>. Will it be decorated? <h1>VFS</h1>: Is very nice!";
129         String JavaDoc resultText7 = "<Strong><abbr>CMS</abbr></strong>. Will it be decorated? <h1><abbr>VFS</abbr></h1>: Is very nice!";
130   
131         String JavaDoc inputText7a = "Test with a dash - the dashes should be still there - even if I write RFS.";
132         String JavaDoc resultText7a = "Test with a dash - the dashes should be still there - even if I write <abbr>RFS</abbr>.";
133     
134         String JavaDoc inputText8 = "Hello, my name is Dr. Bull!";
135         String JavaDoc resultText8 = "Hello, my name is <abbr title=\"Doctor\">Dr.</abbr> Bull!";
136         
137         String JavaDoc inputText8a = "<p>Dr. Dr.</p>";
138         String JavaDoc resultText8a = "<p><abbr>Dr.</abbr> <abbr>Dr.</abbr></p>";
139         
140         String JavaDoc inputText9 = "Do we find words with multiple lookups, e.g. CMS?";
141         String JavaDoc resultText9 = "Do we find words with multiple lookups, <abbr title=\"example given\">e.g.</abbr> <abbr>CMS</abbr>?";
142
143         String JavaDoc inputText9a = "Another example: z. B. is very nice.";
144         String JavaDoc resultText9a = "Another example: <abbr title=\"zum Beispiel\">z. B.</abbr> is very nice.";
145         
146         String JavaDoc inputText10 = "Let's see: ZB MED - a CMS decoration in the VFS with a blank in it.";
147         String JavaDoc resultText10 = "Let's see: <abbr title=\"a decoarion with a blank in it\">ZB MED</abbr> - a <abbr>CMS</abbr> decoration in the <abbr>VFS</abbr> with a blank in it.";
148
149         String JavaDoc inputText10a = "Let's see: ZB&nbsp;MED - a CMS decoration in the VFS with a blank in it.";
150         String JavaDoc resultText10a = "Let's see: <abbr title=\"a decoarion with a blank in it\">ZB&nbsp;MED</abbr> - a <abbr>CMS</abbr> decoration in the <abbr>VFS</abbr> with a blank in it.";
151
152         
153         String JavaDoc inputText11 = "This is a word inside quotations: \"CMS\".";
154         String JavaDoc resultText11 = "This is a word inside quotations: \"<abbr>CMS</abbr>\".";
155         
156         String JavaDoc inputText11a = "This is a word inside quotations: &quot;CMS&quot;.";
157         String JavaDoc resultText11a = "This is a word inside quotations: &quot;<abbr>CMS</abbr>&quot;.";
158         
159         String JavaDoc preTextFirst = "<abbr title=\"${decoration}\">";
160         String JavaDoc postTextFirst = "</abbr>";
161         String JavaDoc preText = "<abbr>";
162         String JavaDoc postText = "</abbr>";
163         
164         System.out.println("Testing the OpenCms decorator.");
165         
166         // add a DecorationDefintinion
167
CmsDecorationDefintion decDef1 = new CmsDecorationDefintion();
168         decDef1.setMarkFirst(true);
169         decDef1.setPreTextFirst(preTextFirst);
170         decDef1.setPostTextFirst(postTextFirst);
171         decDef1.setPreText(preText);
172         decDef1.setPostText(postText);
173         decDef1.setName("Abbr-Decoration");
174         
175         Locale JavaDoc locale = new Locale JavaDoc("en");
176         // add some text decorations to the decoration map
177
CmsDecorationBundle decorationMap = new CmsDecorationBundle();
178         decorationMap.put("CMS", new CmsDecorationObject("CMS", "Content Management System", decDef1, locale));
179         decorationMap.put("VFS", new CmsDecorationObject("VFS", "Virtual File System", decDef1, locale));
180         decorationMap.put("RFS", new CmsDecorationObject("RFS", "Real File System", decDef1, locale));
181         decorationMap.put("TÜV", new CmsDecorationObject("TÜV", "Technischer Überwachungsverein", decDef1, locale));
182         decorationMap.put("Dr.", new CmsDecorationObject("Dr.", "Doctor", decDef1, locale));
183         decorationMap.put("z. B.", new CmsDecorationObject("z. B.", "zum Beispiel", decDef1, locale));
184         decorationMap.put("e.g.", new CmsDecorationObject("e.g.", "example given", decDef1, locale));
185         decorationMap.put("ZB MED", new CmsDecorationObject("ZB MED", "a decoarion with a blank in it", decDef1, locale));
186         decorationMap.put("ZB&nbsp;MED", new CmsDecorationObject("ZB&nbsp;MED", "a decoarion with a blank in it", decDef1, locale));
187         decorationMap.put("CMS-UI", new CmsDecorationObject("CMS-UI", "Content Management System User Interface", decDef1, locale));
188         decorationMap.put("ABC@DEF", new CmsDecorationObject("ABC@DEF", "A strange thing with a @ in it", decDef1, locale));
189         
190         
191         // create a decorator configuration
192
CmsDecoratorConfiguration configuration = new CmsDecoratorConfiguration(getCmsObject());
193         configuration.setDecorations(decorationMap);
194         
195         // create the decorator
196
CmsHtmlDecorator processor = new CmsHtmlDecorator(configuration);
197         processor.resetDecorationDefinitions();
198         
199         // excecute the tests
200
System.out.println("Testing decoration");
201         String JavaDoc result = processor.doDecoration(inputText1, CmsEncoder.ENCODING_ISO_8859_1);
202         System.out.println(inputText1);
203         System.out.println(result);
204         assertEquals(resultText1, result);
205         System.out.println("");
206        
207         processor.resetDecorationDefinitions();
208         
209         System.out.println("Testing decoration in HTML");
210         result = processor.doDecoration(inputText2, CmsEncoder.ENCODING_ISO_8859_1);
211         System.out.println(inputText2);
212         System.out.println(result);
213         assertEquals(resultText2, result);
214         System.out.println("");
215         
216         System.out.println("Testing decoration with nbsp");
217         result = processor.doDecoration(inputText3, CmsEncoder.ENCODING_ISO_8859_1);
218         System.out.println(inputText3);
219         System.out.println(result);
220         assertEquals(resultText3, result);
221         System.out.println("");
222         
223         System.out.println("Testing decoration with Umlaute");
224         result = processor.doDecoration(inputText4, CmsEncoder.ENCODING_ISO_8859_1);
225         System.out.println(inputText4);
226         System.out.println(result);
227         assertEquals(resultText4, result);
228         System.out.println("");
229         
230         System.out.println("Testing decoration with composed words");
231         result = processor.doDecoration(inputText5, CmsEncoder.ENCODING_ISO_8859_1);
232         System.out.println(inputText5);
233         System.out.println(result);
234         assertEquals(resultText5, result);
235         System.out.println("");
236         
237         System.out.println("Testing decoration with additional delimiters");
238         result = processor.doDecoration(inputText6, CmsEncoder.ENCODING_ISO_8859_1);
239         System.out.println(inputText6);
240         System.out.println(result);
241         assertEquals(resultText6, result);
242         result = processor.doDecoration(inputText6a, CmsEncoder.ENCODING_ISO_8859_1);
243         System.out.println(inputText6a);
244         System.out.println(result);
245         assertEquals(resultText6a, result);
246         result = processor.doDecoration(inputText6b, CmsEncoder.ENCODING_ISO_8859_1);
247         System.out.println(inputText6b);
248         System.out.println(result);
249         assertEquals(resultText6b, result);
250         System.out.println("");
251         
252         System.out.println("Testing decoration after closing tags");
253         result = processor.doDecoration(inputText7, CmsEncoder.ENCODING_ISO_8859_1);
254         System.out.println(inputText7);
255         System.out.println(result);
256         assertEquals(resultText7, result);
257         result = processor.doDecoration(inputText7a, CmsEncoder.ENCODING_ISO_8859_1);
258         System.out.println(inputText7a);
259         System.out.println(result);
260         assertEquals(resultText7a, result);
261         System.out.println("");
262         
263         System.out.println("Testing decoration with decoration keys including delimiters (Dr.)");
264         result = processor.doDecoration(inputText8, CmsEncoder.ENCODING_ISO_8859_1);
265         System.out.println(inputText8);
266         System.out.println(result);
267         assertEquals(resultText8, result);
268         result = processor.doDecoration(inputText8a, CmsEncoder.ENCODING_ISO_8859_1);
269         System.out.println(inputText8a);
270         System.out.println(result);
271         assertEquals(resultText8a, result);
272         System.out.println("");
273         
274         System.out.println("Testing decoration with decoration keys including multiple delimiters (z.B.)");
275         result = processor.doDecoration(inputText9, CmsEncoder.ENCODING_ISO_8859_1);
276         System.out.println(inputText9);
277         System.out.println(result);
278         assertEquals(resultText9, result);
279         result = processor.doDecoration(inputText9a, CmsEncoder.ENCODING_ISO_8859_1);
280         System.out.println(inputText9a);
281         System.out.println(result);
282         assertEquals(resultText9a, result);
283         System.out.println("");
284         
285         System.out.println("Testing decoration with blank in it");
286         result = processor.doDecoration(inputText10, CmsEncoder.ENCODING_ISO_8859_1);
287         System.out.println(inputText10);
288         System.out.println(result);
289         assertEquals(resultText10, result);
290         result = processor.doDecoration(inputText10a, CmsEncoder.ENCODING_ISO_8859_1);
291         System.out.println(inputText10a);
292         System.out.println(result);
293         assertEquals(resultText10a, result);
294         System.out.println("");
295         
296         System.out.println("Testing decoration inside of quatations");
297         result = processor.doDecoration(inputText11, CmsEncoder.ENCODING_ISO_8859_1);
298         System.out.println(inputText11);
299         System.out.println(result);
300         assertEquals(resultText11, result);
301         result = processor.doDecoration(inputText11a, CmsEncoder.ENCODING_ISO_8859_1);
302         System.out.println(inputText11a);
303         System.out.println(result);
304         assertEquals(resultText11a, result);
305         System.out.println("");
306     }
307     
308     /**
309      * Tests the decoration configuration.<p>
310      *
311      * @throws Exception if something goes wrong
312      */

313     public void testDecoratorConfiguration() throws Exception JavaDoc {
314         String JavaDoc configFile = "/decoration/configuration.xml";
315         
316         String JavaDoc inputTextEn1 = "CMS";
317         String JavaDoc resultTextEn1 ="<abbr title=\"Concerned Member State\" lang=\"en\">CMS</abbr>";
318    
319         String JavaDoc resultTextEn2 ="BKK";
320         
321         String JavaDoc inputTextDe1 = "BKK";
322         String JavaDoc resultTextDe1 ="<abbr title=\"Betriebskrankenkasse\" lang=\"de\">BKK</abbr>";
323         
324         String JavaDoc resultTextDe2 ="<abbr title=\"Content Management System\" lang=\"\">CMS</abbr>";
325       
326
327         
328         System.out.println("Testing the OpenCms decorator configuration.");
329        
330         // create a decorator configuration
331
CmsDecoratorConfiguration configuration = new CmsDecoratorConfiguration(getCmsObject(), configFile);
332         CmsHtmlDecorator decorator = new CmsHtmlDecorator(configuration);
333         
334         System.out.println("Testing english decoration in english bundle");
335         String JavaDoc result = decorator.doDecoration(inputTextEn1, CmsEncoder.ENCODING_ISO_8859_1);
336         System.out.println(inputTextEn1);
337         System.out.println(result);
338         assertEquals(resultTextEn1, result);
339         System.out.println("");
340         
341         System.out.println("Testing german decoration in english bundle");
342         result = decorator.doDecoration(inputTextDe1, CmsEncoder.ENCODING_ISO_8859_1);
343         System.out.println(inputTextDe1);
344         System.out.println(result);
345         assertEquals(resultTextEn2, result);
346         System.out.println("");
347         
348         // create a german decorator configuration
349
configuration = new CmsDecoratorConfiguration(getCmsObject(), configFile, new Locale JavaDoc("de"));
350         decorator = new CmsHtmlDecorator(configuration);
351
352         System.out.println("Testing german decoration in german bundle");
353         result = decorator.doDecoration(inputTextDe1, CmsEncoder.ENCODING_ISO_8859_1);
354         System.out.println(inputTextDe1);
355         System.out.println(result);
356         assertEquals(resultTextDe1, result);
357         System.out.println("");
358         
359         System.out.println("Testing neutral decoration in german bundle");
360         result = decorator.doDecoration(inputTextEn1, CmsEncoder.ENCODING_ISO_8859_1);
361         System.out.println(inputTextEn1);
362         System.out.println(result);
363         assertEquals(resultTextDe2, result);
364         System.out.println("");
365         
366         // create a language independend decorator configuration
367
configuration = new CmsDecoratorConfiguration(getCmsObject(), configFile, null);
368         decorator = new CmsHtmlDecorator(configuration);
369         
370         System.out.println("Testing english decoration in neutral bundle");
371         result = decorator.doDecoration(inputTextEn1, CmsEncoder.ENCODING_ISO_8859_1);
372         System.out.println(inputTextEn1);
373         System.out.println(result);
374         assertEquals(resultTextEn1, result);
375         System.out.println("");
376         
377         System.out.println("Testing german decoration in neutral bundle");
378         result = decorator.doDecoration(inputTextDe1, CmsEncoder.ENCODING_ISO_8859_1);
379         System.out.println(inputTextDe1);
380         System.out.println(result);
381         assertEquals(resultTextDe1, result);
382         System.out.println("");
383     }
384     
385     
386 }
387
Popular Tags