IGroupTest.java revision 5d709784bbf5001012d7f25172927d46f6c1abe1
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package tests.security.acl; 19 20import dalvik.annotation.TestTargets; 21import dalvik.annotation.TestLevel; 22import dalvik.annotation.TestTargetNew; 23import dalvik.annotation.TestTargetClass; 24 25import junit.framework.TestCase; 26 27import java.security.acl.Group; 28import java.security.Principal; 29import java.util.Enumeration; 30 31import org.apache.harmony.security.tests.support.acl.*; 32 33@TestTargetClass(Group.class) 34public class IGroupTest extends TestCase { 35 36 class MyGroup extends GroupImpl { 37 public MyGroup(String str) { 38 super(str); 39 } 40 } 41 42 /** 43 * @tests java.security.acl.Group#addMember(Principal user) 44 */ 45 @TestTargets({ 46 @TestTargetNew( 47 level = TestLevel.COMPLETE, 48 notes = "", 49 method = "addMember", 50 args = {java.security.Principal.class} 51 ), 52 @TestTargetNew( 53 level = TestLevel.COMPLETE, 54 notes = "", 55 method = "isMember", 56 args = {java.security.Principal.class} 57 ), 58 @TestTargetNew( 59 level = TestLevel.COMPLETE, 60 notes = "", 61 method = "removeMember", 62 args = {java.security.Principal.class} 63 ) 64 }) 65 public void test_addMember() { 66 MyGroup gr = new MyGroup("TestOwners"); 67 Principal pr = new PrincipalImpl("TestPrincipal"); 68 try { 69 assertTrue(gr.addMember(pr)); 70 assertFalse(gr.addMember(pr)); 71 assertTrue(gr.isMember(pr)); 72 assertTrue(gr.removeMember(pr)); 73 assertFalse(gr.isMember(pr)); 74 assertFalse(gr.removeMember(pr)); 75 } catch (Exception e) { 76 fail("Unexpected exception " + e); 77 } 78 } 79 80 /** 81 * @tests java.security.acl.Group#members() 82 */ 83 @TestTargetNew( 84 level = TestLevel.COMPLETE, 85 notes = "", 86 method = "members", 87 args = {} 88 ) 89 public void test_members() { 90 MyGroup gr = new MyGroup("TestOwners"); 91 Principal pr = new PrincipalImpl("TestPrincipal"); 92 try { 93 Enumeration en = gr.members(); 94 assertFalse("Not empty enumeration", en.hasMoreElements()); 95 assertTrue(gr.addMember(pr)); 96 assertTrue("Empty enumeration", en.hasMoreElements()); 97 } catch (Exception e) { 98 fail("Unexpected exception " + e); 99 } 100 } 101}