fixing problem with TaxonServiceImplTest which ocurred only on my machine. The test...
[cdmlib.git] / cdmlib-services / src / test / java / eu / etaxonomy / cdm / api / service / TermServiceImplTest.java
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.UUID;
18
19 import org.apache.log4j.Logger;
20 import org.junit.Ignore;
21 import org.junit.Test;
22 import org.unitils.spring.annotation.SpringBeanByType;
23
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;
32
33 /**
34 * @author a.mueller
35 * @created 27.05.2008
36 * @version 1.0
37 */
38 public class TermServiceImplTest extends CdmIntegrationTest {
39 @SuppressWarnings("unused")
40 private static final Logger logger = Logger.getLogger(TermServiceImplTest.class);
41
42 @SpringBeanByType
43 private ITermService service;
44
45 @SpringBeanByType
46 private IVocabularyService vocabularyService;
47
48 /* ************************* TESTS *************************************************/
49
50 /**
51 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#getTermByUri(java.lang.String)}.
52 */
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
55 @Test
56 /* @DataSet
57 * WARNING:
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
61 */
62 public void testGetTermByUri() {
63 String uriStr = "http://any.uri.com";
64 URI uri = URI.create(uriStr);
65 DefinedTermBase<?> term = service.getByUri(uri);
66 assertNotNull(term);
67 //for testing only
68 // TermVocabulary<?> voc = term.getVocabulary();
69 // service.saveOrUpdate(term);
70 // List<MarkerType> list = service.listByTermClass(MarkerType.class, null, null, null, null);
71
72 //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);
79 }
80
81 /**
82 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#getTermByUuid(java.util.UUID)}.
83 */
84 @Test
85 /* @DataSet
86 * WARNING:
87 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
88 * and thus will cause unitils empty the according tables
89 */
90 public void testGetTermByUuid() {
91 // Rank.Domain
92 String strUUID = "ffca6ec8-8b88-417b-a6a0-f7c992aac19b";
93 UUID uuid = UUID.fromString(strUUID);
94 DefinedTermBase<?> term = service.find(uuid);
95 assertNotNull(term);
96 assertEquals(Rank.DOMAIN(), term);
97 //NULL
98 String strUUIDNotExist = "00000000-8b88-417b-a6a0-f7c992aac19c";
99 UUID uuidNotExist = UUID.fromString(strUUIDNotExist);
100 DefinedTermBase<?> termNotExist = service.find(uuidNotExist);
101 assertNull(termNotExist);
102 }
103
104
105 /**
106 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#listTerms(java.util.UUID)}.
107 */
108 // @Ignore
109 @Test
110 /* @DataSet
111 * WARNING:
112 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
113 * and thus will cause unitils empty the according tables
114 */
115 public void testGetVocabularyUUID() {
116 //Rank
117 String rankVocabularyUuid = "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b";
118 UUID rankUuid = UUID.fromString(rankVocabularyUuid);
119 TermVocabulary<Rank> voc = vocabularyService.find(rankUuid);
120 assertNotNull(voc);
121 assertEquals(66, voc.getTerms().size());
122 //Null
123 String nullVocabularyUuid = "00000000-26e3-4e83-b47b-ca74eed40b1b";
124 UUID nullUuid = UUID.fromString(nullVocabularyUuid);
125 TermVocabulary<Rank> nullVoc = vocabularyService.find(nullUuid);
126 assertNull(nullVoc);
127 }
128
129
130 @Test
131 /* @DataSet
132 * WARNING:
133 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
134 * and thus will cause unitils empty the according tables
135 */
136 public void testGetAreaByTdwgAbbreviation(){
137 String tdwgAbbreviation = "GER-OO";
138 NamedArea germany = service.getAreaByTdwgAbbreviation(tdwgAbbreviation);
139 assertEquals(tdwgAbbreviation, germany.getRepresentation(Language.DEFAULT()).getAbbreviatedLabel());
140 }
141
142 @Test
143 /* @DataSet
144 * WARNING:
145 * the dataset contains records for DEFINEDTERMBASE,DEFINEDTERMBASE_REPRESENTATION and REPRESENTAION
146 * and thus will cause unitils empty the according tables
147 */
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);
151 }
152 }