Menu

Cannot get tests to run in Maven

Users
Sean Blaes
2007-07-10
2013-05-28
  • Sean Blaes

    Sean Blaes - 2007-07-10

    Hi all, I'm having trouble getting tests to run through Maven, through they run great through eclipse.  My errors are slightly different from the prior thread dealing with this, and I already tried adding the srce/test/java path to my test resources in my maven POM.  Here's the error I'm seeing:

    org.unitils.core.unitilsException: Error inserting test data from DbUnit dataset for method public void ...
    at org.unitils.dbunit.DbUnitModule.insertTestData(DbUnitModule.java:151)
    ...
    Caused by: org.unitils.core.UnitilsException: Unable to create DbUnitDataset for file FooTest.xml
    ...
    Caused by: org.unitils.core.UnitilsException: Unable to create DbUnit dataset for input stream.
    ...
    Caused by: org.unitils.core.UnitilsException: Unable to parse data set xml.
    ...
    Caused by: org.unitils.core.UnitilsException: Unable to create SAX parser to read data set xml
    ...
    Caused by: org.xml.sax.SAXNotRecognizedException: Feature: http://xml.org/sax/features/external-parameter-entities
    ...

    Anybody have any idea what's going on here?  I've been looking into this for about 3 days and just can't get maven to run the tests (though through eclipse, they run great).

     
    • Sean Blaes

      Sean Blaes - 2007-07-12

      Does anybody have any ideas on this?  I've still been hacking at this problem and I'm rather at a loss.  I was thinking that perhaps it was a problem with my version of xerces, so I tried overriding my Maven POM to force it to use the latest Xerces, but that didn't help either.  Any ideas at all?

       
    • Tim Ducheyne

      Tim Ducheyne - 2007-08-06

      Sorry for the late response (been on vacation :)

      I think SAX is unable to load the external entities. If you're using a DTD, it could be that the DTD could not be found.
      Could you post the pom file and the full stack traces? Could you also post the FooTest.xml?
      Is a DTD declared in the FooTest.xml? If so, are you using a SYSTEM declaration?

      grtz,
      Tim

       
      • Sean Blaes

        Sean Blaes - 2007-08-06

        Hi Tim, thanks for your help.

        I assume you're referring to my dbunit dataset.  No, I don't have any doctype declared at all actually.  Following is the beginning few lines of my xml dataset (I just have the xml prologue, that's it):

        <?xml version='1.0' encoding='UTF-8'?>
        <dataset>
            <collection id="1000" code="ML" name="Modern Legacy" />   
        ...

        There is probably too much in my POMs to post, but generally they're pretty standard stuff.  The only thing that I can think of that's unitils specific is the following, which I did after seeing a reference in an old message that make me think it might help:

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <source>1.5</source>
                            <target>1.5</target>
                        </configuration>
                    </plugin>
                <!--  you need surfire 2.3 or better to run junit4 tests -->
                <plugin>
                     <artifactId>maven-surefire-plugin</artifactId>
                         <version>2.3</version>
                   </plugin>
                </plugins>
            </build>

        If there's anything in particularly you were looking for in my POM, let me know, otherwise I can email them to you directly rather than through the list.

         
    • Sean Blaes

      Sean Blaes - 2007-08-06

      Sorry, on that last email, I forgot to give you the stack trace:

      testGetTotalOfWinningBids(com.thecollectorsfund.auction.domain.test.BidDaoTest)  Time elapsed: 0 sec  <<< ERROR!
      org.unitils.core.UnitilsException: Error inserting test data from DbUnit dataset for method public void com.thecollectorsfund.auction.domain.test.BidDaoTest.testGetTotalOfWinningBids()
          at org.unitils.dbunit.DbUnitModule.insertTestData(DbUnitModule.java:151)
          at org.unitils.dbunit.DbUnitModule$DbUnitListener.beforeTestMethod(DbUnitModule.java:477)
          at org.unitils.core.Unitils$UnitilsTestListener.beforeTestMethod(Unitils.java:242)
          at org.unitils.UnitilsJUnit4TestClassRunner$CustomTestMethodRunner.executeMethodBody(UnitilsJUnit4TestClassRunner.java:207)
          at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
          at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
          at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
          at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
          at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
          at org.unitils.UnitilsJUnit4TestClassRunner$CustomTestClassMethodsRunner.invokeTestMethod(UnitilsJUnit4TestClassRunner.java:141)
          at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
          at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
          at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
          at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
          at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:84)
          at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
          at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
          at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
          at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:585)
          at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290)
          at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818)
      Caused by: org.unitils.core.UnitilsException: Unable to create DbUnit dataset for file BidDaoTest.xml
          at org.unitils.dbunit.DbUnitModule.getDataSet(DbUnitModule.java:310)
          at org.unitils.dbunit.DbUnitModule.getTestDataSets(DbUnitModule.java:251)
          at org.unitils.dbunit.DbUnitModule.insertTestData(DbUnitModule.java:139)
          ... 24 more
      Caused by: org.unitils.core.UnitilsException: Unable to create DbUnit dataset for input stream.
          at org.unitils.dbunit.DbUnitModule.getDataSet(DbUnitModule.java:334)
          at org.unitils.dbunit.DbUnitModule.getDataSet(DbUnitModule.java:307)
          ... 26 more
      Caused by: org.unitils.core.UnitilsException: Unable to parse data set xml.
          at org.unitils.dbunit.util.MultiSchemaXmlDataSetReader.readDataSetXml(MultiSchemaXmlDataSetReader.java:99)
          at org.unitils.dbunit.DbUnitModule.getDataSet(DbUnitModule.java:331)
          ... 27 more
      Caused by: org.unitils.core.UnitilsException: Unable to create SAX parser to read data set xml.
          at org.unitils.dbunit.util.MultiSchemaXmlDataSetReader.createXMLReader(MultiSchemaXmlDataSetReader.java:122)
          at org.unitils.dbunit.util.MultiSchemaXmlDataSetReader.readDataSetXml(MultiSchemaXmlDataSetReader.java:91)
          ... 28 more
      Caused by: org.xml.sax.SAXNotRecognizedException: Feature: http://xml.org/sax/features/external-parameter-entities
          at org.apache.xerces.jaxp.SAXParserFactoryImpl.setFeature(SAXParserFactoryImpl.java:100)
          at org.unitils.dbunit.util.MultiSchemaXmlDataSetReader.createXMLReader(MultiSchemaXmlDataSetReader.java:116)
          ... 29 more

       
    • Sean Blaes

      Sean Blaes - 2007-08-06

      Just in case...  Here's my unitils.properties file:

      database.driverClassName=org.hsqldb.jdbcDriver
      database.url=jdbc:hsqldb:hsql
      database.userName=sa
      database.password=
      database.dialect=hsqldb
      database.schemaNames=public
      updateDataBaseSchema.enabled=false
      dataSetStructureGenerator.xsd.dirName=target/xsd
      DbUnitModule.DataSet.loadStrategy.default=org.unitils.dbunit.datasetloadstrategy.CleanInsertLoadStrategy

       
    • Tim Ducheyne

      Tim Ducheyne - 2007-08-07

      Ok this is a bug in Unitils. If the used parser does not support external entities, setting the external-parameter-entities will throw a Sax not recognized exception (see description below).

      I set this feature to false, to disable the loading of DTDs and XSDs:

      org.unitils.dbunit.util.MultiSchemaXmlDataSetReader:116
      // disable validation, so dataset can still be used when a DTD or XSD is missing
      saxParserFactory.setValidating(false);
      saxParserFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
      saxParserFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

      I will have to change the initialisation of the XMLReader so that setting this features is done in a try-catch. I'll make a snapshot build available when it's fixed.
      You could also try to upgrade to a parser that supports the feature.

      Description external-parameter-entities:
      If http://xml.org/sax/features/external-parameter-entities is true, then
      the parser resolves all external parameter entity references. If it’s
      false, it does not. If the parser is validating, then this feature is
      required to be true.

      The default value of this feature is parser-dependent. Not all parsers
      are able to resolve external entity references. Attempting to set this
      to true with a parser that cannot resolve external entity references
      will throw a SAXNotRecognizedException

      grtz,
      Tim

       
    • Sean Blaes

      Sean Blaes - 2007-08-07

      I see.  What parser are you using?

       
    • Tim Ducheyne

      Tim Ducheyne - 2007-08-09

      I'm using the parser shipped with Java (i.e. if you have no xerces in your classpath)
      I was able to reproduce the error when I switched to xerces.

      This is a major bug for which a fix should be released asap.

      If you want I can give you the source of the fixed class. If you put that in your project, it will enable you to load the datasets.

      This weekend I'm going to release a snapshot build that will contain this fix.

      sorry for the inconvenience and
      thanks for reporting this,
      Tim  

       
    • Tim Ducheyne

      Tim Ducheyne - 2007-08-15

      The new rc 4 release contains a fix for this bug.

      The parser features are now set in a try catch to avoid the
      exception when the parser does not support the feature.

      grtz,
      Tim

       

Anonymous
Anonymous

Add attachments
Cancel