(no commit message)
[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.List;
17 import java.util.UUID;
18
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.unitils.dbunit.annotation.DataSet;
22 import org.unitils.spring.annotation.SpringBeanByType;
23
24 import eu.etaxonomy.cdm.model.common.Annotation;
25 import eu.etaxonomy.cdm.model.common.MarkerType;
26 import eu.etaxonomy.cdm.persistence.dao.common.IAnnotationDao;
27 import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
28
29 @DataSet
30 public class AnnotationDaoTest extends CdmIntegrationTest {
31
32 @SpringBeanByType
33 IAnnotationDao annotationDao;
34
35 UUID uuid;
36
37 @Before
38 public void setUp() {
39 uuid = UUID.fromString("97097410-a112-4dde-a2c6-0096754076b5");
40 }
41
42 @Test
43 public void testCountAnnotations() {
44 Annotation annotatedObj = annotationDao.findByUuid(uuid);
45 assert annotatedObj != null : "annotatedObj must exist";
46
47 int numberOfAnnotations = annotationDao.countAnnotations(annotatedObj, null);
48 assertEquals("countAnnotations should return 4",4,numberOfAnnotations);
49 }
50
51 @Test
52 public void testGetAnnotations() {
53 Annotation annotatedObj = annotationDao.findByUuid(uuid);
54 assert annotatedObj != null : "annotatedObj must exist";
55
56 List<Annotation> annotations = annotationDao.getAnnotations(annotatedObj, null,null,null);
57 assertNotNull("getAnnotations should return a List",annotations);
58 assertFalse("the list should contain Annotation instances",annotations.isEmpty());
59 assertEquals("getAnnotations should return 4",4,annotations.size());
60 }
61
62 @Test
63 public void testCountAnnotationsWithStatus() {
64 Annotation annotatedObj = annotationDao.findByUuid(uuid);
65 MarkerType markerType = MarkerType.TO_BE_CHECKED();
66 assert annotatedObj != null : "annotatedObj must exist";
67 assert markerType != null : "markerType must exist";
68
69 int numberOfAnnotations = annotationDao.countAnnotations(annotatedObj, markerType);
70 assertEquals("countAnnotations should return 2",2,numberOfAnnotations);
71 }
72
73 @Test
74 public void testGetAnnotationsWithStatus() {
75 Annotation annotatedObj = annotationDao.findByUuid(uuid);
76 MarkerType markerType = MarkerType.TO_BE_CHECKED();
77 assert annotatedObj != null : "annotatedObj must exist";
78 assert markerType != null : "markerType must exist";
79
80 List<Annotation> annotations = annotationDao.getAnnotations(annotatedObj, markerType,null,null);
81 assertNotNull("getAnnotations should return a List",annotations);
82 assertFalse("the list should contain Annotation instances",annotations.isEmpty());
83 assertEquals("getAnnotations should return 2",2,annotations.size());
84 }
85 }