001: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal;
007:
008: import junit.framework.TestCase;
009:
010: /**
011: * Testcase for ExceptionHelper.
012: * @author andrew.petro@yale.edu
013: * @version $Revision: 34862 $ $Date: 2004-10-26 10:26:06 -0700 (Tue, 26 Oct 2004) $
014: */
015: public class ExceptionHelperTest extends TestCase {
016:
017: /**
018: * A trace which requires no trimming.
019: */
020: private String reallyBasicTrace = "Programming error\n"
021: + " org.jasig.portal.PortalException: java.lang.RuntimeException: java.lang.NullPointerException [based on exception: java.lang.NullPointerException]\n"
022: + " at org.jasig.portal.UserInstance.renderState(UserInstance.java:600)\n"
023: + " at org.jasig.portal.UserInstance.writeContent(UserInstance.java:174)\n"
024: + " at org.jasig.portal.PortalSessionManager.doGet(PortalSessionManager.java:234)\n";
025:
026: /**
027: * An example raw stack trace which has only one throwable.
028: */
029: private String basicTrace = "Programming error\n"
030: + " org.jasig.portal.PortalException: java.lang.RuntimeException: java.lang.NullPointerException [based on exception: java.lang.NullPointerException]\n"
031: + " at org.jasig.portal.UserInstance.renderState(UserInstance.java:600)\n"
032: + " at org.jasig.portal.UserInstance.writeContent(UserInstance.java:174)\n"
033: + " at org.jasig.portal.PortalSessionManager.doGet(PortalSessionManager.java:234)\n"
034: + " at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)\n"
035: + " at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)\n"
036: + " at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)\n"
037: + " at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)\n"
038: + " at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)\n"
039: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
040: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
041: + " at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)\n"
042: + " at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)\n"
043: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
044: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
045: + " at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)\n"
046: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
047: + " at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)\n"
048: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)\n"
049: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
050: + " at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)\n"
051: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
052: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
053: + " at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)\n"
054: + " at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)\n"
055: + " at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)\n"
056: + " at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)\n"
057: + " at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)\n"
058: + " at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)\n"
059: + " at java.lang.Thread.run(Thread.java:534)\n";
060:
061: /**
062: * Excpected result of trimming the basic trace.
063: */
064: private String basicTraceTrimmed = "Programming error\n"
065: + " org.jasig.portal.PortalException: java.lang.RuntimeException: java.lang.NullPointerException [based on exception: java.lang.NullPointerException]\n"
066: + " at org.jasig.portal.UserInstance.renderState(UserInstance.java:600)\n"
067: + " at org.jasig.portal.UserInstance.writeContent(UserInstance.java:174)\n"
068: + " at org.jasig.portal.PortalSessionManager.doGet(PortalSessionManager.java:234)\n";
069:
070: /**
071: * An example raw stack trace which has two throwables in the chain and
072: * only the first throwable need be trimmed.
073: */
074: private String rawCauseTrace = "Programming error\n"
075: + " org.jasig.portal.PortalException: java.lang.RuntimeException: java.lang.NullPointerException [based on exception: java.lang.NullPointerException]\n"
076: + " at org.jasig.portal.UserInstance.renderState(UserInstance.java:600)\n"
077: + " at org.jasig.portal.UserInstance.writeContent(UserInstance.java:174)\n"
078: + " at org.jasig.portal.PortalSessionManager.doGet(PortalSessionManager.java:234)\n"
079: + " at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)\n"
080: + " at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)\n"
081: + " at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)\n"
082: + " at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)\n"
083: + " at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)\n"
084: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
085: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
086: + " at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)\n"
087: + " at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)\n"
088: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
089: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
090: + " at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)\n"
091: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
092: + " at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)\n"
093: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)\n"
094: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
095: + " at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)\n"
096: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
097: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
098: + " at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)\n"
099: + " at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)\n"
100: + " at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)\n"
101: + " at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)\n"
102: + " at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)\n"
103: + " at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)\n"
104: + " at java.lang.Thread.run(Thread.java:534)\n"
105: + "Caused by: java.lang.RuntimeException: java.lang.NullPointerException\n"
106: + " at org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:3407)\n"
107: + " at org.apache.xalan.transformer.TransformerHandlerImpl.endDocument(TransformerHandlerImpl.java:433)\n"
108: + " at org.jasig.portal.utils.SAX2FilterImpl.endDocument(SAX2FilterImpl.java:654)\n"
109: + " at org.jasig.portal.utils.SAX2BufferImpl.outputBuffer(SAX2BufferImpl.java:181)\n"
110: + " at org.jasig.portal.UserInstance.renderState(UserInstance.java:557)\n";
111:
112: private String trimmedCauseStackTrace = "Programming error\n"
113: + " org.jasig.portal.PortalException: java.lang.RuntimeException: java.lang.NullPointerException [based on exception: java.lang.NullPointerException]\n"
114: + " at org.jasig.portal.UserInstance.renderState(UserInstance.java:600)\n"
115: + " at org.jasig.portal.UserInstance.writeContent(UserInstance.java:174)\n"
116: + " at org.jasig.portal.PortalSessionManager.doGet(PortalSessionManager.java:234)\n"
117: + "Caused by: java.lang.RuntimeException: java.lang.NullPointerException\n"
118: + " at org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:3407)\n"
119: + " at org.apache.xalan.transformer.TransformerHandlerImpl.endDocument(TransformerHandlerImpl.java:433)\n"
120: + " at org.jasig.portal.utils.SAX2FilterImpl.endDocument(SAX2FilterImpl.java:654)\n"
121: + " at org.jasig.portal.utils.SAX2BufferImpl.outputBuffer(SAX2BufferImpl.java:181)\n"
122: + " at org.jasig.portal.UserInstance.renderState(UserInstance.java:557)\n";
123:
124: /**
125: * An example raw stack trace which has two throwables in the chain and
126: * both need to be trimmed
127: */
128: private String complexCauseTrace = "Programming error\n"
129: + " org.jasig.portal.PortalException: java.lang.RuntimeException: java.lang.NullPointerException [based on exception: java.lang.NullPointerException]\n"
130: + " at org.jasig.portal.UserInstance.renderState(UserInstance.java:600)\n"
131: + " at org.jasig.portal.UserInstance.writeContent(UserInstance.java:174)\n"
132: + " at org.jasig.portal.PortalSessionManager.doGet(PortalSessionManager.java:234)\n"
133: + " at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)\n"
134: + " at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)\n"
135: + " at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)\n"
136: + " at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)\n"
137: + " at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)\n"
138: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
139: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
140: + " at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)\n"
141: + " at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)\n"
142: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
143: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
144: + " at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)\n"
145: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
146: + " at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)\n"
147: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)\n"
148: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
149: + " at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)\n"
150: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
151: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
152: + " at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)\n"
153: + " at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)\n"
154: + " at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)\n"
155: + " at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)\n"
156: + " at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)\n"
157: + " at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)\n"
158: + " at java.lang.Thread.run(Thread.java:534)\n"
159: + "Caused by: java.lang.RuntimeException: java.lang.NullPointerException\n"
160: + " at org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:3407)\n"
161: + " at org.apache.xalan.transformer.TransformerHandlerImpl.endDocument(TransformerHandlerImpl.java:433)\n"
162: + " at org.jasig.portal.utils.SAX2FilterImpl.endDocument(SAX2FilterImpl.java:654)\n"
163: + " at org.jasig.portal.utils.SAX2BufferImpl.outputBuffer(SAX2BufferImpl.java:181)\n"
164: + " at org.jasig.portal.UserInstance.renderState(UserInstance.java:557)\n"
165: + " at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)\n"
166: + " at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)\n"
167: + " at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)\n"
168: + " at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)\n"
169: + " at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)\n"
170: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
171: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
172: + " at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)\n"
173: + " at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)\n"
174: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
175: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
176: + " at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)\n"
177: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)\n"
178: + " at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)\n"
179: + " at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)\n"
180: + " at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)\n"
181: + " at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)\n";
182:
183: /**
184: * Test ability to refrain from trimming stack trace where
185: * no trimming is necessary.
186: */
187: public void testNoTrim() {
188: assertEquals(this .reallyBasicTrace, ExceptionHelper
189: .trimStackTrace(this .reallyBasicTrace));
190: }
191:
192: /**
193: * Test ability to trim a basic stack trace.
194: */
195: public void testTrimStackTrace() {
196: assertEquals(this .basicTraceTrimmed, ExceptionHelper
197: .trimStackTrace(this .basicTrace));
198: }
199:
200: /**
201: * Test that a Cause after trimming is maintained.
202: */
203: public void testCauseTrace() {
204: assertEquals(this .trimmedCauseStackTrace, ExceptionHelper
205: .trimStackTrace(this .rawCauseTrace));
206: }
207:
208: /**
209: * Test that causes are also properly trimmed.
210: */
211: public void testTrimCauseTrace() {
212: assertEquals(this.trimmedCauseStackTrace, ExceptionHelper
213: .trimStackTrace(this.complexCauseTrace));
214: }
215:
216: }
|