001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.tomcat5.util;
043:
044: import java.io.File;
045: import junit.textui.TestRunner;
046: import org.netbeans.junit.NbTestCase;
047: import org.netbeans.junit.NbTestSuite;
048: import org.netbeans.modules.tomcat5.util.LogSupport.LineInfo;
049: import org.netbeans.modules.tomcat5.util.LogViewer.ContextLogSupport;
050:
051: /**
052: *
053: * @author sherold
054: */
055: public class LogViewerTest extends NbTestCase {
056:
057: private File datadir;
058:
059: public LogViewerTest(String testName) {
060: super (testName);
061: }
062:
063: public static NbTestSuite suite() {
064: NbTestSuite suite = new NbTestSuite();
065: suite.addTest(new LogViewerTest("testAnalyzeLine"));
066: return suite;
067: }
068:
069: protected void setUp() throws Exception {
070: super .setUp();
071: datadir = getDataDir();
072: }
073:
074: public void testAnalyzeLine() {
075:
076: String log[] = new String[] {
077: "Jan 5, 2006 6:46:45 PM org.apache.catalina.core.StandardWrapperValve invoke",
078: "SEVERE: Servlet.service() for servlet HyperlinkTest threw exception",
079: "java.lang.IllegalStateException",
080: " at t.HyperlinkTest$1.run(HyperlinkTest.java:24)",
081: " at t.HyperlinkTest.processRequest(HyperlinkTest.java:27)",
082: " at foo.bar", };
083:
084: String files[] = new String[] { null, null, null,
085: "t/HyperlinkTest.java", "t/HyperlinkTest.java", null, };
086:
087: int lines[] = new int[] { -1, -1, -1, 24, 27, -1, };
088:
089: String message[] = new String[] { null, null, null,
090: "java.lang.IllegalStateException",
091: "java.lang.IllegalStateException", null, };
092:
093: ContextLogSupport sup = new ContextLogSupport("foo", "bar");
094: for (int i = 0; i < log.length; i++) {
095: LineInfo nfo = sup.analyzeLine(log[i]);
096: assertEquals("Path \"" + nfo.path()
097: + "\" incorrectly recognized from: " + log[i],
098: files[i], nfo.path());
099: assertEquals("Line \"" + nfo.line()
100: + "\" incorrectly recognized from: " + log[i],
101: lines[i], nfo.line());
102: assertEquals("Message \"" + nfo.message()
103: + "\" incorrectly recognized from: " + log[i],
104: message[i], nfo.message());
105: }
106: }
107:
108: public static void main(java.lang.String[] args) {
109: TestRunner.run(suite());
110: }
111: }
|