Merged in changes from cate-development branch and upgraded to spring 3.0.0.RC1
[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.util.UUID;
17
18 import org.apache.log4j.Logger;
19 import org.junit.Ignore;
20 import org.junit.Test;
21 import org.unitils.spring.annotation.SpringBeanByType;
22
23 import eu.etaxonomy.cdm.api.service.pager.Pager;
24 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
25 import eu.etaxonomy.cdm.model.common.Language;
26 import eu.etaxonomy.cdm.model.common.TermVocabulary;
27 import eu.etaxonomy.cdm.model.location.NamedArea;
28 import eu.etaxonomy.cdm.model.location.TdwgArea;
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 private static final Logger logger = Logger.getLogger(TermServiceImplTest.class);
40
41 @SpringBeanByType
42 private ITermService service;
43
44 @SpringBeanByType
45 private IVocabularyService vocabularyService;
46
47 /* ************************* TESTS *************************************************/
48
49 /**
50 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#setDao(eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao)}.
51 */
52 @Test
53 public void testSetDao() {
54 logger.info("not yet implemented");
55 }
56
57 /**
58 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#getTermByUri(java.lang.String)}.
59 */
60 @Ignore //method not yet implemented
61 @Test
62 public void testGetTermByUri() {
63 String uri = "";
64 DefinedTermBase term = service.getByUri(uri);
65 assertNotNull(term);
66 //assertEquals(Rank.DOMAIN(), term);
67 //NULL
68 String uriNotExist = "";
69 DefinedTermBase termNotExist = service.getByUri(uriNotExist);
70 assertNull(termNotExist);
71 }
72
73 /**
74 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#getTermByUuid(java.util.UUID)}.
75 */
76 @Test
77 public void testGetTermByUuid() {
78 // Rank.Domain
79 String strUUID = "ffca6ec8-8b88-417b-a6a0-f7c992aac19b";
80 UUID uuid = UUID.fromString(strUUID);
81 DefinedTermBase term = service.find(uuid);
82 assertNotNull(term);
83 assertEquals(Rank.DOMAIN(), term);
84 //NULL
85 String strUUIDNotExist = "00000000-8b88-417b-a6a0-f7c992aac19c";
86 UUID uuidNotExist = UUID.fromString(strUUIDNotExist);
87 DefinedTermBase termNotExist = service.find(uuidNotExist);
88 assertNull(termNotExist);
89 }
90
91
92 /**
93 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#listTerms(java.util.UUID)}.
94 */
95 @Ignore
96 @Test
97 public void testGetVocabularyUUID() {
98 //Rank
99 String rankVocabularyUuid = "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b";
100 UUID rankUuid = UUID.fromString(rankVocabularyUuid);
101 TermVocabulary<Rank> voc = vocabularyService.find(rankUuid);
102 assertNotNull(voc);
103 assertEquals(61, voc.getTerms().size());
104 //Null
105 String nullVocabularyUuid = "00000000-26e3-4e83-b47b-ca74eed40b1b";
106 UUID nullUuid = UUID.fromString(nullVocabularyUuid);
107 TermVocabulary<Rank> nullVoc = vocabularyService.find(nullUuid);
108 assertNull(nullVoc);
109 }
110
111 /**
112 * Test method for {@link eu.etaxonomy.cdm.api.service.TermServiceImpl#listVocabularies(java.lang.Class)}.
113 */
114 @Ignore //method not yet implemented
115 @Test
116 public void testSetVocabularies() {
117 logger.warn("Not yet implemented");
118 }
119
120 @Test
121 public void testGetAreaByTdwgAbbreviation(){
122 String tdwgAbbreviation = "GER-OO";
123 NamedArea germany = service.getAreaByTdwgAbbreviation(tdwgAbbreviation);
124 assertEquals(tdwgAbbreviation, germany.getRepresentation(Language.DEFAULT()).getAbbreviatedLabel());
125 }
126
127 @Test
128 public void testListTerms() {
129 Pager<SpecimenTypeDesignationStatus> results = (Pager)service.page(SpecimenTypeDesignationStatus.class, null,null,null,null);
130 assertNotNull("Results should not be null",results);
131 }
132 }