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
.Representation
;
28 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
29 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
30 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
31 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
32 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
39 public class TermServiceImplTest
extends CdmTransactionalIntegrationTest
{
40 @SuppressWarnings("unused")
41 private static final Logger logger
= Logger
.getLogger(TermServiceImplTest
.class);
44 private ITermService termService
;
47 private IVocabularyService vocabularyService
;
49 /* ************************* TESTS *************************************************/
52 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#getTermByUri(java.lang.String)}.
54 @Ignore //second part of test throws unexpected exception & also first part fails since language(406)
55 //is also not found here, for an explanation see comment below
59 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
60 * and thus will cause unitils to empty the according tables, thus all terms etc will be deleted for the
61 * following tests, thus it might be a good idea moving this test to the end
63 public void testGetTermByUri() {
64 String uriStr
= "http://any.uri.com";
65 URI uri
= URI
.create(uriStr
);
66 DefinedTermBase
<?
> term
= termService
.getByUri(uri
);
69 // TermVocabulary<?> voc = term.getVocabulary();
70 // service.saveOrUpdate(term);
71 // List<MarkerType> list = service.listByTermClass(MarkerType.class, null, null, null, null);
74 //FIXME throws object not found exception. Wants to load term.voc(11).representation(496).language(124) which does not exist
75 //I do not understand where the vocabulary data comes from (checked persistence TermsDataSet-with_auditing_info.xml) but somehow this does not apply
76 String uriNotExistStr
= "http://www.notExisting.com";
77 URI uriNotExist
= URI
.create(uriNotExistStr
);
78 DefinedTermBase
<?
> termNotExist
= termService
.getByUri(uriNotExist
);
79 assertNull(termNotExist
);
83 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#getTermByUuid(java.util.UUID)}.
88 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
89 * and thus will cause unitils empty the according tables
91 public void testGetTermByUuid() {
93 String strUUID
= "ffca6ec8-8b88-417b-a6a0-f7c992aac19b";
94 UUID uuid
= UUID
.fromString(strUUID
);
95 DefinedTermBase
<?
> term
= termService
.find(uuid
);
97 assertEquals(Rank
.DOMAIN(), term
);
99 String strUUIDNotExist
= "00000000-8b88-417b-a6a0-f7c992aac19c";
100 UUID uuidNotExist
= UUID
.fromString(strUUIDNotExist
);
101 DefinedTermBase
<?
> termNotExist
= termService
.find(uuidNotExist
);
102 assertNull(termNotExist
);
107 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#listTerms(java.util.UUID)}.
113 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
114 * and thus will cause unitils empty the according tables
116 public void testGetVocabularyUUID() {
118 String rankVocabularyUuid
= "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b";
119 UUID rankUuid
= UUID
.fromString(rankVocabularyUuid
);
120 TermVocabulary
<Rank
> voc
= vocabularyService
.find(rankUuid
);
122 assertEquals(62, voc
.getTerms().size());
124 String nullVocabularyUuid
= "00000000-26e3-4e83-b47b-ca74eed40b1b";
125 UUID nullUuid
= UUID
.fromString(nullVocabularyUuid
);
126 TermVocabulary
<Rank
> nullVoc
= vocabularyService
.find(nullUuid
);
134 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
135 * and thus will cause unitils empty the according tables
137 public void testGetAreaByTdwgAbbreviation(){
138 String tdwgAbbreviation
= "GER-OO";
139 NamedArea germany
= termService
.getAreaByTdwgAbbreviation(tdwgAbbreviation
);
140 assertEquals(tdwgAbbreviation
, germany
.getRepresentation(Language
.DEFAULT()).getAbbreviatedLabel());
146 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
147 * and thus will cause unitils empty the according tables
149 public void testListTerms() {
150 Pager
<SpecimenTypeDesignationStatus
> results
= (Pager
)termService
.page(SpecimenTypeDesignationStatus
.class, null,null,null,null);
151 assertNotNull("Results should not be null",results
);
156 public void testTitleCacheUpdate(){
157 String uuid
= "ae787603-3070-4298-9ca6-4cbe73378122";
158 UUID fromString
= UUID
.fromString(uuid
);
159 DefinedTermBase
<?
> termBase
= termService
.find(fromString
);
162 String expectedTitleCache
= termBase
.getLabel() + "append";
163 termBase
.setLabel(expectedTitleCache
);
165 commitAndStartNewTransaction(null);
167 termBase
= termService
.find(fromString
);
168 assertEquals("Title cache did not update after setting the label and saving the term", expectedTitleCache
, termBase
.getTitleCache());
170 // add new representation for default language
171 String expecteTitleCacheAfterRepresentationChange
= "new label";
172 Representation representation
= termBase
.getRepresentation(Language
.DEFAULT());
173 representation
.setLabel(expecteTitleCacheAfterRepresentationChange
);
174 termBase
.addRepresentation(representation
);
176 //this will create another termBase in the DB which has the same UUID -> test failure
177 // termBase.addRepresentation(Representation.NewInstance(expecteTitleCacheAfterRepresentationChange, "", "", Language.DEFAULT()));////new Representation(expecteTitleCacheAfterRepresentationChange, "", "", Language.DEFAULT()));
180 commitAndStartNewTransaction(null);
182 termBase
= termService
.find(fromString
);
183 assertEquals("Title cache did not update after adding a new representation for default language and saving the term", expecteTitleCacheAfterRepresentationChange
, termBase
.getTitleCache());