Project

General

Profile

Download (3.44 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.cdm.persistence.dao.hibernate.common;
5

    
6
import static org.junit.Assert.assertEquals;
7
import static org.junit.Assert.assertFalse;
8
import static org.junit.Assert.assertNotNull;
9

    
10
import java.util.List;
11
import java.util.UUID;
12

    
13
import org.junit.Before;
14
import org.junit.Test;
15
import org.unitils.dbunit.annotation.DataSet;
16
import org.unitils.spring.annotation.SpringApplicationContext;
17
import org.unitils.spring.annotation.SpringBeanByType;
18

    
19
import eu.etaxonomy.cdm.model.common.LSID;
20
import eu.etaxonomy.cdm.model.common.OriginalSource;
21
import eu.etaxonomy.cdm.model.media.Rights;
22
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
23
import eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl;
24
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
25

    
26
/**
27
 * @author a.mueller
28
 *
29
 */
30
@DataSet
31
public class IdentifiableDaoBaseTest extends CdmIntegrationTest {
32
	
33
	@SpringBeanByType
34
	private  TaxonDaoHibernateImpl identifiableDao;	
35
	
36
	private UUID uuid;
37
	
38
	@Before
39
	public void setUp() {
40
		uuid = UUID.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2");
41
	}
42

    
43
/************ TESTS ********************************/
44
	
45
	/**
46
	 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.IdentifiableDaoBase#IdentifiableDaoBase(java.lang.Class)}.
47
	 */
48
	@Test
49
	public void testIdentifiableDaoBase() {
50
		assertNotNull(identifiableDao);
51
	}
52

    
53
	/**
54
	 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.IdentifiableDaoBase#findByTitle(java.lang.String)}.
55
	 */
56
	@Test
57
	public void testFindByTitle() {
58
		List<TaxonBase> results = identifiableDao.findByTitle("Lorem");
59
		assertNotNull("findByTitle should return a list",results);
60
		assertEquals("findByTitle should return one entity", 1, results.size());
61
		assertEquals("findByTitle should return an entity with uuid " + uuid,uuid, results.get(0).getUuid());
62
	}
63
	
64
	@Test
65
	public void testGetRights() {
66
		TaxonBase taxon = identifiableDao.findByUuid(uuid);
67
		assert taxon != null : "IdentifiableEntity must exist";
68
		
69
		List<Rights> rights = identifiableDao.getRights(taxon, null, null);
70
		
71
		assertNotNull("getRights should return a List",rights);
72
		assertFalse("the list should not be empty",rights.isEmpty());
73
		assertEquals("getRights should return 2 Rights instances",2,rights.size());
74
	}
75
	
76
	@Test
77
	public void testSources() throws Exception {
78
		TaxonBase taxon = identifiableDao.findByUuid(uuid);
79
		assert taxon != null : "IdentifiableEntity must exist";
80
		
81
		List<OriginalSource> sources = identifiableDao.getSources(taxon, null, null);
82

    
83
		assertNotNull("getSources should return a List", sources);
84
		assertFalse("the list should not be empty", sources.isEmpty());
85
		assertEquals("getSources should return 2 OriginalSource instances",2, sources.size());
86
	}
87

    
88
	@Test
89
	public void testGetByLsidWithoutVersion() throws Exception {
90
		LSID lsid = new LSID("urn:lsid:example.org:namespace:1");
91
		TaxonBase result = identifiableDao.find(lsid);
92
		assertNotNull(result);
93
	}
94
	
95
	@Test
96
	public void testGetByLsidWithVersionCurrent() throws Exception {
97
		LSID lsid = new LSID("urn:lsid:example.org:namespace:1:2");
98
		TaxonBase result = identifiableDao.find(lsid);
99
		assertNotNull(result);
100
	}
101
	
102
	@Test
103
	public void testGetByLsidWithVersionPast() throws Exception {
104
		LSID lsid = new LSID("urn:lsid:example.org:namespace:1:1");
105
		TaxonBase result = identifiableDao.find(lsid);
106
		assertNotNull(result);
107
	}
108
	
109
}
(6-6/8)