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

📄 conftest.java

📁 jsp中 urlRewrite的源代码 很有用的喔
💻 JAVA
字号:
/**
 * Copyright (c) 2005, Paul Tuckey
 * All rights reserved.
 *
 * Each copy or derived work must preserve the copyright notice and this
 * notice unmodified.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
package org.tuckey.web.filters.urlrewrite;

import junit.framework.TestCase;
import org.tuckey.web.filters.urlrewrite.utils.Log;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;


/**
 * @author Paul Tuckey
 * @version $Revision: 1.11 $ $Date: 2005/12/07 10:22:10 $
 */
public class ConfTest extends TestCase {

    public static final String BASE_XML_PATH = "/org/tuckey/web/filters/urlrewrite/";

    public void setUp() {
        Log.setLevel("DEBUG");
    }


    public void testGoodNormalConf() throws FileNotFoundException {
        InputStream is = ConfTest.class.getResourceAsStream(BASE_XML_PATH + "conf-test1.xml");
        Conf conf = new Conf(is, "conf-test1.xml");
        assertTrue(conf.isOk());
        List rules = conf.getRules();
        List outboundRules = conf.getOutboundRules();

        Rule rule = (Rule) rules.get(0);
        assertEquals("basicfrom1", rule.getFrom());
        assertEquals("basicto1", rule.getTo());
        assertFalse("rule 1 last not loading correctly", rule.isLast());
        assertEquals("forward", rule.getToType());
        assertEquals(false, rule.isEncodeToUrl());
        SetAttribute set = (SetAttribute) rule.getSetAttributes().get(0);
        assertEquals("name of set, it's " + set.getName(), "valuenull", set.getName());
        assertNull("value of set should be null, it's " + set.getValue(), set.getValue());

        Rule rule1 = (Rule) rules.get(1);
        assertEquals("basicfrom2", rule1.getFrom());
        assertEquals("basicto2", rule1.getTo());
        assertTrue("rule 2 last not loading correctly", rule1.isLast());
        assertEquals("redirect", rule1.getToType());
        assertEquals("true", "" + rule1.isFromCaseSensitive());
        Condition cond = (Condition) rule1.getConditions().get(0);
        assertEquals("true", "" + cond.isCaseSensitive());
        assertEquals("greater", cond.getOperator());

        Rule rule2 = (Rule) rules.get(2);
        SetAttribute set2 = (SetAttribute) rule2.getSetAttributes().get(0);
        assertEquals("blah", set2.getName());
        assertEquals("$1", set2.getValue());

        Rule rule4 = (Rule) rules.get(4);
        Run run = (Run) rule4.getRuns().get(0);
        assertEquals("testValue", run.getInitParam("testName"));

        OutboundRule outboundRule = (OutboundRule) outboundRules.get(0);
        assertEquals("default encode on to test", outboundRule.getName());
        assertEquals(true, outboundRule.isEncodeToUrl());

    }

    public void testNoDtdConf() throws FileNotFoundException {
        InputStream is = ConfTest.class.getResourceAsStream(BASE_XML_PATH + "conf-test-no-dtd.xml");
        Conf conf = new Conf(is, "conf-test-no-dtd.xml");
        assertTrue(conf.isOk());
    }

    public void testConfBadParse() throws FileNotFoundException {
        InputStream is = ConfTest.class.getResourceAsStream(BASE_XML_PATH + "conf-test-bad-parse.xml");
        Conf conf = new Conf(is, "conf-test-bad-parse.xml");
        assertTrue(conf.isOk());
    }

}

⌨️ 快捷键说明

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