public void testErrorHandlingBad() throws Exception {
    final URL url = getClass().getResource("Prd-3985.prpt");
    final ResourceManager mgr = new ResourceManager();
    final MasterReport report =
        (MasterReport) mgr.createDirectly(url, MasterReport.class).getResource();
    report
        .getReportConfiguration()
        .setConfigProperty(
            "org.pentaho.reporting.engine.classic.core.FailOnAttributeExpressionErrors", "true");

    final FormulaExpression function = new FormulaExpression();
    function.setName("Test");
    function.setFormula("=MULTIVALUEQUERY(\"Bad\")");

    report
        .getReportHeader()
        .setAttributeExpression(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, function);

    try {
      DebugReportRunner.createPDF(report);
      Assert.fail();
    } catch (Exception e) {
      // ignored
    }
  }
  @Test
  public void testTableColumns() throws Exception {
    final MasterReport report = DebugReportRunner.parseGoldenSampleReport("Prd-4523.prpt");
    report
        .getReportConfiguration()
        .setConfigProperty(ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY, "false");
    LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 0);
    RenderNode[] elementsByNodeType =
        MatchFactory.findElementsByNodeType(logicalPageBox, LayoutNodeTypes.TYPE_BOX_TABLE);
    assertEquals(1, elementsByNodeType.length);
    TableRenderBox table = (TableRenderBox) elementsByNodeType[0];
    long width = table.getWidth();
    DebugLog.log(width);
    SeparateColumnModel columnModel = (SeparateColumnModel) table.getColumnModel();
    long sum = 0;
    final ArrayList<TableColumn> expected = new ArrayList<TableColumn>();
    expected.add(createTableColumn(4748666, 4222000, 0, 0, 0));
    expected.add(createTableColumn(4694666, 4168000, 0, 0, 0));
    expected.add(createTableColumn(8415666, 7889000, 0, 0, 2824000));
    expected.add(createTableColumn(8415666, 7889000, 0, 0, 0));
    expected.add(createTableColumn(8415666, 7889000, 0, 0, 0));
    expected.add(createTableColumn(8415666, 7889000, 0, 0, 0));
    expected.add(createTableColumn(8415666, 7889000, 0, 0, 2824000));
    expected.add(createTableColumn(8415666, 7889000, 0, 0, 0));
    expected.add(createTableColumn(8415666, 7889000, 0, 0, 0));
    expected.add(createTableColumn(8415666, 7889000, 0, 0, 0));
    expected.add(createTableColumn(8415666, 7889000, 2824000, 0, 0));
    expected.add(createTableColumn(8415666, 7889000, 0, 0, 0));

    TableColumn[] columns = columnModel.getColumns();
    for (int i = 0; i < columns.length; i += 1) {
      TableColumn c = columnModel.getColumn(i);
      assertColumnsEqual(expected.get(i), c);
    }
  }
 protected MasterReport tuneForTesting(final MasterReport report) throws Exception {
   final ModifiableConfiguration configuration = report.getReportConfiguration();
   configuration.setConfigProperty(
       DefaultReportEnvironment.ENVIRONMENT_KEY + "::internal::report.date",
       "2011-04-07T15:00:00.000+0000");
   configuration.setConfigProperty(
       DefaultReportEnvironment.ENVIRONMENT_TYPE + "::internal::report.date", "java.util.Date");
   return report;
 }
 @Test
 public void testComplexCrosstab() throws ResourceException, ReportProcessingException {
   final MasterReport report = DebugReportRunner.parseGoldenSampleReport("Prd-4523.prpt");
   report
       .getReportConfiguration()
       .setConfigProperty(
           "org.pentaho.reporting.engine.classic.core.modules.output.table.base.FailOnCellConflicts",
           "true");
   HtmlReportUtil.createStreamHTML(report, new NullOutputStream());
 }
  public void createReportContent(
      final OutputStream outputStream,
      final Serializable fileId,
      final String path,
      final boolean forceDefaultOutputTarget)
      throws Exception {
    final long start = System.currentTimeMillis();
    final Map<String, Object> inputs = contentGenerator.createInputs();

    AuditHelper.audit(
        userSession.getId(),
        userSession.getName(),
        path,
        contentGenerator.getObjectName(),
        getClass().getName(),
        MessageTypes.INSTANCE_START,
        contentGenerator.getInstanceId(),
        "",
        0,
        contentGenerator); //$NON-NLS-1$

    String result = MessageTypes.INSTANCE_END;
    StagingHandler reportStagingHandler = null;
    try {
      final Object rawSessionId = inputs.get(ParameterXmlContentHandler.SYS_PARAM_SESSION_ID);
      if ((rawSessionId instanceof String) == false || "".equals(rawSessionId)) {
        inputs.put(ParameterXmlContentHandler.SYS_PARAM_SESSION_ID, UUIDUtil.getUUIDAsString());
      }

      // produce rendered report
      final SimpleReportingComponent reportComponent = new SimpleReportingComponent();
      reportComponent.setReportFileId(fileId);
      reportComponent.setPaginateOutput(true);
      reportComponent.setForceDefaultOutputTarget(forceDefaultOutputTarget);
      reportComponent.setDefaultOutputTarget(HtmlTableModule.TABLE_HTML_PAGE_EXPORT_TYPE);
      if (path.endsWith(".prpti")) {
        reportComponent.setForceUnlockPreferredOutput(true);
      }
      reportComponent.setInputs(inputs);

      final MasterReport report = reportComponent.getReport();
      final StagingMode stagingMode = getStagingMode(inputs, report);
      reportStagingHandler = new StagingHandler(outputStream, stagingMode, this.userSession);

      if (reportStagingHandler.isFullyBuffered()) {
        // it is safe to disable the buffered writing for the report now that we have a
        // extra buffering in place.
        report.getReportConfiguration().setConfigProperty(FORCED_BUFFERED_WRITING, "false");
      }

      reportComponent.setOutputStream(reportStagingHandler.getStagingOutputStream());

      // the requested mime type can be null, in that case the report-component will resolve the
      // desired
      // type from the output-target.
      // Hoever, the report-component will inspect the inputs independently from the mimetype here.

      final IUnifiedRepository repository =
          PentahoSystem.get(IUnifiedRepository.class, userSession);
      final RepositoryFile file = repository.getFileById(fileId);

      // add all inputs (request parameters) to report component
      final String mimeType = reportComponent.getMimeType();

      // If we haven't set an accepted page, -1 will be the default, which will give us a report
      // with no pages. This default is used so that when we do our parameter interaction with the
      // engine we can spend as little time as possible rendering unused pages, making it no pages.
      // We are going to intentionally reset the accepted page to the first page, 0, at this point,
      // if the accepted page is -1.
      final String outputTarget = reportComponent.getComputedOutputTarget();
      if (HtmlTableModule.TABLE_HTML_PAGE_EXPORT_TYPE.equals(outputTarget)
          && reportComponent.getAcceptedPage() < 0) {
        reportComponent.setAcceptedPage(0);
      }

      if (logger.isDebugEnabled()) {
        logger.debug(
            Messages.getInstance()
                .getString(
                    "ReportPlugin.logStartGenerateContent",
                    mimeType, //$NON-NLS-1$
                    outputTarget,
                    String.valueOf(reportComponent.getAcceptedPage())));
      }

      HttpServletResponse response = null;
      boolean streamToBrowser = false;
      final IParameterProvider pathProviders = contentGenerator.getParameterProviders().get("path");
      if (pathProviders != null) {
        final Object httpResponse = pathProviders.getParameter("httpresponse");
        if (httpResponse
            instanceof HttpServletResponse) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          response = (HttpServletResponse) httpResponse; // $NON-NLS-1$ //$NON-NLS-2$
          if (reportStagingHandler.getStagingMode() == StagingMode.THRU) {
            // Direct back - check output stream...
            final OutputStream respOutputStream = response.getOutputStream();
            if (respOutputStream == outputStream) {
              //
              // Massive assumption here -
              // Assume the container returns the same object on successive calls to
              // response.getOutputStream()
              streamToBrowser = true;
            }
          }
        }
      }

      final String extension = MimeHelper.getExtension(mimeType);
      String filename = file.getName();
      if (filename.lastIndexOf(".") != -1) { // $NON-NLS-1$
        filename = filename.substring(0, filename.lastIndexOf(".")); // $NON-NLS-1$
      }
      String disposition =
          "inline; filename*=UTF-8''"
              + RepositoryPathEncoder.encode(
                  RepositoryPathEncoder.encodeRepositoryPath(filename + extension));

      final boolean validates = reportComponent.validate();
      if (!validates) {
        sendErrorResponse(response, outputStream, reportStagingHandler);
      } else {
        if (response != null) {
          // Send headers before we begin execution
          response.setHeader("Content-Disposition", disposition);
          response.setHeader("Content-Description", file.getName()); // $NON-NLS-1$
          response.setHeader("Cache-Control", "private, max-age=0, must-revalidate");
        }
        if (reportComponent.execute()) {
          if (response != null) {
            if (reportStagingHandler.canSendHeaders()) {
              response.setHeader("Content-Disposition", disposition);
              response.setHeader("Content-Description", file.getName()); // $NON-NLS-1$
              response.setHeader("Cache-Control", "private, max-age=0, must-revalidate");
              response.setContentLength(reportStagingHandler.getWrittenByteCount());
            }
          }
          if (logger.isDebugEnabled()) {
            logger.debug(
                Messages.getInstance()
                    .getString(
                        "ReportPlugin.logEndGenerateContent",
                        String.valueOf(reportStagingHandler.getWrittenByteCount()))); // $NON-NLS-1$
          }
          reportStagingHandler.complete(); // will copy bytes to final destination...

        } else { // failed execution
          sendErrorResponse(response, outputStream, reportStagingHandler);
        }
      }
    } catch (Exception ex) {
      result = MessageTypes.INSTANCE_FAILED;
      throw ex;
    } finally {
      if (reportStagingHandler != null) {
        reportStagingHandler.close();
      }
      final long end = System.currentTimeMillis();
      AuditHelper.audit(
          userSession.getId(),
          userSession.getName(),
          path,
          contentGenerator.getObjectName(),
          getClass().getName(),
          result,
          contentGenerator.getInstanceId(),
          "",
          ((float) (end - start) / 1000),
          contentGenerator); //$NON-NLS-1$
    }
  }