ExecuteReportContentHandler { public void createReportContent( final OutputStream outputStream, final Serializable fileId, final String path, final boolean forceDefaultOutputTarget ) throws Exception { this.createReportContent( outputStream, fileId, path, forceDefaultOutputTarget, new SimpleReportingComponent(), new AuditWrapper() ); } ExecuteReportContentHandler( final ReportContentGenerator contentGenerator ); void createReportContent( final OutputStream outputStream, final Serializable fileId, final String path,
      final boolean forceDefaultOutputTarget ); void createReportContent( final OutputStream outputStream, final Serializable fileId, final String path,
                                   final boolean forceDefaultOutputTarget,
                                   final SimpleReportingComponent reportComponent,
                                   final AuditWrapper audit ); static final String FORCED_BUFFERED_WRITING; }
@Test public void testSuccessExecutionAudit() throws Exception { final ExecuteReportContentHandler handler = new ExecuteReportContentHandler( contentGenerator ); when( reportComponent.validate() ).thenReturn( true ); when( reportComponent.execute() ).thenReturn( true ); handler.createReportContent( outputStream, fileId, path, true, reportComponent, audit ); verify( audit, times( 1 ) ).audit( eq( sessionId ), eq( sessionName ), eq( path ), eq( ReportContentGenerator.class.getName() ), eq( handler.getClass().getName() ), eq( MessageTypes.INSTANCE_START ), eq( instanceId ), eq( "" ), eq( (float) 0 ), eq( contentGenerator ) ); verify( audit, times( 1 ) ).audit( eq( sessionId ), eq( sessionName ), eq( path ), eq( ReportContentGenerator.class.getName() ), eq( handler.getClass().getName() ), eq( MessageTypes.INSTANCE_END ), eq( instanceId ), eq( "" ), anyFloat(), eq( contentGenerator ) ); }
@Test public void testFailedValidationAudit() throws Exception { final ExecuteReportContentHandler handler = new ExecuteReportContentHandler( contentGenerator ); when( reportComponent.validate() ).thenReturn( false ); when( reportComponent.execute() ) .thenThrow( new Exception( "execution should not be called if valiedation failed" ) ); handler.createReportContent( outputStream, fileId, path, true, reportComponent, audit ); verify( audit, times( 1 ) ).audit( eq( sessionId ), eq( sessionName ), eq( path ), eq( ReportContentGenerator.class.getName() ), eq( handler.getClass().getName() ), eq( MessageTypes.INSTANCE_START ), eq( instanceId ), eq( "" ), eq( (float) 0 ), eq( contentGenerator ) ); verify( audit, times( 1 ) ).audit( eq( sessionId ), eq( sessionName ), eq( path ), eq( ReportContentGenerator.class.getName() ), eq( handler.getClass().getName() ), eq( MessageTypes.FAILED ), eq( instanceId ), eq( "" ), anyFloat(), eq( contentGenerator ) ); }
@Test public void testFailedExecutionAudit() throws Exception { final ExecuteReportContentHandler handler = new ExecuteReportContentHandler( contentGenerator ); when( reportComponent.validate() ).thenReturn( true ); when( reportComponent.execute() ).thenReturn( false ); handler.createReportContent( outputStream, fileId, path, true, reportComponent, audit ); verify( audit, times( 1 ) ).audit( eq( sessionId ), eq( sessionName ), eq( path ), eq( ReportContentGenerator.class.getName() ), eq( handler.getClass().getName() ), eq( MessageTypes.INSTANCE_START ), eq( instanceId ), eq( "" ), eq( (float) 0 ), eq( contentGenerator ) ); verify( audit, times( 1 ) ).audit( eq( sessionId ), eq( sessionName ), eq( path ), eq( ReportContentGenerator.class.getName() ), eq( handler.getClass().getName() ), eq( MessageTypes.FAILED ), eq( instanceId ), eq( "" ), anyFloat(), eq( contentGenerator ) ); }
@Test public void testCreateReportContentReportComponent1() throws Exception { final ExecuteReportContentHandler handler = new ExecuteReportContentHandler( contentGenerator ); when( reportComponent.validate() ).thenReturn( true ); when( reportComponent.execute() ).thenReturn( true ); when( reportComponent.getComputedOutputTarget() ).thenReturn( HtmlTableModule.TABLE_HTML_PAGE_EXPORT_TYPE ); inputs.remove( ParameterXmlContentHandler.SYS_PARAM_SESSION_ID ); boolean force = false; handler.createReportContent( outputStream, fileId, path, force, reportComponent, audit ); assertNotNull( "always have sys param session Id set.", inputs.get( ParameterXmlContentHandler.SYS_PARAM_SESSION_ID ) ); verify( reportComponent, times( 1 ) ).setReportFileId( eq( fileId ) ); verify( reportComponent, times( 1 ) ).setPaginateOutput( eq( true ) ); verify( reportComponent, times( 1 ) ).setForceDefaultOutputTarget( force ); verify( reportComponent, times( 0 ) ).setForceUnlockPreferredOutput( anyBoolean() ); verify( reportComponent, times( 1 ) ).setInputs( eq( inputs ) ); verify( reportComponent, times( 1 ) ).getReport(); verify( reportComponent, times( 1 ) ).setOutputStream( any( OutputStream.class ) ); verify( reportComponent, times( 1 ) ).getMimeType(); }
@Test public void setSuccessHeadersTest() throws Exception { final ExecuteReportContentHandler handler = new ExecuteReportContentHandler( contentGenerator ); when( reportComponent.validate() ).thenReturn( true ); when( reportComponent.execute() ).thenReturn( true ); handler.createReportContent( outputStream, fileId, path, true, reportComponent, audit ); verify( response, times( 1 ) ) .setHeader( eq( "Content-Disposition" ), eq( "inline; filename*=UTF-8''%3AsomeFile.html" ) ); verify( response, times( 1 ) ).setHeader( eq( "Content-Description" ), eq( fileName ) ); verify( response, times( 1 ) ).setHeader( eq( "Cache-Control" ), eq( "private, max-age=0, must-revalidate" ) ); verify( response, times( 1 ) ).setContentLength( anyInt() ); verify( outputStream, times( 0 ) ).flush(); verify( outputStream, times( 0 ) ).close(); }
@Test public void setFailedHeadersTest() throws Exception { final ExecuteReportContentHandler handler = new ExecuteReportContentHandler( contentGenerator ); when( reportComponent.validate() ).thenReturn( true ); when( reportComponent.execute() ).thenReturn( false ); handler.createReportContent( outputStream, fileId, path, true, reportComponent, audit ); verify( response, times( 1 ) ) .setHeader( eq( "Content-Disposition" ), eq( "inline; filename*=UTF-8''%3AsomeFile.html" ) ); verify( response, times( 1 ) ).setHeader( eq( "Content-Description" ), eq( fileName ) ); verify( response, times( 1 ) ).setHeader( eq( "Cache-Control" ), eq( "private, max-age=0, must-revalidate" ) ); verify( response, times( 1 ) ).setStatus( eq( HttpServletResponse.SC_INTERNAL_SERVER_ERROR ) ); verify( outputStream, times( 1 ) ) .write( Messages.getInstance().getString( "ReportPlugin.ReportValidationFailed" ).getBytes() ); verify( outputStream, times( 1 ) ).flush(); verify( outputStream, times( 0 ) ).close(); }