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