Project

General

Profile

Download (5.96 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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.List;
18
import java.util.UUID;
19

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

    
25
import eu.etaxonomy.cdm.model.common.Credit;
26
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
27
import eu.etaxonomy.cdm.model.common.LSID;
28
import eu.etaxonomy.cdm.model.media.Rights;
29
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
30
import eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl;
31
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
32
import eu.etaxonomy.cdm.persistence.query.MatchMode;
33
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
34

    
35
/**
36
 * @author a.mueller
37
 */
38
@DataSet
39
public class IdentifiableDaoBaseTest extends CdmIntegrationTest {
40

    
41
    @SpringBeanByType
42
    private  TaxonDaoHibernateImpl identifiableDao;
43

    
44
    private UUID uuid;
45

    
46
    @Before
47
    public void setUp() {
48
        uuid = UUID.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2");
49
    }
50

    
51
/************ TESTS ********************************/
52

    
53
    @Test
54
    public void testIdentifiableDaoBase() {
55
        assertNotNull(identifiableDao);
56
    }
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 testCountByTitle() {
68
        long result = identifiableDao.countByTitle("%");
69
        assertNotNull("findByTitle should return an integer",result);
70
        assertEquals("findByTitle should return 2", 2, result);
71

    
72
        result = identifiableDao.countByTitle("%", MatchMode.ANYWHERE, null);
73
        assertNotNull("findByTitle should return an integer",result);
74
        assertEquals("findByTitle should return 2", 2, result);
75

    
76
        result = identifiableDao.countByTitle("Lorem");
77
        assertNotNull("findByTitle should return an integer",result);
78
        assertEquals("findByTitle should return 1", 1, result);
79

    
80
        result = identifiableDao.countByTitle("Lorem", MatchMode.ANYWHERE, null);
81
        assertNotNull("findByTitle should return an integer",result);
82
        assertEquals("findByTitle should return 1", 1, result);
83
    }
84

    
85
    @Test
86
    public void testGetRights() {
87
        TaxonBase<?> taxon = identifiableDao.findByUuid(uuid);
88
        assert taxon != null : "IdentifiableEntity must exist";
89

    
90
        List<Rights> rights = identifiableDao.getRights(taxon, null, null, null);
91

    
92
        assertNotNull("getRights should return a List",rights);
93
        assertFalse("the list should not be empty",rights.isEmpty());
94
        assertEquals("getRights should return 2 Rights instances",2,rights.size());
95
    }
96

    
97
    @Test
98
    public void testGetCredits() {
99
        TaxonBase<?> taxon = identifiableDao.findByUuid(uuid);
100
        assert taxon != null : "IdentifiableEntity must exist";
101
        taxon.getCredits();
102

    
103
        List<Credit> credits = identifiableDao.getCredits(taxon, null, null);
104

    
105
        assertNotNull("getCredits should return a List",credits);
106
        assertFalse("the list should not be empty",credits.isEmpty());
107
        assertEquals("getCredits should return 3 Credit instances",3,credits.size());
108
    }
109

    
110
    @Test
111
    public void testCreditsOrder() {
112
        TaxonBase<?> taxon = identifiableDao.findByUuid(uuid);
113
        assert taxon != null : "IdentifiableEntity must exist";
114
        List<Credit> credits = taxon.getCredits();
115

    
116
        assertNotNull("getCredits should return a List",credits);
117
        assertFalse("the list should not be empty",credits.isEmpty());
118
        assertEquals("getCredits should return 3 Credit instances",3,credits.size());
119
        assertEquals("My first credit", credits.get(0).getText());
120
        assertEquals("My second credit", credits.get(1).getText());
121
        assertEquals("My third credit", credits.get(2).getText());
122
    }
123

    
124
    @Test
125
    public void testSources() throws Exception {
126
        TaxonBase<?> taxon = identifiableDao.findByUuid(uuid);
127
        assert taxon != null : "IdentifiableEntity must exist";
128

    
129
        List<IdentifiableSource> sources = identifiableDao.getSources(taxon, null, null,null);
130

    
131
        assertNotNull("getSources should return a List", sources);
132
        assertFalse("the list should not be empty", sources.isEmpty());
133
        assertEquals("getSources should return 2 OriginalSource instances",2, sources.size());
134
    }
135

    
136
    @Test
137
    public void testGetByLsidWithoutVersion() throws Exception {
138
        LSID lsid = new LSID("urn:lsid:example.org:namespace:1");
139
        TaxonBase<?> result = identifiableDao.find(lsid);
140
        assertNotNull(result);
141
    }
142

    
143
    @Test
144
    public void testGetByLsidWithVersionCurrent() throws Exception {
145
        LSID lsid = new LSID("urn:lsid:example.org:namespace:1:2");
146
        TaxonBase<?> result = identifiableDao.find(lsid);
147
        assertNotNull(result);
148
    }
149

    
150
    @Test
151
    public void testGetByLsidWithVersionPast() throws Exception {
152
        LSID lsid = new LSID("urn:lsid:example.org:namespace:1:1");
153
        TaxonBase<?> result = identifiableDao.find(lsid);
154
        assertNotNull(result);
155
    }
156

    
157
    @Test
158
    public void testGetUuidAndTitleCache() {
159
        List<UuidAndTitleCache<TaxonBase>> result = identifiableDao.getUuidAndTitleCache(TaxonBase.class, 10, "Lore*");
160
        assertEquals(1, result.size());
161
    }
162

    
163
    @Override
164
    public void createTestDataSet() throws FileNotFoundException {}
165
}
(6-6/7)