FileDocCategorySizeDatePackage
IOwnerTest.javaAPI DocAndroid 1.5 API5287Wed May 06 22:41:06 BST 2009tests.security.acl

IOwnerTest

public class IOwnerTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtest_addOwner()

tests
java.security.acl.Owner#addOwner(Principal caller, Principal owner)

        Principal p1 = new PrincipalImpl("Owner");
        Principal p2 = new PrincipalImpl("AclOwner");
        Principal pt = new PrincipalImpl("NewOwner");
        MyOwner mo = new MyOwner(p1);
        try {
            //add new owner - TRUE expected
            assertTrue("Method returns FALSE", mo.addOwner(p1, pt));
            //add existent owner - FALSE expected
            assertFalse("Method returns TRUE", mo.addOwner(p1, pt));
        } catch (Exception ex) {
            fail("Unexpected exception " + ex);
        }
        //exception case
        try {
            mo.addOwner(p2, pt);
            fail("NotOwnerException was not thrown");
        } catch (NotOwnerException noe) {
            //expected
        }
    
public voidtest_deleteOwner()

tests
java.security.acl.Owner#deleteOwner(Principal caller, Principal owner)

        Principal caller = new PrincipalImpl("Owner");
        Principal owner1 = new PrincipalImpl("NewOwner1");
        Principal owner2 = new PrincipalImpl("NewOwner2");
        Principal notCaller = new PrincipalImpl("AclOwner");
        MyOwner mo = new MyOwner(caller);
        
        try {
            if (!mo.isOwner(owner1))  mo.addOwner(caller, owner1);
            if (!mo.isOwner(owner2))  mo.addOwner(caller, owner2);
        } catch (Exception e) {
            fail("Unexpected exception " + e + " was thrown for addOwner");
        }
        
        try {
            //remove existent owner - TRUE expected
            assertTrue("Method returns FALSE", mo.deleteOwner(caller, owner1));
            assertFalse("Object presents in the owner list", mo.isOwner(owner1));
            //remove owner which is not part of the list of owners - FALSE expected
            assertFalse("Method returns TRUE", mo.deleteOwner(caller, owner1));
            assertTrue("Method returns FALSE", mo.deleteOwner(caller, owner2));
        } catch (Exception ex) {
            fail("Unexpected exception " + ex);
        }
        //exception case - NotOwnerException
        try {
            mo.deleteOwner(notCaller, owner1);
            fail("NotOwnerException was not thrown");
        } catch (NotOwnerException noe) {
            //expected
        } catch (Exception e) {
            fail(e + " was thrown instead of NotOwnerException");
        }
        //exception case - LastOwnerException
        try {
            mo.deleteOwner(caller, owner2);
            fail("LastOwnerException was not thrown");
        } catch (LastOwnerException loe) {
            //expected
        } catch (Exception e) {
            fail(e + " was thrown instead of LastOwnerException");
        }
    
public voidtest_isOwner()

tests
java.security.acl.Owner#isOwner(Principal owner)

        MyOwner mo = new MyOwner(new PrincipalImpl("NewOwner"));
        try {
            assertFalse("Method returns TRUE", mo.isOwner(new PrincipalImpl("TestOwner")));
            assertTrue("Method returns FALSE", mo.isOwner(new PrincipalImpl("NewOwner")));
        } catch (Exception ex) {
            fail("Unexpected exception " + ex);
        }