Java Code Examples for org.pentaho.reporting.engine.classic.core.MasterReport#setAttribute()

The following examples show how to use org.pentaho.reporting.engine.classic.core.MasterReport#setAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WriterTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testEmptyWrite() throws Exception {
  final DefaultWizardSpecification wizardSpecification = new DefaultWizardSpecification();
  final MasterReport report = new MasterReport();
  report.setAttribute( AttributeNames.Wizard.NAMESPACE, "wizard-spec", wizardSpecification );

  final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  BundleWriter.writeReportToZipStream( report, byteArrayOutputStream );

  final byte[] data = byteArrayOutputStream.toByteArray();
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( data, MasterReport.class );
  final MasterReport parsedReport = (MasterReport) directly.getResource();
  assertNotNull( parsedReport );
  final WizardSpecification specification =
    WizardProcessorUtil.loadWizardSpecification( report, report.getResourceManager() );
  assertNotNull( specification );
}
 
Example 2
Source File: PublishToServerTask.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void storeBundleMetaData( final MasterReport report, final String selectedReport,
    final SelectFileForPublishTask selectFileForPublishTask ) {
  final DocumentMetaData metaData = report.getBundle().getMetaData();
  report.setAttribute( ReportDesignerBoot.DESIGNER_NAMESPACE, ReportDesignerBoot.LAST_FILENAME, selectedReport );

  if ( metaData instanceof WriteableDocumentMetaData ) {
    final WriteableDocumentMetaData writeableDocumentMetaData = (WriteableDocumentMetaData) metaData;
    writeableDocumentMetaData.setBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE,
        ODFMetaAttributeNames.DublinCore.DESCRIPTION, selectFileForPublishTask.getDescription() );
    writeableDocumentMetaData.setBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE,
        ODFMetaAttributeNames.DublinCore.TITLE, selectFileForPublishTask.getReportTitle() );
  }

  report.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.LOCK_PREFERRED_OUTPUT_TYPE, Boolean
      .valueOf( selectFileForPublishTask.isLockOutputType() ) );
  report.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.PREFERRED_OUTPUT_TYPE,
      selectFileForPublishTask.getExportType() );
}
 
Example 3
Source File: WizardProcessorUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static MasterReport materialize( final MasterReport report,
                                        final WizardProcessor processor ) throws ReportProcessingException {
  final PerformanceMonitorContext performanceMonitorContext =
    ClassicEngineBoot.getInstance().getObjectFactory().get( PerformanceMonitorContext.class );
  try {
    final DefaultProcessingContext processingContext = new DefaultProcessingContext( report );
    final DataSchemaDefinition definition = report.getDataSchemaDefinition();
    final DefaultFlowController flowController = new DefaultFlowController( processingContext,
      definition, StateUtilities.computeParameterValueSet( report ), performanceMonitorContext );
    final CachingDataFactory dataFactory =
      new CachingDataFactory( report.getDataFactory(), isCacheEnabled( report ) );
    dataFactory.initialize( new ProcessingDataFactoryContext( processingContext, dataFactory ) );

    try {
      final DefaultFlowController postQueryFlowController = flowController.performDesignTimeQuery
        ( dataFactory, report.getQuery(), report.getQueryLimit(),
          report.getQueryTimeout(), flowController.getMasterRow().getResourceBundleFactory() );

      final Object originalEnable =
        report.getAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ENABLE );
      report.setAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ENABLE, Boolean.TRUE );
      final MasterReport masterReport = processor.performPreProcessing( report, postQueryFlowController );
      masterReport.setAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ENABLE, originalEnable );

      masterReport.setName( null );
      DesignTimeUtil.resetDocumentMetaData( masterReport );
      return masterReport;
    } finally {
      dataFactory.close();
    }
  } finally {
    performanceMonitorContext.close();
  }
}
 
