1 22 package test.implementation.loading; 23 24 import java.util.List ; 25 26 import javax.management.MBeanException ; 27 import javax.management.MBeanServer ; 28 import javax.management.MBeanServerFactory ; 29 import javax.management.ObjectName ; 30 import javax.management.loading.MLet ; 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 s) 40 { 41 super(s); 42 } 43 44 public void testMLetFileLoadWithVersion() throws Exception 45 { 46 49 final String MLET_URL1 = "file:./output/etc/test/implementation/loading/MLetVersion1.mlet"; 50 final String MLET_URL2 = "file:./output/etc/test/implementation/loading/MLetVersion2.mlet"; 51 52 ObjectName registry = new ObjectName (ServerConstants.MBEAN_REGISTRY); 53 54 MBeanServer server = MBeanServerFactory.createMBeanServer(); 55 MLet mlet = new MLet (); 56 ObjectName name = new ObjectName ("test:name=mlet"); 57 server.registerMBean(mlet, name); 58 59 61 server.invoke(name, "getMBeansFromURL", 62 new Object [] { MLET_URL1 }, 63 new String [] { String .class.getName() } 64 ); 65 66 server.invoke(name, "getMBeansFromURL", 67 new Object [] { MLET_URL2 }, 68 new String [] { String .class.getName() } 69 ); 70 71 try 72 { 73 List versions1 = 74 (List ) server.invoke(registry, "getValue", 75 new Object [] 76 { 77 new ObjectName ("test:name=Trivial"), 78 MBeanInstaller.VERSIONS 79 }, 80 new String [] 81 { 82 ObjectName .class.getName(), 83 String .class.getName() 84 } 85 ); 86 List versions2 = 87 (List ) server.invoke(registry, "getValue", 88 new Object [] 89 { 90 new ObjectName ("test:name=Trivial2"), 91 MBeanInstaller.VERSIONS 92 }, 93 new String [] 94 { 95 ObjectName .class.getName(), 96 String .class.getName() 97 } 98 ); 99 100 assertTrue("Trivial1 version=" + versions1, ((String )versions1.get(0)).equals("1.1")); 101 assertTrue("Trivial2 version=" + versions2, ((String )versions2.get(0)).equals("2.1")); 102 } 103 catch (MBeanException e) 104 { 105 e.printStackTrace(); 106 assertTrue(false); 107 } 108 109 assertTrue(server.isRegistered(new ObjectName ("test:name=Trivial"))); 110 assertTrue(server.isRegistered(new ObjectName ("test:name=Trivial2"))); 111 112 assertTrue(server.getMBeanInfo(new ObjectName ("test:name=Trivial")) != null); 113 assertTrue(server.getMBeanInfo(new ObjectName ("test:name=Trivial2")) != null); 114 115 assertTrue(server.getAttribute(new ObjectName ("test:name=Trivial2"), "Something").equals("foo")); 116 117 server.invoke(new ObjectName ("test:name=Trivial"), "doOperation", 118 new Object [] { "Test" }, 119 new String [] { String .class.getName() } 120 ); 121 122 server.invoke(new ObjectName ("test:name=Trivial2"), "doOperation", 123 new Object [] { "Test" }, 124 new String [] { String .class.getName() } 125 ); 126 127 } 128 129 130 public void testMLetFileLoadWithVersion2() throws Exception 131 { 132 135 final String MLET_URL1 = "file:./output/etc/test/implementation/loading/MLetVersion3.mlet"; 136 final String MLET_URL2 = "file:./output/etc/test/implementation/loading/MLetVersion4.mlet"; 137 138 ObjectName registry = new ObjectName (ServerConstants.MBEAN_REGISTRY); 139 140 MBeanServer server = MBeanServerFactory.createMBeanServer(); 141 MLet mlet = new MLet (); 142 ObjectName name = new ObjectName ("test:name=mlet"); 143 server.registerMBean(mlet, name); 144 145 147 server.invoke(name, "getMBeansFromURL", 148 new Object [] { MLET_URL1 }, 149 new String [] { String .class.getName() } 150 ); 151 152 server.invoke(name, "getMBeansFromURL", 153 new Object [] { MLET_URL2 }, 154 new String [] { String .class.getName() } 155 ); 156 157 try 158 { 159 List versions1 = 160 (List ) server.invoke(registry, "getValue", 161 new Object [] 162 { 163 new ObjectName ("test:name=Trivial,round=2"), 164 MBeanInstaller.VERSIONS 165 }, 166 new String [] 167 { 168 ObjectName .class.getName(), 169 String .class.getName() 170 } 171 ); 172 List versions2 = 173 (List ) server.invoke(registry, "getValue", 174 new Object [] 175 { 176 new ObjectName ("test:name=Trivial2,round=2"), 177 MBeanInstaller.VERSIONS 178 }, 179 new String [] 180 { 181 ObjectName .class.getName(), 182 String .class.getName() 183 } 184 ); 185 186 assertTrue("Trivial1 version=" + versions1, versions1 == null); 187 assertTrue("Trivial2 version=" + versions2, ((String )versions2.get(0)).equals("5.1")); 188 } 189 catch (MBeanException e) 190 { 191 e.printStackTrace(); 192 assertTrue(false); 193 } 194 195 assertTrue(server.isRegistered(new ObjectName ("test:name=Trivial,round=2"))); 196 assertTrue(server.isRegistered(new ObjectName ("test:name=Trivial2,round=2"))); 197 198 assertTrue(server.getMBeanInfo(new ObjectName ("test:name=Trivial,round=2")) != null); 199 assertTrue(server.getMBeanInfo(new ObjectName ("test:name=Trivial2,round=2")) != null); 200 201 assertTrue(server.getAttribute(new ObjectName ("test:name=Trivial2,round=2"), "Something").equals("foo")); 202 203 server.invoke(new ObjectName ("test:name=Trivial,round=2"), "doOperation", 204 new Object [] { "Test" }, 205 new String [] { String .class.getName() } 206 ); 207 208 server.invoke(new ObjectName ("test:name=Trivial2,round=2"), "doOperation", 209 new Object [] { "Test" }, 210 new String [] { String .class.getName() } 211 ); 212 213 } 214 215 } 216 | Popular Tags |