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.net.HttpURLConnection ; 34 import java.net.Proxy ; 35 import java.net.URL ; 36 import javax.enterprise.deploy.shared.ModuleType ; 37 import javax.enterprise.deploy.spi.Target ; 38 import javax.enterprise.deploy.spi.TargetModuleID ; 39 import org.netbeans.api.project.Project; 40 import org.netbeans.junit.NbTestCase; 41 import org.netbeans.junit.NbTestSuite; 42 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 43 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; 44 import org.netbeans.spi.project.ActionProvider; 45 46 50 public class WebServiceTest extends NbTestCase{ 51 52 private final int SLEEP = 10000; 53 54 public WebServiceTest(String testName) { 55 super(testName); 56 } 57 58 public void deployWebService() { 59 try { 60 Util.deployModule(ModuleType.WAR, Util.WEBSERVICE_PROJECT_PATH, Util.WEBSERVICE_PROJECT_NAME); 61 62 } catch(Exception e) { 63 fail(e.getMessage()); 64 } 65 } 66 67 public void disableWebService(){ 68 try{ 69 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 70 String [] command = new String []{"disable", Util.WEBSERVICE_PROJECT_NAME}; 71 Process p=Util.runAsadmin(command); 72 Util.sleep(Util.SLEEP); 73 BufferedReader error = new BufferedReader (new InputStreamReader (p.getErrorStream())); 74 String errorMess = error.readLine(); 75 BufferedReader input = new BufferedReader (new InputStreamReader (p.getInputStream())); 76 String output=input.readLine(); 77 if(errorMess!=null) 78 throw new Exception (errorMess+"\n"+output); 79 System.out.println(output); 80 if( Util.getModuleID(ModuleType.WAR, Util.WEBSERVICE_PROJECT_NAME,si,true)!=null) 81 throw new Exception ("Disable of web service failed"); 82 }catch(Exception e){ 83 fail(e.getMessage()); 84 } 85 86 } 87 88 public void enableWebService(){ 89 try{ 90 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 91 String [] command = new String []{"enable", Util.WEBSERVICE_PROJECT_NAME}; 92 Process p=Util.runAsadmin(command); 93 Util.sleep(Util.SLEEP); 94 BufferedReader error = new BufferedReader (new InputStreamReader (p.getErrorStream())); 95 String errorMess = error.readLine(); 96 BufferedReader input = new BufferedReader (new InputStreamReader (p.getInputStream())); 97 String output=input.readLine(); 98 if(errorMess!=null) 99 throw new Exception (errorMess+"\n"+output); 100 System.out.println(output); 101 if( Util.getModuleID(ModuleType.WAR, Util.WEBSERVICE_PROJECT_NAME,si,true)==null) 102 throw new Exception ("Enable of web service failed"); 103 testWebService(); 104 }catch(Exception e){ 105 fail(e.getMessage()); 106 } 107 } 108 109 public void undeployWebService() { 110 try { 111 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 112 TargetModuleID moduleID = Util.getModuleID(ModuleType.WAR, Util.WEBSERVICE_PROJECT_NAME, si,false); 113 114 if(moduleID == null) 115 return; 116 117 Util.undeployModule(ModuleType.WAR, Util.WEBSERVICE_PROJECT_PATH, Util.WEBSERVICE_PROJECT_NAME, moduleID); 118 } catch(Exception e) { 119 fail(e.getMessage()); 120 } 121 } 122 123 public void verifyModule() { 124 try{ 125 File f =new File (Util.WEBSERVICE_PROJECT_PATH + Util._SEP + "verifier_results"); 126 Project project = (Project)Util.openProject(new File (Util.WEBSERVICE_PROJECT_PATH)); 127 ActionProvider ap =(ActionProvider)project.getLookup().lookup(ActionProvider.class); 128 ap.invokeAction("verify", project.getLookup()); 129 Util.sleep(10*Util.SLEEP); 130 Util.closeProject(Util.WEBSERVICE_PROJECT_NAME); 131 Util.sleep(Util.SLEEP); 132 } catch(Exception e){ 133 fail(e.getMessage()); 134 } 135 136 137 } 138 139 public void testWebService(){ 140 try{ 141 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 142 Target target = si.getTargets()[0].getTarget(); 143 TargetModuleID [] modules = si.getDeploymentManager().getRunningModules(ModuleType.WAR, new Target [] {target}); 144 for(int i=0;i<modules.length;i++){ 145 if(modules[i].getModuleID().equals(Util.WEBSERVICE_PROJECT_NAME)) { 146 URL url=new URL (modules[i].getWebURL()); 147 HttpURLConnection httpConn = (HttpURLConnection )url.openConnection(Proxy.NO_PROXY); 148 if( httpConn.getResponseCode()!=200) 149 throw new Exception ("The webService project is not deployed with http error code"+httpConn.getResponseCode()); 150 URL wsdl=new URL (modules[i].getWebURL()+"/CalculatorWSService?wsdl"); 151 HttpURLConnection httpConn_wsdl = (HttpURLConnection )wsdl.openConnection(Proxy.NO_PROXY); 152 if( httpConn_wsdl.getResponseCode()!=200) 153 throw new Exception ("The WSDL file is not published"); 154 return; 155 } 156 } 157 throw new Exception ("The project is not deployed"); 158 }catch(Exception e) { 159 fail(e.getMessage()); 160 } 161 } 162 163 public static NbTestSuite suite() { 164 NbTestSuite suite = new NbTestSuite("WebServiceTest"); 165 return suite; 179 } 180 181 } 182 | Popular Tags |