Project

General

Profile

Download (4.46 KB) Statistics
| Branch: | Tag: | Revision:
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.io.FileNotFoundException;
17
import java.util.ArrayList;
18
import java.util.List;
19
import java.util.UUID;
20

    
21
import org.junit.Before;
22
import org.junit.Test;
23
import org.unitils.dbunit.annotation.DataSet;
24
import org.unitils.spring.annotation.SpringBeanByType;
25

    
26
import eu.etaxonomy.cdm.model.common.Annotation;
27
import eu.etaxonomy.cdm.model.common.MarkerType;
28
import eu.etaxonomy.cdm.model.common.User;
29
import eu.etaxonomy.cdm.persistence.dao.common.IAnnotationDao;
30
import eu.etaxonomy.cdm.persistence.query.OrderHint;
31
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
32
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
33

    
34
@DataSet
35
public class AnnotationDaoTest extends CdmIntegrationTest {
36

    
37
	@SpringBeanByType
38
	private IAnnotationDao annotationDao;
39

    
40
	private UUID uuid;
41

    
42
	@Before
43
	public void setUp() {
44
		uuid = UUID.fromString("97097410-a112-4dde-a2c6-0096754076b5");
45
	}
46

    
47
	@Test
48
	public void testCountAnnotations() {
49
		Annotation annotatedObj = annotationDao.findByUuid(uuid);
50
		assert annotatedObj != null : "annotatedObj must exist";
51

    
52
		int numberOfAnnotations = annotationDao.countAnnotations(annotatedObj, null);
53
		assertEquals("countAnnotations should return 4",4,numberOfAnnotations);
54
	}
55

    
56
	@Test
57
	public void testGetAnnotations() {
58
		Annotation annotatedObj = annotationDao.findByUuid(uuid);
59
		assert annotatedObj != null : "annotatedObj must exist";
60
		List<OrderHint> orderHints = new ArrayList<OrderHint>();
61
		orderHints.add(new OrderHint("created", SortOrder.ASCENDING));
62
		List<String> propertyPaths = new ArrayList<String>();
63
		propertyPaths.add("annotatedObj");
64
		propertyPaths.add("createdBy");
65

    
66
		List<Annotation> annotations = annotationDao.getAnnotations(annotatedObj, null,null,null,orderHints,propertyPaths);
67
		assertNotNull("getAnnotations should return a List",annotations);
68
		assertFalse("the list should contain Annotation instances",annotations.isEmpty());
69
		assertEquals("getAnnotations should return 4",4,annotations.size());
70
	}
71

    
72
	@Test
73
	public void testCountAnnotationsWithStatus() {
74
		Annotation annotatedObj = annotationDao.findByUuid(uuid);
75
		MarkerType markerType = MarkerType.TO_BE_CHECKED();
76

    
77
		assert annotatedObj != null : "annotatedObj must exist";
78
		assert markerType != null : "markerType must exist";
79

    
80
		int numberOfAnnotations = annotationDao.countAnnotations(annotatedObj, markerType);
81
		assertEquals("countAnnotations should return 2",2,numberOfAnnotations);
82
	}
83

    
84
	@Test
85
	public void testGetAnnotationsWithStatus() {
86
		Annotation annotatedObj = annotationDao.findByUuid(uuid);
87
		MarkerType markerType = MarkerType.TO_BE_CHECKED();
88
		assert annotatedObj != null : "annotatedObj must exist";
89
		assert markerType != null : "markerType must exist";
90

    
91
		List<Annotation> annotations = annotationDao.getAnnotations(annotatedObj, markerType,null,null,null,null);
92
		assertNotNull("getAnnotations should return a List",annotations);
93
		assertFalse("the list should contain Annotation instances",annotations.isEmpty());
94
		assertEquals("getAnnotations should return 2",2,annotations.size());
95
	}
96

    
97
	@Test
98
	public void testCountAllAnnotationsWithStatus() {
99
		MarkerType markerType = MarkerType.TO_BE_CHECKED();
100

    
101
		assert markerType != null : "markerType must exist";
102

    
103
		int numberOfAnnotations = annotationDao.count((User)null, markerType);
104
		assertEquals("countAnnotations should return 2",2,numberOfAnnotations);
105
	}
106

    
107
	@Test
108
	public void testListAllAnnotationsWithStatus() {
109
		MarkerType markerType = MarkerType.TO_BE_CHECKED();
110
		assert markerType != null : "markerType must exist";
111

    
112
		List<Annotation> annotations = annotationDao.list((User)null, markerType, null, null, null, null);
113
		assertNotNull("getAnnotations should return a List",annotations);
114
		assertFalse("the list should contain Annotation instances",annotations.isEmpty());
115
		assertEquals("getAnnotations should return 2",2,annotations.size());
116
	}
117

    
118
    /* (non-Javadoc)
119
     * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
120
     */
121
    @Override
122
    public void createTestDataSet() throws FileNotFoundException {
123
        // TODO Auto-generated method stub
124

    
125
    }
126
}
(1-1/11)