c0083659ab2a255d1f163e5bac5efff723f54952
[cdmlib.git] / cdmlib-persistence / src / test / java / eu / etaxonomy / cdm / persistence / dao / hibernate / common / IdentifiableDaoBaseTest.java
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.io.FileNotFoundException;
11 import java.io.FileOutputStream;
12 import java.util.List;
13 import java.util.UUID;
14
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.unitils.dbunit.annotation.DataSet;
19 import org.unitils.spring.annotation.SpringBeanByType;
20
21 import eu.etaxonomy.cdm.model.common.OriginalSource;
22 import eu.etaxonomy.cdm.model.media.Rights;
23 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
24 import eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl;
25 import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
26
27 /**
28 * @author a.mueller
29 *
30 */
31 @DataSet
32 public class IdentifiableDaoBaseTest extends CdmIntegrationTest {
33
34 @SpringBeanByType
35 private TaxonDaoHibernateImpl identifiableDao;
36
37 private UUID uuid;
38
39 @Before
40 public void setUp() {
41 uuid = UUID.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2");
42 }
43
44 /************ TESTS *******************************
45 * @throws FileNotFoundException */
46
47 /**
48 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.IdentifiableDaoBase#IdentifiableDaoBase(java.lang.Class)}.
49 */
50 @Test
51 public void testIdentifiableDaoBase() {
52 assertNotNull(identifiableDao);
53 }
54
55 /**
56 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.IdentifiableDaoBase#findByTitle(java.lang.String)}.
57 */
58 @Test
59 public void testFindByTitle() {
60 List<TaxonBase> results = identifiableDao.findByTitle("Lorem");
61 assertNotNull("findByTitle should return a list",results);
62 assertEquals("findByTitle should return one entity", 1, results.size());
63 assertEquals("findByTitle should return an entity with uuid " + uuid,uuid, results.get(0).getUuid());
64 }
65
66 @Test
67 public void testGetRights() {
68 TaxonBase taxon = identifiableDao.findByUuid(uuid);
69 assert taxon != null : "IdentifiableEntity must exist";
70
71 List<Rights> rights = identifiableDao.getRights(taxon, null, null);
72
73 assertNotNull("getRights should return a List",rights);
74 assertFalse("the list should not be empty",rights.isEmpty());
75 assertEquals("getRights should return 2 Rights instances",2,rights.size());
76 }
77
78 @Test
79 public void testSources() {
80 TaxonBase taxon = identifiableDao.findByUuid(uuid);
81 assert taxon != null : "IdentifiableEntity must exist";
82
83 List<OriginalSource> sources = identifiableDao.getSources(taxon, null, null);
84
85 assertNotNull("getSources should return a List", sources);
86 assertFalse("the list should not be empty", sources.isEmpty());
87 assertEquals("getSources should return 2 OriginalSource instances",2, sources.size());
88 }
89
90 // @Test
91 // TODO - implement this later
92 // public void testGetByLSID() throws Exception {
93 // LSID lsid = new LSID("urn:lsid:cate-project.org:taxonconcepts:1");
94 // TaxonBase result = taxonDAO.find(lsid);
95 //
96 // Assert.assertNotNull(result);
97 // }
98 //
99 }