Example 4
Source File: Prd4542Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static MasterReport loadReport( final Object selectedFile, final ResourceManager resourceManager )
  throws ResourceException, IOException {
  final Resource directly = resourceManager.createDirectly( selectedFile, MasterReport.class );
  final MasterReport resource = (MasterReport) directly.getResource();
  final DocumentBundle bundle = resource.getBundle();
  if ( bundle == null ) {
    // Ok, that should not happen if we work with the engine's parsers, but better safe than sorry.
    final MemoryDocumentBundle documentBundle = new MemoryDocumentBundle( resource.getContentBase() );
    documentBundle.getWriteableDocumentMetaData().setBundleType( ClassicEngineBoot.BUNDLE_TYPE );
    resource.setBundle( documentBundle );
    resource.setContentBase( documentBundle.getBundleMainKey() );
  } else {
    final MemoryDocumentBundle mem = new MemoryDocumentBundle( resource.getContentBase() );
    BundleUtilities.copyStickyInto( mem, bundle );
    BundleUtilities.copyMetaData( mem, bundle );
    resource.setBundle( mem );
    resource.setContentBase( mem.getBundleMainKey() );
  }

  final Object visible =
    resource.getBundle().getMetaData().getBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "visible" );//NON-NLS
  if ( "true".equals( visible ) )//NON-NLS
  {
    resource.setAttribute( AttributeNames.Pentaho.NAMESPACE, "visible", Boolean.TRUE );//NON-NLS
  } else if ( "false".equals( visible ) )//NON-NLS
  {
    resource.setAttribute( AttributeNames.Pentaho.NAMESPACE, "visible", Boolean.FALSE );//NON-NLS
  }
  return resource;
}
 
Example 5
Source File: OpenReportAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static MasterReport loadReport( final Object selectedFile, final ResourceManager resourceManager )
  throws ResourceException, IOException {
  final Resource directly = resourceManager.createDirectly( selectedFile, MasterReport.class );
  final MasterReport resource = (MasterReport) directly.getResource();
  final DocumentBundle bundle = resource.getBundle();
  if ( bundle == null ) {
    // Ok, that should not happen if we work with the engine's parsers, but better safe than sorry.
    final MemoryDocumentBundle documentBundle = new MemoryDocumentBundle( resource.getContentBase() );
    documentBundle.getWriteableDocumentMetaData().setBundleType( ClassicEngineBoot.BUNDLE_TYPE );
    resource.setBundle( documentBundle );
    resource.setContentBase( documentBundle.getBundleMainKey() );
  } else {
    final MemoryDocumentBundle mem = new MemoryDocumentBundle( resource.getContentBase() );
    BundleUtilities.copyStickyInto( mem, bundle );
    BundleUtilities.copyMetaData( mem, bundle );
    resource.setBundle( mem );
    resource.setContentBase( mem.getBundleMainKey() );
  }

  final Object visible =
    resource.getBundle().getMetaData().getBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "visible" );//NON-NLS
  if ( "true".equals( visible ) )//NON-NLS
  {
    resource.setAttribute( AttributeNames.Pentaho.NAMESPACE, "visible", Boolean.TRUE );//NON-NLS
  } else if ( "false".equals( visible ) )//NON-NLS
  {
    resource.setAttribute( AttributeNames.Pentaho.NAMESPACE, "visible", Boolean.FALSE );//NON-NLS
  }
  return resource;
}
 
Example 6
Source File: SortingIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testRunSorting() {
  List<SortConstraint> sc = new ArrayList<SortConstraint>();
  sc.add( new SortConstraint( "A", true ) );
  sc.add( new SortConstraint( "B", true ) );

  MasterReport report = new MasterReport();
  report.setQuery( "default" );
  report.setDataFactory( new ValidateDataFactory( "default", new DefaultTableModel( 10, 10 ), sc ) );
  report.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.AUTOSORT, true );
  RelationalGroup rootGroup = (RelationalGroup) report.getRootGroup();
  rootGroup.setFields( Arrays.asList( "A", "B" ) );

  int i = DebugReportRunner.execGraphics2D( report );
}
 
Example 7
Source File: SortingIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testCrosstabSorting() {
  List<SortConstraint> sc = new ArrayList<SortConstraint>();
  sc.add( new SortConstraint( "A", true ) );
  sc.add( new SortConstraint( "B", true ) );

  MasterReport report = new MasterReport();
  report.setQuery( "default" );
  report.setDataFactory( new ValidateDataFactory( "default", new DefaultTableModel( 10, 10 ), sc ) );
  report.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.AUTOSORT, true );
  RelationalGroup rootGroup = (RelationalGroup) report.getRootGroup();
  rootGroup.setFields( Arrays.asList( "A", "B" ) );

  int i = DebugReportRunner.execGraphics2D( report );
}
 
