/**
   * Validate that the banded subreport contained in an inline subreport page-footer content DOES
   * NOT show up in the layout-editor
   *
   * @throws Exception
   */
  public void testInlineBandedSubReport() throws Exception {
    final URL resource = getClass().getResource("Prd-4637.prpt");
    assertNotNull(resource);

    final ResourceManager mgr = new ResourceManager();
    mgr.registerDefaults();
    final MasterReport report =
        (MasterReport) mgr.createDirectly(resource, MasterReport.class).getResource();

    final GlobalAuthenticationStore globalAuthenticationStore = new GlobalAuthenticationStore();
    final ReportRenderContext masterContext =
        new ReportRenderContext(report, report, null, globalAuthenticationStore);
    final SubReport subReport = (SubReport) report.getReportHeader().getElement(0);
    final ReportRenderContext subContext =
        new ReportRenderContext(report, subReport, masterContext, globalAuthenticationStore);

    final SubReport subReport2 = subReport.getReportHeader().getSubReport(0);
    final ReportRenderContext subSubContext =
        new ReportRenderContext(report, subReport2, subContext, globalAuthenticationStore);

    final TestRootBandRenderer r =
        new TestRootBandRenderer(subReport.getPageFooter(), subSubContext);

    final ValidateTextGraphics graphics2D = new ValidateTextGraphics(468, 108);
    graphics2D.expect("Any Text Printed Is An Error!");
    assertTrue(graphics2D.hitClip(10, 10, 1, 1));
    r.draw(graphics2D);
  }
  public void testRowBoxesEstablishOwnBlockContext() throws Exception {
    // this report defines that the group as well as all bands within that group are row-layout.
    // therefore the two itembands end on the same row.

    // The itemband did not define a width, not even a 100% width, and thus ends with a width of
    // auto/zero.
    // therefore the itemband shrinks to the minimal size that still encloses all elements.
    // the elements that have percentage width are resolved against the block context.
    // A band without a width defined (the itemband!), does not establish an own block-context, so
    // it
    // takes the block context of the parent, or as fallback: page.

    final File file = GoldTestBase.locateGoldenSampleReport("Prd-3479.prpt");
    final ResourceManager mgr = new ResourceManager();
    mgr.registerDefaults();
    final Resource directly = mgr.createDirectly(file, MasterReport.class);
    final MasterReport report = (MasterReport) directly.getResource();
    report.setCompatibilityLevel(null);

    final LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 0);
    final RenderNode[] itembands =
        MatchFactory.findElementsByElementType(logicalPageBox, ItemBandType.INSTANCE);

    assertEquals(2, itembands.length);
    assertEquals(48208843, itembands[0].getWidth());
    assertEquals(48208843, itembands[1].getWidth());
    assertEquals(48208843, itembands[1].getX());
  }
  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
    }
  }
  public void testRun() throws Exception {
    final URL url = getClass().getResource("Pre-492.prpt");
    assertNotNull(url);
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();
    final Resource directly = resourceManager.createDirectly(url, MasterReport.class);
    final MasterReport report = (MasterReport) directly.getResource();

    try {
      final ZipRepository zipRepository = new ZipRepository(new NullOutputStream());
      final ContentLocation root = zipRepository.getRoot();
      final ContentLocation data =
          RepositoryUtilities.createLocation(
              zipRepository, RepositoryUtilities.splitPath("data", "/"));

      final DebugFlowOutputProcessor outputProcessor = new DebugFlowOutputProcessor();

      final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
      printer.setContentWriter(root, new DefaultNameGenerator(root, "report"));
      printer.setDataWriter(data, new DefaultNameGenerator(data, "content"));
      printer.setUrlRewriter(new SingleRepositoryURLRewriter());
      outputProcessor.setPrinter(printer);

      final FlowReportProcessor sp = new FlowReportProcessor(report, outputProcessor);
      sp.processReport();
      sp.close();
      zipRepository.close();
    } catch (IOException ioe) {
      throw ioe;
    } catch (ReportProcessingException re) {
      throw re;
    } catch (Exception re) {
      throw new ReportProcessingException("Failed to process the report", re);
    }
  }
