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