⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdecorator.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/test/org/opencms/jsp/decorator/TestDecorator.java,v $
 * Date   : $Date: 2007-08-13 16:30:15 $
 * Version: $Revision: 1.5 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.jsp.decorator;

import org.opencms.i18n.CmsEncoder;
import org.opencms.test.OpenCmsTestCase;
import org.opencms.test.OpenCmsTestProperties;

import java.util.Locale;

import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestSuite;

/**
 * Tests for the decoration postprocessor.<p>
 * 
 * @author Michael Emmerich
 * 
 * @version $Revision: 1.5 $
 * 
 * @since 6.1.3
 */
public class TestDecorator extends OpenCmsTestCase {

    /**
     * Default JUnit constructor.<p>
     * 
     * @param arg0 JUnit parameters
     */
    public TestDecorator(String arg0) {

        super(arg0);
    }

    /**
     * Test suite for this test class.<p>
     * 
     * @return the test suite
     */
    public static Test suite() {

        OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);

        TestSuite suite = new TestSuite();
        suite.setName(TestDecorator.class.getName());

        suite.addTest(new TestDecorator("testDecoratorBasics"));
        suite.addTest(new TestDecorator("testDecoratorConfiguration"));

        TestSetup wrapper = new TestSetup(suite) {

            protected void setUp() {

                setupOpenCms("decoration", "/sites/default/");
            }

            protected void tearDown() {

                removeOpenCms();
            }
        };

        return wrapper;
    }

    /**
     * Tests the decoration postprocessor.<p>
     * 
     * @throws Exception if something goes wrong
     */
    public void testDecoratorBasics() throws Exception {

        // define test values and results
        String 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.";
        String 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.";
        
        String 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.";
        String 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.";
        
        String inputText3 = "This is a test for VFS&nbsp;RFS and VFS.";
        String resultText3 = "This is a test for <abbr>VFS</abbr>&nbsp;<abbr>RFS</abbr> and <abbr>VFS</abbr>.";
        
        String inputText4 = "This is a test German Umlaute: T躒 is fine, but does T&UumlV work as well?";
        String resultText4 = "This is a test German Umlaute: <abbr title=\"Technischer 躡erwachungsverein\">T躒</abbr> is fine, but does <abbr>T躒</abbr> work as well?";
        
        String inputText5 = "The CMS has a nice user interface, the so called CMS-UI. This must not be mixed up with the CMS-IU!";
        String 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!";
  
        String inputText6 = "Does it work to use a '?' as a delimiter for the CMS?";
        String resultText6 = "Does it work to use a '?' as a delimiter for the <abbr>CMS</abbr>?";
 
        String inputText6a = "This is VFS@CMS.";
        String resultText6a = "This is <abbr>VFS</abbr>@<abbr>CMS</abbr>.";
        
        String inputText6b = "This is ABC@DEF.";
        String resultText6b = "This is <abbr title=\"A strange thing with a @ in it\">ABC@DEF</abbr>.";

        String inputText7 = "<Strong>CMS</strong>. Will it be decorated? <h1>VFS</h1>: Is very nice!";
        String resultText7 = "<Strong><abbr>CMS</abbr></strong>. Will it be decorated? <h1><abbr>VFS</abbr></h1>: Is very nice!";
  
        String inputText7a = "Test with a dash - the dashes should be still there - even if I write RFS.";
        String resultText7a = "Test with a dash - the dashes should be still there - even if I write <abbr>RFS</abbr>.";
    
        String inputText8 = "Hello, my name is Dr. Bull!";
        String resultText8 = "Hello, my name is <abbr title=\"Doctor\">Dr.</abbr> Bull!";
        
        String inputText8a = "<p>Dr. Dr.</p>";
        String resultText8a = "<p><abbr>Dr.</abbr> <abbr>Dr.</abbr></p>";       
        
        String inputText9 = "Do we find words with multiple lookups, e.g. CMS?";
        String resultText9 = "Do we find words with multiple lookups, <abbr title=\"example given\">e.g.</abbr> <abbr>CMS</abbr>?";

        String inputText9a = "Another example: z. B. is very nice.";
        String resultText9a = "Another example: <abbr title=\"zum Beispiel\">z. B.</abbr> is very nice.";
        
        String inputText10 = "Let's see: ZB MED - a CMS decoration in the VFS with a blank in it.";
        String 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.";

        String inputText10a = "Let's see: ZB&nbsp;MED - a CMS decoration in the VFS with a blank in it.";
        String 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.";

        
        String inputText11 = "This is a word inside quotations: \"CMS\".";
        String resultText11 = "This is a word inside quotations: \"<abbr>CMS</abbr>\".";
        
        String inputText11a = "This is a word inside quotations: &quot;CMS&quot;.";
        String resultText11a = "This is a word inside quotations: &quot;<abbr>CMS</abbr>&quot;.";
        
        String preTextFirst = "<abbr title=\"${decoration}\">";
        String postTextFirst = "</abbr>";
        String preText = "<abbr>";
        String postText = "</abbr>";
        
        System.out.println("Testing the OpenCms decorator.");
        
        // add a DecorationDefintinion
        CmsDecorationDefintion decDef1 = new CmsDecorationDefintion();
        decDef1.setMarkFirst(true);
        decDef1.setPreTextFirst(preTextFirst);
        decDef1.setPostTextFirst(postTextFirst);
        decDef1.setPreText(preText);
        decDef1.setPostText(postText);
        decDef1.setName("Abbr-Decoration");
        
        Locale locale = new Locale("en");
        // add some text decorations to the decoration map
        CmsDecorationBundle decorationMap = new CmsDecorationBundle();
        decorationMap.put("CMS", new CmsDecorationObject("CMS", "Content Management System", decDef1, locale));
        decorationMap.put("VFS", new CmsDecorationObject("VFS", "Virtual File System", decDef1, locale));
        decorationMap.put("RFS", new CmsDecorationObject("RFS", "Real File System", decDef1, locale));
        decorationMap.put("T躒", new CmsDecorationObject("T躒", "Technischer 躡erwachungsverein", decDef1, locale));
        decorationMap.put("Dr.", new CmsDecorationObject("Dr.", "Doctor", decDef1, locale));
        decorationMap.put("z. B.", new CmsDecorationObject("z. B.", "zum Beispiel", decDef1, locale));
        decorationMap.put("e.g.", new CmsDecorationObject("e.g.", "example given", decDef1, locale));
        decorationMap.put("ZB MED", new CmsDecorationObject("ZB MED", "a decoarion with a blank in it", decDef1, locale));
        decorationMap.put("ZB&nbsp;MED", new CmsDecorationObject("ZB&nbsp;MED", "a decoarion with a blank in it", decDef1, locale));        
        decorationMap.put("CMS-UI", new CmsDecorationObject("CMS-UI", "Content Management System User Interface", decDef1, locale));
        decorationMap.put("ABC@DEF", new CmsDecorationObject("ABC@DEF", "A strange thing with a @ in it", decDef1, locale));
        
        
        // create a decorator  configuration
        CmsDecoratorConfiguration configuration = new CmsDecoratorConfiguration(getCmsObject());
        configuration.setDecorations(decorationMap);
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -