Package com.ecyrd.jspwiki.url

Source Code of com.ecyrd.jspwiki.url.DefaultURLConstructorTest

/*
* (C) Janne Jalkanen 2005
*
*/
package com.ecyrd.jspwiki.url;

import java.util.Properties;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import com.ecyrd.jspwiki.TestEngine;
import com.ecyrd.jspwiki.WikiContext;
import com.ecyrd.jspwiki.WikiEngine;
import com.ecyrd.jspwiki.WikiException;

public class DefaultURLConstructorTest extends TestCase
{
    TestEngine testEngine;

    Properties props = new Properties();
   
    protected void setUp() throws Exception
    {
        props.load( TestEngine.findTestProperties() );
    }

    private URLConstructor getConstructor( String baseURL, String prefix )
        throws WikiException
    {
        props.setProperty( WikiEngine.PROP_BASEURL, baseURL );
        if( prefix != null ) props.setProperty( ShortViewURLConstructor.PROP_PREFIX, prefix );
       
        testEngine = new TestEngine(props);
        URLConstructor constr = new DefaultURLConstructor();
       
        constr.initialize( testEngine, props );
       
        return constr;
    }
   
    public void testViewURL1()
        throws Exception
    {
        URLConstructor c = getConstructor( "http://localhost/", "wiki/" );
       
        assertEquals( "http://localhost/Wiki.jsp?page=Main", c.makeURL(WikiContext.VIEW,"Main",true,null) );
    }

    public void testViewURL2()
       throws Exception
    {
        URLConstructor c = getConstructor( "http://localhost/mywiki/", null );
   
        assertEquals( "http://localhost/mywiki/Wiki.jsp?page=Main", c.makeURL(WikiContext.VIEW,"Main",true,null) );
    }

    public void testViewURL3()
       throws Exception
    {
        URLConstructor c = getConstructor( "http://localhost:8080/", null );
        assertEquals( "http://localhost:8080/Wiki.jsp?page=Main", c.makeURL(WikiContext.VIEW,"Main",true,null) );
    }

    public void testViewURL4()
        throws Exception
    {
        URLConstructor c = getConstructor( "http://localhost/mywiki/", null );
        assertEquals( "/mywiki/Wiki.jsp?page=Main", c.makeURL(WikiContext.VIEW,"Main",false,null) );
    }

    public void testViewURL5()
        throws Exception
    {
        URLConstructor c = getConstructor( "http://localhost/", "" );
        assertEquals( "http://localhost/Wiki.jsp?page=Main", c.makeURL(WikiContext.VIEW,"Main",true,null) );
    }
   
    public void testViewURL6()
       throws Exception
    {
        URLConstructor c = getConstructor( "http://localhost/mywiki/app1/", null );
        assertEquals( "http://localhost/mywiki/app1/Wiki.jsp?page=Main", c.makeURL(WikiContext.VIEW,"Main",true,null) );
    }

    public void testViewURL7()
       throws Exception
    {
        URLConstructor c = getConstructor( "http://localhost/mywiki/app1/", "view/" );

        assertEquals( "http://localhost/mywiki/app1/Wiki.jsp?page=Main", c.makeURL(WikiContext.VIEW,"Main",true,null) );
    }

    public void testEditURL1()
        throws Exception
    {
        URLConstructor c = getConstructor( "http://localhost/mywiki/", null );
        assertEquals( "http://localhost/mywiki/Edit.jsp?page=Main", c.makeURL(WikiContext.EDIT,"Main",true,null) );
    }

    public void testAttachURL1()
        throws Exception
    {
        URLConstructor c = getConstructor( "http://localhost/mywiki/", null );

        assertEquals( "http://localhost/mywiki/attach/Main/foo.txt", c.makeURL(WikiContext.ATTACH,"Main/foo.txt",true,null) );
    }

    public void testAttachURLRelative1()
        throws Exception
    {
        URLConstructor c = getConstructor( "http://localhost/mywiki/", null );

        assertEquals( "/mywiki/attach/Main/foo.txt", c.makeURL(WikiContext.ATTACH,"Main/foo.txt",false,null) );
    }

    public void testOtherURL1()
        throws Exception
    {
        URLConstructor c = getConstructor( "http://localhost/mywiki/", null );

        assertEquals( "http://localhost/mywiki/foo.jsp", c.makeURL(WikiContext.NONE,"foo.jsp",true,null) );
    }
   
    public void testOtherURL2()
        throws Exception
    {
        URLConstructor c = getConstructor( "http://localhost/mywiki/dobble/", null );
   
        assertEquals( "http://localhost/mywiki/dobble/foo.jsp?a=1&b=2", c.makeURL(WikiContext.NONE,"foo.jsp",true,"a=1&b=2") );
    }

    public static Test suite()
    {
        return new TestSuite( DefaultURLConstructorTest.class );
    }
}
TOP

Related Classes of com.ecyrd.jspwiki.url.DefaultURLConstructorTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.