001: /*
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */
008:
009: package test.javax.management;
010:
011: import java.io.ByteArrayInputStream;
012: import java.io.ByteArrayOutputStream;
013: import java.io.ObjectInputStream;
014: import java.io.ObjectOutputStream;
015:
016: import javax.management.MBeanServerPermission;
017:
018: /**
019: * @version $Revision: 1.9 $
020: */
021: public class MBeanServerPermissionTest extends PermissionTestCase {
022: public MBeanServerPermissionTest(String s) {
023: super (s);
024: }
025:
026: public void testInvalid() throws Exception {
027: try {
028: new MBeanServerPermission(null);
029: fail("Invalid MBeanServerPermission");
030: } catch (NullPointerException ignored) {
031: }
032:
033: try {
034: new MBeanServerPermission("");
035: fail("Invalid MBeanServerPermission");
036: } catch (IllegalArgumentException ignored) {
037: }
038:
039: try {
040: new MBeanServerPermission(" ");
041: fail("Invalid MBeanServerPermission");
042: } catch (IllegalArgumentException ignored) {
043: }
044:
045: try {
046: new MBeanServerPermission(" , ");
047: fail("Invalid MBeanServerPermission");
048: } catch (IllegalArgumentException ignored) {
049: }
050:
051: try {
052: new MBeanServerPermission("invalid");
053: fail("Invalid MBeanServerPermission");
054: } catch (IllegalArgumentException ignored) {
055: }
056:
057: try {
058: new MBeanServerPermission("*", "invalid");
059: fail("Invalid MBeanServerPermission");
060: } catch (IllegalArgumentException ignored) {
061: }
062: }
063:
064: public void testValid() throws Exception {
065: new MBeanServerPermission("*");
066: new MBeanServerPermission("*", "");
067: new MBeanServerPermission("createMBeanServer");
068: new MBeanServerPermission("releaseMBeanServer, findMBeanServer");
069: new MBeanServerPermission("newMBeanServer, *");
070: }
071:
072: public void testShuffledAreEquals() throws Exception {
073: MBeanServerPermission mbsp1 = new MBeanServerPermission(
074: "createMBeanServer, releaseMBeanServer");
075: MBeanServerPermission mbsp2 = new MBeanServerPermission(
076: "releaseMBeanServer, createMBeanServer");
077:
078: shouldBeEqual(mbsp1, mbsp2);
079:
080: MBeanServerPermission mbsp3 = new MBeanServerPermission("*");
081: MBeanServerPermission mbsp4 = new MBeanServerPermission(
082: "releaseMBeanServer, *");
083:
084: shouldBeEqual(mbsp3, mbsp4);
085: }
086:
087: public void testCreateImpliesNew() throws Exception {
088: shouldImply(new MBeanServerPermission("createMBeanServer"),
089: new MBeanServerPermission("newMBeanServer"));
090: }
091:
092: public void testImplies() throws Exception {
093: shouldImply(new MBeanServerPermission("*"),
094: new MBeanServerPermission("createMBeanServer"));
095: shouldImply(new MBeanServerPermission("*"),
096: new MBeanServerPermission("newMBeanServer"));
097: shouldImply(new MBeanServerPermission("*"),
098: new MBeanServerPermission("findMBeanServer"));
099: shouldImply(new MBeanServerPermission("*"),
100: new MBeanServerPermission("releaseMBeanServer"));
101: shouldImply(new MBeanServerPermission("*"),
102: new MBeanServerPermission(
103: "createMBeanServer, releaseMBeanServer"));
104: shouldImply(new MBeanServerPermission(
105: "createMBeanServer, releaseMBeanServer"),
106: new MBeanServerPermission("createMBeanServer"));
107: shouldImply(new MBeanServerPermission(
108: "createMBeanServer, releaseMBeanServer"),
109: new MBeanServerPermission("releaseMBeanServer"));
110: }
111:
112: public void testNotImplies() {
113: shouldNotImply(new MBeanServerPermission("createMBeanServer"),
114: new MBeanServerPermission("releaseMBeanServer"));
115: shouldNotImply(new MBeanServerPermission("createMBeanServer"),
116: new MBeanServerPermission(
117: "newMBeanServer, releaseMBeanServer"));
118: }
119:
120: public void testSerializationDeserialization() throws Exception {
121: MBeanServerPermission permission = new MBeanServerPermission(
122: "newMBeanServer, *");
123:
124: ByteArrayOutputStream baos = new ByteArrayOutputStream();
125: ObjectOutputStream oos = new ObjectOutputStream(baos);
126: oos.writeObject(permission);
127: oos.close();
128:
129: ByteArrayInputStream bais = new ByteArrayInputStream(baos
130: .toByteArray());
131: ObjectInputStream ois = new ObjectInputStream(bais);
132: MBeanServerPermission deserialized = (MBeanServerPermission) ois
133: .readObject();
134: ois.close();
135:
136: if (!(deserialized.equals(permission)))
137: fail("Serialization/Deserialization failed");
138: }
139: }
|