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.WebResponse; 37 38 39 public class F_JonasAdminRange extends JonasAdminTestCase { 40 41 44 private static final String URL_JONASADMIN_MEMORY = "/jonasAdmin/EditMemory.do"; 45 46 49 private static final int CONSTANT = 2; 50 51 54 private static final String INITIAL_RANGE = "10"; 55 56 60 public F_JonasAdminRange(String s) { 61 super(s, URL_JONASADMIN); 62 } 63 64 69 public F_JonasAdminRange(WebConversation wc, String s) { 70 super(wc, s, URL_JONASADMIN); 71 } 72 73 77 public static void main(String [] args) { 78 79 String testtorun = null; 80 for (int argn = 0; argn < args.length; argn++) { 82 String sArg = args[argn]; 83 if (sArg.equals("-n")) { 84 testtorun = args[++argn]; 85 } 86 } 87 if (testtorun == null) { 88 junit.textui.TestRunner.run(suite()); 89 } else { 90 junit.textui.TestRunner.run(new F_JonasAdminRange(testtorun)); 91 } 92 } 93 94 98 public static TestSuite suite() { 99 return new TestSuite(F_JonasAdminRange.class); 100 } 101 102 107 public static TestSuite suite(WebConversation wc) { 108 TestSuite suite = new TestSuite(); 109 suite.addTest(new F_JonasAdminRange(wc, "testSuccessful")); 110 suite.addTest(new F_JonasAdminRange(wc, "testTooSmallValue")); 111 return suite; 112 } 113 114 119 protected void setUp() throws Exception { 120 super.setUp(); 121 122 if (wc.getCurrentPage().getURL() == null) { 123 useWar("jonasAdmin"); 124 try { 126 JonasAdminAuth.doValidAuth(wc, url); 127 } catch (Exception e) { 128 fail("authentification failed : " + e); 129 } 130 } else { 131 try { 133 wc.getFrameContents(FRAME_TREE); 134 } catch (Exception e) { 135 wc.getResponse(urlLogOut); 136 try { 138 JonasAdminAuth.doValidAuth(wc, url); 139 } catch (Exception auth) { 140 fail("authentification failed : " + auth); 141 } 142 } 143 } 144 } 145 146 151 public void testSuccessful() throws Exception { 152 153 String range = "22"; 154 WebResponse wr; 155 156 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 158 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 160 161 wr = modifyNbMeasures(range); 163 164 String text = wr.getText(); 166 int start = text.indexOf("function refresh()"); 167 int end = text.indexOf("}", start); 168 String refreshScript = text.substring(start, end); 170 171 start = refreshScript.indexOf("setTimeout(\"refresh()\", ") + "setTimeout(\"refresh()\", ".length(); 173 end = refreshScript.indexOf(");", start); 174 String value = refreshScript.substring(start, end); 175 176 assertEquals("the range of the Memory image is wrong. ", "" + calculateTimerGraphic(range), value); 178 179 assertFalse("there is an error message. ", wr.getElementsWithAttribute("class", "errors").length > 0); 181 } 182 183 188 public void testTooSmallValue() throws Exception { 189 190 String range = "9"; 191 WebResponse wr; 192 193 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 195 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 197 198 wr = modifyNbMeasures(range); 200 201 assertTrue("there is not error message. ", wr.getElementsWithAttribute("class", "errors").length > 0); 203 } 204 205 210 public int calculateTimerGraphic(String range) { 211 return (Integer.parseInt(range) + CONSTANT) * 1000; 212 } 213 214 220 public WebResponse modifyNbMeasures(String range) throws Exception { 221 222 WebResponse wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN_MEMORY)); 224 225 WebForm[] webForms = wr.getForms(); 226 WebForm webForm = webForms[0]; 227 228 webForm.setParameter("range", range); 229 return wr = webForm.submit(); 230 } 231 232 236 public void tearDown() throws Exception { 237 WebResponse wr = wc.getResponse(getAbsoluteUrl(URL_JONASADMIN_MEMORY)); 238 WebForm[] webForms = wr.getForms(); 239 WebForm webForm = webForms[0]; 240 241 webForm.setParameter("range", INITIAL_RANGE); 242 wr = webForm.submit(); 243 } 244 } | Popular Tags |