1 17 package org.apache.geronimo.connector.deployment; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.util.Collections ; 22 import java.util.List ; 23 import java.util.Map ; 24 import java.util.HashMap ; 25 26 import junit.framework.TestCase; 27 import org.apache.geronimo.common.DeploymentException; 28 import org.apache.geronimo.connector.AdminObjectWrapperGBean; 29 import org.apache.geronimo.gbean.AbstractName; 30 import org.apache.geronimo.gbean.GBeanData; 31 import org.apache.geronimo.j2ee.deployment.ConnectorModule; 32 import org.apache.geronimo.j2ee.deployment.EARContext; 33 import org.apache.geronimo.j2ee.deployment.Module; 34 import org.apache.geronimo.j2ee.deployment.NamingBuilder; 35 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 36 import org.apache.geronimo.kernel.Jsr77Naming; 37 import org.apache.geronimo.kernel.Naming; 38 import org.apache.geronimo.kernel.config.Configuration; 39 import org.apache.geronimo.kernel.config.ConfigurationData; 40 import org.apache.geronimo.kernel.config.ConfigurationManager; 41 import org.apache.geronimo.kernel.config.ConfigurationModuleType; 42 import org.apache.geronimo.kernel.config.ConfigurationResolver; 43 import org.apache.geronimo.kernel.config.ConfigurationStore; 44 import org.apache.geronimo.kernel.config.LifecycleException; 45 import org.apache.geronimo.kernel.config.LifecycleMonitor; 46 import org.apache.geronimo.kernel.config.LifecycleResults; 47 import org.apache.geronimo.kernel.config.NoSuchConfigException; 48 import org.apache.geronimo.kernel.config.NoSuchStoreException; 49 import org.apache.geronimo.kernel.repository.Artifact; 50 import org.apache.geronimo.kernel.repository.ArtifactResolver; 51 import org.apache.geronimo.kernel.repository.Environment; 52 import org.apache.geronimo.kernel.repository.Version; 53 import org.apache.geronimo.naming.deployment.AbstractNamingBuilder; 54 import org.apache.geronimo.schema.SchemaConversionUtils; 55 import org.apache.xmlbeans.XmlCursor; 56 import org.apache.xmlbeans.XmlException; 57 import org.apache.xmlbeans.XmlObject; 58 59 62 public class MessageDestinationTest extends TestCase { 63 64 private static final Naming naming = new Jsr77Naming(); 65 Configuration configuration; 66 AbstractName baseName; 67 AdminObjectRefBuilder adminObjectRefBuilder = new AdminObjectRefBuilder(null, new String [] {SchemaConversionUtils.J2EE_NAMESPACE}); 68 Module module; 69 70 Map componentContext = new HashMap (); 71 72 protected void setUp() throws Exception { 73 super.setUp(); 74 componentContext.put(NamingBuilder.JNDI_KEY, new HashMap ()); 75 Artifact id = new Artifact("test", "test", "", "car"); 76 configuration = new Configuration(Collections.EMPTY_LIST, 77 new ConfigurationData(id, naming), 78 new ConfigurationResolver(id, null), 79 null); 80 module = new ConnectorModule(false, new AbstractName(id, Collections.singletonMap("name", "test")), null, null, "foo", null, null, null); 81 EARContext earContext = new EARContext(new File ("foo"), null, new Environment(new Artifact("foo", "bar", "1.0", "car")), ConfigurationModuleType.EAR, naming, 82 new ConfigurationManager() { 83 public boolean isInstalled(Artifact configurationId) { 84 return false; 85 } 86 87 public Artifact[] getInstalled(Artifact query) { 88 return new Artifact[0]; 89 } 90 91 public Artifact[] getLoaded(Artifact query) { 92 return new Artifact[0]; 93 } 94 95 public Artifact[] getRunning(Artifact query) { 96 return new Artifact[0]; 97 } 98 99 public boolean isLoaded(Artifact configID) { 100 return false; 101 } 102 103 public List listStores() { 104 return Collections.EMPTY_LIST; 105 } 106 107 public ConfigurationStore[] getStores() { 108 return new ConfigurationStore[0]; 109 } 110 111 public ConfigurationStore getStoreForConfiguration(Artifact configuration) { 112 return null; 113 } 114 115 public List listConfigurations(AbstractName store) throws NoSuchStoreException { 116 return Collections.EMPTY_LIST; 117 } 118 119 public boolean isRunning(Artifact configurationId) { 120 return false; 121 } 122 123 public List listConfigurations() { 124 return null; 125 } 126 127 public boolean isConfiguration(Artifact artifact) { 128 return false; 129 } 130 131 public Configuration getConfiguration(Artifact configurationId) { 132 return null; 133 } 134 135 public LifecycleResults loadConfiguration(Artifact configurationId) throws NoSuchConfigException, LifecycleException { 136 return null; 137 } 138 139 public LifecycleResults loadConfiguration(ConfigurationData configurationData) throws NoSuchConfigException, LifecycleException { 140 return null; 141 } 142 143 public LifecycleResults loadConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException { 144 return null; 145 } 146 147 public LifecycleResults loadConfiguration(ConfigurationData configurationData, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException { 148 return null; 149 } 150 151 public LifecycleResults unloadConfiguration(Artifact configurationId) throws NoSuchConfigException { 152 return null; 153 } 154 155 public LifecycleResults unloadConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException { 156 return null; 157 } 158 159 public LifecycleResults startConfiguration(Artifact configurationId) throws NoSuchConfigException, LifecycleException { 160 return null; 161 } 162 163 public LifecycleResults startConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException { 164 return null; 165 } 166 167 public LifecycleResults stopConfiguration(Artifact configurationId) throws NoSuchConfigException { 168 return null; 169 } 170 171 public LifecycleResults stopConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException { 172 return null; 173 } 174 175 public LifecycleResults restartConfiguration(Artifact configurationId) throws NoSuchConfigException, LifecycleException { 176 return null; 177 } 178 179 public LifecycleResults restartConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException { 180 return null; 181 } 182 183 public LifecycleResults reloadConfiguration(Artifact configurationId) throws NoSuchConfigException, LifecycleException { 184 return null; 185 } 186 187 public LifecycleResults reloadConfiguration(Artifact configurationId, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException { 188 return null; 189 } 190 191 public LifecycleResults reloadConfiguration(Artifact configurationId, Version version) throws NoSuchConfigException, LifecycleException { 192 return null; 193 } 194 195 public LifecycleResults reloadConfiguration(Artifact configurationId, Version version, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException { 196 return null; 197 } 198 199 public LifecycleResults reloadConfiguration(ConfigurationData configurationData) throws NoSuchConfigException, LifecycleException { 200 return null; 201 } 202 203 public LifecycleResults reloadConfiguration(ConfigurationData configurationData, LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException { 204 return null; 205 } 206 207 public void uninstallConfiguration(Artifact configurationId) throws IOException , NoSuchConfigException { 208 209 } 210 211 public ArtifactResolver getArtifactResolver() { 212 return null; 213 } 214 215 public boolean isOnline() { 216 return true; 217 } 218 219 public void setOnline(boolean online) { 220 } 221 222 }, null, null, null, null, null, null, null, null); 223 module.setEarContext(earContext); 224 module.setRootEarContext(earContext); 225 baseName = naming.createRootName(configuration.getId(), "testRoot", NameFactory.RESOURCE_ADAPTER_MODULE); 226 } 227 228 private static final String SPECDD1 = "<tmp xmlns=\"http://java.sun.com/xml/ns/j2ee\">" + 229 "<message-destination><message-destination-name>d1</message-destination-name></message-destination>" + 230 "<message-destination><message-destination-name>d2</message-destination-name></message-destination>" + 231 "<message-destination-ref>" + 232 " <message-destination-ref-name>n1</message-destination-ref-name>" + 233 " <message-destination-type>java.lang.Object</message-destination-type>" + 234 " <message-destination-usage>Consumes</message-destination-usage>" + 235 " <message-destination-link>d1</message-destination-link>" + 236 "</message-destination-ref>" + 237 "<message-destination-ref>" + 238 " <message-destination-ref-name>n2</message-destination-ref-name>" + 239 " <message-destination-type>java.lang.Object</message-destination-type>" + 240 " <message-destination-usage>Consumes</message-destination-usage>" + 241 " <message-destination-link>d2</message-destination-link>" + 242 "</message-destination-ref>" + 243 "</tmp>"; 244 245 private static final String PLAN1 = "<tmp xmlns=\"http://geronimo.apache.org/xml/ns/naming-1.2\">" + 246 "<message-destination>" + 247 " <message-destination-name>d1</message-destination-name>" + 248 " <admin-object-link>l1</admin-object-link>" + 249 "</message-destination>" + 250 "<message-destination>" + 251 " <message-destination-name>d2</message-destination-name>" + 252 " <admin-object-link>l2</admin-object-link>" + 253 "</message-destination>" + 254 "</tmp>"; 255 256 public void testMessageDestinations() throws Exception { 257 XmlObject specDD = parse(SPECDD1); 258 XmlObject plan = parse(PLAN1); 259 adminObjectRefBuilder.initContext(specDD, plan, configuration, configuration, module); 260 AbstractName n1 = naming.createChildName(baseName, "l1", NameFactory.JCA_ADMIN_OBJECT); 261 AbstractName n2 = naming.createChildName(baseName, "l2", NameFactory.JCA_ADMIN_OBJECT); 262 configuration.addGBean(new GBeanData(n1, AdminObjectWrapperGBean.GBEAN_INFO)); 263 configuration.addGBean(new GBeanData(n2, AdminObjectWrapperGBean.GBEAN_INFO)); 264 adminObjectRefBuilder.buildNaming(specDD, plan, configuration, configuration, module, componentContext); 265 assertEquals(2, ((Map )componentContext.get(NamingBuilder.JNDI_KEY)).size()); 266 } 267 268 private static final String PLAN2 = "<tmp xmlns=\"http://geronimo.apache.org/xml/ns/naming-1.2\">" + 269 "<message-destination>" + 270 " <message-destination-name>d1</message-destination-name>" + 271 " <admin-object-module>testRoot</admin-object-module>" + 272 " <admin-object-link>l1</admin-object-link>" + 273 "</message-destination>" + 274 "<message-destination>" + 275 " <message-destination-name>d2</message-destination-name>" + 276 " <admin-object-module>testRoot</admin-object-module>" + 277 " <admin-object-link>l2</admin-object-link>" + 278 "</message-destination>" + 279 "</tmp>"; 280 public void testMessageDestinationsWithModule() throws Exception { 281 XmlObject specDD = parse(SPECDD1); 282 XmlObject plan = parse(PLAN2); 283 adminObjectRefBuilder.initContext(specDD, plan, configuration, configuration, module); 284 AbstractName n1 = naming.createChildName(baseName, "l1", NameFactory.JCA_ADMIN_OBJECT); 285 AbstractName n2 = naming.createChildName(baseName, "l2", NameFactory.JCA_ADMIN_OBJECT); 286 configuration.addGBean(new GBeanData(n1, AdminObjectWrapperGBean.GBEAN_INFO)); 287 configuration.addGBean(new GBeanData(n2, AdminObjectWrapperGBean.GBEAN_INFO)); 288 adminObjectRefBuilder.buildNaming(specDD, plan, configuration, configuration, module, componentContext); 289 assertEquals(2, ((Map )componentContext.get(NamingBuilder.JNDI_KEY)).size()); 290 } 291 292 private static final String SPECDD2 = "<tmp xmlns=\"http://java.sun.com/xml/ns/j2ee\">" + 293 "</tmp>"; 294 295 296 public void testMessageDestinationsMatch() throws Exception { 297 XmlObject specDD = parse(SPECDD2); 298 XmlObject plan = parse(PLAN1); 299 try { 300 adminObjectRefBuilder.initContext(specDD, plan, configuration, configuration, module); 301 fail("tried to register a GerMessageDestination witout a MessageDestination and it succeeded"); 302 } catch (DeploymentException e) { 303 304 } 305 } 306 307 private XmlObject parse(String xmlString) throws XmlException { 308 XmlObject xmlObject = XmlObject.Factory.parse(xmlString); 309 XmlCursor xmlCursor = xmlObject.newCursor(); 310 try { 311 xmlCursor.toFirstChild(); 312 return xmlCursor.getObject(); 313 } finally { 314 xmlCursor.dispose(); 315 } 316 } 317 318 319 } 320 321 | Popular Tags |