1 package com.tonbeller.wcf.web; 2 3 import org.xml.sax.SAXException ; 4 5 import com.meterware.httpunit.GetMethodWebRequest; 6 import com.meterware.httpunit.WebForm; 7 import com.meterware.httpunit.WebResponse; 8 import com.meterware.httpunit.WebTable; 9 import com.tonbeller.wcf.log.LogHandler; 10 11 public class LogTest extends HttpUnitTestCase { 12 13 public LogTest(String name) { 14 super(name); 15 } 16 17 public void testForm() throws Exception { 18 wc.sendRequest(new GetMethodWebRequest(servletUrl + "/logdemo.jsp")); 19 20 WebForm wf; 21 22 wf = wc.getCurrentPage().getFormWithID("logform"); 24 wf.setParameter("logConfs", String.valueOf(LogHandler.ERROR_STDOUT.hashCode())); 25 wf.submit(wf.getSubmitButtonWithID("logdemo.ok")); 26 assertLogLevel("ERROR", wc.getCurrentPage()); 27 28 wf = wc.getCurrentPage().getFormWithID("logform"); 30 wf.setParameter("logConfs", String.valueOf(LogHandler.DEBUG_STDOUT.hashCode())); 31 wf.submit(wf.getSubmitButtonWithID("logdemo.ok")); 32 assertLogLevel("DEBUG", wc.getCurrentPage()); 33 34 wf = wc.getCurrentPage().getFormWithID("logform"); 36 wf.setParameter("logConfs", String.valueOf(LogHandler.NOLOG.hashCode())); 37 wf.submit(wf.getSubmitButtonWithID("logdemo.ok")); 38 assertLogLevel("OFF", wc.getCurrentPage()); 39 40 } 41 46 private void assertLogLevel(String ref, WebResponse webResponse) { 47 try { 48 WebTable tab = webResponse.getTables()[0]; 49 assertEquals(ref, tab.getCellAsText(1,1)); 50 } 51 catch (SAXException e) { 52 e.printStackTrace(); 53 fail(e.toString()); 54 } 55 } 56 57 } 58 | Popular Tags |