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);
    }
  }
  /**
   * 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 static MasterReport createReport(final Serializable fileId)
      throws ResourceException, IOException {
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();
    final HashMap helperObjects = new HashMap();
    // add the runtime context so that PentahoResourceData class can get access
    // to the solution repo

    ResourceKey key = null;

    IUnifiedRepository unifiedRepository =
        PentahoSystem.get(IUnifiedRepository.class, PentahoSessionHolder.getSession());
    RepositoryFile repositoryFile = unifiedRepository.getFileById(fileId);
    if (repositoryFile != null) {
      key =
          resourceManager.createKey(
              RepositoryResourceLoader.SOLUTION_SCHEMA_NAME
                  + RepositoryResourceLoader.SCHEMA_SEPARATOR
                  + repositoryFile.getPath(),
              helperObjects);
    } else {
      key =
          resourceManager.createKey(
              RepositoryResourceLoader.SOLUTION_SCHEMA_NAME
                  + RepositoryResourceLoader.SCHEMA_SEPARATOR
                  + fileId,
              helperObjects);
    }

    final Resource resource = resourceManager.create(key, null, MasterReport.class);
    return (MasterReport) resource.getResource();
  }
Пример #5
0
  public void testParseStyleRule() throws Exception {
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();

    StyleSheetParserUtil.getInstance()
        .parseStyleRule(
            null, "* { width: 10% }", null, null, resourceManager, StyleKeyRegistry.getRegistry());
  }
Пример #6
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();
  }
  @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);
  }
  /**
   * 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 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);
  }
Пример #13
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());
  }
Пример #14
0
 private ResourceKey createImageKey() throws IOException, ResourceKeyCreationException {
   final ResourceManager resMgr = new ResourceManager();
   resMgr.registerDefaults();
   return resMgr.createKey(new URL("http://127.0.0.1:65535/image.jpg"));
 }
 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();
 }
  public void testSerialize() throws Exception {
    final ResourceLoader resourceLoader = new ClassloaderResourceLoader();
    final ResourceManager manager = new ResourceManager();
    manager.registerDefaults();

    // Test failure - null key
    try {
      resourceLoader.serialize(null, null);
      fail("Serialization of a null key should throw an exception");
    } catch (NullPointerException npe) {
      // success
    }

    // Test failure - not a Classloader resource key
    try {
      final File tempFile = File.createTempFile("junit-test", ".tmp");
      final ResourceKey tempKey = manager.createKey(tempFile);
      resourceLoader.serialize(null, tempKey);
      fail(
          "The Classloader Resource Loader should fail when handling a non-classloader resource key");
    } catch (IllegalArgumentException iae) {
      // success
    }

    // Create key
    final String key1source =
        "res://org/pentaho/reporting/libraries/resourceloader/test1.properties";
    final ResourceKey key1 = manager.createKey(key1source);
    assertNotNull(key1);

    // Serialize the key
    final String serKey1 = resourceLoader.serialize(null, key1);
    assertNotNull("The returned key should not be null", serKey1); // $NON-NLS-1$
    assertTrue(
        "Serialized verison does not start with the correct header",
        serKey1.startsWith(STRING_SERIALIZATION_PREFIX));
    assertTrue(
        "Serialized version does not contain the correct schema information",
        serKey1.startsWith(DESERIALIZE_PREFIX));
    assertTrue(
        "Serialized version should contain the identifier intact",
        serKey1.endsWith(key1.getIdentifier().toString()));

    // Serialize a key created from a derived key
    final String key2source = "test2.properties";
    final ResourceKey key2 = manager.deriveKey(key1, key2source);
    assertNotNull(key2);

    final String serKey2 = resourceLoader.serialize(null, key2);
    assertNotNull("The returned key should not be null", serKey2); // $NON-NLS-1$
    assertTrue(
        "Serialized verison does not start with the correct header",
        serKey2.startsWith(STRING_SERIALIZATION_PREFIX));
    assertTrue(
        "Serialized version does not contain the correct schema information",
        serKey2.startsWith(DESERIALIZE_PREFIX));
    assertTrue(
        "Serialized version should contain the identifier intact",
        serKey2.endsWith(";res://org/pentaho/reporting/libraries/resourceloader/test2.properties"));

    // Serialize a key with factory parameters
    final Map<ParameterKey, Object> factoryParams = new HashMap<ParameterKey, Object>();
    factoryParams.put(new FactoryParameterKey("this"), "that");
    factoryParams.put(new FactoryParameterKey("null"), null);
    final ResourceKey key3 = manager.createKey(key1source, factoryParams);
    assertNotNull(key3);

    final String serKey3 = resourceLoader.serialize(null, key3);
    assertEquals(
        "resourcekey:org.pentaho.reporting.libraries.resourceloader"
            + ".loader.resource.ClassloaderResourceLoader;"
            + "res://org/pentaho/reporting/libraries/resourceloader/"
            + "test1.properties;\"\"\"f:this=that\"\":\"\"f:null=\"\"\"",
        serKey3);
  }