1 19 20 package org.netbeans.modules.tomcat5.util; 21 22 import java.io.File ; 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 33 public class ServerLogTest extends NbTestCase { 34 35 private File datadir; 36 37 public ServerLogTest(String 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 { 48 super.setUp (); 49 datadir = getDataDir(); 50 } 51 52 public void testAnalyzeLine() { 53 54 String log[] = new String [] { 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 files[] = new String [] { 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 message[] = new String [] { 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 [] args) { 104 TestRunner.run(suite()); 105 } 106 } 107 | Popular Tags |