1 25 26 package org.objectweb.jonas.jonasadmin.test.logging; 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 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils; 33 import org.xml.sax.SAXException ; 34 35 import com.meterware.httpunit.HttpUnitOptions; 36 import com.meterware.httpunit.SubmitButton; 37 import com.meterware.httpunit.WebConversation; 38 import com.meterware.httpunit.WebForm; 39 import com.meterware.httpunit.WebLink; 40 import com.meterware.httpunit.WebResponse; 41 import com.meterware.httpunit.WebTable; 42 43 44 50 public class F_JonasAdminLogger extends JonasAdminTestCase { 51 52 55 private static final String URL_JONASADMIN_JONAS_LOGGER = "/EditLoggingJonas.do"; 56 57 60 private static final String INPUT_CHECKBOX = "input type=\"checkbox\""; 61 62 65 private static final String TITLE_LOGGER_TYPE = "Logger type"; 66 67 70 private static final String TITLE_CONTAINER_TYPE = "Container type"; 71 72 75 private static final String TITLE_CONTAINER_NAME = "Container name (or path)"; 76 77 80 private static WebConversation wc2 = new WebConversation(); 81 82 86 public F_JonasAdminLogger(String s) { 87 super(s, URL_JONASADMIN); 88 } 89 90 95 public F_JonasAdminLogger(WebConversation wc, String s) { 96 super(wc, s, URL_JONASADMIN); 97 } 98 99 103 public static void main(String [] args) { 104 105 String testtorun = null; 106 for (int argn = 0; argn < args.length; argn++) { 108 String sArg = args[argn]; 109 if (sArg.equals("-n")) { 110 testtorun = args[++argn]; 111 } 112 } 113 if (testtorun == null) { 114 junit.textui.TestRunner.run(suite()); 115 } else { 116 junit.textui.TestRunner.run(new F_JonasAdminLogger(testtorun)); 117 } 118 } 119 120 124 public static TestSuite suite() { 125 return new TestSuite(F_JonasAdminLogger.class); 126 } 127 128 133 public static TestSuite suite(WebConversation wc) { 134 TestSuite suite = new TestSuite(); 135 suite.addTest(new F_JonasAdminLogger(wc, "testLoggers")); 136 suite.addTest(new F_JonasAdminLogger(wc, "testJonasLogger")); 137 return suite; 138 } 139 140 145 protected void setUp() throws Exception { 146 super.setUp(); 147 148 if (wc.getCurrentPage().getURL() == null) { 149 useWar("jonasAdmin"); 150 try { 152 JonasAdminAuth.doValidAuth(wc, url); 153 } catch (Exception e) { 154 fail("authentification failed : " + e); 155 } 156 } else { 157 try { 159 wc.getFrameContents(FRAME_TREE); 160 } catch (Exception e) { 161 wc.getResponse(urlLogOut); 162 try { 164 JonasAdminAuth.doValidAuth(wc, url); 165 } catch (Exception auth) { 166 fail("authentification failed : " + auth); 167 } 168 } 169 } 170 } 171 172 177 public void testLoggers() throws Exception { 178 179 WebResponse wr; 180 WebLink link; 181 WebTable table; 182 WebForm form; 183 String host = "localhost"; 184 int row; 185 int columnLoggerType; 186 JonasAdminUtils utils = new JonasAdminUtils(); 187 188 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 190 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 192 193 194 try { 197 JonasAdminAuth.doValidAuth(wc2, url); 198 } catch (Exception e) { 199 fail("authentification failed : " + e); 200 } 201 202 if (jProp.isCatalina()) { 203 wr = LoggerUtils.getLoggerPage(wc); 204 table = utils.getTable(wr, 3); 205 206 if (table.getRowCount() == 2) { 207 assertFalse("There is a remove button. ", wr.getText().indexOf("'remove'") != -1); 208 } else { 209 assertTrue("There is no remove button but there is no one and only one logger. ", wr.getText().indexOf("'remove'") != -1); 210 } 211 212 LoggerUtils.createNewEngineLogger(wc); 214 wr = LoggerUtils.getLoggerPage(wc); 216 table = utils.getTable(wr, 3); 217 form = wr.getForms()[0]; 218 columnLoggerType = utils.getColumn(TITLE_LOGGER_TYPE, table).intValue(); 219 row = utils.getFirstRow("Access log valve engine", table, columnLoggerType).intValue(); 220 if (row == -1) { 221 throw new IllegalThreadStateException ("There is no row, which contains 'Access log valve engine'. "); 222 } 223 assertEquals("There is no the correct number of loggers. ", 3, table.getRowCount()); 224 assertTrue("There is no remove button. ", wr.getText().indexOf("'remove'") != -1); 225 assertEquals("There is no the correct number of parameters in the form. ", 2, form.getParameterNames().length); 226 assertTrue("There is no checkbox", wr.getText().indexOf(INPUT_CHECKBOX) != -1); 227 assertEquals("The container type is not 'Engine'. ", "Engine", table.getTableCell(row, utils.getColumn(TITLE_CONTAINER_TYPE, table).intValue()).getText()); 228 assertEquals("The container name is not 'engine'. ", "engine", table.getTableCell(row, utils.getColumn(TITLE_CONTAINER_NAME, table).intValue()).getText()); 229 230 LoggerUtils.createNewHostLogger(wc); 231 wr = LoggerUtils.getLoggerPage(wc); 233 table = utils.getTable(wr, 3); 234 form = wr.getForms()[0]; 235 row = utils.getFirstRow("Access log valve " + host, table, columnLoggerType).intValue(); 236 if (row == -1) { 237 throw new IllegalThreadStateException ("There is no row, which contains 'Access log valve " + host + "'. "); 238 } 239 assertEquals("There is no the correct number of loggers. ", 4, table.getRowCount()); 240 assertTrue("There is no remove button. ", wr.getText().indexOf("'remove'") != -1); 241 assertEquals("There is no the correct number of parameters in the form. ", 2, form.getParameterNames().length); 242 assertEquals("The container type is not 'Host'. ", "Host", table.getTableCell(row, utils.getColumn(TITLE_CONTAINER_TYPE, table).intValue()).getText()); 243 assertEquals("The container name is not '" + host + "'. ", host, table.getTableCell(row, utils.getColumn(TITLE_CONTAINER_NAME, table).intValue()).getText()); 244 245 LoggerUtils.modifyLogger(wc, null, "dir", "true", "false", ".suffix", "prefix_", "%v"); 247 wr = wc.getFrameContents(FRAME_CONTENT); 249 verifyAccessLogValve(wr, "dir", "true", "false", ".suffix", "prefix_", "%v"); 250 251 LoggerUtils.modifyLogger(wc, host, "dir", "true", "false", ".suffix", "prefix_", "%v"); 252 wr = wc.getFrameContents(FRAME_CONTENT); 254 verifyAccessLogValve(wr, "dir", "true", "false", ".suffix", "prefix_", "%v"); 255 256 257 LoggerUtils.deleteLogger(wc, null); 259 wr = LoggerUtils.getLoggerPage(wc); 261 table = utils.getTable(wr, 3); 262 assertEquals("The number of loggers is not 2. ", 3, table.getRowCount()); 263 264 LoggerUtils.deleteLogger(wc, host); 265 wr = LoggerUtils.getLoggerPage(wc); 267 table = utils.getTable(wr, 3); 268 assertEquals("The number of loggers is not 1. ", 2, table.getRowCount()); 269 } 270 } 271 272 276 public void testJonasLogger() throws Exception { 277 278 if (jProp.isCatalina()) { 279 WebResponse wr; 280 WebLink link; 281 WebTable table; 282 WebForm form; 283 SubmitButton button = null; 284 int row; 285 int columnLevels; 286 int columnTopics; 287 JonasAdminUtils utils = new JonasAdminUtils(); 288 289 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 291 HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); 293 294 wr = LoggerUtils.getLoggerPage(wc); 295 link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_JONAS_LOGGER); 296 if (link != null) { 297 link.click(); 298 } else { 299 throw new IllegalThreadStateException ("The link " + URL_JONASADMIN_JONAS_LOGGER + " is not found. "); 300 } 301 302 wr = wc.getFrameContents(FRAME_CONTENT); 304 table = utils.getTable(wr, 3); 305 form = wr.getForms()[0]; 306 String [] topics = form.getOptions("topic"); 307 columnTopics = utils.getColumn("Topics", table).intValue(); 308 if (columnTopics == -1) { 309 throw new IllegalThreadStateException ("There is no column, which contains 'Topics'. "); 310 } 311 assertEquals("Number of topics is not the same in the select menu and in the table.", topics.length, table.getRowCount() - 1); 312 for (int i = 0; i < topics.length; i++) { 313 assertEquals("Topic " + topics[i] + " is not found in the table. ", topics[i], table.getTableCell(i+1, columnTopics).getText()); 314 } 315 316 columnLevels = utils.getColumn("Levels", table).intValue(); 318 if (columnLevels == -1) { 319 throw new IllegalThreadStateException ("There is no column, which contains 'Levels'. "); 320 } 321 String level = table.getTableCell(topics.length, columnLevels).getText(); 322 String topic = "org.objectweb.jonas.web"; 323 if (level.equals("WARN")) { 324 level = "INFO"; 325 } else if (level.equals("INFO")) { 326 level = "ERROR"; 327 } else if (level.equals("FATAL")) { 328 level = "INHERIT"; 329 } else if (level.equals("INHERIT")) { 330 level = "DEBUG"; 331 } else if (level.equals("DEBUG")) { 332 level = "WARN"; 333 } 334 335 form.setParameter("topic", topic); 336 form.setParameter("level", level); 337 338 button = form.getSubmitButtons()[0]; 339 button.click(); 340 341 wr = wc.getFrameContents(FRAME_CONTENT); 343 table = utils.getTable(wr, 3); 344 if (level.equals("ERROR")) { 345 level = "FATAL"; 346 } 347 row = utils.getFirstRow(topic, table, columnTopics).intValue(); 348 if (row == -1) { 349 throw new IllegalThreadStateException ("There is no row, which contains '" + topic + "' in the topic column. "); 350 } 351 assertEquals("The level of " + topic + " is not " + level + ". ", level, table.getTableCell(row, columnLevels).getText()); 352 } 353 } 354 355 366 private void verifyAccessLogValve(WebResponse wr, String directory, String resolveHosts, 367 String rotatable, String suffix, String prefix, String pattern) throws SAXException { 368 WebForm form = wr.getForms()[0]; 369 assertEquals("Directory value is not" + directory + ". ", directory, form.getParameterValue("directory")); 370 assertEquals("Resolve hosts value is not" + resolveHosts + ". ", resolveHosts, form.getParameterValue("resolveHosts")); 371 assertEquals("Rotatable value is not" + rotatable + ". ", rotatable, form.getParameterValue("rotatable")); 372 assertEquals("Suffix value is not" + suffix + ". ", suffix, form.getParameterValue("suffix")); 373 assertEquals("Prefix value is not" + prefix + ". ", prefix, form.getParameterValue("prefix")); 374 assertEquals("Pattern value is not" + pattern + ". ", pattern, form.getParameterValue("pattern")); 375 } 376 } 377 | Popular Tags |