org.eclipse.birt.report.tests.model
Class BaseTestCase

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.eclipse.birt.report.tests.model.BaseTestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
ActionHandleTest, CellHandleTest, ClientsDerivedIteratorTest, ColorHandleTest, ColumnHandleTest, ComponentsInGridHandleTest, CustomColorHandleTest, DataSetHandleTest, DataSourceHandleTest, DefaultSearchFileAlgorithmTest, DesignWriterTest, DimensionHandleTest, ExtendedReportItemTest, FactoryPropertyHandleTest, GridItemHandleTest, GroupHandleTest, GroupPropertyHandleTest, LabelHandleTest, MasterPageHandleTest, ParameterValidationUtilTest, PropertyHandleTest, PropertySortingTest, ReportDesignHandleTest, ReportElementHandleTest, ReportItemHandleTest, ScalarParameterHandleTest, SimpleMasterPageHandleTest, SlotHandleTest, TableItemHandleTest, TranslationHandleTest, UserPropertyHandleTest

public abstract class BaseTestCase
extends junit.framework.TestCase

This class is abstract class used for tests, which contains the design file name and report design handle, and provides the basic design file reading methods. This class performs mainly the following functionalities:

Note:

  • The derived unit test class must call 'super.setUp()' in their 'setUp' method.
  • In testing environment, when open a design file by calling openDesign( String fileName, InputStream is ), you can simply pass 'null' as the file name; but, when printing out the error list, to make the file name appear in the message, you can call 'design.setfileName( fileName )' in the child test case.

  • Field Summary
    protected  org.eclipse.birt.report.model.elements.ReportDesign design
              the root element for this design.
    protected  org.eclipse.birt.report.model.api.ReportDesignHandle designHandle
              The report design handle.
    protected static java.lang.String GOLDEN_FOLDER
               
    protected static java.lang.String INPUT_FOLDER
               
    protected static java.lang.String OUTPUT_FOLDER
               
    protected static java.lang.String PLUGIN_NAME
               
    protected static java.lang.String PLUGIN_PATH
               
    protected static java.lang.String PLUGINLOC
               
    protected static java.lang.String ROM_DEF_NAME
              The file name of metadata file.
    protected  org.eclipse.birt.report.model.api.SessionHandle sessionHandle
              The session handle.
    protected static java.lang.String TEST_FOLDER
               
    protected static java.util.Locale TEST_LOCALE
               
     
    Constructor Summary
    BaseTestCase(java.lang.String name)
               
     
    Method Summary
    protected  void compareErrors(java.lang.String filename)
              Compares the error messages against the golden file.
    protected  boolean compareTextFile(java.lang.String goldenFileName, java.lang.String outputFileName)
              Compares two text file.
    protected  boolean compareTextFileAsResource(java.lang.Class theClass, java.lang.String goldenFileName, java.lang.String outputFileName)
              Compares two text files.
    protected  org.eclipse.birt.report.model.api.ReportDesignHandle createDesign()
              Creates a new report.
    protected  org.eclipse.birt.report.model.api.ReportDesignHandle createDesign(java.util.Locale locale)
              Creates a new report with given locale.
    protected  void dumpErrors(java.lang.String filename)
              Dumps the parsing errors into a text file.
    protected  java.lang.String getClassFolder()
              Locates the folder where the unit test java source file is saved.
    protected  java.lang.String getFullQualifiedClassName()
              Returns the full qualified class name.
    protected  void openDesign(java.lang.String fileName)
              Opens design file with default locale.
    protected  void openDesign(java.lang.String fileName, java.io.InputStream is)
              Reads design file as InputStream.
    protected  void openDesign(java.lang.String fileName, java.io.InputStream is, java.util.Locale locale)
              Opens a design file.
    protected  void openDesign(java.lang.String fileName, java.util.Locale locale)
              Opens design file providing the file name and the locale.
    protected  void openDesignAsResource(java.lang.Class theClass, java.lang.String fileName)
              Opens design file as resource with default locale.
    protected  void openDesignAsResource(java.lang.Class theClass, java.lang.String fileName, java.util.Locale locale)
              Opens design file as resource with the given locale.
    protected  void printSemanticError(org.eclipse.birt.report.model.elements.ReportDesign design)
              Prints out all semantic errors stored in the error list during parsing the design file.
    protected  void printSemanticErrors()
              Prints out all semantic errors stored in the error list during parsing the design file.
    protected  void printSyntaxError(org.eclipse.birt.report.model.api.DesignFileException e)
              Prints out all syntax errors stored in the error list during parsing the design file.
    protected  void saveAs(java.lang.String filename)
              Eventually, this method will call ReportDesignHandle.saveAs(String)to save the output file of some unit test.
    protected  void saveAsInTempDir(java.lang.String filename)
              Saves the design file to temp directory.
    protected  void setUp()
               
    protected  void tearDown()
               
     
    Methods inherited from class junit.framework.TestCase
    countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
     
    Methods inherited from class junit.framework.Assert
    assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
     

    Field Detail

    designHandle

    protected org.eclipse.birt.report.model.api.ReportDesignHandle designHandle
    The report design handle.


    sessionHandle

    protected org.eclipse.birt.report.model.api.SessionHandle sessionHandle
    The session handle.


    design

    protected org.eclipse.birt.report.model.elements.ReportDesign design
    the root element for this design.


    ROM_DEF_NAME

    protected static final java.lang.String ROM_DEF_NAME
    The file name of metadata file.

    See Also:
    Constant Field Values

    PLUGIN_NAME

    protected static final java.lang.String PLUGIN_NAME
    See Also:
    Constant Field Values

    PLUGINLOC

    protected static final java.lang.String PLUGINLOC

    PLUGIN_PATH

    protected static final java.lang.String PLUGIN_PATH

    TEST_FOLDER

    protected static final java.lang.String TEST_FOLDER
    See Also:
    Constant Field Values

    OUTPUT_FOLDER

    protected static final java.lang.String OUTPUT_FOLDER
    See Also:
    Constant Field Values

    INPUT_FOLDER

    protected static final java.lang.String INPUT_FOLDER
    See Also:
    Constant Field Values

    GOLDEN_FOLDER

    protected static final java.lang.String GOLDEN_FOLDER
    See Also:
    Constant Field Values

    TEST_LOCALE

    protected static final java.util.Locale TEST_LOCALE
    Constructor Detail

    BaseTestCase

    public BaseTestCase(java.lang.String name)
    Method Detail

    setUp

    protected void setUp()
                  throws java.lang.Exception
    Throws:
    java.lang.Exception

    tearDown

    protected void tearDown()
                     throws java.lang.Exception
    Throws:
    java.lang.Exception

    createDesign

    protected org.eclipse.birt.report.model.api.ReportDesignHandle createDesign()
    Creates a new report.

    Returns:
    the handle for new report

    createDesign

    protected org.eclipse.birt.report.model.api.ReportDesignHandle createDesign(java.util.Locale locale)
    Creates a new report with given locale.

    Parameters:
    locale - the user locale
    Returns:
    the handle for new report

    openDesign

    protected void openDesign(java.lang.String fileName)
                       throws org.eclipse.birt.report.model.api.DesignFileException
    Opens design file with default locale.

    Parameters:
    fileName - design file name
    Throws:
    org.eclipse.birt.report.model.api.DesignFileException - if any exception

    openDesign

    protected void openDesign(java.lang.String fileName,
                              java.util.Locale locale)
                       throws org.eclipse.birt.report.model.api.DesignFileException
    Opens design file providing the file name and the locale.

    Parameters:
    fileName - the design file to be opened
    locale - the user locale
    Throws:
    org.eclipse.birt.report.model.api.DesignFileException - if any exception.

    openDesignAsResource

    protected void openDesignAsResource(java.lang.Class theClass,
                                        java.lang.String fileName)
                                 throws org.eclipse.birt.report.model.api.DesignFileException
    Opens design file as resource with default locale.

    Parameters:
    fileName - the file name without path
    Throws:
    org.eclipse.birt.report.model.api.DesignFileException - if any exception.

    openDesignAsResource

    protected void openDesignAsResource(java.lang.Class theClass,
                                        java.lang.String fileName,
                                        java.util.Locale locale)
                                 throws org.eclipse.birt.report.model.api.DesignFileException
    Opens design file as resource with the given locale.

    Parameters:
    fileName - the file name without path
    locale - the given locale
    Throws:
    org.eclipse.birt.report.model.api.DesignFileException - if any exception.

    openDesign

    protected void openDesign(java.lang.String fileName,
                              java.io.InputStream is)
                       throws org.eclipse.birt.report.model.api.DesignFileException
    Reads design file as InputStream.

    Parameters:
    fileName - Design file name
    is - InputStream of this design file
    Throws:
    org.eclipse.birt.report.model.api.DesignFileException - if any exception.

    openDesign

    protected void openDesign(java.lang.String fileName,
                              java.io.InputStream is,
                              java.util.Locale locale)
                       throws org.eclipse.birt.report.model.api.DesignFileException
    Opens a design file.

    Parameters:
    fileName - the design file name
    is - the input stream of the design file.
    locale - the user locale.
    Throws:
    org.eclipse.birt.report.model.api.DesignFileException - if any exception.

    compareTextFile

    protected boolean compareTextFile(java.lang.String goldenFileName,
                                      java.lang.String outputFileName)
                               throws java.lang.Exception
    Compares two text file. The comparison will ignore the line containing "modificationDate".

    Parameters:
    goldenFileName - the 1st file name to be compared.
    outputFileName - the 2nd file name to be compared.
    Returns:
    true if two text files are same line by line
    Throws:
    java.lang.Exception - if any exception.

    compareTextFileAsResource

    protected boolean compareTextFileAsResource(java.lang.Class theClass,
                                                java.lang.String goldenFileName,
                                                java.lang.String outputFileName)
                                         throws java.lang.Exception
    Compares two text files. The comparison will ignore the line containing "modificationDate".

    Parameters:
    goldenFileName - the golden file name. The golden file should be located with class loader.
    outputFileName - the output file name. The output file should be in temperary directory of Java VM.
    Returns:
    true if two text files are same line by line
    Throws:
    java.lang.Exception - if any exception.

    printSemanticErrors

    protected void printSemanticErrors()
    Prints out all semantic errors stored in the error list during parsing the design file.


    printSemanticError

    protected void printSemanticError(org.eclipse.birt.report.model.elements.ReportDesign design)
    Prints out all semantic errors stored in the error list during parsing the design file.

    Parameters:
    design - report design

    printSyntaxError

    protected void printSyntaxError(org.eclipse.birt.report.model.api.DesignFileException e)
    Prints out all syntax errors stored in the error list during parsing the design file.

    Parameters:
    e - DesignFileException containing syntax error list.

    dumpErrors

    protected void dumpErrors(java.lang.String filename)
                       throws java.lang.Exception
    Dumps the parsing errors into a text file.

    Parameters:
    filename - the file name into which the error will be dumped.
    Throws:
    java.lang.Exception - if any exception.

    saveAs

    protected void saveAs(java.lang.String filename)
                   throws java.io.IOException
    Eventually, this method will call ReportDesignHandle.saveAs(String)to save the output file of some unit test. The output test file will be saved in the folder of 'output' under the folder where the unit test java source file locates, so before calling ReportDesignHandle.saveAs(String), the file name will be modified to include the path information. For example, in a unit test class, it can call saveAs( "PropertyCommandTest.out" ).

    Parameters:
    filename - the test output file to be saved.
    Throws:
    java.io.IOException - if error occurs while saving the file.

    saveAsInTempDir

    protected void saveAsInTempDir(java.lang.String filename)
                            throws java.io.IOException
    Saves the design file to temp directory.

    Parameters:
    filename - the new file name to save
    Throws:
    java.io.IOException - if any exception

    getClassFolder

    protected java.lang.String getClassFolder()
    Locates the folder where the unit test java source file is saved.

    Returns:
    the path name where the test java source file locates.

    getFullQualifiedClassName

    protected java.lang.String getFullQualifiedClassName()
    Returns the full qualified class name. For example, "/org/eclipse/birt/report/model".

    Returns:
    the full qualified class name

    compareErrors

    protected void compareErrors(java.lang.String filename)
                          throws java.lang.Exception
    Compares the error messages against the golden file.

    Parameters:
    filename - the golden file name which contains the error messages.
    Throws:
    java.lang.Exception - if any exception