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