Example 8
Source File: Prd3245IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testGoldenSampleSubReportHeightMigrated() throws Exception {
  final MasterReport report = DebugReportRunner.parseGoldenSampleReport( "Prd-3245.prpt" );

  // migrate to latest version
  final CompatibilityUpdater updater = new CompatibilityUpdater();
  updater.performUpdate( report );
  report.setAttribute( AttributeNames.Internal.NAMESPACE, AttributeNames.Internal.COMAPTIBILITY_LEVEL, null );

  LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage( report, 0 );
  RenderNode elementByName = MatchFactory.findElementByName( logicalPageBox, "Subreport 1.1.1" );
  assertTrue( "SubReport height of " + StrictGeomUtility.toExternalValue( elementByName.getHeight() )
      + " is greater than 600pt", elementByName.getHeight() > StrictGeomUtility.toInternalValue( 600 ) );
}
 
Example 9
Source File: OpenReportAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static MasterReport loadReport( final File selectedFile )
  throws ResourceException, IOException {
  final ResourceManager resourceManager = new ResourceManager();
  final MasterReport reportDefinition = loadReport( selectedFile, resourceManager );
  try {
    reportDefinition.setAttribute
      ( ReportDesignerBoot.DESIGNER_NAMESPACE, ReportDesignerBoot.LAST_FILENAME, selectedFile.getCanonicalPath() ); // NON-NLS
  } catch ( IOException ioe ) {
    reportDefinition.setAttribute
      ( ReportDesignerBoot.DESIGNER_NAMESPACE, ReportDesignerBoot.LAST_FILENAME, selectedFile.getAbsolutePath() ); // NON-NLS
  }

  return reportDefinition;
}
 
Example 10
Source File: PublishUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static MasterReport loadReport( final byte[] data, final String fileName ) throws IOException,
  ResourceException {
  if ( data == null ) {
    throw new NullPointerException();
  }
  final ResourceManager resourceManager = new ResourceManager();
  final MasterReport resource = OpenReportAction.loadReport( data, resourceManager );
  resource.setAttribute( ReportDesignerBoot.DESIGNER_NAMESPACE, "report-save-path", fileName ); // NON-NLS
  return resource;
}
 
Example 11
Source File: UndoManagerTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testRecords() {
  final UndoManager manager = new UndoManager();
  final MasterReport report = new MasterReport();
  final ReportRenderContext rrc = new ReportRenderContext( report, report, null, new GlobalAuthenticationStore() );

  final InstanceID id = report.getObjectID();
  manager.addChange( "name1", new AttributeEditUndoEntry( id, "test-ns", "test", null, "new" ) );
  manager.addChange( "name2", new AttributeEditUndoEntry( id, "test-ns", "test2", null, "groovy" ) );
  manager.addChange( "name3", new AttributeEditUndoEntry( id, "test-ns", "test", "new", "other" ) );

  report.setAttribute( "test-ns", "test", "other" );
  report.setAttribute( "test-ns", "test2", "groovy" );

  assertFalse( manager.isRedoPossible() );
  assertTrue( manager.isUndoPossible() );
  assertEquals( "Attr test = other", "other", report.getAttribute( "test-ns", "test" ) );
  assertEquals( "Attr test2 = groovy", "groovy", report.getAttribute( "test-ns", "test2" ) );

  manager.undo( rrc );
  assertTrue( manager.isRedoPossible() );
  assertTrue( manager.isUndoPossible() );
  assertEquals( "Attr test = new", "new", report.getAttribute( "test-ns", "test" ) );
  assertEquals( "Attr test2 = groovy", "groovy", report.getAttribute( "test-ns", "test2" ) );

  manager.redo( rrc );
  assertFalse( manager.isRedoPossible() );
  assertTrue( manager.isUndoPossible() );
  assertEquals( "Attr test = other", "other", report.getAttribute( "test-ns", "test" ) );
  assertEquals( "Attr test2 = groovy", "groovy", report.getAttribute( "test-ns", "test2" ) );

  manager.undo( rrc );
  assertTrue( manager.isRedoPossible() );
  assertTrue( manager.isUndoPossible() );
  assertEquals( "Attr test = new", "new", report.getAttribute( "test-ns", "test" ) );
  assertEquals( "Attr test2 = groovy", "groovy", report.getAttribute( "test-ns", "test2" ) );

  manager.undo( rrc );
  assertTrue( manager.isRedoPossible() );
  assertTrue( manager.isUndoPossible() );
  assertEquals( "Attr test = new", "new", report.getAttribute( "test-ns", "test" ) );
  assertEquals( "Attr test2 = <null>", null, report.getAttribute( "test-ns", "test2" ) );

  manager.undo( rrc );
  assertTrue( manager.isRedoPossible() );
  assertFalse( manager.isUndoPossible() );
  assertEquals( "Attr test = <null>", null, report.getAttribute( "test-ns", "test" ) );
  assertEquals( "Attr test2 = <null>", null, report.getAttribute( "test-ns", "test2" ) );

}
 
