PageableHTMLOutput extends AbstractHtmlOutput { public int paginate( final MasterReport report, final int yieldRate ) throws ReportProcessingException, IOException, ContentIOException { if ( proc == null ) { proc = createReportProcessor( report, yieldRate ); } reinitOutputTarget(); try { if ( proc.isPaginated() == false ) { proc.paginate(); } } finally { printer.setContentWriter( null, null ); printer.setDataWriter( null, null ); } return proc.getLogicalPageCount(); } PageableHTMLOutput(); Object getReportLock(); ProxyOutputStream getProxyOutputStream(); void setProxyOutputStream( final ProxyOutputStream proxyOutputStream ); HtmlPrinter getPrinter(); void setPrinter( final AllItemsHtmlPrinter printer ); PageableReportProcessor getReportProcessor(); void setReportProcessor( final PageableReportProcessor proc ); 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 testPaginate() throws Exception { PageableHTMLOutput output = mock( PageableHTMLOutput.class, CALLS_REAL_METHODS ); PageableReportProcessor processor = mock( PageableReportProcessor.class ); doNothing().when( output ).reinitOutputTarget(); doReturn( true ).when( processor ).isPaginated(); MasterReport report = mock( MasterReport.class ); AllItemsHtmlPrinter printer = mock( AllItemsHtmlPrinter.class ); doNothing().when( printer ).setContentWriter( null, null ); doNothing().when( printer ).setDataWriter( null, null ); output.setReportProcessor( processor ); output.setPrinter( printer ); Assert.assertEquals( 0, output.paginate( report, 0 ) ); doReturn( false ).when( processor ).isPaginated(); output.setReportProcessor( processor ); Assert.assertEquals( 0, output.paginate( report, 0 ) ); }
@Test public void testPaginateInCache() throws PlatformInitializationException, ContentIOException, ReportProcessingException, IOException, ResourceException { ClassicEngineBoot.getInstance().start(); MicroPlatform microPlatform = MicroPlatformFactory.create(); try { microPlatform.define( ReportOutputHandlerFactory.class, FastExportReportOutputHandlerFactory.class ); final IReportContentCache mockCache = mock( IReportContentCache.class ); final IReportContent iReportContent = mock( IReportContent.class ); final int value = new Random().nextInt(); when( iReportContent.getPageCount() ).thenReturn( value ); final String key = "test"; when( mockCache.get( key ) ).thenReturn( iReportContent ); final IPluginCacheManager iPluginCacheManager = new PluginCacheManagerImpl( mockCache ); microPlatform.define( "IPluginCacheManager", iPluginCacheManager ); microPlatform.start(); final IPentahoSession session = new StandaloneSession(); PentahoSessionHolder.setSession( session ); final CachingPageableHTMLOutput cachingPageableHTMLOutput = spy( new CachingPageableHTMLOutput() ); final ResourceManager mgr = new ResourceManager(); final File src = new File( "target/test/resource/solution/test/reporting/report.prpt" ); final MasterReport r = (MasterReport) mgr.createDirectly( src, MasterReport.class ).getResource(); r.setContentCacheKey( key ); assertEquals( value, cachingPageableHTMLOutput.paginate( r, 1 ) ); } finally { microPlatform.stop(); microPlatform = null; } }