MessageFormatter implements IMessageFormatter { public void formatExceptionMessage( String mimeType, ActionSequenceException exception, StringBuffer messageBuffer ) { formatExceptionMessage( mimeType, exception, messageBuffer, false ); }  void formatErrorMessage( final String mimeType, final String title, final String message,
      final StringBuffer messageBuffer ); String getFirstError( final List messages ); void formatErrorMessage( final String mimeType, final String title, final List messages,
      final StringBuffer messageBuffer ); void formatFailureMessage( final String mimeType, final IRuntimeContext context,
      final StringBuffer messageBuffer, final List defaultMessages ); @Override void formatFailureMessage( final String mimeType, final IRuntimeContext context,
      final StringBuffer messageBuffer, final List defaultMessages, final boolean showStacktrace ); void formatExceptionMessage( String mimeType, ActionSequenceException exception, StringBuffer messageBuffer ); void formatExceptionMessage( String mimeType, ActionSequenceException exception, StringBuffer messageBuffer,
      boolean showStacktrace ); void formatFailureMessage( final String mimeType, final IRuntimeContext context,
      final StringBuffer messageBuffer ); @SuppressWarnings( { "deprecation", "null" } ) void formatResultSetAsHTMLRows( final IPentahoResultSet resultSet, final StringBuffer messageBuffer ); void formatSuccessMessage( final String mimeType, final IRuntimeContext context,
      final StringBuffer messageBuffer, final boolean doMessages ); @SuppressWarnings( { "deprecation", "null" } ) void formatSuccessMessage( final String mimeType, final IRuntimeContext context,
      final StringBuffer messageBuffer, final boolean doMessages, final boolean doWrapper ); static final String HTML_MIME_TYPE; static final String TEXT_MIME_TYPE; static final int MAX_RESULT_THRESHOLD; }
@Test public void shouldAddStacktraceWhenShowStacktraceIsTrue() throws Exception { MessageFormatter mf = new MessageFormatter() { @Override String getTemplate( StringBuffer messageBuffer ) { try { return IOUtils.toString( this.getClass() .getResourceAsStream( "viewActionErrorTestTemplate.html" ), "UTF-8" ); } catch ( IOException e ) { return null; } } @Override String getStacktrace( ActionSequenceException exception ) { return "Error stacktrace"; } }; StringBuffer messageBuffer = new StringBuffer(); mf.formatExceptionMessage( MessageFormatter.HTML_MIME_TYPE, new ActionValidationException( "Test Error" ), messageBuffer, true ); assertEquals( "<div id=\"controls\">" + "<a href=\"#\" id=\"details-show\" class=\"showLink\" onclick=\"showHide('details');return false;\">View " + "Details</a>" + "<a href=\"#\" id=\"details-hide\" class=\"hideLink\" onclick=\"showHide('details');return false;\">Hide " + "Details</a>" + "</div>" + "<div id=\"details\" class=\"details\"><span class=\"label\">Stack Trace:</span><pre " + "class=\"stackTrace\">Error stacktrace<pre></div>", messageBuffer.toString() ); }
@Test public void shouldNotAddStacktraceWhenShowStacktraceIsFalse() throws Exception { MessageFormatter mf = new MessageFormatter() { @Override String getTemplate( StringBuffer messageBuffer ) { try { return IOUtils.toString( this.getClass() .getResourceAsStream( "viewActionErrorTestTemplate.html" ), "UTF-8" ); } catch ( IOException e ) { return null; } } }; StringBuffer messageBuffer = new StringBuffer(); mf.formatExceptionMessage( MessageFormatter.HTML_MIME_TYPE, new ActionValidationException( "Test Error" ), messageBuffer, false ); assertEquals( "<div id=\"controls\" hidden>" + "<a href=\"#\" id=\"details-show\" class=\"showLink\" onclick=\"showHide('details');return false;\">View " + "Details</a>" + "<a href=\"#\" id=\"details-hide\" class=\"hideLink\" onclick=\"showHide('details');return false;\">Hide " + "Details</a>" + "</div>" + "<div id=\"details\" class=\"details\"><span class=\"label\">%STACK_TRACE_LABEL%</span><pre " + "class=\"stackTrace\">%STACK_TRACE%<pre></div>", messageBuffer.toString() ); }