1 19 20 package org.netbeans.modules.j2ee.sun.test; 21 22 import java.io.File ; 23 import java.util.Vector ; 24 import org.netbeans.api.db.explorer.ConnectionManager; 25 import org.netbeans.api.db.explorer.DatabaseConnection; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.junit.NbTestSuite; 28 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 29 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; 30 import org.netbeans.modules.j2ee.sun.api.ServerInterface; 31 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface; 32 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.Resources; 33 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils; 34 import org.netbeans.modules.j2ee.sun.ide.sunresources.resourcesloader.SunResourceDataObject; 35 import org.netbeans.modules.j2ee.sun.ide.sunresources.wizards.ResourceConfigData; 36 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants; 37 import org.openide.filesystems.FileObject; 38 import org.openide.filesystems.FileUtil; 39 40 44 public class SunResourcesTest extends NbTestCase implements WizardConstants{ 45 46 private static String CONNECTION_POOL_NAME = "connectionPoolTest"; 47 48 49 public SunResourcesTest(String testName) { 50 super(testName); 51 } 52 53 public void registerConnectionPool() { 54 try { 55 ResourceConfigData cpdata = new ResourceConfigData(); 57 DatabaseConnection dbconn = ConnectionManager.getDefault().getConnections()[0]; 58 ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL); 59 60 cpdata.setProperties(new Vector ()); 62 cpdata.addProperty(__DerbyPortNumber, "1527"); 63 cpdata.addProperty(__DerbyDatabaseName, "sample"); 64 cpdata.addProperty(__ServerName, "localhost"); 65 cpdata.addProperty(__User, dbconn.getUser()); 66 cpdata.addProperty(__Password, dbconn.getPassword()); 67 cpdata.setString(__Name, CONNECTION_POOL_NAME); 68 cpdata.setString(__ResType, "javax.sql.DataSource"); 69 cpdata.setString(__IsXA, "false"); 70 cpdata.setString(__DatasourceClassname, "org.apache.derby.jdbc.ClientDataSource"); 71 cpdata.setString(__SteadyPoolSize, "8"); 72 cpdata.setString(__MaxPoolSize, "32"); 73 cpdata.setString(__MaxWaitTimeInMillis, "60000"); 74 cpdata.setString(__PoolResizeQuantity, "2"); 75 cpdata.setString(__IdleTimeoutInSeconds, "300"); 76 77 File fpf = File.createTempFile("falseProject",""); 79 fpf.delete(); 80 FileObject falseProject = FileUtil.createFolder(fpf); 81 falseProject.createFolder("setup"); 82 cpdata.setTargetFileObject(falseProject); 83 cpdata.setTargetFile("poolTest"); 84 85 ResourceUtils.saveConnPoolDatatoXml(cpdata); 86 87 SunResourceDataObject resourceObj = (SunResourceDataObject)SunResourceDataObject.find(falseProject.getFileObject("setup/poolTest.sun-resource")); 88 Resources res = Util.getResourcesObject(resourceObj); 89 ServerInterface mejb = ((SunDeploymentManagerInterface)inst.getDeploymentManager()).getManagement(); 90 91 ResourceUtils.register(res.getJdbcConnectionPool(0), mejb, false); 92 resourceObj.delete(); 93 falseProject.delete(); 94 96 Util.sleep(5000); 97 98 String [] connPools = Util.getResourcesNames("getJdbcConnectionPool", "name", mejb); 99 100 for(int i=0;i<connPools.length;i++) { 101 if(connPools[i].equals(CONNECTION_POOL_NAME)) 102 return; 103 } 104 105 throw new Exception ("Connection Pool hasn't been created !"); 106 } catch(Exception e) { 107 fail(e.getMessage()); 108 } 109 } 110 111 public void unregisterConnectionPool() { 112 try { 113 ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL); 114 ServerInterface mejb = ((SunDeploymentManagerInterface)inst.getDeploymentManager()).getManagement(); 115 116 String password = System.getProperty("sjsas.server.password"); 117 118 String [] command = new String [] {"delete-jdbc-connection-pool", "--user", "admin", "--password", password, CONNECTION_POOL_NAME}; 119 Util.runAsadmin(command); 120 Util.closeProject(Util.WEB_PROJECT_NAME); 121 122 Util.sleep(5000); 123 124 String [] connPools = Util.getResourcesNames("getJdbcConnectionPool", "name", mejb); 125 126 for(int i=0;i<connPools.length;i++) { 127 if(connPools[i].equals(CONNECTION_POOL_NAME)) 128 throw new Exception ("Connection Pool hasn't been removed !"); 129 } 130 } catch(Exception e) { 131 fail(e.getMessage()); 132 } 133 } 134 135 public static NbTestSuite suite() { 136 NbTestSuite suite = new NbTestSuite("SunResourcesTest"); 137 suite.addTest(new AddRemoveSjsasInstanceTest("addSjsasInstance")); 138 suite.addTest(new StartStopServerTest("startServer")); 139 suite.addTest(new SunResourcesTest("registerConnectionPool")); 140 suite.addTest(new SunResourcesTest("unregisterConnectionPool")); 141 suite.addTest(new StartStopServerTest("stopServer")); 142 suite.addTest(new AddRemoveSjsasInstanceTest("removeSjsasInstance")); 143 return suite; 144 } 145 } | Popular Tags |