1 19 27 28 package org.netbeans.modules.j2ee.sun.test; 29 30 31 import java.io.BufferedReader ; 32 import javax.enterprise.deploy.shared.ModuleType ; 33 import javax.enterprise.deploy.spi.TargetModuleID ; 34 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.spi.project.ActionProvider; 40 import org.netbeans.api.project.Project; 41 import java.io.File ; 42 import java.io.FileOutputStream ; 43 import java.io.InputStreamReader ; 44 import java.io.OutputStream ; 45 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 46 import org.netbeans.modules.j2ee.sun.ide.j2ee.VerifierImpl; 47 import org.openide.util.RequestProcessor; 48 import org.openide.util.Task; 49 50 51 55 public class JSFModuleTest extends NbTestCase { 56 57 private final int SLEEP = 10000; 58 59 public JSFModuleTest(String testName) { 60 super(testName); 61 } 62 63 public void deployJSFModule() { 64 try { 65 Util.deployModule(ModuleType.WAR, Util.JSF_PROJECT_PATH, Util.JSF_PROJECT_NAME); 66 } catch(Exception e) { 67 fail(e.getMessage()); 68 } 69 } 70 public void executeJSFModule() { 72 try{ 73 74 int errorcode=Util.executeWebModule(ModuleType.WAR, Util.JSF_PROJECT_NAME); 75 if(errorcode!=200) 76 throw new Exception ("Execution of project failed with errorcode "+errorcode); 77 }catch(Exception e){ 78 fail(e.getMessage()); 79 } 80 } 81 public void disableJSFModule(){ 82 try{ 83 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 84 String [] command = new String []{"disable", Util.JSF_PROJECT_NAME}; 85 Process p=Util.runAsadmin(command); 86 Util.sleep(Util.SLEEP); 87 BufferedReader error = new BufferedReader (new InputStreamReader (p.getErrorStream())); 88 String errorMess = error.readLine(); 89 BufferedReader input = new BufferedReader (new InputStreamReader (p.getInputStream())); 90 String output=input.readLine(); 91 if(errorMess!=null) 92 throw new Exception (errorMess+"\n"+output); 93 System.out.println(output); 94 if(Util.getModuleID(ModuleType.WAR, Util.JSF_PROJECT_NAME, si,true)!=null) 95 throw new Exception ("Disable of application failed."); 96 }catch(Exception e){ 97 fail(e.getMessage()); 98 } 99 100 } 101 public void enableJSFModule(){ 102 try{ 103 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 104 String [] command = new String []{"enable", Util.JSF_PROJECT_NAME}; 105 Process p=Util.runAsadmin(command); 106 Util.sleep(Util.SLEEP); 107 BufferedReader error = new BufferedReader (new InputStreamReader (p.getErrorStream())); 108 String errorMess = error.readLine(); 109 BufferedReader input = new BufferedReader (new InputStreamReader (p.getInputStream())); 110 String output=input.readLine(); 111 if(errorMess!=null) 112 throw new Exception (errorMess+"\n"+output); 113 System.out.println(output); 114 executeJSFModule(); 115 }catch(Exception e){ 116 fail(e.getMessage()); 117 } 118 } 119 public void undeployJSFModule() { 120 try { 121 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 122 TargetModuleID moduleID = Util.getModuleID(ModuleType.WAR, Util.JSF_PROJECT_NAME, si,false); 123 124 if(moduleID == null) 125 return; 126 127 Util.undeployModule(ModuleType.WAR, Util.JSF_PROJECT_PATH, Util.JSF_PROJECT_NAME, moduleID); 128 } catch(Exception e) { 129 fail(e.getMessage()); 130 } 131 } 132 public void verifyJSFModule() { 134 try{ 135 File f =new File (Util.JSF_PROJECT_PATH + Util._SEP + "verifier_results"); 136 Project project = (Project)Util.openProject(new File (Util.JSF_PROJECT_PATH)); 137 ActionProvider ap=(ActionProvider)project.getLookup().lookup(ActionProvider.class); 138 ap.invokeAction("verify", project.getLookup()); 139 Util.sleep(10*Util.SLEEP); 140 Util.closeProject(Util.JSF_PROJECT_NAME); 141 Util.sleep(Util.SLEEP); 142 143 } catch(Exception e){ 144 fail(e.getMessage()); 145 } 146 147 148 } 149 public void updateModule(){ 150 try{ 151 File javaFile = new File (Util.JSF_PROJECT_PATH+Util._SEP+"src"+Util._SEP+"java"+Util._SEP+"org"+Util._SEP+"demo"+Util._SEP+"Customer.java"); 152 File warFile = new File (Util.JSF_PROJECT_PATH+Util._SEP+"dist"+Util._SEP+Util.JSF_PROJECT_NAME+".war"); 153 Long initialDate=warFile.lastModified(); 154 javaFile.setLastModified(new java.util.Date ().getTime()); 155 deployJSFModule(); 156 if(warFile.lastModified()!= initialDate) 157 System.out.println("war updated"); 158 else 159 throw new Exception ("war was not updated despite java code being modified"); 160 }catch(Exception e){ 161 fail(e.getMessage()); 162 } 163 164 } 165 public void runJSFModule(){ 167 try{ 168 Project project = (Project)Util.openProject(new File (Util.JSF_PROJECT_PATH)); 169 ActionProvider ap = (ActionProvider)project.getLookup().lookup(ActionProvider.class); 170 J2eeModuleProvider jmp = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); 171 final ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 172 173 Runnable startCondition = new Runnable () { 174 public void run() { 175 while(!si.isConnected()) { 176 try { 177 Thread.sleep(5000); 178 } catch(Exception e) {} 179 } 180 } 181 }; 182 183 Runnable runCondition = new Runnable () { 184 public void run() { 185 while(Util.getModuleID(ModuleType.WAR, Util.JSF_PROJECT_NAME, si,true) == null) { 186 try { 187 188 Thread.sleep(5000); 189 } catch(Exception e) {} 190 } 191 } 192 }; 193 194 Task t = RequestProcessor.getDefault().create(startCondition); 195 ap.invokeAction(ap.COMMAND_RUN, project.getLookup()); 196 t.run(); 197 if(!t.waitFinished(300000)) 198 throw new Exception ("Server start timeout"); 199 200 Util.sleep(Util.SLEEP); 201 202 t = RequestProcessor.getDefault().create(runCondition); 203 t.run(); 204 if(!t.waitFinished(300000)) 205 throw new Exception ("WEB Application execution timeout"); 206 207 Util. sleep(Util.SLEEP); 208 209 Util.closeProject(Util.JSF_PROJECT_NAME); 210 211 Util.sleep(Util.SLEEP); 212 executeJSFModule(); 213 214 }catch(Exception e){ 215 fail(e.getMessage()); 216 } 217 218 219 } 220 221 public static NbTestSuite suite() { 222 NbTestSuite suite = new NbTestSuite("JSFModuleTest"); 223 suite.addTest(new AddRemoveSjsasInstanceTest("addSjsasInstance")); 225 suite.addTest(new StartStopServerTest("startServer")); 226 suite.addTest(new JSFModuleTest("deployJSFModule")); 227 suite.addTest(new JSFModuleTest("executeJSFModule")); 228 suite.addTest(new JSFModuleTest("updateModule")); 229 suite.addTest(new JSFModuleTest("disableJSFModule")); 231 suite.addTest(new JSFModuleTest("enableJSFModule")); 232 suite.addTest(new StartStopServerTest("restartServer")); 233 suite.addTest(new JSFModuleTest("executeJSFModule")); 234 suite.addTest(new JSFModuleTest("runJSFModule")); 235 suite.addTest(new JSFModuleTest("undeployJSFModule")); 236 suite.addTest(new StartStopServerTest("stopServer")); 237 suite.addTest(new AddRemoveSjsasInstanceTest("removeSjsasInstance")); 238 return suite; 239 } 240 } 241 | Popular Tags |