KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tomcat5 > util > ServerLogTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tomcat5.util;
21
22 import java.io.File JavaDoc;
23 import junit.textui.TestRunner;
24 import org.netbeans.junit.NbTestCase;
25 import org.netbeans.junit.NbTestSuite;
26 import org.netbeans.modules.tomcat5.util.LogSupport.LineInfo;
27 import org.netbeans.modules.tomcat5.util.ServerLog.ServerLogSupport;
28
29 /**
30  *
31  * @author sherold
32  */

33 public class ServerLogTest extends NbTestCase {
34     
35     private File JavaDoc datadir;
36     
37     public ServerLogTest(String JavaDoc testName) {
38         super(testName);
39     }
40     
41     public static NbTestSuite suite() {
42         NbTestSuite suite = new NbTestSuite();
43         suite.addTest(new ServerLogTest("testAnalyzeLine"));
44         return suite;
45     }
46     
47     protected void setUp() throws Exception JavaDoc {
48         super.setUp ();
49         datadir = getDataDir();
50     }
51     
52     public void testAnalyzeLine() {
53         
54         String JavaDoc log[] = new String JavaDoc[] {
55             "Jan 5, 2006 6:46:45 PM org.apache.catalina.core.StandardWrapperValve invoke",
56             "SEVERE: Servlet.service() for servlet HyperlinkTest threw exception",
57             "java.lang.IllegalStateException",
58             " at t.HyperlinkTest$1.run(HyperlinkTest.java:24)",
59             " at t.HyperlinkTest.processRequest(HyperlinkTest.java:27)",
60             " at foo.bar",
61         };
62         
63         String JavaDoc files[] = new String JavaDoc[] {
64             null,
65             null,
66             null,
67             "t/HyperlinkTest.java",
68             "t/HyperlinkTest.java",
69             null,
70         };
71         
72         int lines[] = new int[] {
73             -1,
74             -1,
75             -1,
76             24,
77             27,
78             -1,
79         };
80         
81         String JavaDoc message[] = new String JavaDoc[] {
82             null,
83             null,
84             null,
85             "java.lang.IllegalStateException",
86             "java.lang.IllegalStateException",
87             null,
88         };
89         
90         ServerLogSupport sup = new ServerLogSupport();
91         for (int i = 0; i < log.length; i++) {
92             LineInfo nfo = sup.analyzeLine(log[i]);
93             System.out.println(nfo);
94             assertEquals("Path \"" + nfo.path() + "\" incorrectly recognized from: " + log[i],
95                          files[i], nfo.path());
96             assertEquals("Line \"" + nfo.line() + "\" incorrectly recognized from: " + log[i],
97                          lines[i], nfo.line());
98             assertEquals("Message \"" + nfo.message() + "\" incorrectly recognized from: " + log[i],
99                          message[i], nfo.message());
100         }
101     }
102     
103     public static void main(java.lang.String JavaDoc[] args) {
104         TestRunner.run(suite());
105     }
106 }
107
Popular Tags