Project

General

Profile

Download (4.54 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.api.service;
11

    
12
import static org.junit.Assert.assertEquals;
13
import static org.junit.Assert.assertNotNull;
14
import static org.junit.Assert.assertNull;
15

    
16
import java.net.URI;
17
import java.util.List;
18
import java.util.UUID;
19

    
20
import org.apache.log4j.Logger;
21
import org.junit.Ignore;
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.api.service.pager.Pager;
27
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
28
import eu.etaxonomy.cdm.model.common.Language;
29
import eu.etaxonomy.cdm.model.common.MarkerType;
30
import eu.etaxonomy.cdm.model.common.TermVocabulary;
31
import eu.etaxonomy.cdm.model.location.NamedArea;
32
import eu.etaxonomy.cdm.model.name.Rank;
33
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
34
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
35

    
36
/**
37
 * @author a.mueller
38
 * @created 27.05.2008
39
 * @version 1.0
40
 */
41
public class TermServiceImplTest extends CdmIntegrationTest {
42
	@SuppressWarnings("unused")
43
	private static final Logger logger = Logger.getLogger(TermServiceImplTest.class);
44

    
45
	@SpringBeanByType
46
	private ITermService service;
47
	
48
	@SpringBeanByType
49
	private IVocabularyService vocabularyService;
50

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

    
53
	/**
54
	 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#getTermByUri(java.lang.String)}.
55
	 */
56
	@Ignore //second part of test throws unexpected exception & also first part fails since language(406) 
57
	//is also not found here
58
	@Test
59
	@DataSet
60
	public void testGetTermByUri() {
61
		String uriStr = "http://any.uri.com"; 
62
		URI uri = URI.create(uriStr);
63
		DefinedTermBase<?> term = service.getByUri(uri);
64
		assertNotNull(term);
65
		//for testing only
66
//		TermVocabulary<?> voc = term.getVocabulary();
67
//		service.saveOrUpdate(term);
68
//		List<MarkerType> list = service.listByTermClass(MarkerType.class, null, null, null, null);
69
		
70
		//NULL
71
		//FIXME throws object not found exception. Wants to load term.voc(11).representation(496).language(124) which does not exist
72
		//I do not understand where the vocabulary data comes from (checked persistence TermsDataSet-with_auditing_info.xml) but somehow this does not apply
73
		String uriNotExistStr = "http://www.notExisting.com";
74
		URI uriNotExist = URI.create(uriNotExistStr);
75
		DefinedTermBase<?> termNotExist = service.getByUri(uriNotExist);
76
		assertNull(termNotExist);
77
	}
78

    
79
	/**
80
	 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#getTermByUuid(java.util.UUID)}.
81
	 */
82
	@Test
83
	public void testGetTermByUuid() {
84
		// Rank.Domain
85
		String strUUID = "ffca6ec8-8b88-417b-a6a0-f7c992aac19b"; 
86
		UUID uuid = UUID.fromString(strUUID);
87
		DefinedTermBase<?> term = service.find(uuid);
88
		assertNotNull(term);
89
		assertEquals(Rank.DOMAIN(), term);
90
		//NULL
91
		String strUUIDNotExist = "00000000-8b88-417b-a6a0-f7c992aac19c";
92
		UUID uuidNotExist = UUID.fromString(strUUIDNotExist);
93
		DefinedTermBase<?> termNotExist = service.find(uuidNotExist);
94
		assertNull(termNotExist);
95
	}
96

    
97

    
98
	/**
99
	 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#listTerms(java.util.UUID)}.
100
	 */
101
//	@Ignore
102
	@Test
103
	public void testGetVocabularyUUID() {
104
		//Rank
105
		String rankVocabularyUuid = "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b"; 
106
		UUID rankUuid = UUID.fromString(rankVocabularyUuid);
107
		TermVocabulary<Rank> voc = vocabularyService.find(rankUuid);
108
		assertNotNull(voc);
109
		assertEquals(66, voc.getTerms().size());
110
		//Null
111
		String nullVocabularyUuid = "00000000-26e3-4e83-b47b-ca74eed40b1b"; 
112
		UUID nullUuid = UUID.fromString(nullVocabularyUuid);
113
		TermVocabulary<Rank> nullVoc = vocabularyService.find(nullUuid);
114
		assertNull(nullVoc);
115
	}
116

    
117
	
118
	@Test
119
	public void testGetAreaByTdwgAbbreviation(){
120
		String tdwgAbbreviation = "GER-OO";
121
		NamedArea germany = service.getAreaByTdwgAbbreviation(tdwgAbbreviation);
122
		assertEquals(tdwgAbbreviation, germany.getRepresentation(Language.DEFAULT()).getAbbreviatedLabel());
123
	}
124
	
125
	@Test
126
	public void testListTerms() {
127
		Pager<SpecimenTypeDesignationStatus> results = (Pager)service.page(SpecimenTypeDesignationStatus.class, null,null,null,null);
128
		assertNotNull("Results should not be null",results);
129
	}
130
}
(12-12/13)