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.api.project.Project; 40 import java.io.File ; 41 import java.io.InputStreamReader ; 42 import org.netbeans.modules.j2ee.deployment.common.api.ValidationException; 43 import org.netbeans.spi.project.ActionProvider; 44 45 46 50 public class MDBTest extends NbTestCase { 51 52 private final int SLEEP = 10000; 53 54 public MDBTest(String testName) { 55 super(testName); 56 } 57 58 public void deployMDB() { 59 try { 60 Util.deployModule(ModuleType.EJB, Util.MDB_PROJECT_PATH, Util.MDB_PROJECT_NAME); 61 } catch(Exception e) { 62 fail(e.getMessage()); 63 } 64 } 65 66 public void disableMDB(){ 67 try{ 68 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 69 String [] command = new String []{"disable", Util.MDB_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.EJB, Util.MDB_PROJECT_NAME, si,true)!=null) 80 throw new Exception ("Disable of bean failed."); 81 }catch(Exception e){ 82 fail(e.getMessage()); 83 } 84 85 } 86 87 public void enableMDB(){ 88 try{ 89 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 90 String [] command = new String []{"enable", Util.MDB_PROJECT_NAME}; 91 Process p=Util.runAsadmin(command); 92 Util.sleep(Util.SLEEP); 93 BufferedReader error = new BufferedReader (new InputStreamReader (p.getErrorStream())); 94 String errorMess = error.readLine(); 95 BufferedReader input = new BufferedReader (new InputStreamReader (p.getInputStream())); 96 String output=input.readLine(); 97 if(errorMess!=null) 98 throw new Exception (errorMess+"\n"+output); 99 System.out.println(output); 100 if(Util.getModuleID(ModuleType.EJB, Util.MDB_PROJECT_NAME, si,true)==null) 101 throw new Exception ("Enable of bean failed."); 102 }catch(Exception e){ 103 fail(e.getMessage()); 104 } 105 } 106 107 public void undeployMDB() { 108 try { 109 ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL); 110 TargetModuleID moduleID = Util.getModuleID(ModuleType.EJB, Util.MDB_PROJECT_NAME, si,false); 111 112 if(moduleID == null) 113 return; 114 115 Util.undeployModule(ModuleType.EJB, Util.MDB_PROJECT_PATH, Util.MDB_PROJECT_NAME, moduleID); 116 } catch(Exception e) { 117 fail(e.getMessage()); 118 } 119 } 120 121 public void updateMDB(){ 122 123 try{ 124 File javaFile = new File (Util.MDB_PROJECT_PATH+Util._SEP+"src"+Util._SEP+"java"+Util._SEP+"beans"+Util._SEP+"SimpleMessageBean.java"); 125 File jarFile = new File (Util.MDB_PROJECT_PATH+Util._SEP+"dist"+Util._SEP+Util.MDB_PROJECT_NAME+".jar"); 126 Long initialDate=jarFile.lastModified(); 127 javaFile.setLastModified(new java.util.Date ().getTime()); 128 deployMDB(); 129 if(jarFile.lastModified()!= initialDate) 130 System.out.println("jar updated"); 131 else 132 throw new Exception ("jar was not updated despite java code being modified"); 133 }catch(Exception e){ 134 fail(e.getMessage()); 135 } 136 137 } 138 139 public void verifyMDB() { 140 try{ 141 File f =new File (Util.MDB_PROJECT_PATH + Util._SEP + "verifier_results"); 142 Project project = (Project)Util.openProject(new File (Util.MDB_PROJECT_PATH)); 143 ActionProvider ap=(ActionProvider)project.getLookup().lookup(ActionProvider.class); 144 ap.invokeAction("verify", project.getLookup()); 145 Util.sleep(10*Util.SLEEP); 146 Util.closeProject(Util.MDB_PROJECT_NAME); 147 Util.sleep(Util.SLEEP); 148 } catch(Exception e){ 149 fail(e.getMessage()); 150 } 151 152 153 } 154 public static NbTestSuite suite() { 155 NbTestSuite suite = new NbTestSuite("MDBTest"); 156 return suite; 168 } 169 170 } | Popular Tags |