Example 12
Source File: AbstractSaveReportAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean saveReport( final ReportDesignerContext context, final ReportDocumentContext activeContext,
                           final Component parent ) {
  final MasterReport report = activeContext.getContextRoot();

  // Get the current file target
  File target = getTarget( report, parent );
  if ( target == null ) {
    return false;
  }

  // if no name has been set for the report, default to the name of the file
  String attPath;
  try {
    attPath = target.getCanonicalPath();
  } catch ( IOException ioe ) {
    // then let's not set the save path attribute to the *canonical path*
    attPath = target.getAbsolutePath();
  }

  // Write the report to the filename
  if ( SaveReportUtilities.saveReport( context, activeContext, target ) ) {
    try {
      // change report save path only in case save success. see PRD-5567
      report
        .setAttribute( ReportDesignerBoot.DESIGNER_NAMESPACE, ReportDesignerBoot.LAST_FILENAME, attPath );

      // Update the definition source to be the location from which the file is saved
      final ResourceManager resourceManager = report.getResourceManager();
      final Resource bundleResource = resourceManager.createDirectly( target, DocumentBundle.class );
      final DocumentBundle bundle = (DocumentBundle) bundleResource.getResource();
      final ResourceKey bundleKey = bundle.getBundleKey();
      report.setDefinitionSource( bundleKey );
      report.setContentBase( bundleKey );
      report.setResourceManager( bundle.getResourceManager() );
      activeContext.resetChangeTracker();
    } catch ( ResourceException e ) {
      UncaughtExceptionsModel.getInstance().addException( e );
    }
    return true;
  }

  final ExceptionDialog exceptionDialog;
  final Window window = LibSwingUtil.getWindowAncestor( parent );
  if ( window instanceof Dialog ) {
    exceptionDialog = new ExceptionDialog( (Dialog) window );
  } else if ( window instanceof Frame ) {
    exceptionDialog = new ExceptionDialog( (Frame) window );
  } else {
    exceptionDialog = new ExceptionDialog();
  }
  exceptionDialog.showDialog();
  return false;
}
 
Example 13
Source File: GoldTestBase.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected MasterReport tuneForCurrentMode( final MasterReport report ) {
  report.setAttribute( AttributeNames.Internal.NAMESPACE, AttributeNames.Internal.COMAPTIBILITY_LEVEL, null );
  return report;
}
 
Example 14
Source File: GoldTestBase.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected MasterReport tuneForMigrationMode( final MasterReport report ) {
  final CompatibilityUpdater updater = new CompatibilityUpdater();
  updater.performUpdate( report );
  report.setAttribute( AttributeNames.Internal.NAMESPACE, AttributeNames.Internal.COMAPTIBILITY_LEVEL, null );
  return report;
}
 
Example 15
Source File: ExtraFooterIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected MasterReport tuneForMigrationMode( final MasterReport report ) {
  final CompatibilityUpdater updater = new CompatibilityUpdater();
  updater.performUpdate( report );
  report.setAttribute( AttributeNames.Internal.NAMESPACE, AttributeNames.Internal.COMAPTIBILITY_LEVEL, null );
  return report;
}
 
