2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.assertNull
;
17 import java
.util
.UUID
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.junit
.Ignore
;
21 import org
.junit
.Test
;
22 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
24 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
25 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
27 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
28 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
29 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
30 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
31 import eu
.etaxonomy
.cdm
.test
.integration
.CdmIntegrationTest
;
38 public class TermServiceImplTest
extends CdmIntegrationTest
{
39 @SuppressWarnings("unused")
40 private static final Logger logger
= Logger
.getLogger(TermServiceImplTest
.class);
43 private ITermService service
;
46 private IVocabularyService vocabularyService
;
48 /* ************************* TESTS *************************************************/
51 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#getTermByUri(java.lang.String)}.
53 @Ignore //second part of test throws unexpected exception & also first part fails since language(406)
54 //is also not found here, for an explanation see comment below
58 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
59 * and thus will cause unitils to empty the according tables, thus all terms etc will be deleted for the
60 * following tests, thus it might be a good idea moving this test to the end
62 public void testGetTermByUri() {
63 String uriStr
= "http://any.uri.com";
64 URI uri
= URI
.create(uriStr
);
65 DefinedTermBase
<?
> term
= service
.getByUri(uri
);
68 // TermVocabulary<?> voc = term.getVocabulary();
69 // service.saveOrUpdate(term);
70 // List<MarkerType> list = service.listByTermClass(MarkerType.class, null, null, null, null);
73 //FIXME throws object not found exception. Wants to load term.voc(11).representation(496).language(124) which does not exist
74 //I do not understand where the vocabulary data comes from (checked persistence TermsDataSet-with_auditing_info.xml) but somehow this does not apply
75 String uriNotExistStr
= "http://www.notExisting.com";
76 URI uriNotExist
= URI
.create(uriNotExistStr
);
77 DefinedTermBase
<?
> termNotExist
= service
.getByUri(uriNotExist
);
78 assertNull(termNotExist
);
82 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#getTermByUuid(java.util.UUID)}.
87 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
88 * and thus will cause unitils empty the according tables
90 public void testGetTermByUuid() {
92 String strUUID
= "ffca6ec8-8b88-417b-a6a0-f7c992aac19b";
93 UUID uuid
= UUID
.fromString(strUUID
);
94 DefinedTermBase
<?
> term
= service
.find(uuid
);
96 assertEquals(Rank
.DOMAIN(), term
);
98 String strUUIDNotExist
= "00000000-8b88-417b-a6a0-f7c992aac19c";
99 UUID uuidNotExist
= UUID
.fromString(strUUIDNotExist
);
100 DefinedTermBase
<?
> termNotExist
= service
.find(uuidNotExist
);
101 assertNull(termNotExist
);
106 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#listTerms(java.util.UUID)}.
112 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
113 * and thus will cause unitils empty the according tables
115 public void testGetVocabularyUUID() {
117 String rankVocabularyUuid
= "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b";
118 UUID rankUuid
= UUID
.fromString(rankVocabularyUuid
);
119 TermVocabulary
<Rank
> voc
= vocabularyService
.find(rankUuid
);
121 assertEquals(66, voc
.getTerms().size());
123 String nullVocabularyUuid
= "00000000-26e3-4e83-b47b-ca74eed40b1b";
124 UUID nullUuid
= UUID
.fromString(nullVocabularyUuid
);
125 TermVocabulary
<Rank
> nullVoc
= vocabularyService
.find(nullUuid
);
133 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
134 * and thus will cause unitils empty the according tables
136 public void testGetAreaByTdwgAbbreviation(){
137 String tdwgAbbreviation
= "GER-OO";
138 NamedArea germany
= service
.getAreaByTdwgAbbreviation(tdwgAbbreviation
);
139 assertEquals(tdwgAbbreviation
, germany
.getRepresentation(Language
.DEFAULT()).getAbbreviatedLabel());
145 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
146 * and thus will cause unitils empty the according tables
148 public void testListTerms() {
149 Pager
<SpecimenTypeDesignationStatus
> results
= (Pager
)service
.page(SpecimenTypeDesignationStatus
.class, null,null,null,null);
150 assertNotNull("Results should not be null",results
);