KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > web > LogTest


1 package com.tonbeller.wcf.web;
2
3 import org.xml.sax.SAXException JavaDoc;
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 JavaDoc name) {
14     super(name);
15   }
16
17   public void testForm() throws Exception JavaDoc {
18     wc.sendRequest(new GetMethodWebRequest(servletUrl + "/logdemo.jsp"));
19
20     WebForm wf;
21     
22     // Logging fuer Errors aktivieren
23
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     // Logging fuer alle Meldungen
29
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     // Logging abschalten
35
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   /**
42    * Method assertLogLevel.
43    * @param ref
44    * @param webResponse
45    */

46   private void assertLogLevel(String JavaDoc ref, WebResponse webResponse) {
47     try {
48       WebTable tab = webResponse.getTables()[0];
49       assertEquals(ref, tab.getCellAsText(1,1));
50     }
51     catch (SAXException JavaDoc e) {
52       e.printStackTrace();
53       fail(e.toString());
54     }
55   }
56
57 }
58
Popular Tags