KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > compliance > security > MBeanPermissionTestCase


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.jmx.compliance.security;
23
24 import javax.management.MBeanPermission JavaDoc;
25
26 import junit.framework.TestCase;
27
28 /** Tests of the javax.management.MBeanPermission
29  *
30  * @author Scott.Stark@jboss.org
31  * @version $Revision: 37459 $
32  */

33 public class MBeanPermissionTestCase
34   extends TestCase
35 {
36    public MBeanPermissionTestCase(String JavaDoc s)
37    {
38       super(s);
39    }
40    
41    public void testCtor()
42    {
43       MBeanPermission JavaDoc p = new MBeanPermission JavaDoc("*", "*");
44    }
45
46    public void testImpiles()
47    {
48       MBeanPermission JavaDoc p0 = new MBeanPermission JavaDoc("*", "*");
49       MBeanPermission JavaDoc p1 = new MBeanPermission JavaDoc("*", "*");
50       assertTrue("* implies *", p1.implies(p0));
51
52       p0 = new MBeanPermission JavaDoc("[*:*]", "*");
53       p1 = new MBeanPermission JavaDoc("[*:*]", "*");
54       assertTrue("[*:*] * implies [*:*] *", p1.implies(p0));
55
56       p0 = new MBeanPermission JavaDoc("*", "*");
57       p1 = new MBeanPermission JavaDoc("#", "*");
58       assertTrue("# implies *", p1.implies(p0));
59
60       p0 = new MBeanPermission JavaDoc("*#", "*");
61       p1 = new MBeanPermission JavaDoc("*", "*");
62       assertTrue("*# implies *", p1.implies(p0));
63
64       p0 = new MBeanPermission JavaDoc("*", "addNotificationListener");
65       p1 = new MBeanPermission JavaDoc("*", "*");
66       assertTrue("* * implies * addNotificationListener", p1.implies(p0));
67
68       p0 = new MBeanPermission JavaDoc("*", "queryMBeans");
69       p1 = new MBeanPermission JavaDoc("*", "queryNames");
70       assertTrue("* queryMBeans implies * queryNames", p0.implies(p1));
71
72       p0 = new MBeanPermission JavaDoc("[MyDomain:type=Product]", "getAttribute");
73       p1 = new MBeanPermission JavaDoc("test.Product#Price[MyDomain:type=Product]", "getAttribute");
74       assertTrue(p0+" implies "+p1, p0.implies(p1));
75
76       p0 = new MBeanPermission JavaDoc("a.b.c#d[e:f=g]", "*");
77       p1 = new MBeanPermission JavaDoc("a.b.c#d[e:f=g]", "getAttribute");
78       assertTrue(p0+" implies "+p1, p0.implies(p1));
79
80       p0 = new MBeanPermission JavaDoc("a.b.c#*[e:f=g]", "*");
81       p1 = new MBeanPermission JavaDoc("a.b.c#d[e:f=g]", "getAttribute");
82       assertTrue(p0+" implies "+p1, p0.implies(p1));
83    }
84
85    public void testNotImpiled() throws Exception JavaDoc
86    {
87       MBeanPermission JavaDoc p0 = new MBeanPermission JavaDoc("test.Product#Price[MyDomain:type=Product]", "getAttribute");
88       MBeanPermission JavaDoc p1 = new MBeanPermission JavaDoc("test.Product#Cost[MyDomain:type=Product]", "getAttribute");
89       assertTrue("!p0 implies p1", p0.implies(p1) == false);
90
91       p0 = new MBeanPermission JavaDoc("a.b.c#d[e:f=g]", "*");
92       p1 = new MBeanPermission JavaDoc("a.b.c#d[e:f=g]", "getAttribute");
93       assertTrue(p1+" ! implies "+p0, p1.implies(p0) == false);
94    }
95 }
96
Popular Tags