fixing transaction problems
[cdmlib.git] / cdmlib-persistence / src / test / java / eu / etaxonomy / cdm / persistence / dao / hibernate / common / AnnotationDaoTest.java
index 47df29d335e7a150f6bd470ee43d196750193573..8a7e8dbb5b858165e78d95e9771cfafd0c1942ed 100644 (file)
@@ -1,9 +1,19 @@
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy 
+* http://www.e-taxonomy.eu
+* 
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
 package eu.etaxonomy.cdm.persistence.dao.hibernate.common;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
 
@@ -14,8 +24,10 @@ import org.unitils.spring.annotation.SpringBeanByType;
 
 import eu.etaxonomy.cdm.model.common.Annotation;
 import eu.etaxonomy.cdm.model.common.MarkerType;
+import eu.etaxonomy.cdm.model.common.User;
 import eu.etaxonomy.cdm.persistence.dao.common.IAnnotationDao;
-import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
+import eu.etaxonomy.cdm.persistence.query.OrderHint;
+import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
 import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
 
 @DataSet
@@ -44,8 +56,13 @@ public class AnnotationDaoTest extends CdmIntegrationTest {
        public void testGetAnnotations() {
                Annotation annotatedObj = annotationDao.findByUuid(uuid);
                assert annotatedObj != null : "annotatedObj must exist";
+               List<OrderHint> orderHints = new ArrayList<OrderHint>();
+               orderHints.add(new OrderHint("created", SortOrder.ASCENDING));
+               List<String> propertyPaths = new ArrayList<String>();
+               propertyPaths.add("annotatedObj");
+               propertyPaths.add("createdBy");
                
-               List<Annotation> annotations = annotationDao.getAnnotations(annotatedObj, null,null,null);
+               List<Annotation> annotations = annotationDao.getAnnotations(annotatedObj, null,null,null,orderHints,propertyPaths);
                assertNotNull("getAnnotations should return a List",annotations);
                assertFalse("the list should contain Annotation instances",annotations.isEmpty());
                assertEquals("getAnnotations should return 4",4,annotations.size());            
@@ -55,6 +72,7 @@ public class AnnotationDaoTest extends CdmIntegrationTest {
        public void testCountAnnotationsWithStatus() {
                Annotation annotatedObj = annotationDao.findByUuid(uuid);
                MarkerType markerType = MarkerType.TO_BE_CHECKED();
+               
                assert annotatedObj != null : "annotatedObj must exist";
                assert markerType != null : "markerType must exist";
                
@@ -69,7 +87,28 @@ public class AnnotationDaoTest extends CdmIntegrationTest {
                assert annotatedObj != null : "annotatedObj must exist";
                assert markerType != null : "markerType must exist";
                
-               List<Annotation> annotations = annotationDao.getAnnotations(annotatedObj, markerType,null,null);
+               List<Annotation> annotations = annotationDao.getAnnotations(annotatedObj, markerType,null,null,null,null);
+               assertNotNull("getAnnotations should return a List",annotations);
+               assertFalse("the list should contain Annotation instances",annotations.isEmpty());
+               assertEquals("getAnnotations should return 2",2,annotations.size());            
+       }
+       
+       @Test
+       public void testCountAllAnnotationsWithStatus() {
+               MarkerType markerType = MarkerType.TO_BE_CHECKED();     
+
+               assert markerType != null : "markerType must exist";
+               
+               int numberOfAnnotations = annotationDao.count((User)null, markerType);
+               assertEquals("countAnnotations should return 2",2,numberOfAnnotations);         
+       }
+       
+       @Test
+       public void testListAllAnnotationsWithStatus() {
+               MarkerType markerType = MarkerType.TO_BE_CHECKED();
+               assert markerType != null : "markerType must exist";
+               
+               List<Annotation> annotations = annotationDao.list((User)null, markerType, null, null, null, null);
                assertNotNull("getAnnotations should return a List",annotations);
                assertFalse("the list should contain Annotation instances",annotations.isEmpty());
                assertEquals("getAnnotations should return 2",2,annotations.size());