1 25 26 package org.objectweb.jonas.jonasadmin.test.monitoring; 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.WebConversation; 35 import com.meterware.httpunit.WebForm; 36 import com.meterware.httpunit.WebImage; 37 import com.meterware.httpunit.WebResponse; 38 39 40 45 public class F_JonasAdminNumberOfMeasures extends JonasAdminTestCase { 46 47 50 private static final String URL_JONASADMIN_MEMORY = "/jonasAdmin/EditMemory.do"; 51 52 55 private static final int CONSTANT = 190; 56 57 60 private static final String INITIAL_NB_MEASURES = "120"; 61 62 66 public F_JonasAdminNumberOfMeasures(String s) { 67 super(s, URL_JONASADMIN); 68 } 69 70 75 public F_JonasAdminNumberOfMeasures(WebConversation wc, String s) { 76 super(wc, s, URL_JONASADMIN); 77 } 78 79 83 public static void main(String [] args) { 84 85 String testtorun = null; 86 for (int argn = 0; argn < args.length; argn++) { 88 String sArg = args[argn]; 89 if (sArg.equals("-n")) { 90 testtorun = args[++argn]; 91 } 92 } 93 if (testtorun == null) { 94 junit.textui.TestRunner.run(suite()); 95 } else { 96 junit.textui.TestRunner.run(new F_JonasAdminNumberOfMeasures(testtorun)); 97 } 98 } 99 100 104 public static TestSuite suite() { 105 return new TestSuite(F_JonasAdminNumberOfMeasures.class); 106 } 107 108 113 public static TestSuite suite(WebConversation wc) { 114 TestSuite suite = new TestSuite(); 115 suite.addTest(new F_JonasAdminNumberOfMeasures(wc, "testValidNbMeasures")); 116 suite.addTest(new F_JonasAdminNumberOfMeasures(wc, "testNotIntegerNbMeasures")); 117 suite.addTest(new F_JonasAdminNumberOfMeasures(wc, "testNbMeasuresLessThanOne")); 118 return suite; 119 } 120 121 126 protected void setUp() throws Exception { 127 super.setUp(); 128 129 if (wc.getCurrentPage().getURL() == null) { 130 useWar("jonasAdmin"); 131 try { 133 JonasAdminAuth.doValidAuth(wc, url); 134 } catch (Exception e) { 135 fail("authentification failed : " + e); 136 } 137 } else { 138 try { 140 wc.getFrameContents(FRAME_TREE); 141 } catch (Exception e) { 142 wc.getResponse(urlLogOut); 143 try { 145 JonasAdminAuth.doValidAuth(wc, url); 146 } catch (Exception auth) { 147 fail("authentification failed : " + auth); 148 } 149 } 150 } 151 } 152 153 158 protected void tearDown() throws Exception { 159 WebResponse wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN_MEMORY)); 160 WebForm[] webForms = wr.getForms(); 161 WebForm webForm = webForms[0]; 162 163 webForm.setParameter("numberOfMeasures", INITIAL_NB_MEASURES); 164 wr = webForm.submit(); 165 } 166 167 171 public void testValidNbMeasures() throws Exception { 172 173 String nbMeasures = "300"; 174 WebResponse wr; 175 176 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 178 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 180 181 wr = modifyNbMeasures(nbMeasures); 183 184 WebImage imageMemory = wr.getImageWithName("memory"); 186 assertEquals("the width of the Memory image is wrong. ", "" + calculateWidth(nbMeasures), imageMemory.getAttribute("width")); 187 188 } 189 190 194 public void testNotIntegerNbMeasures() throws Exception { 195 196 String nbMeasures = "100.2"; 197 WebResponse wr; 198 199 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 201 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 203 204 wr = modifyNbMeasures(nbMeasures); 206 207 assertNull("there is the Memory image. ", wr.getImageWithName("memory")); 209 210 assertTrue("there is not error message. ", wr.getText().indexOf("<li>") != -1); 212 } 213 214 218 public void testNbMeasuresLessThanOne() throws Exception { 219 220 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 222 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 224 225 226 String nbMeasures = "1"; 227 WebResponse wr; 228 229 wr = modifyNbMeasures(nbMeasures); 231 assertNull("there is the Memory image. ", wr.getImageWithName("memory")); 233 assertTrue("there is not error message. ", wr.getText().indexOf("<li>") != -1); 235 236 237 nbMeasures = "0"; 238 239 wr = modifyNbMeasures(nbMeasures); 241 assertNull("there is the Memory image. ", wr.getImageWithName("memory")); 243 assertTrue("there is not error message. ", wr.getText().indexOf("<li>") != -1); 245 246 247 nbMeasures = "-1"; 248 249 wr = modifyNbMeasures(nbMeasures); 251 assertNull("there is the Memory image. ", wr.getImageWithName("memory")); 253 assertTrue("there is not error message. ", wr.getText().indexOf("<li>") != -1); 255 256 257 nbMeasures = "-99999"; 258 259 wr = modifyNbMeasures(nbMeasures); 261 assertNull("there is the Memory image. ", wr.getImageWithName("memory")); 263 assertTrue("there is not error message. ", wr.getText().indexOf("<li>") != -1); 265 } 266 267 272 public int calculateWidth(String nbMeasures) { 273 return Integer.parseInt(nbMeasures) * 2 + CONSTANT; 274 } 275 276 282 public WebResponse modifyNbMeasures(String nbMeasures) throws Exception { 283 284 WebResponse wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN_MEMORY)); 286 WebForm[] webForms = wr.getForms(); 287 WebForm webForm = webForms[0]; 288 289 webForm.setParameter("numberOfMeasures", nbMeasures); 290 return wr = webForm.submit(); 291 } 292 } 293 | Popular Tags |