mysterious problems with some service tests
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 4 Jul 2012 09:56:00 +0000 (09:56 +0000)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 4 Jul 2012 09:56:00 +0000 (09:56 +0000)
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/database/TestingTermInitializerTest.java
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/test/integration/CdmIntegrationTest.java
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/test/unitils/CleanSweepInsertLoadStrategy.java
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/NameServiceImplTest.java
cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/NameServiceImplTest.xml

index 9d6b42d283e86473b7078555c2f68488fb5067bc..acbed5c64bb66455c790394f79a225a3c73ecc55 100644 (file)
@@ -34,60 +34,60 @@ public class TestingTermInitializerTest extends CdmIntegrationTest {
     private UUID taxonomicallyIncludedInUuid;\r
 \r
     @Before\r
-       public void setUp() {\r
-       taxonomicallyIncludedInUuid = UUID.fromString("d13fecdf-eb44-4dd7-9244-26679c05df1c");\r
+    public void setUp() {\r
+        taxonomicallyIncludedInUuid = UUID.fromString("d13fecdf-eb44-4dd7-9244-26679c05df1c");\r
     }\r
 \r
 //    @Test  uncomment for creating datasets\r
-       public void testPrintDataSet() {\r
-               try {\r
-                       ExcludeTableFilter filter = new ExcludeTableFilter();\r
-                       filter.excludeTable("Rights");  //throws exception wiht H2\r
-                       printDataSetWithNull(new FileOutputStream("NewDataSet.xml"), filter);\r
-               } catch (FileNotFoundException e) {\r
-                       e.printStackTrace();\r
-               }\r
-       }\r
+    public void testPrintDataSet() {\r
+        try {\r
+            ExcludeTableFilter filter = new ExcludeTableFilter();\r
+            filter.excludeTable("Rights");  //throws exception wiht H2\r
+            printDataSetWithNull(new FileOutputStream("NewDataSet.xml"), null, filter);\r
+        } catch (FileNotFoundException e) {\r
+            e.printStackTrace();\r
+        }\r
+    }\r
 \r
-       @Test\r
-       public void testInit() {\r
-               assertNotNull("TermInitializer should have initialized Language.DEFAULT",Language.DEFAULT());\r
-               assertEquals("Language.DEFAULT should equal Language.ENGLISH",Language.DEFAULT(),Language.ENGLISH());\r
-       }\r
+    @Test\r
+    public void testInit() {\r
+        assertNotNull("TermInitializer should have initialized Language.DEFAULT",Language.DEFAULT());\r
+        assertEquals("Language.DEFAULT should equal Language.ENGLISH",Language.DEFAULT(),Language.ENGLISH());\r
+    }\r
 \r
-       @Test\r
-       public void testMarkerTypeIds() {\r
-               assertEquals("We expect MarkerType.TO_BE_CHECKED to have an id of 893",893,MarkerType.TO_BE_CHECKED().getId());\r
-       }\r
+    @Test\r
+    public void testMarkerTypeIds() {\r
+        assertEquals("We expect MarkerType.TO_BE_CHECKED to have an id of 893",893,MarkerType.TO_BE_CHECKED().getId());\r
+    }\r
 \r
-       @Test\r
-       public void testFeatureIds() {\r
-               assertEquals("We expect Feature.ECOLOGY to have an id of 922",922,Feature.ECOLOGY().getId());\r
-       }\r
+    @Test\r
+    public void testFeatureIds() {\r
+        assertEquals("We expect Feature.ECOLOGY to have an id of 922",922,Feature.ECOLOGY().getId());\r
+    }\r
 \r
-       /**\r
-        * Test method for {@link eu.etaxonomy.cdm.model.taxon.ConceptRelationshipType#TAXONOMICALLY_INCLUDED_IN()}.\r
-        */\r
-       @Test\r
-       public final void testTermsAreLoaded() {\r
-               assertNotNull("TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN should have been initialized",TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN());\r
-               assertEquals("TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN should have a uuid of " + taxonomicallyIncludedInUuid.toString(),taxonomicallyIncludedInUuid, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN().getUuid());\r
-               assertNotNull("SynonymRelationshipType.INFERREDEPITHET should be loaded" + SynonymRelationshipType.INFERRED_EPITHET_OF());\r
-       }\r
+    /**\r
+     * Test method for {@link eu.etaxonomy.cdm.model.taxon.ConceptRelationshipType#TAXONOMICALLY_INCLUDED_IN()}.\r
+     */\r
+    @Test\r
+    public final void testTermsAreLoaded() {\r
+        assertNotNull("TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN should have been initialized",TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN());\r
+        assertEquals("TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN should have a uuid of " + taxonomicallyIncludedInUuid.toString(),taxonomicallyIncludedInUuid, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN().getUuid());\r
+        assertNotNull("SynonymRelationshipType.INFERREDEPITHET should be loaded" + SynonymRelationshipType.INFERRED_EPITHET_OF());\r
+    }\r
 \r
-       @Test\r
-       public void testUnlazyStatusTerms() {\r
-                       assertNotNull("NomenclaturalStatusType.SUPERFLUOUS should exist",NomenclaturalStatusType.SUPERFLUOUS());\r
-                       assertNotNull("NomenclaturalStatusType.NUDUM should exist",NomenclaturalStatusType.NUDUM());\r
-                       assertNotNull("NomenclaturalStatusType.ILLEGITIMATE should exist",NomenclaturalStatusType.ILLEGITIMATE());\r
-                       assertNotNull("NomenclaturalStatusType.INVALID should exist",NomenclaturalStatusType.INVALID());\r
-                       assertNotNull("NomenclaturalStatusType.CONSERVED should exist",NomenclaturalStatusType.CONSERVED());\r
-                       assertNotNull("NomenclaturalStatusType.ALTERNATIVE should exist",NomenclaturalStatusType.ALTERNATIVE());\r
-                       assertNotNull("NomenclaturalStatusType.REJECTED should exist",NomenclaturalStatusType.REJECTED());\r
-                       assertNotNull("NomenclaturalStatusType.REJECTED_PROP should exist",NomenclaturalStatusType.REJECTED_PROP());\r
-                       assertNotNull("NomenclaturalStatusType.PROVISIONAL should exist",NomenclaturalStatusType.PROVISIONAL());\r
-                       assertNotNull("NomenclaturalStatusType.SUBNUDUM should exist",NomenclaturalStatusType.SUBNUDUM());\r
-                       assertNotNull("NomenclaturalStatusType.OPUS_UTIQUE_OPPR should exist",NomenclaturalStatusType.OPUS_UTIQUE_OPPR());\r
-                       assertNotNull("NomenclaturalStatusType.VALID should exist",NomenclaturalStatusType.VALID());\r
-       }\r
+    @Test\r
+    public void testUnlazyStatusTerms() {\r
+            assertNotNull("NomenclaturalStatusType.SUPERFLUOUS should exist",NomenclaturalStatusType.SUPERFLUOUS());\r
+            assertNotNull("NomenclaturalStatusType.NUDUM should exist",NomenclaturalStatusType.NUDUM());\r
+            assertNotNull("NomenclaturalStatusType.ILLEGITIMATE should exist",NomenclaturalStatusType.ILLEGITIMATE());\r
+            assertNotNull("NomenclaturalStatusType.INVALID should exist",NomenclaturalStatusType.INVALID());\r
+            assertNotNull("NomenclaturalStatusType.CONSERVED should exist",NomenclaturalStatusType.CONSERVED());\r
+            assertNotNull("NomenclaturalStatusType.ALTERNATIVE should exist",NomenclaturalStatusType.ALTERNATIVE());\r
+            assertNotNull("NomenclaturalStatusType.REJECTED should exist",NomenclaturalStatusType.REJECTED());\r
+            assertNotNull("NomenclaturalStatusType.REJECTED_PROP should exist",NomenclaturalStatusType.REJECTED_PROP());\r
+            assertNotNull("NomenclaturalStatusType.PROVISIONAL should exist",NomenclaturalStatusType.PROVISIONAL());\r
+            assertNotNull("NomenclaturalStatusType.SUBNUDUM should exist",NomenclaturalStatusType.SUBNUDUM());\r
+            assertNotNull("NomenclaturalStatusType.OPUS_UTIQUE_OPPR should exist",NomenclaturalStatusType.OPUS_UTIQUE_OPPR());\r
+            assertNotNull("NomenclaturalStatusType.VALID should exist",NomenclaturalStatusType.VALID());\r
+    }\r
 }\r
index 8d11d78897942db49565ab1fdf4ead3421d8406d..ea4ce3c5f836b5978d012237d4f80296258f6875 100644 (file)
@@ -20,6 +20,9 @@ import java.io.OutputStreamWriter;
 import java.net.URISyntaxException;\r
 import java.net.URL;\r
 import java.sql.SQLException;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Collections;\r
 import java.util.List;\r
 \r
 import javax.sql.DataSource;\r
@@ -62,6 +65,7 @@ import org.unitils.spring.annotation.SpringApplicationContext;
 import org.unitils.spring.annotation.SpringBean;\r
 import org.unitils.spring.annotation.SpringBeanByType;\r
 \r
+import eu.etaxonomy.cdm.database.PersistentTermInitializer;\r
 import eu.etaxonomy.cdm.model.agent.AgentBase;\r
 import eu.etaxonomy.cdm.persistence.dao.agent.IAgentDao;\r
 import eu.etaxonomy.cdm.persistence.dao.hibernate.agent.AgentDaoImpl;\r
@@ -76,8 +80,28 @@ import eu.etaxonomy.cdm.test.unitils.FlatFullXmlWriter;
  */\r
 @SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/applicationContext-test.xml")\r
 public abstract class CdmIntegrationTest extends UnitilsJUnit4 {\r
+\r
     protected static final Logger logger = Logger.getLogger(CdmIntegrationTest.class);\r
 \r
+    /**\r
+     * List of the tables which are initially being populated during term loading. {@link PersistentTermInitializer}\r
+     */\r
+    public static final String[] termLoadingTables = new String[]{\r
+        "DEFINEDTERMBASE",\r
+        "DEFINEDTERMBASE_AUD",\r
+        "DEFINEDTERMBASE_CONTINENT",\r
+        "DEFINEDTERMBASE_REPRESENTATION",\r
+        "DEFINEDTERMBASE_REPRESENTATION_AUD",\r
+        "HIBERNATE_SEQUENCES",\r
+        "RELATIONSHIPTERMBASE_INVERSEREPRESENTATION",\r
+        "RELATIONSHIPTERMBASE_INVERSEREPRESENTATION_AUD",\r
+        "REPRESENTATION",\r
+        "REPRESENTATION_AUD",\r
+        "TERMVOCABULARY",\r
+        "TERMVOCABULARY_AUD",\r
+        "TERMVOCABULARY_REPRESENTATION",\r
+        "TERMVOCABULARY_REPRESENTATION_AUD"};\r
+\r
 //     @SpringBeanByType\r
 //     private IAgentDao agentDao;\r
 //\r
@@ -116,7 +140,7 @@ public abstract class CdmIntegrationTest extends UnitilsJUnit4 {
 \r
     /**\r
      * Prints the data set to an output stream, using the\r
-     * {@link FlatFullXmlWriter}.\r
+     * {@link FlatXmlDataSet}.\r
      * <p>\r
      * <h2>NOTE: for compatibility with unitils 3.x you may\r
      * want to use the {@link #printDataSetWithNull(OutputStream)}\r
@@ -171,20 +195,27 @@ public abstract class CdmIntegrationTest extends UnitilsJUnit4 {
      * @see FlatFullXmlWriter\r
      */\r
     public void printDataSetWithNull(OutputStream out) {\r
-       printDataSetWithNull(out, null);\r
+        printDataSetWithNull(out, null, null);\r
     }\r
-    \r
-    public void printDataSetWithNull(OutputStream out, ITableFilterSimple filter) {\r
+\r
+    public void printDataSetWithNull(OutputStream out, Boolean excludeTermLoadingTables, ITableFilterSimple filter) {\r
+\r
+        if(excludeTermLoadingTables != null && excludeTermLoadingTables.equals(true)){\r
+            ExcludeTableFilter excludeTableFilter = new ExcludeTableFilter();\r
+\r
+            for(String tname : termLoadingTables){\r
+                excludeTableFilter.excludeTable(tname);\r
+            }\r
+            filter = excludeTableFilter;\r
+        }\r
+\r
         if (filter == null){\r
-               filter = new ExcludeTableFilter();\r
+            filter = new ExcludeTableFilter();\r
         }\r
-       IDatabaseConnection connection = null;\r
-        \r
-        \r
+\r
+        IDatabaseConnection connection = null;\r
         try {\r
             connection = getConnection();\r
-\r
-//                     IDataSet dataSet = connection.createDataSet();\r
             DatabaseDataSet dataSet = new DatabaseDataSet(connection, false, filter);\r
 \r
             FlatFullXmlWriter writer = new FlatFullXmlWriter(out);\r
@@ -253,7 +284,7 @@ public abstract class CdmIntegrationTest extends UnitilsJUnit4 {
             IDataSet actualDataSet = connection.createDataSet(tableNames);\r
             FlatXmlDataSet.write(actualDataSet, out);\r
 \r
-            \r
+\r
         } catch (Exception e) {\r
             logger.error(e);\r
         } finally {\r
@@ -275,10 +306,10 @@ public abstract class CdmIntegrationTest extends UnitilsJUnit4 {
      */\r
     public void printDataSet(OutputStream out, ITableFilterSimple filter) {\r
         if (filter == null){\r
-               filter = new ExcludeTableFilter();\r
+            filter = new ExcludeTableFilter();\r
         }\r
-        \r
-       IDatabaseConnection connection = null;\r
+\r
+        IDatabaseConnection connection = null;\r
 \r
         try {\r
             connection = getConnection();\r
@@ -288,7 +319,7 @@ public abstract class CdmIntegrationTest extends UnitilsJUnit4 {
 \r
             FlatXmlWriter writer = new FlatXmlWriter(out);\r
             writer.write(dataSet);\r
-            \r
+\r
         } catch (Exception e) {\r
             logger.error(e);\r
         } finally {\r
@@ -300,7 +331,7 @@ public abstract class CdmIntegrationTest extends UnitilsJUnit4 {
         }\r
     }\r
 \r
-    \r
+\r
     /**\r
      * Prints a dtd to an output stream, using dbunit's\r
      * {@link org.dbunit.dataset.xml.FlatDtdDataSet}.\r
index 13e696f4e28e11484f2e8cdf0c7935a1cc1aca40..857036fc2f3fed53f18d080bf3af15a1a140ff32 100644 (file)
@@ -100,8 +100,9 @@ public class CleanSweepInsertLoadStrategy extends CleanInsertLoadStrategy {
      * @param classPathResourceName
      * @param fileSystemDirectoryName
      * @return
+     * @throws IOException
      */
-    public File copyClassPathResource(URL resourceURL, String fileSystemDirectoryName) {
+    public File copyClassPathResource(URL resourceURL, String fileSystemDirectoryName) throws IOException {
 
         InputStream resourceInputStream = null;
         OutputStream fileOutputStream = null;
@@ -115,8 +116,11 @@ public class CleanSweepInsertLoadStrategy extends CleanInsertLoadStrategy {
             fileOutputStream = new FileOutputStream(filePath);
             IOUtils.copy(resourceInputStream, fileOutputStream);
             file = new File(filePath);
+            if(!file.canRead()){
+                throw new IOException("tmp file " + file.toString() + " not readable.");
+            }
         } catch (IOException e) {
-            throw new UnitilsException(e);
+            throw e;
         } finally {
             closeQuietly(resourceInputStream);
             closeQuietly(fileOutputStream);
index 949e51460da09d123c428b772c47ecf2871a46c6..7f15a7cffde4277e8f54c66ff19e422979edb57f 100644 (file)
 <RELATIONSHIPTERMBASE_INVERSEREPRESENTATION />\r
 <RELATIONSHIPTERMBASE_INVERSEREPRESENTATION_AUD />\r
 <REPRESENTATION />\r
+<REPRESENTATION_AUD />\r
 <REPRESENTATION_ANNOTATION />\r
 <REPRESENTATION_ANNOTATION_AUD />\r
-<REPRESENTATION_AUD />\r
 <REPRESENTATION_MARKER />\r
 <REPRESENTATION_MARKER_AUD />\r
   <RIGHTS/>\r
index 3d1424f740b9e21eb1baeb5ce3c49f128449de1f..ebd8eb9026151ddf4f1effd8e7cd727fbd1a5be6 100644 (file)
@@ -190,6 +190,8 @@ public class NameServiceImplTest extends CdmTransactionalIntegrationTest {
     public void testDeleteTaxonNameBaseWithNameRelations() {\r
         final String[] tableNames = new String[]{"TaxonNameBase","NameRelationship","HybridRelationship","DescriptionBase","NomenclaturalStatus","TaxonBase","SpecimenOrObservationBase","OriginalSourceBase","DescriptionElementBase"};\r
 \r
+        printDataSet(System.err, new String[]{"TaxonNameBase","NameRelationship","HybridRelationship","DescriptionBase","NomenclaturalStatus","TaxonBase","SpecimenOrObservationBase","OriginalSourceBase","DescriptionElementBase","USERACCOUNT","USERACCOUNT_PERMISSIONGROUP", "USERACCOUNT_GRANTEDAUTHORITYIMPL", "GRANTEDAUTHORITYIMPL"});\r
+\r
         NonViralName<?> name1 = BotanicalName.NewInstance(getSpeciesRank());\r
         name1.setTitleCache("Name1", true);\r
         TaxonNameBase<?,?> nameWithBasionym = BotanicalName.NewInstance(getSpeciesRank());\r
@@ -236,6 +238,12 @@ public class NameServiceImplTest extends CdmTransactionalIntegrationTest {
     public void testDeleteTaxonNameBaseConfiguratorWithNameRelations() {\r
         final String[] tableNames = new String[]{"TaxonNameBase","NameRelationship","HybridRelationship"};\r
 \r
+//        printDataSet(System.err, new String[]{"TaxonNameBase","NameRelationship","HybridRelationship","DescriptionBase","NomenclaturalStatus","TaxonBase","SpecimenOrObservationBase","OriginalSourceBase",\r
+//                "DescriptionElementBase",\r
+//                "AGENTBASE", "USERACCOUNT", "PERMISSIONGROUP", "USERACCOUNT_PERMISSIONGROUP", "USERACCOUNT_GRANTEDAUTHORITYIMPL", "GRANTEDAUTHORITYIMPL"});\r
+\r
+        printDataSetWithNull(System.err, true, null);\r
+\r
         NonViralName<?> name1 = BotanicalName.NewInstance(getSpeciesRank());\r
         name1.setTitleCache("Name1", true);\r
         TaxonNameBase<?,?> nameWithBasionym = BotanicalName.NewInstance(getSpeciesRank());\r
index 035778ae7faa47607a1901d0debf823967cb0aaf..a273f29b6737a4bea72da82cde3d58da33aa92e4 100644 (file)
@@ -6,14 +6,16 @@
 \r
   <TYPEDESIGNATIONBASE DTYPE="SpecimenTypeDesignation" ID="10" CREATED="2011-10-06 12:10:14.0" UUID="9bbda70b-7272-4e65-a807-852a3f2eba63" NOTDESIGNATED="false" TYPESPECIMEN_ID="10" CONSERVEDTYPE="[null]" REJECTEDTYPE="[null]" TYPENAME_ID="[null]"/>\r
   <TYPEDESIGNATIONBASE DTYPE="SpecimenTypeDesignation" ID="11" CREATED="2011-10-06 12:10:14.0" UUID="1357c307-00c3-499c-8e20-0849d4706125" NOTDESIGNATED="false" TYPESPECIMEN_ID="11" CONSERVEDTYPE="[null]" REJECTEDTYPE="[null]" TYPENAME_ID="[null]"/>\r
-  <TYPEDESIGNATIONBASE DTYPE="NameTypeDesignation" ID="12" CREATED="2011-10-06 12:10:14.0" UUID="0b67b4e1-3183-4272-ace8-7b533f2cc2e5" NOTDESIGNATED="false"  TYPESPECIMEN_ID="[null]" CONSERVEDTYPE="false" REJECTEDTYPE="false" TYPENAME_ID="10"/>\r
+  <TYPEDESIGNATIONBASE DTYPE="NameTypeDesignation"     ID="12" CREATED="2011-10-06 12:10:14.0" UUID="0b67b4e1-3183-4272-ace8-7b533f2cc2e5" NOTDESIGNATED="false"  TYPESPECIMEN_ID="[null]" CONSERVEDTYPE="false" REJECTEDTYPE="false" TYPENAME_ID="10"/>\r
 \r
   <TAXONNAMEBASE_TYPEDESIGNATIONBASE TYPEDESIGNATIONS_ID="10" TAXONNAMEBASE_ID="10"/>\r
   <TAXONNAMEBASE_TYPEDESIGNATIONBASE TYPEDESIGNATIONS_ID="11" TAXONNAMEBASE_ID="10"/>\r
   <TAXONNAMEBASE_TYPEDESIGNATIONBASE TYPEDESIGNATIONS_ID="11" TAXONNAMEBASE_ID="11"/>\r
   <TAXONNAMEBASE_TYPEDESIGNATIONBASE TYPEDESIGNATIONS_ID="12" TAXONNAMEBASE_ID="12"/>\r
+\r
   <SPECIMENOROBSERVATIONBASE DTYPE="Fossil" ID="10" CREATED="2011-10-06 12:10:14.0" UUID="4c48b7c8-4c8d-4e48-b083-0837fe51a0a9" PROTECTEDTITLECACHE="false" TITLECACHE="-title cache generation not implemented-"/>\r
   <SPECIMENOROBSERVATIONBASE DTYPE="Specimen" ID="11" CREATED="2011-10-06 12:10:14.0" UUID="0d19a9ca-21a7-4adb-8640-8d6719e15eea" PROTECTEDTITLECACHE="false" TITLECACHE="-title cache generation not implemented-"/>\r
+\r
   <HOMOTYPICALGROUP ID="1" CREATED="2011-10-12 19:57:31.0" UUID="d8652fa0-eff9-460d-8990-aed0ebf1322e"/>\r
   <HOMOTYPICALGROUP ID="2" CREATED="2011-10-12 19:57:31.0" UUID="2a1b0776-b4b5-462a-9be7-f88378ebd732"/>\r
   <HOMOTYPICALGROUP ID="3" CREATED="2011-10-12 19:57:31.0" UUID="3ac4e376-31cd-47fd-9dd6-eaff415ff0e7"/>\r