1 19 27 28 package org.netbeans.modules.j2ee.sun.test; 29 30 import java.io.File ; 31 import org.netbeans.junit.NbTestCase; 32 import org.netbeans.junit.NbTestSuite; 33 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 34 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; 35 import org.netbeans.modules.j2ee.sun.api.ServerInterface; 36 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface; 37 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.Resources; 38 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils; 39 import org.netbeans.modules.j2ee.sun.ide.sunresources.resourcesloader.SunResourceDataObject; 40 import org.netbeans.modules.j2ee.sun.ide.sunresources.wizards.ResourceConfigData; 41 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants; 42 import org.openide.filesystems.FileObject; 43 import org.openide.filesystems.FileUtil; 44 45 49 public class ConnectionFactoryResourceTest extends NbTestCase implements WizardConstants{ 50 private static String JMS_QUEUE_RESOURCE_NAME = "jmsqResourceTest"; 51 private static String JMS_TOPIC_RESOURCE_NAME = "jmstResourceTest"; 52 53 public ConnectionFactoryResourceTest(String testName) { 54 super(testName); 55 } 56 57 public void registerJMSQueueResource() { 58 try { 59 ResourceConfigData jmsdata = new ResourceConfigData(); 62 ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL); 63 jmsdata.setString(__JndiName, JMS_QUEUE_RESOURCE_NAME); 65 jmsdata.setString(__ResType, "javax.jms.QueueConnectionFactory"); 66 jmsdata.setString(__Enabled, "true"); 67 File fpf = File.createTempFile("falseProject",""); 70 fpf.delete(); 71 FileObject falseProject = FileUtil.createFolder(fpf); 72 falseProject.createFolder("setup"); 73 jmsdata.setTargetFileObject(falseProject); 74 jmsdata.setTargetFile("jmsqResourceTest"); 75 ResourceUtils.saveJMSResourceDatatoXml(jmsdata); 76 SunResourceDataObject resourceObj = (SunResourceDataObject)SunResourceDataObject.find(falseProject.getFileObject("setup/jmsqResourceTest.sun-resource")); 77 Resources res = Util.getResourcesObject(resourceObj); 78 ServerInterface mejb = ((SunDeploymentManagerInterface)inst.getDeploymentManager()).getManagement(); 79 ResourceUtils.register(res.getConnectorConnectionPool(0),mejb,false); 80 ResourceUtils.register(res.getConnectorResource(0), mejb, false); 81 resourceObj.delete(); 82 falseProject.delete(); 83 Util.sleep(5000); 85 String [] jmsResource=Util.getResourcesNames("getConnectorResource","jndi-name",mejb); 86 for(int i=0;i<jmsResource.length;i++) { 87 if(jmsResource[i].equals(JMS_QUEUE_RESOURCE_NAME)) 88 return; 89 } 90 throw new Exception ("JMS Queue Connection Factory Resource hasn't been created !"); 91 } catch(Exception e) { 92 fail(e.getMessage()); 93 } 94 } 95 public void registerJMSTopicResource() { 96 try { 97 ResourceConfigData jmsdata = new ResourceConfigData(); 100 ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL); 101 jmsdata.setString(__JndiName, JMS_TOPIC_RESOURCE_NAME); 103 jmsdata.setString(__ResType, "javax.jms.TopicConnectionFactory"); 104 jmsdata.setString(__Enabled, "true"); 105 File fpf = File.createTempFile("falseProject",""); 109 fpf.delete(); 110 FileObject falseProject = FileUtil.createFolder(fpf); 111 falseProject.createFolder("setup"); 112 jmsdata.setTargetFileObject(falseProject); 113 jmsdata.setTargetFile("jmsResourceTest"); 114 ResourceUtils.saveJMSResourceDatatoXml(jmsdata); 115 SunResourceDataObject resourceObj = (SunResourceDataObject)SunResourceDataObject.find(falseProject.getFileObject("setup/jmsResourceTest.sun-resource")); 116 Resources res = Util.getResourcesObject(resourceObj); 117 ServerInterface mejb = ((SunDeploymentManagerInterface)inst.getDeploymentManager()).getManagement(); 118 ResourceUtils.register(res.getConnectorConnectionPool(0),mejb,false); 119 ResourceUtils.register(res.getConnectorResource(0), mejb, false); 120 resourceObj.delete(); 121 falseProject.delete(); 122 Util.sleep(5000); 124 String [] jmsResource=Util.getResourcesNames("getConnectorResource","jndi-name",mejb); 125 for(int i=0;i<jmsResource.length;i++) { 126 if(jmsResource[i].equals(JMS_TOPIC_RESOURCE_NAME)) 127 return; 128 } 129 throw new Exception ("JMS Topic Connection Factory Resource hasn't been created !"); 130 } catch(Exception e) { 131 fail(e.getMessage()); 132 } 133 } 134 public void unregisterJMSQueueResource() { 135 try { 136 ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL); 137 ServerInterface mejb = ((SunDeploymentManagerInterface)inst.getDeploymentManager()).getManagement(); 138 String [] command = new String [] {"delete-jms-resource", "--user", "admin", JMS_QUEUE_RESOURCE_NAME}; 139 Util.runAsadmin(command); 140 Util.closeProject(Util.EJB_PROJECT_NAME); 141 Util.sleep(10000); 142 String [] jmsResource = Util.getResourcesNames("getConnectorResource", "jndi-name", mejb); 143 for(int i=0;i<jmsResource.length;i++) { 144 if(jmsResource[i].equals(JMS_QUEUE_RESOURCE_NAME)) 145 throw new Exception ("JMS Queue Connection Factory Resource hasn't been removed !"); 146 } 147 } catch(Exception e) { 148 fail(e.getMessage()); 149 } 150 } 151 public void unregisterJMSTopicResource() { 152 try { 153 ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL); 154 ServerInterface mejb = ((SunDeploymentManagerInterface)inst.getDeploymentManager()).getManagement(); 155 String [] command = new String [] {"delete-jms-resource", "--user", "admin", JMS_TOPIC_RESOURCE_NAME}; 156 Util.runAsadmin(command); 157 Util.closeProject(Util.EJB_PROJECT_NAME); 158 Util.sleep(10000); 159 String [] jmsResource = Util.getResourcesNames("getConnectorResource", "jndi-name", mejb); 160 for(int i=0;i<jmsResource.length;i++) { 161 if(jmsResource[i].equals(JMS_TOPIC_RESOURCE_NAME)) 162 throw new Exception ("JMS Resource hasn't been removed !"); 163 } 164 } catch(Exception e) { 165 fail(e.getMessage()); 166 } 167 } 168 public static NbTestSuite suite() { 169 NbTestSuite suite = new NbTestSuite("JMSConnectionFactoryResourcesTest"); 170 suite.addTest(new AddRemoveSjsasInstanceTest("addSjsasInstance")); 171 suite.addTest(new StartStopServerTest("startServer")); 172 suite.addTest(new ConnectionFactoryResourceTest("registerJMSQueueResource")); 173 suite.addTest(new ConnectionFactoryResourceTest("registerJMSTopicResource")); 174 suite.addTest(new ConnectionFactoryResourceTest("unregisterJMSQueueResource")); 175 suite.addTest(new ConnectionFactoryResourceTest("unregisterJMSTopicResource")); 176 suite.addTest(new StartStopServerTest("stopServer")); 177 suite.addTest(new AddRemoveSjsasInstanceTest("removeSjsasInstance")); 178 return suite; 179 } 180 } 181 | Popular Tags |