remove deprecated call for description.setAddSource
[cdmlib.git] / cdmlib-persistence / src / test / java / eu / etaxonomy / cdm / persistence / dao / hibernate / common / AnnotationDaoTest.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.cdm.persistence.dao.hibernate.common;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertNotNull;
15
16 import java.util.ArrayList;
17 import java.util.List;
18 import java.util.UUID;
19
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.unitils.dbunit.annotation.DataSet;
23 import org.unitils.spring.annotation.SpringBeanByType;
24
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;
32
33 @DataSet
34 public class AnnotationDaoTest extends CdmIntegrationTest {
35
36 @SpringBeanByType
37 IAnnotationDao annotationDao;
38
39 UUID uuid;
40
41 @Before
42 public void setUp() {
43 uuid = UUID.fromString("97097410-a112-4dde-a2c6-0096754076b5");
44 }
45
46 @Test
47 public void testCountAnnotations() {
48 Annotation annotatedObj = annotationDao.findByUuid(uuid);
49 assert annotatedObj != null : "annotatedObj must exist";
50
51 int numberOfAnnotations = annotationDao.countAnnotations(annotatedObj, null);
52 assertEquals("countAnnotations should return 4",4,numberOfAnnotations);
53 }
54
55 @Test
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");
64
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());
69 }
70
71 @Test
72 public void testCountAnnotationsWithStatus() {
73 Annotation annotatedObj = annotationDao.findByUuid(uuid);
74 MarkerType markerType = MarkerType.TO_BE_CHECKED();
75
76 assert annotatedObj != null : "annotatedObj must exist";
77 assert markerType != null : "markerType must exist";
78
79 int numberOfAnnotations = annotationDao.countAnnotations(annotatedObj, markerType);
80 assertEquals("countAnnotations should return 2",2,numberOfAnnotations);
81 }
82
83 @Test
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";
89
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());
94 }
95
96 @Test
97 public void testCountAllAnnotationsWithStatus() {
98 MarkerType markerType = MarkerType.TO_BE_CHECKED();
99
100 assert markerType != null : "markerType must exist";
101
102 int numberOfAnnotations = annotationDao.count((User)null, markerType);
103 assertEquals("countAnnotations should return 2",2,numberOfAnnotations);
104 }
105
106 @Test
107 public void testListAllAnnotationsWithStatus() {
108 MarkerType markerType = MarkerType.TO_BE_CHECKED();
109 assert markerType != null : "markerType must exist";
110
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());
115 }
116 }