Example 16
Source File: GeneratorTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testCrosstab() throws Exception {
  final GroupDefinition[] groupDefs = new GroupDefinition[ 3 ];
  groupDefs[ 0 ] = new DefaultGroupDefinition( GroupType.RELATIONAL, "group-field1" );
  groupDefs[ 1 ] = new DefaultGroupDefinition( GroupType.CT_ROW, "group-field2" );
  groupDefs[ 2 ] = new DefaultGroupDefinition( GroupType.CT_COLUMN, "group-field3" );

  final DetailFieldDefinition[] detailFields = new DetailFieldDefinition[ 1 ];
  detailFields[ 0 ] = new DefaultDetailFieldDefinition( "detail-field1" );

  final DefaultWizardSpecification wizardSpecification = new DefaultWizardSpecification();
  wizardSpecification.setGroupDefinitions( groupDefs );
  wizardSpecification.setDetailFieldDefinitions( detailFields );

  final MasterReport report = new MasterReport();
  report.setAttribute( AttributeNames.Wizard.NAMESPACE, "wizard-spec", wizardSpecification );

  final ProcessingContext processingContext = new DefaultProcessingContext();
  final DefaultFlowController flowController = new DefaultFlowController
    ( processingContext, report.getDataSchemaDefinition(), new ReportParameterValues(),
      new NoOpPerformanceMonitorContext() );

  final WizardProcessor processor = new WizardProcessor();
  final MasterReport masterReport = processor.performPreProcessing( report, flowController );

  final int count = masterReport.getGroupCount();
  assertEquals( groupDefs.length + 2, count );
  final RelationalGroup defaultGroup = (RelationalGroup) masterReport.getRootGroup();
  assertEquals( "Default-Group detector", 0, defaultGroup.getFieldsArray().length );
  final SubGroupBody body = (SubGroupBody) defaultGroup.getBody();
  final RelationalGroup group1 = (RelationalGroup) body.getGroup();
  assertEquals( "Rel-Group", "group-field1", group1.getFieldsArray()[ 0 ] );
  final SubGroupBody body1 = (SubGroupBody) group1.getBody();
  final CrosstabGroup ctGroup = (CrosstabGroup) body1.getGroup();
  final CrosstabRowGroupBody body2 = (CrosstabRowGroupBody) ctGroup.getBody();
  final CrosstabRowGroup rowGroup = body2.getGroup();
  assertEquals( "Row-Group", "group-field2", rowGroup.getField() );

  final CrosstabColumnGroupBody body3 = (CrosstabColumnGroupBody) rowGroup.getBody();
  final CrosstabColumnGroup colGroup = body3.getGroup();
  assertEquals( "Col-Group", "group-field3", colGroup.getField() );

}
 
