Index: gnu/testlet/javax/management/MBeanServerInvocationHandler/Colour.java =================================================================== RCS file: gnu/testlet/javax/management/MBeanServerInvocationHandler/Colour.java diff -N gnu/testlet/javax/management/MBeanServerInvocationHandler/Colour.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/javax/management/MBeanServerInvocationHandler/Colour.java 5 Mar 2007 00:31:51 -0000 @@ -0,0 +1,27 @@ +// Tags: not-a-test + +// Copyright (C) 2007 Andrew John Hughes + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +package gnu.testlet.javax.management.MBeanServerInvocationHandler; + +public enum Colour +{ + RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET; +} Index: gnu/testlet/javax/management/MBeanServerInvocationHandler/MBeanProxy.java =================================================================== RCS file: gnu/testlet/javax/management/MBeanServerInvocationHandler/MBeanProxy.java diff -N gnu/testlet/javax/management/MBeanServerInvocationHandler/MBeanProxy.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/javax/management/MBeanServerInvocationHandler/MBeanProxy.java 5 Mar 2007 00:31:51 -0000 @@ -0,0 +1,149 @@ +// Tags: JDK1.5 + +// Copyright (C) 2007 Andrew John Hughes + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +package gnu.testlet.javax.management.MBeanServerInvocationHandler; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +import java.lang.management.ManagementFactory; + +import java.lang.reflect.Proxy; + +import javax.management.JMX; +import javax.management.MalformedObjectNameException; +import javax.management.MBeanServer; +import javax.management.ObjectName; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + +/** + * Tests {@link MBeanServerInvocationHandler} + * for MBeans. + * + * @author Andrew John Hughes + */ +public class MBeanProxy + implements Testlet +{ + + public void test(TestHarness h) + { + ObjectName name = null; + ObjectName namex = null; + ObjectName namec = null; + try + { + name = new ObjectName("mauve:test=go"); + namex = new ObjectName("mauve:test=gox"); + namec = new ObjectName("mauve:test=goc"); + } + catch (MalformedObjectNameException e) + { + h.debug(e); + } + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + try + { + server.registerMBean(new Test("GNU Classpath"), name); + server.registerMBean(new TestX("GNU Classpath"), namex); + server.registerMBean(new TestC(), namec); + } + catch (Exception e) + { + h.debug(e); + } + TestMBean test = JMX.newMBeanProxy(server, name, TestMBean.class); + h.check(test.getName(), "GNU Classpath", "Name test"); + h.check(test.isEdible(), false, "Edible test"); + h.checkPoint("Mutator test"); + test.setName("Mauve"); + h.check(test.getName(), "Mauve", "Name test after change"); + h.check(test.equals(test), "Proxy equivalence reflection test"); + TestXMBean testx = JMX.newMBeanProxy(server, namex, TestXMBean.class); + h.checkPoint("Calling equals"); + testx.equals(null); + h.check(testx.getLastMethodCalled(), "equals"); + h.checkPoint("Calling hashCode"); + testx.hashCode(); + h.check(testx.getLastMethodCalled(), "hashCode"); + h.checkPoint("Calling toString"); + testx.toString(); + h.check(testx.getLastMethodCalled(), "toString"); + TestCMXBean testc = JMX.newMXBeanProxy(server, namec, TestCMXBean.class); + h.checkPoint("Setting id"); + testc.setId(42); + h.check(testc.getId(), 42, "Getting id"); + h.checkPoint("Setting size"); + testc.setSize(5); + h.check(testc.getSize() == 5, "Getting size"); + h.checkPoint("Setting name"); + testc.setName(namec); + h.check(testc.getName(), namec, "Getting name"); + h.checkPoint("Setting weights"); + float[] weights = new float[] { 0.5f, -0.7f }; + testc.setWeights(weights); + h.check(testc.getWeights(), weights, "Getting weights"); + h.checkPoint("Setting names"); + String[] names = new String[] { "Bob", "Jim", "Jake" }; + testc.setNames(names); + h.check(testc.getNames(), names, "Getting names"); + h.checkPoint("Setting ages"); + Set ages = new HashSet(); + ages.add(45); + ages.add(24); + testc.setAges(ages); + h.check(testc.getAges(), ages, "Getting ages"); + h.checkPoint("Setting biscuits"); + SortedSet biscuits = new TreeSet(); + biscuits.add("Chocolate"); + biscuits.add("Ginger"); + biscuits.add("Plain"); + testc.setBiscuits(biscuits); + h.check(testc.getBiscuits(), biscuits, "Getting biscuits"); + h.checkPoint("Setting colour"); + testc.setColour(Colour.RED); + h.check(testc.getColour(), Colour.RED, "Getting colour"); + h.checkPoint("Setting phone numbers"); + Map numbers = new HashMap(); + numbers.put("Bob",999); + numbers.put("Jim",111); + numbers.put("Sam",55); + testc.setPhoneNumbers(numbers); + h.check(testc.getPhoneNumbers(), numbers, "Getting phone numbers"); + h.checkPoint("Setting sorted phone numbers"); + SortedMap snumbers = new TreeMap(); + snumbers.put("Bob",999); + snumbers.put("Jim",111); + snumbers.put("Sam",55); + testc.setSortedPhoneNumbers(snumbers); + h.check(testc.getSortedPhoneNumbers(), numbers, "Getting sorted phone numbers"); + } + +} + Index: gnu/testlet/javax/management/MBeanServerInvocationHandler/Test.java =================================================================== RCS file: gnu/testlet/javax/management/MBeanServerInvocationHandler/Test.java diff -N gnu/testlet/javax/management/MBeanServerInvocationHandler/Test.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/javax/management/MBeanServerInvocationHandler/Test.java 5 Mar 2007 00:31:51 -0000 @@ -0,0 +1,55 @@ +// Tags: not-a-test + +// Copyright (C) 2007 Andrew John Hughes + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +package gnu.testlet.javax.management.MBeanServerInvocationHandler; + +/** + * Test bean implementation for proxying. + * + * @author Andrew John Hughes + */ +public class Test + implements TestMBean +{ + + private String name; + + public Test(String name) + { + setName(name); + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public boolean isEdible() + { + return false; + } + +} Index: gnu/testlet/javax/management/MBeanServerInvocationHandler/TestC.java =================================================================== RCS file: gnu/testlet/javax/management/MBeanServerInvocationHandler/TestC.java diff -N gnu/testlet/javax/management/MBeanServerInvocationHandler/TestC.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/javax/management/MBeanServerInvocationHandler/TestC.java 5 Mar 2007 00:31:51 -0000 @@ -0,0 +1,159 @@ +// Tags: not-a-test + +// Copyright (C) 2007 Andrew John Hughes + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +package gnu.testlet.javax.management.MBeanServerInvocationHandler; + +import javax.management.ObjectName; + +import java.util.Map; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; + +/** + * Test {@link javax.management.MXBean} implementation for proxying. + * + * @author Andrew John Hughes + */ +public class TestC + implements TestCMXBean +{ + + private int id; + + private Integer size; + + private ObjectName name; + + private float[] weights; + + private String[] names; + + private Set ages; + + private SortedSet biscuits; + + private Colour colour; + + private Map numbers; + + private SortedMap sortedNumbers; + + public int getId() + { + return id; + } + + public void setId(int id) + { + this.id = id; + } + + public Integer getSize() + { + return size; + } + + public void setSize(Integer size) + { + this.size = size; + } + + public ObjectName getName() + { + return name; + } + + public void setName(ObjectName name) + { + this.name = name; + } + + public float[] getWeights() + { + return weights; + } + + public void setWeights(float[] weights) + { + this.weights = weights; + } + + public String[] getNames() + { + return names; + } + + public void setNames(String[] names) + { + this.names = names; + } + + public Set getAges() + { + return ages; + } + + public void setAges(Set ages) + { + this.ages = ages; + } + + public SortedSet getBiscuits() + { + return biscuits; + } + + public void setBiscuits(SortedSet biscuits) + { + this.biscuits = biscuits; + } + + public Colour getColour() + { + return colour; + } + + public void setColour(Colour colour) + { + this.colour = colour; + } + + public Map getPhoneNumbers() + { + return numbers; + } + + public void setPhoneNumbers(Map numbers) + { + this.numbers = numbers; + } + + public SortedMap getSortedPhoneNumbers() + { + return sortedNumbers; + } + + public void setSortedPhoneNumbers(SortedMap numbers) + { + sortedNumbers = numbers; + } +} Index: gnu/testlet/javax/management/MBeanServerInvocationHandler/TestCMXBean.java =================================================================== RCS file: gnu/testlet/javax/management/MBeanServerInvocationHandler/TestCMXBean.java diff -N gnu/testlet/javax/management/MBeanServerInvocationHandler/TestCMXBean.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/javax/management/MBeanServerInvocationHandler/TestCMXBean.java 5 Mar 2007 00:31:51 -0000 @@ -0,0 +1,78 @@ +// Tags: not-a-test + +// Copyright (C) 2007 Andrew John Hughes + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +package gnu.testlet.javax.management.MBeanServerInvocationHandler; + +import javax.management.ObjectName; + +import java.util.Map; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; + +/** + * Test {@link javax.management.MXBean} for proxying. + * + * @author Andrew John Hughes + */ +public interface TestCMXBean +{ + + int getId(); + + void setId(int id); + + Integer getSize(); + + void setSize(Integer size); + + ObjectName getName(); + + void setName(ObjectName name); + + float[] getWeights(); + + void setWeights(float[] weights); + + String[] getNames(); + + void setNames(String[] names); + + Set getAges(); + + void setAges(Set ages); + + SortedSet getBiscuits(); + + void setBiscuits(SortedSet biscuits); + + Colour getColour(); + + void setColour(Colour colour); + + Map getPhoneNumbers(); + + void setPhoneNumbers(Map numbers); + + SortedMap getSortedPhoneNumbers(); + + void setSortedPhoneNumbers(SortedMap numbers); +} Index: gnu/testlet/javax/management/MBeanServerInvocationHandler/TestMBean.java =================================================================== RCS file: gnu/testlet/javax/management/MBeanServerInvocationHandler/TestMBean.java diff -N gnu/testlet/javax/management/MBeanServerInvocationHandler/TestMBean.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/javax/management/MBeanServerInvocationHandler/TestMBean.java 5 Mar 2007 00:31:52 -0000 @@ -0,0 +1,40 @@ +// Tags: not-a-test + +// Copyright (C) 2007 Andrew John Hughes + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +package gnu.testlet.javax.management.MBeanServerInvocationHandler; + +import javax.management.MBeanServerInvocationHandler; + +/** + * Test bean for proxying. + * + * @author Andrew John Hughes + */ +public interface TestMBean +{ + + String getName(); + + void setName(String name); + + boolean isEdible(); + +} Index: gnu/testlet/javax/management/MBeanServerInvocationHandler/TestX.java =================================================================== RCS file: gnu/testlet/javax/management/MBeanServerInvocationHandler/TestX.java diff -N gnu/testlet/javax/management/MBeanServerInvocationHandler/TestX.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/javax/management/MBeanServerInvocationHandler/TestX.java 5 Mar 2007 00:31:52 -0000 @@ -0,0 +1,69 @@ +// Tags: not-a-test + +// Copyright (C) 2007 Andrew John Hughes + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +package gnu.testlet.javax.management.MBeanServerInvocationHandler; + +/** + * Test bean implementation for proxying. + * + * @author Andrew John Hughes + */ +public class TestX + extends Test + implements TestXMBean +{ + + private String lastMethodCalled; + + public TestX(String name) + { + super(name); + } + + public boolean equals(Object obj) + { + lastMethodCalled = "equals"; + return false; + } + + public int hashCode() + { + lastMethodCalled = "hashCode"; + return 42; + } + + public String getLastMethodCalled() + { + return lastMethodCalled; + } + + public String toString() + { + lastMethodCalled = "toString"; + return getClass().getName() + + "[name=" + getName() + + ",isEdible=" + isEdible() + + ",lastMethodCalled=" + lastMethodCalled + + "]"; + } + + +} Index: gnu/testlet/javax/management/MBeanServerInvocationHandler/TestXMBean.java =================================================================== RCS file: gnu/testlet/javax/management/MBeanServerInvocationHandler/TestXMBean.java diff -N gnu/testlet/javax/management/MBeanServerInvocationHandler/TestXMBean.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/javax/management/MBeanServerInvocationHandler/TestXMBean.java 5 Mar 2007 00:31:52 -0000 @@ -0,0 +1,43 @@ +// Tags: not-a-test + +// Copyright (C) 2007 Andrew John Hughes + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +package gnu.testlet.javax.management.MBeanServerInvocationHandler; + +import javax.management.MBeanServerInvocationHandler; + +/** + * Test bean for proxying. + * + * @author Andrew John Hughes + */ +public interface TestXMBean + extends TestMBean +{ + + boolean equals(Object obj); + + int hashCode(); + + String getLastMethodCalled(); + + String toString(); + +} Index: gnu/testlet/javax/management/MBeanServerPermission/Constructor.java =================================================================== RCS file: gnu/testlet/javax/management/MBeanServerPermission/Constructor.java diff -N gnu/testlet/javax/management/MBeanServerPermission/Constructor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/javax/management/MBeanServerPermission/Constructor.java 5 Mar 2007 00:31:52 -0000 @@ -0,0 +1,177 @@ +// Tags: JDK1.5 + +// Copyright (C) 2006 Andrew John Hughes + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +package gnu.testlet.javax.management.MBeanServerPermission; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +import javax.management.MBeanServerPermission; + +/** + * Tests creation of an + * {@link MBeanServerPermission}. + * + * @author Andrew John Hughes + */ +public class Constructor + implements Testlet +{ + + public void test(TestHarness h) + { + Exception caught = null; + + // Check null name throws NullPointerException + try + { + new MBeanServerPermission(null); + } + catch (Exception ex) + { + caught = ex; + } + h.check(caught instanceof NullPointerException, "Null name"); + + caught = null; + // Check "*" is a valid name + try + { + new MBeanServerPermission("*"); + } + catch (Exception ex) + { + caught = ex; + } + h.check(caught, null, "* is valid"); + + // Check valid values are allowed + String[] valid = new String[] { "createMBeanServer", "newMBeanServer", + "findMBeanServer", "releaseMBeanServer" }; + // 1 + for (int a = 0; a < valid.length; ++a) + { + caught = null; + try + { + new MBeanServerPermission(valid[a]); + } + catch (Exception ex) + { + caught = ex; + } + h.check(caught, null, valid[a] + " is valid"); + } + // 2 + for (int a = 0; a < valid.length; ++a) + for (int b = 0; b < valid.length; ++b) + { + caught = null; + String permit = valid[a] + "," + valid[b]; + try + { + new MBeanServerPermission(permit); + } + catch (Exception ex) + { + caught = ex; + } + h.check(caught, null, permit + " is valid"); + } + // 3 + for (int a = 0; a < valid.length; ++a) + for (int b = 0; b < valid.length; ++b) + for (int c = 0; c < valid.length; ++c) + { + caught = null; + String permit = valid[a] + "," + valid[b] + "," + valid[c]; + try + { + new MBeanServerPermission(permit); + } + catch (Exception ex) + { + caught = ex; + } + h.check(caught, null, permit + " is valid"); + } + // 4 + for (int a = 0; a < valid.length; ++a) + for (int b = 0; b < valid.length; ++b) + for (int c = 0; c < valid.length; ++c) + for (int d = 0; d < valid.length; ++d) + { + caught = null; + String permit = valid[a] + "," + valid[b] + "," + valid[c] + + "," + valid[d]; + try + { + new MBeanServerPermission(permit); + } + catch (Exception ex) + { + caught = ex; + } + h.check(caught, null, permit + " is valid"); + } + + caught = null; + // Check with spaces + try + { + new MBeanServerPermission(" createMBeanServer , newMBeanServer "); + } + catch (Exception ex) + { + caught = ex; + } + h.check(caught, null, "spaces are valid"); + + caught = null; + // Check random stuff gets thrown out + try + { + new MBeanServerPermission("fjafjlskjflka"); + } + catch (Exception ex) + { + caught = ex; + } + h.check(caught instanceof IllegalArgumentException, + "other names are invalid"); + + caught = null; + // Check non-null non-empty actions are caught + try + { + new MBeanServerPermission("*","fishcakes"); + } + catch (Exception ex) + { + caught = ex; + } + h.check(caught instanceof IllegalArgumentException, + "non-null non-empty actions are invalid"); + + } + +} +