2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.common
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertFalse
;
14 import static org
.junit
.Assert
.assertNotNull
;
16 import java
.util
.ArrayList
;
17 import java
.util
.List
;
18 import java
.util
.UUID
;
20 import org
.junit
.Before
;
21 import org
.junit
.Test
;
22 import org
.unitils
.dbunit
.annotation
.DataSet
;
23 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
25 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
26 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
27 import eu
.etaxonomy
.cdm
.model
.common
.User
;
28 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IAnnotationDao
;
29 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
30 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
31 import eu
.etaxonomy
.cdm
.test
.integration
.CdmIntegrationTest
;
34 public class AnnotationDaoTest
extends CdmIntegrationTest
{
37 IAnnotationDao annotationDao
;
43 uuid
= UUID
.fromString("97097410-a112-4dde-a2c6-0096754076b5");
47 public void testCountAnnotations() {
48 Annotation annotatedObj
= annotationDao
.findByUuid(uuid
);
49 assert annotatedObj
!= null : "annotatedObj must exist";
51 int numberOfAnnotations
= annotationDao
.countAnnotations(annotatedObj
, null);
52 assertEquals("countAnnotations should return 4",4,numberOfAnnotations
);
56 public void testGetAnnotations() {
57 Annotation annotatedObj
= annotationDao
.findByUuid(uuid
);
58 assert annotatedObj
!= null : "annotatedObj must exist";
59 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
60 orderHints
.add(new OrderHint("created", SortOrder
.ASCENDING
));
61 List
<String
> propertyPaths
= new ArrayList
<String
>();
62 propertyPaths
.add("annotatedObj");
63 propertyPaths
.add("createdBy");
65 List
<Annotation
> annotations
= annotationDao
.getAnnotations(annotatedObj
, null,null,null,orderHints
,propertyPaths
);
66 assertNotNull("getAnnotations should return a List",annotations
);
67 assertFalse("the list should contain Annotation instances",annotations
.isEmpty());
68 assertEquals("getAnnotations should return 4",4,annotations
.size());
72 public void testCountAnnotationsWithStatus() {
73 Annotation annotatedObj
= annotationDao
.findByUuid(uuid
);
74 MarkerType markerType
= MarkerType
.TO_BE_CHECKED();
76 assert annotatedObj
!= null : "annotatedObj must exist";
77 assert markerType
!= null : "markerType must exist";
79 int numberOfAnnotations
= annotationDao
.countAnnotations(annotatedObj
, markerType
);
80 assertEquals("countAnnotations should return 2",2,numberOfAnnotations
);
84 public void testGetAnnotationsWithStatus() {
85 Annotation annotatedObj
= annotationDao
.findByUuid(uuid
);
86 MarkerType markerType
= MarkerType
.TO_BE_CHECKED();
87 assert annotatedObj
!= null : "annotatedObj must exist";
88 assert markerType
!= null : "markerType must exist";
90 List
<Annotation
> annotations
= annotationDao
.getAnnotations(annotatedObj
, markerType
,null,null,null,null);
91 assertNotNull("getAnnotations should return a List",annotations
);
92 assertFalse("the list should contain Annotation instances",annotations
.isEmpty());
93 assertEquals("getAnnotations should return 2",2,annotations
.size());
97 public void testCountAllAnnotationsWithStatus() {
98 MarkerType markerType
= MarkerType
.TO_BE_CHECKED();
100 assert markerType
!= null : "markerType must exist";
102 int numberOfAnnotations
= annotationDao
.count((User
)null, markerType
);
103 assertEquals("countAnnotations should return 2",2,numberOfAnnotations
);
107 public void testListAllAnnotationsWithStatus() {
108 MarkerType markerType
= MarkerType
.TO_BE_CHECKED();
109 assert markerType
!= null : "markerType must exist";
111 List
<Annotation
> annotations
= annotationDao
.list((User
)null, markerType
, null, null, null, null);
112 assertNotNull("getAnnotations should return a List",annotations
);
113 assertFalse("the list should contain Annotation instances",annotations
.isEmpty());
114 assertEquals("getAnnotations should return 2",2,annotations
.size());