KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > implementation > loading > MLetVersionTEST


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 test.implementation.loading;
23
24 import java.util.List JavaDoc;
25
26 import javax.management.MBeanException JavaDoc;
27 import javax.management.MBeanServer JavaDoc;
28 import javax.management.MBeanServerFactory JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import javax.management.loading.MLet JavaDoc;
31
32 import junit.framework.TestCase;
33
34 import org.jboss.mx.server.ServerConstants;
35 import org.jboss.mx.util.MBeanInstaller;
36
37 public class MLetVersionTEST extends TestCase
38 {
39    public MLetVersionTEST(String JavaDoc s)
40    {
41       super(s);
42    }
43
44    public void testMLetFileLoadWithVersion() throws Exception JavaDoc
45    {
46       // NOTE:
47
// the urls used here are relative to the location of the build.xml
48

49       final String JavaDoc MLET_URL1 = "file:./output/etc/test/implementation/loading/MLetVersion1.mlet";
50       final String JavaDoc MLET_URL2 = "file:./output/etc/test/implementation/loading/MLetVersion2.mlet";
51
52       ObjectName JavaDoc registry = new ObjectName JavaDoc(ServerConstants.MBEAN_REGISTRY);
53
54       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
55       MLet JavaDoc mlet = new MLet JavaDoc();
56       ObjectName JavaDoc name = new ObjectName JavaDoc("test:name=mlet");
57       server.registerMBean(mlet, name);
58
59       // Repeat to call the getMBeansFromURL method
60

61       server.invoke(name, "getMBeansFromURL",
62       new Object JavaDoc[] { MLET_URL1 },
63       new String JavaDoc[] { String JavaDoc.class.getName() }
64       );
65
66       server.invoke(name, "getMBeansFromURL",
67       new Object JavaDoc[] { MLET_URL2 },
68       new String JavaDoc[] { String JavaDoc.class.getName() }
69       );
70
71       try
72       {
73          List JavaDoc versions1 =
74                (List JavaDoc) server.invoke(registry, "getValue",
75                                     new Object JavaDoc[]
76                                     {
77                                        new ObjectName JavaDoc("test:name=Trivial"),
78                                        MBeanInstaller.VERSIONS
79                                     },
80                                     new String JavaDoc[]
81                                     {
82                                        ObjectName JavaDoc.class.getName(),
83                                        String JavaDoc.class.getName()
84                                     }
85                );
86          List JavaDoc versions2 =
87                (List JavaDoc) server.invoke(registry, "getValue",
88                                     new Object JavaDoc[]
89                                     {
90                                        new ObjectName JavaDoc("test:name=Trivial2"),
91                                        MBeanInstaller.VERSIONS
92                                     },
93                                     new String JavaDoc[]
94                                     {
95                                        ObjectName JavaDoc.class.getName(),
96                                        String JavaDoc.class.getName()
97                                     }
98                );
99
100          assertTrue("Trivial1 version=" + versions1, ((String JavaDoc)versions1.get(0)).equals("1.1"));
101          assertTrue("Trivial2 version=" + versions2, ((String JavaDoc)versions2.get(0)).equals("2.1"));
102        }
103       catch (MBeanException JavaDoc e)
104       {
105          e.printStackTrace();
106          assertTrue(false);
107       }
108
109       assertTrue(server.isRegistered(new ObjectName JavaDoc("test:name=Trivial")));
110       assertTrue(server.isRegistered(new ObjectName JavaDoc("test:name=Trivial2")));
111
112       assertTrue(server.getMBeanInfo(new ObjectName JavaDoc("test:name=Trivial")) != null);
113       assertTrue(server.getMBeanInfo(new ObjectName JavaDoc("test:name=Trivial2")) != null);
114
115       assertTrue(server.getAttribute(new ObjectName JavaDoc("test:name=Trivial2"), "Something").equals("foo"));
116
117       server.invoke(new ObjectName JavaDoc("test:name=Trivial"), "doOperation",
118       new Object JavaDoc[] { "Test" },
119       new String JavaDoc[] { String JavaDoc.class.getName() }
120       );
121
122       server.invoke(new ObjectName JavaDoc("test:name=Trivial2"), "doOperation",
123       new Object JavaDoc[] { "Test" },
124       new String JavaDoc[] { String JavaDoc.class.getName() }
125       );
126
127    }
128
129
130    public void testMLetFileLoadWithVersion2() throws Exception JavaDoc
131    {
132       // NOTE:
133
// the urls used here are relative to the location of the build.xml
134

135       final String JavaDoc MLET_URL1 = "file:./output/etc/test/implementation/loading/MLetVersion3.mlet";
136       final String JavaDoc MLET_URL2 = "file:./output/etc/test/implementation/loading/MLetVersion4.mlet";
137
138       ObjectName JavaDoc registry = new ObjectName JavaDoc(ServerConstants.MBEAN_REGISTRY);
139
140       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
141       MLet JavaDoc mlet = new MLet JavaDoc();
142       ObjectName JavaDoc name = new ObjectName JavaDoc("test:name=mlet");
143       server.registerMBean(mlet, name);
144
145       // Repeat to call the getMBeansFromURL method
146

147       server.invoke(name, "getMBeansFromURL",
148       new Object JavaDoc[] { MLET_URL1 },
149       new String JavaDoc[] { String JavaDoc.class.getName() }
150       );
151
152       server.invoke(name, "getMBeansFromURL",
153       new Object JavaDoc[] { MLET_URL2 },
154       new String JavaDoc[] { String JavaDoc.class.getName() }
155       );
156
157       try
158       {
159          List JavaDoc versions1 =
160                (List JavaDoc) server.invoke(registry, "getValue",
161                                     new Object JavaDoc[]
162                                     {
163                                        new ObjectName JavaDoc("test:name=Trivial,round=2"),
164                                        MBeanInstaller.VERSIONS
165                                     },
166                                     new String JavaDoc[]
167                                     {
168                                        ObjectName JavaDoc.class.getName(),
169                                        String JavaDoc.class.getName()
170                                     }
171                );
172          List JavaDoc versions2 =
173                (List JavaDoc) server.invoke(registry, "getValue",
174                                     new Object JavaDoc[]
175                                     {
176                                        new ObjectName JavaDoc("test:name=Trivial2,round=2"),
177                                        MBeanInstaller.VERSIONS
178                                     },
179                                     new String JavaDoc[]
180                                     {
181                                        ObjectName JavaDoc.class.getName(),
182                                        String JavaDoc.class.getName()
183                                     }
184                );
185
186          assertTrue("Trivial1 version=" + versions1, versions1 == null);
187          assertTrue("Trivial2 version=" + versions2, ((String JavaDoc)versions2.get(0)).equals("5.1"));
188        }
189       catch (MBeanException JavaDoc e)
190       {
191          e.printStackTrace();
192          assertTrue(false);
193       }
194
195       assertTrue(server.isRegistered(new ObjectName JavaDoc("test:name=Trivial,round=2")));
196       assertTrue(server.isRegistered(new ObjectName JavaDoc("test:name=Trivial2,round=2")));
197
198       assertTrue(server.getMBeanInfo(new ObjectName JavaDoc("test:name=Trivial,round=2")) != null);
199       assertTrue(server.getMBeanInfo(new ObjectName JavaDoc("test:name=Trivial2,round=2")) != null);
200
201       assertTrue(server.getAttribute(new ObjectName JavaDoc("test:name=Trivial2,round=2"), "Something").equals("foo"));
202
203       server.invoke(new ObjectName JavaDoc("test:name=Trivial,round=2"), "doOperation",
204       new Object JavaDoc[] { "Test" },
205       new String JavaDoc[] { String JavaDoc.class.getName() }
206       );
207
208       server.invoke(new ObjectName JavaDoc("test:name=Trivial2,round=2"), "doOperation",
209       new Object JavaDoc[] { "Test" },
210       new String JavaDoc[] { String JavaDoc.class.getName() }
211       );
212
213    }
214    
215 }
216
Popular Tags