1 17 18 package org.apache.geronimo.j2ee.management; 19 20 import java.util.HashSet ; 21 import java.util.Set ; 22 import java.util.Hashtable ; 23 import java.util.LinkedHashSet ; 24 import java.util.Collections ; 25 import javax.management.ObjectName ; 26 import javax.management.MalformedObjectNameException ; 27 28 import junit.framework.TestCase; 29 import org.apache.geronimo.gbean.GBeanData; 30 import org.apache.geronimo.gbean.GBeanInfo; 31 import org.apache.geronimo.gbean.AbstractName; 32 import org.apache.geronimo.gbean.ReferencePatterns; 33 import org.apache.geronimo.gbean.AbstractNameQuery; 34 import org.apache.geronimo.j2ee.management.impl.J2EEDomainImpl; 35 import org.apache.geronimo.j2ee.management.impl.J2EEServerImpl; 36 import org.apache.geronimo.j2ee.management.impl.JVMImpl; 37 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 38 import org.apache.geronimo.kernel.KernelFactory; 39 import org.apache.geronimo.kernel.Kernel; 40 import org.apache.geronimo.kernel.repository.Artifact; 41 import org.apache.geronimo.system.serverinfo.BasicServerInfo; 42 import org.apache.geronimo.system.plugin.PluginInstaller; 43 import org.apache.geronimo.system.plugin.PluginRepositoryList; 44 import org.apache.geronimo.management.J2EEResource; 45 import org.apache.geronimo.management.EJBModule; 46 import org.apache.geronimo.management.AppClientModule; 47 import org.apache.geronimo.management.geronimo.WebModule; 48 import org.apache.geronimo.management.geronimo.ResourceAdapterModule; 49 import org.apache.geronimo.management.geronimo.J2EEApplication; 50 import org.apache.geronimo.management.geronimo.J2EEServer; 51 import org.apache.geronimo.management.geronimo.JVM; 52 53 56 public abstract class Abstract77Test extends TestCase { 57 protected static final GBeanData SERVER_INFO_DATA = buildGBeanData(new String [] {"role"}, new String [] {"ServerInfo"}, BasicServerInfo.getGBeanInfo()); 58 59 protected static final String DOMAIN = "geronimo.test"; 60 protected static final GBeanData DOMAIN_DATA = buildGBeanData(new String [] {"j2eeType", "name"}, new String [] {"J2EEDomain", DOMAIN}, J2EEDomainImpl.GBEAN_INFO); 61 protected static final GBeanData SERVER_DATA = buildGBeanData(new String [] {"j2eeType", "name"}, new String [] {"J2EEServer", "test"}, J2EEServerImpl.GBEAN_INFO); 62 protected static final GBeanData JVM_DATA = buildGBeanData(new String [] {"j2eeType", "J2EEServer", "name"}, new String [] {"JVM", "test", "JVM"}, JVMImpl.GBEAN_INFO); 63 64 protected Kernel kernel; 65 66 private static GBeanData buildGBeanData(String [] key, String [] value, GBeanInfo info) { 67 AbstractName abstractName = buildAbstractName(key, value); 68 return new GBeanData(abstractName, info); 69 } 70 71 private static AbstractName buildAbstractName(String [] key, String value[]) { 72 Hashtable names = new Hashtable (); 73 for (int i = 0; i < key.length; i++) { 74 String k = key[i]; 75 String v = value[i]; 76 names.put(k, v); 77 } 78 79 ObjectName objectName; 80 try { 81 objectName = new ObjectName (DOMAIN, names); 82 } catch (MalformedObjectNameException e) { 83 throw new IllegalArgumentException ("Malformed ObjectName: " + DOMAIN + ":" + names); 84 } 85 return new AbstractName(new Artifact("test", "foo", "1", "car"), names, objectName); 86 } 87 88 protected void setUp() throws Exception { 89 super.setUp(); 90 kernel = KernelFactory.newInstance().createKernel(DOMAIN); 91 kernel.boot(); 92 93 ClassLoader classLoader = getClass().getClassLoader(); 94 95 SERVER_INFO_DATA.setAttribute("baseDirectory", System.getProperty("java.io.tmpdir")); 97 kernel.loadGBean(SERVER_INFO_DATA, classLoader); 98 99 DOMAIN_DATA.setReferencePatterns("Servers", new ReferencePatterns(new AbstractNameQuery(J2EEServer.class.getName()))); 101 kernel.loadGBean(DOMAIN_DATA, classLoader); 102 103 SERVER_DATA.setReferencePattern("ServerInfo", SERVER_INFO_DATA.getAbstractName()); 105 SERVER_DATA.setReferencePatterns("JVMs", new ReferencePatterns(new AbstractNameQuery(JVM.class.getName()))); 106 LinkedHashSet resourcePatterns = new LinkedHashSet (); 107 resourcePatterns.add(new AbstractNameQuery(null, Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.JAVA_MAIL_RESOURCE), J2EEResource.class.getName())); 108 resourcePatterns.add(new AbstractNameQuery(null, Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.JCA_CONNECTION_FACTORY), J2EEResource.class.getName())); 109 resourcePatterns.add(new AbstractNameQuery(null, Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.JDBC_RESOURCE), J2EEResource.class.getName())); 110 resourcePatterns.add(new AbstractNameQuery(null, Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.JMS_RESOURCE), J2EEResource.class.getName())); 111 resourcePatterns.add(new AbstractNameQuery(null, Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.JNDI_RESOURCE), J2EEResource.class.getName())); 112 resourcePatterns.add(new AbstractNameQuery(null, Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.JTA_RESOURCE), J2EEResource.class.getName())); 113 resourcePatterns.add(new AbstractNameQuery(null, Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.RMI_IIOP_RESOURCE), J2EEResource.class.getName())); 114 resourcePatterns.add(new AbstractNameQuery(null, Collections.singletonMap(NameFactory.J2EE_TYPE, NameFactory.URL_RESOURCE), J2EEResource.class.getName())); 115 SERVER_DATA.setReferencePatterns("Resources", resourcePatterns); 116 SERVER_DATA.setReferencePatterns("Applications", new ReferencePatterns(new AbstractNameQuery(J2EEApplication.class.getName()))); 117 SERVER_DATA.setReferencePatterns("AppClientModules", new ReferencePatterns(new AbstractNameQuery(AppClientModule.class.getName()))); 118 SERVER_DATA.setReferencePatterns("EJBModules", new ReferencePatterns(new AbstractNameQuery(EJBModule.class.getName()))); 119 SERVER_DATA.setReferencePatterns("ResourceAdapterModules", new ReferencePatterns(new AbstractNameQuery(ResourceAdapterModule.class.getName()))); 120 SERVER_DATA.setReferencePatterns("WebModules", new ReferencePatterns(new AbstractNameQuery(WebModule.class.getName()))); 121 SERVER_DATA.setReferencePatterns("PluginRepoLists", new ReferencePatterns(new AbstractNameQuery(PluginRepositoryList.class.getName()))); 124 kernel.loadGBean(SERVER_DATA, classLoader); 125 126 kernel.loadGBean(JVM_DATA, classLoader); 128 129 kernel.startGBean(SERVER_INFO_DATA.getAbstractName()); 131 kernel.startGBean(DOMAIN_DATA.getAbstractName()); 132 kernel.startGBean(SERVER_DATA.getAbstractName()); 133 kernel.startGBean(JVM_DATA.getAbstractName()); 134 } 135 136 protected void tearDown() throws Exception { 137 super.tearDown(); 138 kernel.stopGBean(JVM_DATA.getAbstractName()); 139 kernel.stopGBean(SERVER_DATA.getAbstractName()); 140 kernel.stopGBean(DOMAIN_DATA.getAbstractName()); 141 kernel.stopGBean(SERVER_INFO_DATA.getAbstractName()); 142 kernel.unloadGBean(JVM_DATA.getAbstractName()); 143 kernel.unloadGBean(SERVER_DATA.getAbstractName()); 144 kernel.unloadGBean(DOMAIN_DATA.getAbstractName()); 145 kernel.unloadGBean(SERVER_INFO_DATA.getAbstractName()); 146 kernel.shutdown(); 147 kernel = null; 148 } 149 150 protected void assertObjectNamesEqual(String [] expected, String [] test) throws Exception { 151 Set expectedSet = new HashSet (expected.length); 152 for (int i = 0; i < expected.length; i++) { 153 expectedSet.add(new ObjectName (expected[i])); 154 } 155 Set testSet = new HashSet (test.length); 156 for (int i = 0; i < test.length; i++) { 157 testSet.add(new ObjectName (test[i])); 158 } 159 assertEquals(expectedSet, testSet); 160 } 161 } 162 | Popular Tags |