Project

General

Profile

Download (4.21 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
package eu.etaxonomy.cdm.persistence.dao.hibernate.media;
10

    
11
import static org.junit.Assert.assertEquals;
12
import static org.junit.Assert.assertFalse;
13
import static org.junit.Assert.assertNotNull;
14
import static org.junit.Assert.assertTrue;
15

    
16
import java.io.FileNotFoundException;
17
import java.util.ArrayList;
18
import java.util.HashSet;
19
import java.util.List;
20
import java.util.Set;
21
import java.util.UUID;
22

    
23
import org.hibernate.Hibernate;
24
import org.junit.Before;
25
import org.junit.Test;
26
import org.unitils.dbunit.annotation.DataSet;
27
import org.unitils.spring.annotation.SpringBeanByType;
28

    
29
import eu.etaxonomy.cdm.model.description.MediaKey;
30
import eu.etaxonomy.cdm.model.location.NamedArea;
31
import eu.etaxonomy.cdm.model.taxon.Taxon;
32
import eu.etaxonomy.cdm.persistence.dao.media.IMediaDao;
33
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
34
import eu.etaxonomy.cdm.persistence.dao.term.IDefinedTermDao;
35
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
36

    
37
@DataSet
38
public class MediaDaoImplTest extends CdmIntegrationTest {
39

    
40
	@SpringBeanByType
41
	IMediaDao mediaDao;
42

    
43
	@SpringBeanByType
44
	IDefinedTermDao definedTermDao;
45

    
46
	@SpringBeanByType
47
	ITaxonDao taxonDao;
48

    
49
	UUID europeUuid;
50
	UUID africaUuid;
51
	UUID sphingidaeUuid;
52

    
53
	Set<Taxon> taxonomicScope;
54
	Set<NamedArea> geoScopes;
55

    
56
	@Before
57
	public void setUp() {
58
		europeUuid = UUID.fromString("e860871c-3a14-4ef2-9367-bbd92586c95b");
59
		africaUuid = UUID.fromString("9444016a-b334-4772-8795-ed4019552087");
60
		sphingidaeUuid = UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
61

    
62
		taxonomicScope = new HashSet<Taxon>();
63
		geoScopes = new HashSet<NamedArea>();
64
	}
65

    
66
	@Test
67
	public void testCountMediaKeys() {
68
		long numberOfMediaKeys = mediaDao.countMediaKeys(null,null);
69

    
70
		assertEquals("countMediaKeys should return 3",3,numberOfMediaKeys);
71
	}
72

    
73
	@Test
74
	public void testGetMediaKeys() {
75
		List<String> propertyPaths = new ArrayList<String>();
76
		propertyPaths.add("title");
77
		List<MediaKey> keys = mediaDao.getMediaKeys(null, null, null, null,propertyPaths);
78

    
79
		assertNotNull("getMediaKeys should return a List",keys);
80
		assertFalse("The list should not be empty",keys.isEmpty());
81
		assertEquals("The list should contain 3 MediaKey instances",3, keys.size());
82
		assertTrue("Media.title should have been initialized",Hibernate.isInitialized(keys.get(0).getTitle()));
83
	}
84

    
85
	@Test
86
	public void testCountMediaKeysWithScope() {
87
		NamedArea europe = (NamedArea)definedTermDao.findByUuid(europeUuid);
88
		NamedArea africa = (NamedArea)definedTermDao.findByUuid(africaUuid);
89
		Taxon sphingidae = (Taxon)taxonDao.findByUuid(sphingidaeUuid);
90
		assert europe != null : "NamedArea must exist";
91
		assert africa != null : "NamedArea must exist";
92
		assert sphingidae != null : "Taxon must exist";
93

    
94
		geoScopes.add(europe);
95
		geoScopes.add(africa);
96
		taxonomicScope.add(sphingidae);
97

    
98
		long numberOfMediaKeys = mediaDao.countMediaKeys(taxonomicScope,geoScopes);
99

    
100
		assertEquals("countMediaKeys should return 1",1,numberOfMediaKeys);
101
	}
102

    
103
	@Test
104
	public void testGetMediaKeysWithScope() {
105
		List<String> propertyPaths = new ArrayList<String>();
106
		propertyPaths.add("title");
107
		NamedArea europe = (NamedArea)definedTermDao.findByUuid(europeUuid);
108
		NamedArea africa = (NamedArea)definedTermDao.findByUuid(africaUuid);
109
		Taxon sphingidae = (Taxon)taxonDao.findByUuid(sphingidaeUuid);
110
		assert europe != null : "NamedArea must exist";
111
		assert africa != null : "NamedArea must exist";
112
		assert sphingidae != null : "Taxon must exist";
113

    
114
		geoScopes.add(europe);
115
		geoScopes.add(africa);
116
		taxonomicScope.add(sphingidae);
117

    
118
		List<MediaKey> keys = mediaDao.getMediaKeys(taxonomicScope,geoScopes, null, null,propertyPaths);
119

    
120
		assertNotNull("getMediaKeys should return a List",keys);
121
		assertFalse("The list should not be empty",keys.isEmpty());
122
		assertEquals("The list should contain 1 MediaKey instance",1, keys.size());
123
		assertTrue("Media.title should have been initialized",Hibernate.isInitialized(keys.get(0).getTitle()));
124
	}
125

    
126
    @Override
127
    public void createTestDataSet() throws FileNotFoundException {}
128
}
(1-1/2)