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.FileOutputStream ; 33 import java.io.InputStreamReader ; 34 import java.io.OutputStream ; 35 import javax.enterprise.deploy.shared.ModuleType ; 36 import javax.enterprise.deploy.spi.TargetModuleID ; 37 import org.netbeans.api.project.Project; 38 import org.netbeans.junit.NbTestCase; 39 import org.netbeans.junit.NbTestSuite; 40 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 41 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; 42 import org.netbeans.spi.project.ActionProvider; 43 44 48 public class DukeStatefulTest extends NbTestCase{ 49 50 51 private final int SLEEP = 10000; 52 53 public DukeStatefulTest(String testName) { 54 super(testName); 55 } 56 57 public void deployApplication() { 58 try { 59 Util.deployModule(ModuleType.EAR,Util.STATEFUL_PROJECT_PATH, Util.STATEFUL_PROJECT_NAME ); 60 } catch(Exception e) { 61 fail(e.getMessage()); 62 } 63 } 64 65 66 public void disableApplication(){ 67 try{ 68 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 69 String [] command = new String []{"disable", Util.STATEFUL_PROJECT_NAME}; 70 Process p=Util.runAsadmin(command); 71 Util.sleep(Util.SLEEP); 72 BufferedReader error = new BufferedReader (new InputStreamReader (p.getErrorStream())); 73 String errorMess = error.readLine(); 74 BufferedReader input = new BufferedReader (new InputStreamReader (p.getInputStream())); 75 String output=input.readLine(); 76 if(errorMess!=null) 77 throw new Exception (errorMess+"\n"+output); 78 System.out.println(output); 79 if (Util.getModuleID(ModuleType.EAR, Util.STATEFUL_PROJECT_NAME, si,true)!=null) 80 throw new Exception ("Disable of application failed."); 81 }catch(Exception e){ 82 fail(e.getMessage()); 83 } 84 } 85 86 public void enableApplication(){ 87 try{ 88 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 89 String [] command = new String []{"enable", Util.STATEFUL_PROJECT_NAME}; 90 Process p=Util.runAsadmin(command); 91 Util.sleep(Util.SLEEP); 92 BufferedReader error = new BufferedReader (new InputStreamReader (p.getErrorStream())); 93 String errorMess = error.readLine(); 94 BufferedReader input = new BufferedReader (new InputStreamReader (p.getInputStream())); 95 String output=input.readLine(); 96 if(errorMess!=null) 97 throw new Exception (errorMess+"\n"+output); 98 System.out.println(output); 99 }catch(Exception e){ 100 fail(e.getMessage()); 101 } 102 } 103 104 public void undeployApplication() { 105 try { 106 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 107 TargetModuleID moduleID = Util.getModuleID(ModuleType.EAR, Util.CUSTOMER_APPLICATION_PROJECT_NAME, si,false); 108 if(moduleID == null) 109 return; 110 Util.undeployModule(ModuleType.EAR, Util.STATEFUL_PROJECT_PATH, Util.STATEFUL_PROJECT_NAME, moduleID); 111 } catch(Exception e) { 112 fail(e.getMessage()); 113 } 114 } 115 116 public void verifyApplication() { 117 try{ 118 File f =new File (Util.STATEFUL_PROJECT_PATH + Util._SEP + "verifier_results"); 119 Project project = (Project)Util.openProject(new File (Util.STATEFUL_PROJECT_PATH)); 120 ActionProvider ap =(ActionProvider)project.getLookup().lookup(ActionProvider.class); 121 OutputStream logger=(OutputStream )new FileOutputStream (f); 122 ap.invokeAction("verify", project.getLookup()); 123 Util.sleep(10*Util.SLEEP); 124 Util.closeProject(Util.STATEFUL_PROJECT_NAME); 125 Util.sleep(Util.SLEEP); 126 127 } catch(Exception e){ 128 fail(e.getMessage()); 129 } 130 131 132 } 133 134 135 public void runClient(){ 136 try{ 137 String [] getClientStubs = new String []{"get-client-stubs", "--user", "admin","--appname", Util.STATEFUL_PROJECT_NAME, "." }; 138 Util.runAsadmin(getClientStubs); 139 Util.sleep(Util.SLEEP); 140 Process p = Runtime.getRuntime().exec(Util._PLATFORM_LOCATION+Util._SEP+"bin"+Util._SEP+"appclient -client "+Util.STATEFUL_PROJECT_NAME+"Client.jar"); 141 BufferedReader error = new BufferedReader (new InputStreamReader (p.getErrorStream())); 142 String errorMess = error.readLine(); 143 BufferedReader input = new BufferedReader (new InputStreamReader (p.getInputStream())); 144 String output=input.readLine(); 145 if(errorMess!=null) 146 throw new Exception (errorMess+"\n"+output); 147 if (!output.equals("duke")) 148 throw new Exception ("The client of application giving wrong results"); 149 }catch(Exception e){ 150 fail(e.getMessage()); 151 } 152 } 153 public static NbTestSuite suite() { 154 NbTestSuite suite = new NbTestSuite("DukeStatefulTest"); 155 return suite; 169 } 170 } 171 172 | Popular Tags |