implemented tests for marker scope on descriptions
authorAndreas Müller <a.mueller@bgbm.org>
Tue, 22 Nov 2011 12:18:28 +0000 (12:18 +0000)
committerAndreas Müller <a.mueller@bgbm.org>
Tue, 22 Nov 2011 12:18:28 +0000 (12:18 +0000)
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/description/IDescriptionDao.java
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/DescriptionDaoImpl.java
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/DescriptionDaoHibernateImplTest.java
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/description/DescriptionDaoHibernateImplTest.xml

index 71c05c7863b87e14bafd58ddad79cdb70e330325..d847c44b7f8f05d1b410326a495695fbbb806ad1 100644 (file)
@@ -85,13 +85,13 @@ public interface IDescriptionDao extends IIdentifiableDao<DescriptionBase> {
         * @param taxon The taxon which the description refers to (can be null for all TaxonDescription instances)\r
         * @param scopes Restrict the results to those descriptions which are scoped by one of the Scope instances passed (can be null or empty)\r
         * @param geographicalScope Restrict the results to those descriptions which have a geographical scope that overlaps with the NamedArea instances passed (can be null or empty)\r
-        * @param markerType Restrict the results to those descriptions which are marked as true by one of the given marker types (can be null or empty)\r
+        * @param markerTypes Restrict the results to those descriptions which are marked as true by one of the given marker types (can be null or empty)\r
         * @param pageSize The maximum number of descriptions returned (can be null for all descriptions)\r
         * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)\r
         * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}\r
         * @return a List of TaxonDescription instances\r
         */\r
