KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > compliance > security > MBeanPermissionTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package test.compliance.security;
9
10 import java.security.PermissionCollection;
11 import javax.management.MBeanPermission;
12
13 import junit.framework.TestCase;
14
15 /** Tests of the javax.management.MBeanPermission
16  *
17  * @author Scott.Stark@jboss.org
18  * @version $Revision: 1.2 $
19  */

20 public class MBeanPermissionTestCase
21   extends TestCase
22 {
23    public MBeanPermissionTestCase(String s)
24    {
25       super(s);
26    }
27    
28    public void testCtor()
29    {
30       MBeanPermission p = new MBeanPermission("*", "*");
31
32       
33    }
34
35    public void testImpiles()
36    {
37       MBeanPermission p0 = new MBeanPermission("*", "*");
38       MBeanPermission p1 = new MBeanPermission("*", "*");
39       assertTrue("* implies *", p1.implies(p0));
40
41       p0 = new MBeanPermission("[*:*]", "*");
42       p1 = new MBeanPermission("[*:*]", "*");
43       assertTrue("[*:*] * implies [*:*] *", p1.implies(p0));
44
45       p0 = new MBeanPermission("*", "*");
46       p1 = new MBeanPermission("#", "*");
47       assertTrue("# implies *", p1.implies(p0));
48
49       p0 = new MBeanPermission("*#", "*");
50       p1 = new MBeanPermission("*", "*");
51       assertTrue("*# implies *", p1.implies(p0));
52
53       p0 = new MBeanPermission("*", "addNotificationListener");
54       p1 = new MBeanPermission("*", "*");
55       assertTrue("* * implies * addNotificationListener", p1.implies(p0));
56
57       p0 = new MBeanPermission("*", "queryMBeans");
58       p1 = new MBeanPermission("*", "queryNames");
59       assertTrue("* queryMBeans implies * queryNames", p0.implies(p1));
60
61       p0 = new MBeanPermission("[MyDomain:type=Product]", "getAttribute");
62       p1 = new MBeanPermission("test.Product#Price[MyDomain:type=Product]", "getAttribute");
63       assertTrue(p0+" implies "+p1, p0.implies(p1));
64
65       p0 = new MBeanPermission("a.b.c#d[e:f=g]", "*");
66       p1 = new MBeanPermission("a.b.c#d[e:f=g]", "getAttribute");
67       assertTrue(p0+" implies "+p1, p0.implies(p1));
68    }
69
70    public void testNotImpiled() throws Exception
71    {
72       MBeanPermission p0 = new MBeanPermission("test.Product#Price[MyDomain:type=Product]", "getAttribute");
73       MBeanPermission p1 = new MBeanPermission("test.Product#Cost[MyDomain:type=Product]", "getAttribute");
74       assertTrue("!p0 implies p1", p0.implies(p1) == false);
75
76       p0 = new MBeanPermission("a.b.c#d[e:f=g]", "*");
77       p1 = new MBeanPermission("a.b.c#d[e:f=g]", "getAttribute");
78       assertTrue(p1+" ! implies "+p0, p1.implies(p0) == false);
79    }
80 }
81
Popular Tags