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

📄 webcontainerauthorizertest.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
字号:
package com.ecyrd.jspwiki.auth.authorize;import java.security.Principal;import java.util.Properties;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;import org.apache.commons.lang.ArrayUtils;import org.jdom.Document;import com.ecyrd.jspwiki.TestEngine;import com.ecyrd.jspwiki.WikiEngine;public class WebContainerAuthorizerTest extends TestCase{    WikiEngine m_engine;    WebContainerAuthorizer m_authorizer;    Document   m_webxml;    public WebContainerAuthorizerTest( String s )    {        super( s );    }    public void setUp() throws Exception    {        Properties props = new Properties();        props.load( TestEngine.findTestProperties() );        m_engine = new TestEngine( props );        m_authorizer = new WebContainerAuthorizer();        m_authorizer.initialize( m_engine, props );        m_webxml = m_authorizer.getWebXml();        if ( m_webxml == null )        {            throw new Exception("Could not load web.xml");        }    }    public void testConstraints() throws Exception    {        assertTrue( m_authorizer.isConstrained( "/Delete.jsp", new Role( "Admin" ) ) );        assertTrue( m_authorizer.isConstrained( "/Login.jsp", Role.AUTHENTICATED ) );        assertFalse( m_authorizer.isConstrained( "/UserPreferences.jsp", Role.AUTHENTICATED ) );    }        public void testGetRoles()    {        // We should find 2 roles: AUTHENTICATED plus custom role "Admin"        Principal[] roles = m_authorizer.getRoles();        assertEquals( 2, roles.length );        assertTrue( ArrayUtils.contains( roles, Role.AUTHENTICATED ) );        assertTrue( ArrayUtils.contains( roles, new Role( "Admin" ) ) );    }        public void testRoles() throws Exception    {        Role[] roles = m_authorizer.getRoles( m_webxml );        boolean found = false;        for ( int i = 0; i < roles.length; i++ )        {            if ( roles[i].equals( Role.AUTHENTICATED ) )            {                found = true;            }        }        assertTrue( "Didn't find AUTHENTICATED", found );        for ( int i = 0; i < roles.length; i++ )        {            if ( roles[i].equals( new Role( "Admin" ) ) )            {                found = true;            }        }        assertTrue( "Didn't find ADMIN", found );    }        public void testIsContainerAuthorized()    {        assertTrue( m_authorizer.isContainerAuthorized() );    }    public static Test suite()    {        return new TestSuite( WebContainerAuthorizerTest.class );    }}

⌨️ 快捷键说明

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