001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package test.implementation.loading;
023:
024: import java.util.List;
025:
026: import javax.management.MBeanException;
027: import javax.management.MBeanServer;
028: import javax.management.MBeanServerFactory;
029: import javax.management.ObjectName;
030: import javax.management.loading.MLet;
031:
032: import junit.framework.TestCase;
033:
034: import org.jboss.mx.server.ServerConstants;
035: import org.jboss.mx.util.MBeanInstaller;
036:
037: public class MLetVersionTEST extends TestCase {
038: public MLetVersionTEST(String s) {
039: super (s);
040: }
041:
042: public void testMLetFileLoadWithVersion() throws Exception {
043: // NOTE:
044: // the urls used here are relative to the location of the build.xml
045:
046: final String MLET_URL1 = "file:./output/etc/test/implementation/loading/MLetVersion1.mlet";
047: final String MLET_URL2 = "file:./output/etc/test/implementation/loading/MLetVersion2.mlet";
048:
049: ObjectName registry = new ObjectName(
050: ServerConstants.MBEAN_REGISTRY);
051:
052: MBeanServer server = MBeanServerFactory.createMBeanServer();
053: MLet mlet = new MLet();
054: ObjectName name = new ObjectName("test:name=mlet");
055: server.registerMBean(mlet, name);
056:
057: // Repeat to call the getMBeansFromURL method
058:
059: server.invoke(name, "getMBeansFromURL",
060: new Object[] { MLET_URL1 }, new String[] { String.class
061: .getName() });
062:
063: server.invoke(name, "getMBeansFromURL",
064: new Object[] { MLET_URL2 }, new String[] { String.class
065: .getName() });
066:
067: try {
068: List versions1 = (List) server.invoke(registry, "getValue",
069: new Object[] { new ObjectName("test:name=Trivial"),
070: MBeanInstaller.VERSIONS }, new String[] {
071: ObjectName.class.getName(),
072: String.class.getName() });
073: List versions2 = (List) server.invoke(registry, "getValue",
074: new Object[] {
075: new ObjectName("test:name=Trivial2"),
076: MBeanInstaller.VERSIONS }, new String[] {
077: ObjectName.class.getName(),
078: String.class.getName() });
079:
080: assertTrue("Trivial1 version=" + versions1,
081: ((String) versions1.get(0)).equals("1.1"));
082: assertTrue("Trivial2 version=" + versions2,
083: ((String) versions2.get(0)).equals("2.1"));
084: } catch (MBeanException e) {
085: e.printStackTrace();
086: assertTrue(false);
087: }
088:
089: assertTrue(server.isRegistered(new ObjectName(
090: "test:name=Trivial")));
091: assertTrue(server.isRegistered(new ObjectName(
092: "test:name=Trivial2")));
093:
094: assertTrue(server.getMBeanInfo(new ObjectName(
095: "test:name=Trivial")) != null);
096: assertTrue(server.getMBeanInfo(new ObjectName(
097: "test:name=Trivial2")) != null);
098:
099: assertTrue(server.getAttribute(
100: new ObjectName("test:name=Trivial2"), "Something")
101: .equals("foo"));
102:
103: server.invoke(new ObjectName("test:name=Trivial"),
104: "doOperation", new Object[] { "Test" },
105: new String[] { String.class.getName() });
106:
107: server.invoke(new ObjectName("test:name=Trivial2"),
108: "doOperation", new Object[] { "Test" },
109: new String[] { String.class.getName() });
110:
111: }
112:
113: public void testMLetFileLoadWithVersion2() throws Exception {
114: // NOTE:
115: // the urls used here are relative to the location of the build.xml
116:
117: final String MLET_URL1 = "file:./output/etc/test/implementation/loading/MLetVersion3.mlet";
118: final String MLET_URL2 = "file:./output/etc/test/implementation/loading/MLetVersion4.mlet";
119:
120: ObjectName registry = new ObjectName(
121: ServerConstants.MBEAN_REGISTRY);
122:
123: MBeanServer server = MBeanServerFactory.createMBeanServer();
124: MLet mlet = new MLet();
125: ObjectName name = new ObjectName("test:name=mlet");
126: server.registerMBean(mlet, name);
127:
128: // Repeat to call the getMBeansFromURL method
129:
130: server.invoke(name, "getMBeansFromURL",
131: new Object[] { MLET_URL1 }, new String[] { String.class
132: .getName() });
133:
134: server.invoke(name, "getMBeansFromURL",
135: new Object[] { MLET_URL2 }, new String[] { String.class
136: .getName() });
137:
138: try {
139: List versions1 = (List) server
140: .invoke(
141: registry,
142: "getValue",
143: new Object[] {
144: new ObjectName(
145: "test:name=Trivial,round=2"),
146: MBeanInstaller.VERSIONS },
147: new String[] { ObjectName.class.getName(),
148: String.class.getName() });
149: List versions2 = (List) server
150: .invoke(
151: registry,
152: "getValue",
153: new Object[] {
154: new ObjectName(
155: "test:name=Trivial2,round=2"),
156: MBeanInstaller.VERSIONS },
157: new String[] { ObjectName.class.getName(),
158: String.class.getName() });
159:
160: assertTrue("Trivial1 version=" + versions1,
161: versions1 == null);
162: assertTrue("Trivial2 version=" + versions2,
163: ((String) versions2.get(0)).equals("5.1"));
164: } catch (MBeanException e) {
165: e.printStackTrace();
166: assertTrue(false);
167: }
168:
169: assertTrue(server.isRegistered(new ObjectName(
170: "test:name=Trivial,round=2")));
171: assertTrue(server.isRegistered(new ObjectName(
172: "test:name=Trivial2,round=2")));
173:
174: assertTrue(server.getMBeanInfo(new ObjectName(
175: "test:name=Trivial,round=2")) != null);
176: assertTrue(server.getMBeanInfo(new ObjectName(
177: "test:name=Trivial2,round=2")) != null);
178:
179: assertTrue(server.getAttribute(
180: new ObjectName("test:name=Trivial2,round=2"),
181: "Something").equals("foo"));
182:
183: server.invoke(new ObjectName("test:name=Trivial,round=2"),
184: "doOperation", new Object[] { "Test" },
185: new String[] { String.class.getName() });
186:
187: server.invoke(new ObjectName("test:name=Trivial2,round=2"),
188: "doOperation", new Object[] { "Test" },
189: new String[] { String.class.getName() });
190:
191: }
192:
193: }
|