<commit_before>package com.ecyrd.jspwiki.auth.acl;

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

import com.ecyrd.jspwiki.auth.acl.AclEntryImpl;
import com.ecyrd.jspwiki.auth.permissions.PagePermission;

public class AclEntryImplTest
    extends TestCase
{
    AclEntryImpl m_ae;

    public AclEntryImplTest( String s )
    {
        super( s );
    }

    public void setUp()
    {
        m_ae = new AclEntryImpl();
    }

    public void tearDown()
    {
    }

    public void testAddPermission()
    {
        m_ae.addPermission( new PagePermission( "view" ) );

        assertTrue( "no permission", m_ae.checkPermission( new PagePermission( "view" ) ) );
        assertFalse( "permission found", m_ae.checkPermission( new PagePermission( "edit" ) ) );
    }


    public void testAddPermission2()
    {
        m_ae.addPermission( new PagePermission( "view" ) );
        m_ae.addPermission( new PagePermission( "edit" ) );

        assertTrue( "no editpermission", m_ae.checkPermission( new PagePermission( "edit" ) ) );
        assertTrue( "no viewpermission", m_ae.checkPermission( new PagePermission( "view" ) ) );
    }

    public void testAddPermission3()
    {
        m_ae.addPermission( new PagePermission( "comment" ) );

        assertFalse( "has edit permission", m_ae.checkPermission( new PagePermission( "edit" ) ) );
    }

    public void testAddPermission4()
    {
        m_ae.addPermission( new PagePermission( "edit" ) );

        assertTrue( "has comment permission", m_ae.checkPermission( new PagePermission( "comment" ) ) );
    }
    
    public void testAddPermission5() {
        m_ae.addPermission( new PagePermission( "view" ) );
        
        assertTrue( "has view all", m_ae.checkPermission( new PagePermission( "view" ) ) );
        assertTrue( "has view on single page", m_ae.checkPermission( new PagePermission( "SamplePage", "view" ) ) );
    }

    public void testRemovePermission()
    {
        m_ae.addPermission( new PagePermission( "view" ) );
        m_ae.addPermission( new PagePermission( "edit" ) );

        assertTrue( "has edit permission", m_ae.checkPermission( new PagePermission( "edit" ) ) );
        assertTrue( "has view permission", m_ae.checkPermission( new PagePermission( "view" ) ) );

        m_ae.removePermission( new PagePermission( "edit" ) );

        assertFalse( "no edit permission", m_ae.checkPermission( new PagePermission( "edit" ) ) );
        assertTrue( "has view permission", m_ae.checkPermission( new PagePermission( "view" ) ) );
    }

    public void testDefaults()
    {
        assertFalse( "elements", m_ae.permissions().hasMoreElements() );
        assertNull( "principal", m_ae.getPrincipal() );<commit_msg>Replaced permission instances with enum members.<commit_after>package com.ecyrd.jspwiki.auth.acl;

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

import com.ecyrd.jspwiki.auth.acl.AclEntryImpl;
import com.ecyrd.jspwiki.auth.permissions.PagePermission;

public class AclEntryImplTest
    extends TestCase
{
    AclEntryImpl m_ae;

    public AclEntryImplTest( String s )
    {
        super( s );
    }

    public void setUp()
    {
        m_ae = new AclEntryImpl();
    }

    public void tearDown()
    {
    }

    public void testAddPermission()
    {
        m_ae.addPermission( PagePermission.VIEW );

        assertTrue( "no permission", m_ae.checkPermission( PagePermission.VIEW ) );
        assertFalse( "permission found", m_ae.checkPermission( PagePermission.EDIT ) );
    }


    public void testAddPermission2()
    {
        m_ae.addPermission( PagePermission.VIEW );
        m_ae.addPermission( PagePermission.EDIT );

        assertTrue( "no editpermission", m_ae.checkPermission( PagePermission.EDIT ) );
        assertTrue( "no viewpermission", m_ae.checkPermission( PagePermission.VIEW ) );
    }

    public void testAddPermission3()
    {
        m_ae.addPermission( PagePermission.COMMENT );

        assertFalse( "has edit permission", m_ae.checkPermission( PagePermission.EDIT ) );
    }

    public void testAddPermission4()
    {
        m_ae.addPermission( PagePermission.EDIT );

        assertTrue( "has comment permission", m_ae.checkPermission( PagePermission.COMMENT ) );
    }
    
    public void testAddPermission5() {
        m_ae.addPermission( PagePermission.VIEW );
        
        assertTrue( "has view all", m_ae.checkPermission( PagePermission.VIEW ) );
        assertTrue( "has view on single page", m_ae.checkPermission( new PagePermission( "mywiki:SamplePage", "view" ) ) );
    }

    public void testRemovePermission()
    {
        m_ae.addPermission( PagePermission.VIEW );
        m_ae.addPermission( PagePermission.EDIT );

        assertTrue( "has edit permission", m_ae.checkPermission( PagePermission.EDIT ) );
        assertTrue( "has view permission", m_ae.checkPermission( PagePermission.VIEW ) );

        m_ae.removePermission( PagePermission.EDIT );

        assertFalse( "no edit permission", m_ae.checkPermission( PagePermission.EDIT ) );
        assertTrue( "has view permission", m_ae.checkPermission( PagePermission.VIEW ) );
    }

    public void testDefaults()
    {
        assertFalse( "elements", m_ae.permissions().hasMoreElements() );
        assertNull( "principal", m_ae.getPrincipal() );
{'fraction_non_alphanumeric': 0.11177347242921014, 'fraction_numerical': 0.0014903129657228018, 'mean_word_length': 3.120491174213354, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3015132', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1545, 'n_words': 349}