Ejemplo n.º 5
0
  public void testParseInitialStyleSheet() throws Exception {
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();

    final Resource directly =
        resourceManager.createDirectly(
            "res://org/pentaho/reporting/libraries/css/initial.css", StyleSheet.class);
    assertNotNull(directly.getResource());
  }
  public void testGoldRun() throws Exception {
    final File file = GoldTestBase.locateGoldenSampleReport("Prd-3239.prpt");
    final ResourceManager mgr = new ResourceManager();
    mgr.registerDefaults();
    final Resource directly = mgr.createDirectly(file, MasterReport.class);
    final MasterReport report = (MasterReport) directly.getResource();
    report.setCompatibilityLevel(ClassicEngineBoot.computeVersionId(3, 8, 0));

    DebugReportRunner.createXmlFlow(report);
  }
  protected MasterReport postProcess(final MasterReport originalReport) throws Exception {
    final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream();
    BundleWriter.writeReportToZipStream(originalReport, bout);
    assertTrue(bout.getLength() > 0);

    final ResourceManager mgr = new ResourceManager();
    mgr.registerDefaults();
    final Resource reportRes = mgr.createDirectly(bout.toByteArray(), MasterReport.class);
    return (MasterReport) reportRes.getResource();
  }
Ejemplo n.º 8
0
  /**
   * This method does what the report designer does on save.
   *
   * @param report
   * @param file
   * @throws Exception
   */
  private void saveReport(final MasterReport report, final File file) throws Exception {
    BundleWriter.writeReportToZipFile(report, file);
    final ResourceManager resourceManager = report.getResourceManager();
    final Resource bundleResource = resourceManager.createDirectly(file, DocumentBundle.class);
    final DocumentBundle bundle = (DocumentBundle) bundleResource.getResource();
    final ResourceKey bundleKey = bundle.getBundleKey();

    final MemoryDocumentBundle mem = new MemoryDocumentBundle();
    BundleUtilities.copyStickyInto(mem, bundle);
    BundleUtilities.copyMetaData(mem, bundle);
    report.setBundle(mem);
    report.setContentBase(mem.getBundleMainKey());
    report.setDefinitionSource(bundleKey);
  }
  @Test
  public void testPrd3857Report() throws Exception {
    File file = GoldenSampleGenerator.locateGoldenSampleReport("Prd-3857-001.prpt");
    Assert.assertNotNull(file);

    final ResourceManager manager = new ResourceManager();
    manager.registerDefaults();
    final Resource res = manager.createDirectly(file, MasterReport.class);
    final MasterReport report = (MasterReport) res.getResource();

    List<LogicalPageBox> pages = DebugReportRunner.layoutPages(report, 0, 1);
    assertPageValid(pages, 0);
    assertPageValid(pages, 1);
  }
  public void testWizardDefinitionIsAvailable() throws Exception {
    final File url = GoldTestBase.locateGoldenSampleReport("prd-2887.prpt");
    assertNotNull(url);
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();
    final Resource directly = resourceManager.createDirectly(url, MasterReport.class);
    final MasterReport org = (MasterReport) directly.getResource();

    assertNotNull(WizardProcessorUtil.loadWizardSpecification(org, resourceManager));
    final MasterReport report = postProcess(org);
    assertNotNull(WizardProcessorUtil.loadWizardSpecification(report, report.getResourceManager()));
    DetailsHeader detailsHeader = report.getDetailsHeader();
    detailsHeader.getElement(0).setName("MagicChange");

    LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 1);
    ModelPrinter.INSTANCE.print(logicalPageBox);
  }
 public void load(final File file) {
   try {
     final ResourceManager resourceManager = new ResourceManager();
     final Resource resource =
         resourceManager.createDirectly(file, DrillDownProfileCollection.class);
     final DrillDownProfileCollection typeCollection =
         (DrillDownProfileCollection) resource.getResource();
     final DrillDownProfile[] types = typeCollection.getData();
     for (int i = 0; i < types.length; i++) {
       final DrillDownProfile metaData = types[i];
       if (metaData != null) {
         drillDownProfiles.addElement(metaData);
       }
     }
   } catch (Exception e) {
     DrillDownProfileEditor.logger.error("Failed:", e);
   }
 }
  public MasterReport getReportDefinition() {
    try {
      // Get the URL to the reportDefinition file
      final Class classVar = this.getClass();
      final URL reportDefinitionURL =
          classVar.getResource("/reports/LC_Total_Number_Of_Cancelled_Bookings.prpt");

      // Parse the report file
      final ResourceManager resourceManager = new ResourceManager();
      final Resource directly =
          resourceManager.createDirectly(reportDefinitionURL, MasterReport.class);

      return (MasterReport) directly.getResource();
    } catch (ResourceException e) {
      e.printStackTrace();
    }
    return null;
  }
