@Test
  public void testCanvasWithPrePostPad() throws Exception {
    final MasterReport report = new MasterReport();
    report.setDataFactory(new TableDataFactory("query", new DefaultTableModel(10, 1)));
    report.setQuery("query");

    final Band table = TableTestUtil.createTable(1, 1, 6, new CustomProducer());
    table.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 200f);
    table.getStyle().setStyleProperty(ElementStyleKeys.POS_X, 100f);
    table.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, 10f);
    table.setName("table");
    report.getReportHeader().addElement(TableTestUtil.createDataItem("Pre-Padding", 100, 10));
    report.getReportHeader().addElement(table);

    Element postPaddingItem = TableTestUtil.createDataItem("Post-Padding", 100, 10);
    postPaddingItem.getStyle().setStyleProperty(ElementStyleKeys.POS_X, 300f);
    report.getReportHeader().addElement(postPaddingItem);
    report.getReportHeader().setLayout("canvas");

    PdfReportUtil.createPDF(report, "test-output/PRD-3857-output-canvas.pdf");

    List<LogicalPageBox> pages = DebugReportRunner.layoutPages(report, 0, 1, 2);
    assertPageValid(pages, 0, StrictGeomUtility.toInternalValue(10));
    assertPageValid(pages, 1);
    assertPageValid(pages, 2);
  }
  @Test
  public void testRunSimpleReport() throws Exception {
    final MasterReport report = new MasterReport();
    report.setDataFactory(new TableDataFactory("query", new DefaultTableModel(10, 1)));
    report.setQuery("query");

    final Band table = TableTestUtil.createTable(1, 1, 6, true);
    table.setName("table");
    report.getReportHeader().addElement(table);
    report.getReportHeader().setLayout("block");

    List<LogicalPageBox> pages = DebugReportRunner.layoutPages(report, 0, 1, 2);
    assertPageValid(pages, 0);
    assertPageValid(pages, 1);
    assertPageValid(pages, 2);
  }
  public void testWrite() throws Exception {
    final JndiConnectionProvider dummy = new JndiConnectionProvider();
    dummy.setConnectionPath("Dummy");
    final SQLReportDataFactory df = new SQLReportDataFactory(dummy);
    df.setGlobalScript("GlobalScript");
    df.setGlobalScriptLanguage("GlobalScriptLanguage");
    df.setQuery("QueryName", "QueryText", "ScriptLanguage", "Script");
    final MasterReport report = new MasterReport();
    report.setDataFactory(df);

    final MasterReport masterReport = postProcess(report);
    final SQLReportDataFactory dataFactory = (SQLReportDataFactory) masterReport.getDataFactory();
    assertEquals("QueryName", dataFactory.getQueryNames()[0]);
    assertEquals("QueryText", dataFactory.getQuery("QueryName"));
    assertEquals("ScriptLanguage", dataFactory.getScriptingLanguage("QueryName"));
    assertEquals("Script", dataFactory.getScript("QueryName"));
    assertEquals("GlobalScript", dataFactory.getGlobalScript());
    assertEquals("GlobalScriptLanguage", dataFactory.getGlobalScriptLanguage());
  }
 /**
  * Creates a new demo application.
  *
  * @param filename the output filename.
  * @throws ParseException if the report could not be parsed.
  */
 public StraightToEverything(final String filename) throws ParseException {
   final URL in =
       ObjectUtilities.getResource(
           "org/pentaho/reporting/engine/classic/demo/opensource/opensource.xml",
           StraightToEverything.class);
   final MasterReport report = parseReport(in);
   final TableModel data = new OpenSourceProjects();
   report.setDataFactory(new TableDataFactory("default", data));
   try {
     createPDF(report, filename + ".pdf");
     createCSV(report, filename + ".csv");
     createDirectoryHTML(report, filename + ".html");
     createPlainText(report, filename + ".txt");
     createRTF(report, filename + ".rtf");
     createStreamHTML(report, filename + "-single-file.html");
     createXLS(report, filename + ".xls");
     createZIPHTML(report, filename + ".zip");
   } catch (Exception e) {
     logger.error("Failed to write report", e);
   }
 }
  @Test
  public void testBlockWithPrePostPad() throws Exception {
    final MasterReport report = new MasterReport();
    report.setDataFactory(new TableDataFactory("query", new DefaultTableModel(10, 1)));
    report.setQuery("query");

    final Band table = TableTestUtil.createTable(1, 1, 6, true);
    table.setName("table");
    report.getReportHeader().addElement(TableTestUtil.createDataItem("Pre-Padding", 100, 10));
    report.getReportHeader().addElement(table);
    report.getReportHeader().addElement(TableTestUtil.createDataItem("Post-Padding", 100, 10));
    report.getReportHeader().setLayout("block");

    PdfReportUtil.createPDF(report, "test-output/PRD-3857-output-block.pdf");

    List<LogicalPageBox> pages = DebugReportRunner.layoutPages(report, 0, 1, 2);
    assertPageValid(pages, 0, StrictGeomUtility.toInternalValue(10));
    assertPageValid(pages, 1);
    assertPageValid(pages, 2);
    //    assertPageValid(report, 3);
    //    assertPageValid(report, 4);
  }
  /**
   * The starting point for the application.
   *
   * @param args ignored.
   */
  public static void main(final String[] args) {
    ClassicEngineBoot.getInstance().start();
    final ReportGenerator gen = ReportGenerator.getInstance();
    final URL reportURL =
        ObjectUtilities.getResourceRelative(REFERENCE_REPORT, StyleKeyReferenceGenerator.class);
    if (reportURL == null) {
      System.err.println("The report was not found in the classpath"); // $NON-NLS-1$
      System.err.println("File: " + REFERENCE_REPORT); // $NON-NLS-1$
      System.exit(1);
      return;
    }

    final MasterReport report;
    try {
      report = gen.parseReport(reportURL);
    } catch (Exception e) {
      System.err.println("The report could not be parsed."); // $NON-NLS-1$
      System.err.println("File: " + REFERENCE_REPORT); // $NON-NLS-1$
      e.printStackTrace(System.err);
      System.exit(1);
      return;
    }
    report.setDataFactory(new TableDataFactory("default", createData())); // $NON-NLS-1$
    try {
      HtmlReportUtil.createStreamHTML(
          report,
          System.getProperty("user.home") // $NON-NLS-1$
              + "/stylekey-reference.html"); //$NON-NLS-1$
      PdfReportUtil.createPDF(
          report,
          System.getProperty("user.home") // $NON-NLS-1$
              + "/stylekey-reference.pdf"); //$NON-NLS-1$
    } catch (Exception e) {
      System.err.println("The report processing failed."); // $NON-NLS-1$
      System.err.println("File: " + REFERENCE_REPORT); // $NON-NLS-1$
      e.printStackTrace(System.err);
      System.exit(1);
    }
  }
  @Test
  public void testRowWithPrePostPad() throws Exception {
    final MasterReport report = new MasterReport();
    report.setDataFactory(new TableDataFactory("query", new DefaultTableModel(10, 1)));
    report.setQuery("query");

    final Band table = TableTestUtil.createTable(1, 1, 6, true);
    table.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 200f);
    table.setName("table");
    report.getReportHeader().addElement(TableTestUtil.createDataItem("Pre-Padding", 100, 10));
    report.getReportHeader().addElement(table);
    report.getReportHeader().addElement(TableTestUtil.createDataItem("Post-Padding", 100, 10));
    report.getReportHeader().setLayout("row");

    PdfReportUtil.createPDF(report, "test-output/PRD-3857-output-row.pdf");
    List<LogicalPageBox> pages = DebugReportRunner.layoutPages(report, 0, 1, 2);

    assertPageValid(pages, 0);
    assertPageValid(pages, 1);
    assertPageValid(pages, 2);
    //    assertPageValid(report, 3);
    //    assertPageValid(report, 4);
  }
  @Test
  public void testRunRowSpanReport() throws Exception {
    final MasterReport report = new MasterReport();
    report.setDataFactory(new TableDataFactory("query", new DefaultTableModel(10, 1)));
    report.setQuery("query");

    final Band table = TableTestUtil.createTable(1, 1, 6, true);
    final Band section = (Band) table.getElement(1);
    final Band row = (Band) section.getElement(0);
    final Band cell = TableTestUtil.createCell(6, 1);
    cell.addElement(TableTestUtil.createDataItem("Text", 100, 20));
    row.addElement(0, cell);

    table.setName("table");
    report.getReportHeader().addElement(table);
    report.getReportHeader().setLayout("block");

    PdfReportUtil.createPDF(report, "test-output/PRD-3857-rowspan-output.pdf");
    /*
    assertPageValid(report, 0);
    assertPageValid(report, 1);
    assertPageValid(report, 2);
    */
  }
 /**
  * Creates the report. This calls the standard parse method and then assigns the table model to
  * the report.
  *
  * @return the fully initialized JFreeReport object.
  * @throws ReportDefinitionException if an error occured preventing the report definition.
  */
 public MasterReport createReport() throws ReportDefinitionException {
   final MasterReport report = parseReport();
   report.setDataFactory(new TableDataFactory("default", data));
   return report;
 }
  /**
   * @param model
   * @param dataFactory
   * @param reportTemplate
   * @param output
   * @return
   * @throws ReportException
   * @throws ReportProcessingException
   * @throws SaikuAdhocException
   * @throws IOException
   * @throws ResourceException
   */
  protected MasterReport processReport(SaikuMasterModel model)
      throws ReportException, ReportProcessingException, SaikuAdhocException, ResourceException,
          IOException {

    CachingDataFactory dataFactory = null;

    try {

      model.deriveModels();

      final MasterReport reportTemplate = model.getDerivedModels().getReportTemplate();

      final WizardSpecification wizardSpecification = model.getWizardSpecification();

      reportTemplate.setDataFactory(model.getDerivedModels().getCdaDataFactory());
      reportTemplate.setQuery(model.getDerivedModels().getSessionId());

      reportTemplate.setAttribute(
          AttributeNames.Wizard.NAMESPACE, "wizard-spec", wizardSpecification);

      final ProcessingContext processingContext = new DefaultProcessingContext();
      final DataSchemaDefinition definition = reportTemplate.getDataSchemaDefinition();

      final ReportParameterValues parameterValues =
          StateUtilities.computeParameterValueSet(reportTemplate, getReportParameterValues(model));

      final ParameterDefinitionEntry[] parameterDefinitions =
          reportTemplate.getParameterDefinition().getParameterDefinitions();

      final DefaultFlowController flowController =
          new DefaultFlowController(
              processingContext, definition, parameterValues, parameterDefinitions, false);

      ensureSaikuPreProcessorIsAdded(reportTemplate, model);
      ensureHasOverrideWizardFormatting(reportTemplate, flowController);

      dataFactory = new CachingDataFactory(reportTemplate.getDataFactory(), false);
      dataFactory.initialize(
          processingContext.getConfiguration(),
          processingContext.getResourceManager(),
          processingContext.getContentBase(),
          processingContext.getResourceBundleFactory());

      final DefaultFlowController postQueryFlowController =
          flowController.performQuery(
              dataFactory,
              reportTemplate.getQuery(),
              reportTemplate.getQueryLimit(),
              reportTemplate.getQueryTimeout(),
              flowController.getMasterRow().getResourceBundleFactory());

      reportTemplate.setAttribute(
          AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ENABLE, Boolean.TRUE);

      ReportPreProcessor processor = new SaikuAdhocPreProcessor();
      ((SaikuAdhocPreProcessor) processor).setSaikuMasterModel(model);
      MasterReport output = processor.performPreProcessing(reportTemplate, postQueryFlowController);
      output.setAttribute(
          AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ENABLE, Boolean.FALSE);

      output.setAttribute(
          AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ENABLE, Boolean.FALSE);

      TemplateUtils.mergePageSetup(model, output);

      return output;

    } finally {
      dataFactory.close();
    }
  }