* Tests that getPermissions() does proper permission evaluation.
*/
public void testGetPermissions() {
SecurityPermission sp = new SecurityPermission("abc");
SecurityPermission sp2 = new SecurityPermission("fbdf");
PermissionCollection spc = sp.newPermissionCollection();
spc.add(sp2);
ProtectionDomain pd = new ProtectionDomain(null, null);
ProtectionDomain pd2 = new ProtectionDomain(null, spc);
TestProvider policy = new TestProvider();
policy.pc = sp.newPermissionCollection();
//case1: empty policy, no static permissions in PD
PermissionCollection pc4pd = policy.getPermissions(pd);
assertNotNull(pc4pd);
Enumeration en = pc4pd.elements();
assertFalse(en.hasMoreElements());
//case2: empty policy, some static permissions in PD
pc4pd = policy.getPermissions(pd2);
assertNotNull(pc4pd);
//no check for static permissions
//case3: non-empty policy, no static permissions in PD
policy.pc.add(sp);
pc4pd = policy.getPermissions(pd);
assertNotNull(pc4pd);
Collection c = new HashSet();
for (en = pc4pd.elements();en.hasMoreElements(); c.add(en.nextElement())) {
}
assertTrue(c.contains(sp));
//case4: non-empty policy, some static permissions in PD
pc4pd = policy.getPermissions(pd2);
assertNotNull(pc4pd);
c = new HashSet();
for (en = pc4pd.elements();en.hasMoreElements(); c.add(en.nextElement())) {
}
assertTrue(c.contains(sp));
//no check for static permissions
}