Ejemplo n.º 13
0
  /**
   * Validate that the master-report page-footer content shows up in the layout-editor
   *
   * @throws Exception
   */
  public void testOutsidePageFooter() throws Exception {
    final URL resource = getClass().getResource("Prd-4637.prpt");
    assertNotNull(resource);

    final ResourceManager mgr = new ResourceManager();
    mgr.registerDefaults();
    final MasterReport report =
        (MasterReport) mgr.createDirectly(resource, MasterReport.class).getResource();

    final GlobalAuthenticationStore globalAuthenticationStore = new GlobalAuthenticationStore();
    final ReportRenderContext reportContext =
        new ReportRenderContext(report, report, null, globalAuthenticationStore);
    final TestRootBandRenderer r = new TestRootBandRenderer(report.getPageFooter(), reportContext);

    final ValidateTextGraphics graphics2D = new ValidateTextGraphics(468, 108);
    graphics2D.expect("Outside", "Page", "Footer");
    assertTrue(graphics2D.hitClip(10, 10, 1, 1));
    r.draw(graphics2D);
  }
 public void registerFromXml(final URL expressionMetaSource) throws IOException {
   if (expressionMetaSource == null) {
     throw new NullPointerException(
         "Error: Could not find the expression meta-data description file");
   }
   try {
     final Resource resource =
         resourceManager.createDirectly(expressionMetaSource, ExpressionMetaDataCollection.class);
     final ExpressionMetaDataCollection typeCollection =
         (ExpressionMetaDataCollection) resource.getResource();
     final ExpressionMetaData[] types = typeCollection.getExpressionMetaData();
     for (int i = 0; i < types.length; i++) {
       final ExpressionMetaData metaData = types[i];
       if (metaData != null) {
         registerExpression(metaData);
       }
     }
   } catch (Exception e) {
     throw new IOException("Error: Could not parse the element meta-data description file", e);
   }
 }
  public void testResourceLabelAfterSerialization() throws Exception {
    final File url = GoldTestBase.locateGoldenSampleReport("Prd-3514.prpt");
    assertNotNull(url);
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();
    final Resource directly = resourceManager.createDirectly(url, MasterReport.class);
    final MasterReport org = (MasterReport) directly.getResource();

    final MasterReport report = postProcess(org);

    RelationalGroup relationalGroup = report.getRelationalGroup(0);
    GroupHeader header = relationalGroup.getHeader();
    Band band = (Band) header.getElement(0);
    Element element = band.getElement(1);
    assertTrue(element.getElementType() instanceof ResourceMessageType);
    element.setName("DateTitleField");
    //    LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 1);
    LogicalPageBox logicalPageBox =
        DebugReportRunner.layoutSingleBand(report, header, false, false);
    RenderNode dateTitleField = MatchFactory.findElementByName(logicalPageBox, "DateTitleField");
    assertNotNull(dateTitleField);
    //    ModelPrinter.INSTANCE.print(logicalPageBox);
  }
Ejemplo n.º 16
0
  public void testLoadSaveFromDisk() throws Exception {
    final ResourceKey key = createImageKey();

    final Element element = new Element();
    element.setElementType(new ContentType());
    element.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, key);
    // .. save it.
    final MasterReport report = new MasterReport();
    report.getReportHeader().addElement(element);

    saveReport(report, new File("bin/test-tmp/prd-3319-load-save-disk-1.prpt"));

    // load it to establish the context in all resource-keys ..
    final ResourceManager mgr = new ResourceManager();
    mgr.registerDefaults();
    final Resource resource =
        mgr.createDirectly(
            new File("bin/test-tmp/prd-3319-load-save-disk-1.prpt"), MasterReport.class);

    // save it once, that changes the bundle ...
    final MasterReport report2 = (MasterReport) resource.getResource();
    saveReport(report2, new File("bin/test-tmp/prd-3319-load-save-disk-2.prpt"));
    // save it twice, that triggers the crash...
    saveReport(report2, new File("bin/test-tmp/prd-3319-load-save-disk-2.prpt"));

    final ProcessingContext processingContext = new DefaultProcessingContext();
    final DebugExpressionRuntime runtime =
        new DebugExpressionRuntime(new DefaultTableModel(), 0, processingContext);

    final Element reportElement = report2.getReportHeader().getElement(0);
    Object attribute =
        reportElement.getAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE);

    assertTrue(attribute instanceof ResourceKey);
    ResourceKey atKey = (ResourceKey) attribute;
    assertEquals("http://127.0.0.1:65535/image.jpg", atKey.getIdentifierAsString());
  }
 public static MasterReport parseReport(final Object file) throws ResourceException {
   final ResourceManager manager = new ResourceManager();
   manager.registerDefaults();
   final Resource resource = manager.createDirectly(file, MasterReport.class);
   return (MasterReport) resource.getResource();
 }