-       List<TaxonDescription> getTaxonDescriptions(Taxon taxon, Set<Scope> scopes, Set<NamedArea> geographicalScope, Set<MarkerType> markerType, Integer pageSize, Integer pageNumber, List<String> propertyPaths);\r
+       List<TaxonDescription> getTaxonDescriptions(Taxon taxon, Set<Scope> scopes, Set<NamedArea> geographicalScope, Set<MarkerType> markerTypes, Integer pageSize, Integer pageNumber, List<String> propertyPaths);\r
        \r
        /**\r
         * Returns a count of TaxonDescription instances, optionally filtered by parameters passed to this method\r
index 4f653ea0b3f5314f84695b5725bf5754cf3c17d2..d2f2e022e8ae62c8acbd9c8e6d92f953062b5817 100644 (file)
@@ -234,7 +234,7 @@ public class DescriptionDaoImpl extends IdentifiableDaoBase<DescriptionBase> imp
                        }\r
                        criteria.createCriteria("markers").add(Restrictions.eq("flag", true))\r
                                        .createAlias("markerType", "mt")\r
-                                       .add(Restrictions.in("id", markerTypeIds));\r
+                                       .add(Restrictions.in("mt.id", markerTypeIds));\r
                }\r
        }\r
 \r
index 51efcb71e2b299b870663451fa1d279ff2f4b3a6..23c06fb483114b56130f1873c89451b49d52efb3 100644 (file)
@@ -32,12 +32,15 @@ import org.unitils.spring.annotation.SpringBeanByType;
 
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.LanguageString;
+import eu.etaxonomy.cdm.model.common.Marker;
+import eu.etaxonomy.cdm.model.common.MarkerType;
 import eu.etaxonomy.cdm.model.description.AbsenceTerm;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Distribution;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.PresenceTerm;
+import eu.etaxonomy.cdm.model.description.Scope;
 import eu.etaxonomy.cdm.model.description.Sex;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.description.TextData;
@@ -358,5 +361,63 @@ public class DescriptionDaoHibernateImplTest extends CdmIntegrationTest {
                
        }
        
+       @Test
+       public void testListTaxonDescriptionWithMarker(){
+               Taxon taxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("b04cc9cb-2b4a-4cc4-a94a-3c93a2158b06"));
+               Set<Scope> scopes = null;
+               Set<NamedArea> geographicalScope = null;
+               Integer pageSize = null;
+               Integer pageNumber = null;
+               List<String> propertyPaths = null;
+               
+               //complete
+               MarkerType completeMarkerType = (MarkerType)this.definedTermDao.findByUuid(UUID.fromString("b4b1b2ab-89a8-4ce6-8110-d60b8b1bc433")); //Marker "complete"
+               Assert.assertNotNull("MarkerType for 'complete' should exist", completeMarkerType);
+               Set<MarkerType> markerTypes = new HashSet<MarkerType>();
+               markerTypes.add(completeMarkerType);
+               int n1 = this.descriptionDao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
+               Assert.assertEquals("There should be 1 description marked 'complete'", 1, n1);
+               List<TaxonDescription> descriptions = this.descriptionDao.getTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
+               Assert.assertEquals("There should be 1 description marked 'complete'", 1, descriptions.size());
+               
+               //doubtful
+               MarkerType isDoubtfulMarkerType = (MarkerType)this.definedTermDao.findByUuid(UUID.fromString("b51325c8-05fe-421a-832b-d86fc249ef6e")); //Marker "doubtful"
+               Assert.assertNotNull("MarkerType for 'doubtful' should exist", isDoubtfulMarkerType);
+               markerTypes = new HashSet<MarkerType>();  //reset
+               markerTypes.add(isDoubtfulMarkerType);
+               int n2 = this.descriptionDao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
+               Assert.assertEquals("There should be no description marked 'doubtful'", 0, n2);
+               descriptions = this.descriptionDao.getTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
+               Assert.assertEquals("There should be 0 description marked 'doubtful'", 0, descriptions.size());
+               
+               //imported = false
+               UUID uuidImported = UUID.fromString("96878790-4ceb-42a2-9738-a2242079b679");
+               MarkerType importedMarkerType = (MarkerType)this.definedTermDao.findByUuid(uuidImported); 
+               Assert.assertNotNull("MarkerType for 'imported' should exist", completeMarkerType);
+               markerTypes = new HashSet<MarkerType>();
+               markerTypes.add(importedMarkerType);
+               int n3 = this.descriptionDao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
+               Assert.assertEquals("There should be no description marked 'imported' as true", 0, n3);
+               descriptions = this.descriptionDao.getTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
+               Assert.assertEquals("There should be no description marked 'imported' as true", 0, descriptions.size());
+               markerTypes = null;
+               descriptions = this.descriptionDao.getTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
+               Assert.assertEquals("There should be 1 description", 1, descriptions.size());
+               TaxonDescription desc = descriptions.iterator().next();
+               
+               Set<Marker> markers = desc.getMarkers();
+               boolean hasMarkerImportedAsFalse = false;
+               for (Marker marker: markers){
+                       if (marker.getMarkerType().getUuid().equals(uuidImported)){
+                               if (marker.getFlag() == false){
+                                       hasMarkerImportedAsFalse = true;
+                                       break;
+                               }
+                       }
+               }
+               Assert.assertTrue("The only description should have a negative marker on 'imported'", hasMarkerImportedAsFalse);
+               
+       }
+       
        
 }
index af7df680d54996f6317ef8b7357a2bcc27eb0009..5d36d2774d1da6aa025243d9aa10dfd88b5bfab5 100644 (file)
Binary files a/cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml and b/cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml differ
index 863e7c53da122dc9589a66b6f8a785dfd15dda9d..c043aa305ea8ef79d3036bac12e4eb05050dbea3 100644 (file)
   <DESCRIPTIONBASE DTYPE="TaxonDescription" ID="31" CREATED="2008-12-10 09:56:07.0" UUID="fd6cdb64-142c-4df1-b366-c5e76f08a1fc" UPDATED="2008-12-10 09:56:07.253" TITLECACHE="Acherontia lachesis (Fabricius, 1798) sec. cate-sphingidae.org" PROTECTEDTITLECACHE="true" TAXON_ID="36" IMAGEGALLERY="false"/>
   <DESCRIPTIONBASE DTYPE="TaxonDescription" ID="32" CREATED="2008-12-10 09:56:07.0" UUID="6d647bbe-5d91-46be-87f5-1781d9d5842c" UPDATED="2008-12-10 09:56:07.253" TITLECACHE="Acherontia styx Westwood, 1847 sec. cate-sphingidae.org" PROTECTEDTITLECACHE="true" TAXON_ID="37" IMAGEGALLERY="false"/>
   <DESCRIPTIONBASE DTYPE="TaxonDescription" ID="33" CREATED="2008-12-10 09:56:07.0" UUID="620de7a8-8c83-42c9-add7-fdc55ebf943a" UPDATED="2008-12-10 09:56:07.253" TITLECACHE="Cryptocoryne x purpurea nothovar borneoensis N.Jacobsen, Bastm. &amp; Yuji Sasaki sec. cate-sphingidae.org" PROTECTEDTITLECACHE="true" TAXON_ID="38" IMAGEGALLERY="false"/>\r
+  <DESCRIPTIONBASE_MARKER DESCRIPTIONBASE_ID="31" MARKERS_ID="1"/>\r
+  <DESCRIPTIONBASE_MARKER DESCRIPTIONBASE_ID="31" MARKERS_ID="2"/>\r
+  <MARKER ID="1" UUID="a0b943f6-3737-4ba4-9d5c-72f3f1476996" FLAG="TRUE" MARKEDOBJ_TYPE="eu.etaxonomy.cdm.model.description.TaxonDescription" MARKEDOBJ_ID="31" MARKERTYPE_ID="890"/>\r
+  <MARKER ID="2" UUID="e873c908-ec5b-4edf-8e80-11da5a9d26b3" FLAG="FALSE" MARKEDOBJ_TYPE="eu.etaxonomy.cdm.model.description.TaxonDescription" MARKEDOBJ_ID="31" MARKERTYPE_ID="892"/>\r
   <DESCRIPTIONELEMENTBASE DTYPE="Distribution" ID="1" INDESCRIPTION_ID="1" CREATED="2008-12-10 09:56:07.0" UUID="40458e70-a065-450f-b27d-adf61cc28a7f" UPDATED="2008-12-10 09:56:07.253" AREA_ID="1969" STATUS_ID="1994"/>\r
   <DESCRIPTIONELEMENTBASE DTYPE="Distribution" ID="2" INDESCRIPTION_ID="2" CREATED="2008-12-10 09:56:07.0" UUID="d4099b8d-0644-4025-8a56-e7fc2d95004e" UPDATED="2008-12-10 09:56:07.253" AREA_ID="1969" STATUS_ID="1994"/>\r
   <DESCRIPTIONELEMENTBASE DTYPE="Distribution" ID="3" INDESCRIPTION_ID="3" CREATED="2008-12-10 09:56:07.0" UUID="317fafca-3722-4d8d-8c4f-701d4f5b911d" UPDATED="2008-12-10 09:56:07.253" AREA_ID="1969" STATUS_ID="1994"/>\r