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.LogViewer.ContextLogSupport; 28 29 33 public class LogViewerTest extends NbTestCase { 34 35 private File datadir; 36 37 public LogViewerTest(String testName) { 38 super(testName); 39 } 40 41 public static NbTestSuite suite() { 42 NbTestSuite suite = new NbTestSuite(); 43 suite.addTest(new LogViewerTest("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 ContextLogSupport sup = new ContextLogSupport("foo", "bar"); 91 for (int i = 0; i < log.length; i++) { 92 LineInfo nfo = sup.analyzeLine(log[i]); 93 assertEquals("Path \"" + nfo.path() + "\" incorrectly recognized from: " + log[i], 94 files[i], nfo.path()); 95 assertEquals("Line \"" + nfo.line() + "\" incorrectly recognized from: " + log[i], 96 lines[i], nfo.line()); 97 assertEquals("Message \"" + nfo.message() + "\" incorrectly recognized from: " + log[i], 98 message[i], nfo.message()); 99 } 100 } 101 102 public static void main(java.lang.String [] args) { 103 TestRunner.run(suite()); 104 } 105 } 106 | Popular Tags |