EmailOutput implements ReportOutputHandler { public int generate( final MasterReport report, final int acceptedPage, final OutputStream outputStream, final int yieldRate ) throws ReportProcessingException, IOException, ContentIOException { final IApplicationContext ctx = PentahoSystem.getApplicationContext(); if ( ctx == null ) { return -1; } try { final Configuration configuration = report.getConfiguration(); if ( configuration instanceof ModifiableConfiguration ) { final ModifiableConfiguration modifiableConfiguration = (ModifiableConfiguration) configuration; modifiableConfiguration.setConfigProperty( HtmlTableModule.INLINE_STYLE, "true" ); modifiableConfiguration.setConfigProperty( HtmlTableModule.EXTERNALIZE_STYLE, "false" ); modifiableConfiguration.setConfigProperty( ROTATED_TEXT_AS_IMAGES, "true" ); } final Properties props = new Properties(); final Session session = Session.getInstance( props ); final EmailRepository dataRepository = new EmailRepository( session ); final ContentLocation dataLocation = dataRepository.getRoot(); final HtmlOutputProcessor outputProcessor = new StreamHtmlOutputProcessor( configuration ); final HtmlPrinter printer = new AllItemsHtmlPrinter( report.getResourceManager() ); printer.setContentWriter( dataLocation, new DefaultNameGenerator( dataLocation, "index", "html" ) ); printer.setDataWriter( dataLocation, new DefaultNameGenerator( dataLocation ) ); printer.setUrlRewriter( new MailURLRewriter() ); outputProcessor.setPrinter( printer ); final StreamReportProcessor sp = new StreamReportProcessor( report, outputProcessor ); if ( yieldRate > 0 ) { sp.addReportProgressListener( getYieldListener( yieldRate ) ); } final IAsyncReportListener listener = ReportListenerThreadHolder.getListener(); doProcess( listener, sp ); dataRepository.writeEmail( outputStream ); outputStream.flush(); return 0; } catch ( final MessagingException e ) { throw new ReportProcessingException( "Error", e ); } } EmailOutput(); Object getReportLock(); int paginate( final MasterReport report, final int yieldRate ); int generate( final MasterReport report, final int acceptedPage, final OutputStream outputStream,
                       final int yieldRate ); boolean supportsPagination(); void close();  }
@Test public void testGenerateListener() throws Exception { MicroPlatform microPlatform = MicroPlatformFactory.create(); microPlatform.start(); ClassicEngineBoot.getInstance().start(); try { emailOutput.generate( new MasterReport(), 1, new ByteArrayOutputStream(), 1 ); verify( listener, times( 1 ) ).reportProcessingStarted( any( ReportProgressEvent.class ) ); verify( listener, times( 1 ) ).reportProcessingFinished( any( ReportProgressEvent.class ) ); verify( listener, atLeastOnce() ).reportProcessingUpdate( any( ReportProgressEvent.class ) ); } finally { microPlatform.stop(); microPlatform = null; } }
@Test public void testGenerate() throws Exception { MicroPlatform microPlatform = MicroPlatformFactory.create(); microPlatform.start(); ClassicEngineBoot.getInstance().start(); ReportListenerThreadHolder.clear(); try { emailOutput.generate( new MasterReport(), 1, new ByteArrayOutputStream(), 1 ); verify( listener, times( 0 ) ).reportProcessingStarted( any( ReportProgressEvent.class ) ); verify( listener, times( 0 ) ).reportProcessingFinished( any( ReportProgressEvent.class ) ); verify( listener, times( 0 ) ).reportProcessingUpdate( any( ReportProgressEvent.class ) ); verify( yieldReportListener, atLeast( 1 ) ).reportProcessingUpdate( any( ReportProgressEvent.class ) ); } finally { microPlatform.stop(); microPlatform = null; } }
@Test public void testInlineStyles() throws PlatformInitializationException { final Map<Object, Object> configMap = new HashMap<>(); final MasterReport report = mock( MasterReport.class ); final ModifiableConfiguration configuration = mock( ModifiableConfiguration.class ); doAnswer( i -> configMap.put( i.getArguments()[ 0 ], i.getArguments()[ 1 ] ) ).when( configuration ) .setConfigProperty( any(), any() ); when( report.getConfiguration() ).thenReturn( configuration ); MicroPlatform microPlatform = MicroPlatformFactory.create(); microPlatform.start(); ClassicEngineBoot.getInstance().start(); ReportListenerThreadHolder.clear(); try { emailOutput.generate( report, 1, new ByteArrayOutputStream(), 1 ); } catch ( final Exception ignored ) { } finally { assertEquals( configMap.get( HtmlTableModule.INLINE_STYLE ), "true" ); assertEquals( configMap.get( HtmlTableModule.EXTERNALIZE_STYLE ), "false" ); assertEquals( configMap.get( "org.pentaho.reporting.engine.classic.core.modules.output.table.html.RotatedTextAsImages" ), "true" ); microPlatform.stop(); microPlatform = null; } }
@Test public void testGenerateNoContext() throws Exception { MicroPlatform microPlatform = MicroPlatformFactory.create(); try { microPlatform.start(); ClassicEngineBoot.getInstance().start(); PentahoSystem.setApplicationContext( null ); assertEquals( -1, emailOutput.generate( new MasterReport(), 1, new ByteArrayOutputStream(), 1 ) ); } finally { microPlatform.stop(); microPlatform = null; } }
@Test public void testGenerateYield0() throws Exception { MicroPlatform microPlatform = MicroPlatformFactory.create(); microPlatform.start(); ClassicEngineBoot.getInstance().start(); ReportListenerThreadHolder.clear(); try { emailOutput.generate( new MasterReport(), 1, new ByteArrayOutputStream(), 0 ); verify( listener, times( 0 ) ).reportProcessingStarted( any( ReportProgressEvent.class ) ); verify( listener, times( 0 ) ).reportProcessingFinished( any( ReportProgressEvent.class ) ); verify( listener, times( 0 ) ).reportProcessingUpdate( any( ReportProgressEvent.class ) ); verifyZeroInteractions( yieldReportListener ); } finally { microPlatform.stop(); microPlatform = null; } }