Example 17
Source File: WriterTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testFullCrosstabWrite() throws Exception {
  final GroupDefinition[] groupDefs = new GroupDefinition[ 3 ];
  groupDefs[ 0 ] = new DefaultGroupDefinition( GroupType.RELATIONAL, "group-field1" );
  groupDefs[ 1 ] = new DefaultGroupDefinition( GroupType.CT_ROW, "group-field2" );
  groupDefs[ 2 ] = new DefaultGroupDefinition( GroupType.CT_COLUMN, "group-field3" );

  final DetailFieldDefinition[] detailFields = new DetailFieldDefinition[ 3 ];
  detailFields[ 0 ] = new DefaultDetailFieldDefinition( "detail-field1" );
  detailFields[ 1 ] = new DefaultDetailFieldDefinition( "detail-field2" );
  detailFields[ 2 ] = new DefaultDetailFieldDefinition( "detail-field3" );

  final DefaultWizardSpecification wizardSpecification = new DefaultWizardSpecification();
  wizardSpecification.setGroupDefinitions( groupDefs );
  wizardSpecification.setDetailFieldDefinitions( detailFields );

  final MasterReport report = new MasterReport();
  report.setAttribute( AttributeNames.Wizard.NAMESPACE, "wizard-spec", wizardSpecification );

  final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  BundleWriter.writeReportToZipStream( report, byteArrayOutputStream );

  final byte[] data = byteArrayOutputStream.toByteArray();
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( data, MasterReport.class );
  final MasterReport parsedReport = (MasterReport) directly.getResource();
  assertNotNull( parsedReport );

  final WizardSpecification specification =
    WizardProcessorUtil.loadWizardSpecification( report, report.getResourceManager() );
  assertNotNull( specification );

  final GroupDefinition[] resultGroups = specification.getGroupDefinitions();
  assertEquals( 3, resultGroups.length );
  assertEquals( "group-field1", resultGroups[ 0 ].getField() );
  assertEquals( "group-field2", resultGroups[ 1 ].getField() );
  assertEquals( "group-field3", resultGroups[ 2 ].getField() );
  assertEquals( GroupType.RELATIONAL, resultGroups[ 0 ].getGroupType() );
  assertEquals( GroupType.CT_ROW, resultGroups[ 1 ].getGroupType() );
  assertEquals( GroupType.CT_COLUMN, resultGroups[ 2 ].getGroupType() );

  final DetailFieldDefinition[] resultDetails = specification.getDetailFieldDefinitions();
  assertEquals( 3, resultDetails.length );
  assertEquals( "detail-field1", resultDetails[ 0 ].getField() );
  assertEquals( "detail-field2", resultDetails[ 1 ].getField() );
  assertEquals( "detail-field3", resultDetails[ 2 ].getField() );

}
 
Example 18
Source File: WriterTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testFullRelationalWrite() throws Exception {
  final GroupDefinition[] groupDefs = new GroupDefinition[ 3 ];
  groupDefs[ 0 ] = new DefaultGroupDefinition( GroupType.RELATIONAL, "group-field1" );
  groupDefs[ 1 ] = new DefaultGroupDefinition( GroupType.RELATIONAL, "group-field2" );
  groupDefs[ 2 ] = new DefaultGroupDefinition( GroupType.RELATIONAL, "group-field3" );

  final DetailFieldDefinition[] detailFields = new DetailFieldDefinition[ 3 ];
  detailFields[ 0 ] = new DefaultDetailFieldDefinition( "detail-field1" );
  detailFields[ 1 ] = new DefaultDetailFieldDefinition( "detail-field2" );
  detailFields[ 2 ] = new DefaultDetailFieldDefinition( "detail-field3" );

  final DefaultWizardSpecification wizardSpecification = new DefaultWizardSpecification();
  wizardSpecification.setGroupDefinitions( groupDefs );
  wizardSpecification.setDetailFieldDefinitions( detailFields );

  final MasterReport report = new MasterReport();
  report.setAttribute( AttributeNames.Wizard.NAMESPACE, "wizard-spec", wizardSpecification );

  final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  BundleWriter.writeReportToZipStream( report, byteArrayOutputStream );

  final byte[] data = byteArrayOutputStream.toByteArray();
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( data, MasterReport.class );
  final MasterReport parsedReport = (MasterReport) directly.getResource();
  assertNotNull( parsedReport );

  final WizardSpecification specification =
    WizardProcessorUtil.loadWizardSpecification( report, report.getResourceManager() );
  assertNotNull( specification );

  final GroupDefinition[] resultGroups = specification.getGroupDefinitions();
  assertEquals( 3, resultGroups.length );
  assertEquals( "group-field1", resultGroups[ 0 ].getField() );
  assertEquals( "group-field2", resultGroups[ 1 ].getField() );
  assertEquals( "group-field3", resultGroups[ 2 ].getField() );
  assertEquals( GroupType.RELATIONAL, resultGroups[ 0 ].getGroupType() );
  assertEquals( GroupType.RELATIONAL, resultGroups[ 1 ].getGroupType() );
  assertEquals( GroupType.RELATIONAL, resultGroups[ 2 ].getGroupType() );

  final DetailFieldDefinition[] resultDetails = specification.getDetailFieldDefinitions();
  assertEquals( 3, resultDetails.length );
  assertEquals( "detail-field1", resultDetails[ 0 ].getField() );
  assertEquals( "detail-field2", resultDetails[ 1 ].getField() );
  assertEquals( "detail-field3", resultDetails[ 2 ].getField() );

}