1 25 26 package org.objectweb.jonas.jonasadmin.test.deploy; 27 28 import junit.framework.TestSuite; 29 30 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth; 31 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase; 32 33 import com.meterware.httpunit.HttpUnitOptions; 34 import com.meterware.httpunit.TableCell; 35 import com.meterware.httpunit.WebForm; 36 import com.meterware.httpunit.WebResponse; 37 import com.meterware.httpunit.WebTable; 38 39 44 public class F_JonasAdminDeploy extends JonasAdminTestCase { 45 46 50 public static void main(String [] args) { 51 52 String testtorun = null; 53 for (int argn = 0; argn < args.length; argn++) { 55 String sArg = args[argn]; 56 if (sArg.equals("-n")) { 57 testtorun = args[++argn]; 58 } 59 } 60 if (testtorun == null) { 61 junit.textui.TestRunner.run(suite()); 62 } else { 63 junit.textui.TestRunner.run(new F_JonasAdminDeploy(testtorun)); 64 } 65 } 66 67 71 public static TestSuite suite() { 72 return new TestSuite(F_JonasAdminDeploy.class); 73 } 74 75 80 protected void setUp() throws Exception { 81 super.setUp(); 82 83 if (wc.getCurrentPage().getURL() == null) { 84 useWar("jonasAdmin"); 85 } else { 86 try { 88 wc.getFrameContents(FRAME_TREE); 89 } catch (Exception e) { 90 wc.getResponse(urlLogOut); 91 } 92 } 93 } 94 95 96 100 public F_JonasAdminDeploy(String s) { 101 super(s, URL_JONASADMIN); 102 } 103 104 108 public void testTryBadAuth() throws Exception { 109 WebResponse wRes = JonasAdminAuth.doAuth(wc, url, "bad", "bad"); 111 String txt = wRes.getText(); 112 113 if (txt.indexOf("Invalid username or password") == -1) { 114 fail("The login/password bad/bad can't be a valid l/p."); 115 } 116 } 117 118 122 public void testTryWithGoodAuth() throws Exception { 123 WebResponse wRes = JonasAdminAuth.doValidAuth(wc, url); 124 String txt = wRes.getText(); 125 126 if (txt.indexOf("Invalid username or password") != -1) { 127 fail("The login/password jadmin/jonas must be valid."); 128 } 129 } 130 131 138 private String getDeployTable(WebResponse wr, boolean deployed) throws Exception { 139 140 WebTable bigTable = wr.getTables()[0]; 142 WebTable firstTable = bigTable.getTableCell(1, 0).getTables()[0]; 143 WebTable cellTable = firstTable.getTableCell(0, 0).getTables()[0]; 144 WebTable subTable = cellTable.getTableCell(0, 0).getTables()[0]; 145 146 TableCell deployableCell = subTable.getTableCell(1, 0); 147 TableCell deployedCell = subTable.getTableCell(1, 2); 148 149 if (deployed) { 150 return deployedCell.getText(); 151 } else { 152 return deployableCell.getText(); 153 } 154 } 155 156 157 163 private void unDeployAndDeployEar(String name) throws Exception { 164 String fileName = name + ".ear"; 165 String url = URL_JONASADMIN_DEPLOYEAR; 166 167 useEar(name); 169 170 WebResponse wr = wc.getResponse(getAbsoluteUrl(url)); 171 String txt = getDeployTable(wr, true); 172 173 if (txt.indexOf(fileName) == -1) { 174 fail("The file" + fileName + " was not found as deployed."); 175 } 176 177 WebForm[] webForms = wr.getForms(); 178 WebForm webForm = webForms[0]; 179 180 String params = webForm.getParameterValue("undeploy"); 181 WebForm.Scriptable script = webForm.getScriptableObject(); 182 183 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 185 186 if (params.length() == 0) { 187 params += fileName; 188 } else { 189 params += "," + fileName; 190 } 191 192 script.setParameterValue("undeploy", params); 193 194 WebResponse submitUndeploy = webForm.submit(); 195 196 webForms = submitUndeploy.getForms(); 198 webForm = webForms[0]; 199 200 WebResponse endResp = webForm.submit(); 201 202 203 wr = wc.getResponse(getAbsoluteUrl(url)); 204 txt = getDeployTable(wr, true); 205 206 if (txt.indexOf(fileName) != -1) { 207 fail("The jonasAdmin webApp has not removed. " + fileName); 208 } 209 210 webForms = wr.getForms(); 212 webForm = webForms[0]; 213 214 params = webForm.getParameterValue("deploy"); 215 script = webForm.getScriptableObject(); 216 217 if (params.length() == 0) { 218 params += fileName; 219 } else { 220 params += "," + fileName; 221 } 222 223 script.setParameterValue("deploy", params); 224 225 submitUndeploy = webForm.submit(); 226 227 webForms = submitUndeploy.getForms(); 229 webForm = webForms[0]; 230 231 endResp = webForm.submit(); 232 233 wr = wc.getResponse(getAbsoluteUrl(url)); 234 txt = getDeployTable(wr, true); 235 236 if (txt.indexOf(fileName) == -1) { 237 fail("The file " + fileName + " was not found as deployed."); 238 } 239 } 240 241 247 public void testTryDeployUndeployEars() throws Exception { 248 JonasAdminAuth.doValidAuth(wc, url); 250 251 unDeployAndDeployEar("alarm"); 252 unDeployAndDeployEar("cmp2"); 253 } 254 255 } 256 | Popular Tags |