fix search for common names in editor and minor
[cdmlib.git] / cdmlib-services / src / test / java / eu / etaxonomy / cdm / api / service / ClassificationServiceImplTest.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.cdm.api.service;
12
13 import java.io.FileNotFoundException;
14 import java.util.Arrays;
15 import java.util.Collections;
16 import java.util.Comparator;
17 import java.util.List;
18 import java.util.UUID;
19
20 import org.apache.log4j.Level;
21 import org.apache.log4j.Logger;
22 import org.junit.Assert;
23 import org.junit.Ignore;
24 import org.junit.Test;
25 import org.unitils.dbunit.annotation.DataSet;
26 import org.unitils.spring.annotation.SpringBeanByType;
27
28 import eu.etaxonomy.cdm.model.name.Rank;
29 import eu.etaxonomy.cdm.model.taxon.Classification;
30 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
31 import eu.etaxonomy.cdm.model.taxon.TaxonNodeByNameComparator;
32 import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
33
34 /**
35 * @author n.hoffmann
36 * @created Sep 22, 2009
37 * @version 1.0
38 */
39 public class ClassificationServiceImplTest extends CdmIntegrationTest{
40
41 private static final Logger logger = Logger.getLogger(ClassificationServiceImplTest.class);
42
43 @SpringBeanByType
44 IClassificationService service;
45
46 @SpringBeanByType
47 ITaxonNodeService taxonNodeService;
48 private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[]{
49 "childNodes",
50 "childNodes.taxon",
51 "childNodes.taxon.name",
52 "taxon.sec",
53 "taxon.name.*"
54 });
55
56 private Comparator<? super TaxonNode> taxonNodeComparator;
57
58
59 /**
60 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#setTaxonNodeComparator(eu.etaxonomy.cdm.model.taxon.ITaxonNodeComparator)}.
61 */
62 // @Test
63 public final void testSetTaxonNodeComparator() {
64
65
66 // fail("Not yet implemented");
67 }
68
69 /**
70 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#loadTaxonNodeByTaxon(eu.etaxonomy.cdm.model.taxon.Taxon, java.util.UUID, java.util.List)}.
71 */
72 // @Test
73 public final void testLoadTaxonNodeByTaxon() {
74 // fail("Not yet implemented");
75 }
76
77 /**
78 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#loadTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode, java.util.List)}.
79 */
80 @Test
81 public final void testLoadTaxonNode() {
82 // fail("Not yet implemented");
83 }
84
85
86 @Test
87 @DataSet
88 public final void testTaxonNodeByNameComparator() {
89 taxonNodeComparator = new TaxonNodeByNameComparator();
90 Classification classification = service.find(UUID.fromString("6c2bc8d9-ee62-4222-be89-4a8e31770878"));
91
92 // try {
93 // printDataSet(new FileOutputStream(new File("testTaxonNodeByNameComparator-dump.xml")), new String[] {"DefinedTermBase"});
94 // } catch (FileNotFoundException e) {
95 // /* IGNORE */
96 // }
97
98 //List<TaxonNode> taxonNodes = service.loadRankSpecificRootNodes(classification, Rank.GENUS(), NODE_INIT_STRATEGY);
99
100 List<TaxonNode> taxonNodes = service.getAllNodes();
101 for (TaxonNode node: taxonNodes){
102 taxonNodeService.load(node.getUuid(), NODE_INIT_STRATEGY);
103 }
104 TaxonNode nodeGenus = taxonNodeService.find(UUID.fromString("19a4fce2-8be5-4ec7-a6a7-f3974047ba5f"));
105 int index = taxonNodes.indexOf(nodeGenus);
106 taxonNodes.remove(index);
107 Collections.sort(taxonNodes, taxonNodeComparator);
108
109 /**
110 * expected order is:
111 * Acacia subg. Aculeiferum Pedley
112 * Acacia sect. Botrycephalae Yuji Sasaki
113 * Acacia subg. Phyllodineae N.Jacobsen, Bastm. & Yuji Sasaki
114 * Acacia cuspidifolia Maslin
115 * Acacia mearnsii Benth
116 */
117
118 logger.setLevel(Level.DEBUG);
119 if(logger.isDebugEnabled()){
120 logger.debug("-------------");
121 for (TaxonNode node: taxonNodes){
122 if (node!= null && node.getTaxon() != null && node.getTaxon().getName()!= null){
123 logger.debug(node.getTaxon().getName().getTitleCache() );
124 }
125 /*for (TaxonNode child : node.getChildNodes()){
126 logger.debug(child.getTaxon().getName().getTitleCache());
127 }*/
128 }
129 }
130
131 Assert.assertEquals("Acacia subg. Aculeiferum Pedley", taxonNodes.get(1).getTaxon().getName().getTitleCache());
132
133 /*
134 ((TaxonNodeByNameComparator)taxonNodeComparator).setSortInfraGenericFirst(false);
135 Collections.sort(taxonNodes, taxonNodeComparator);
136
137 Assert.assertEquals("Acacia cuspidifolia Maslin", taxonNodes.get(0).getTaxon().getName().getTitleCache());
138 System.err.println();
139 for (TaxonNode node: taxonNodes){
140 System.err.println(node.getTaxon().getName().getTitleCache() );
141 /*for (TaxonNode child : node.getChildNodes()){
142 System.err.println(child.getTaxon().getName().getTitleCache());
143 }
144 }*/
145 // fail("Not yet implemented");
146
147 }
148
149
150 /**
151 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#loadRankSpecificRootNodes(eu.etaxonomy.cdm.model.taxon.Classification, eu.etaxonomy.cdm.model.name.Rank, java.util.List)}.
152 */
153 @Test
154 @DataSet
155 public final void testlistRankSpecificRootNodes(){
156 Classification classification = service.find(UUID.fromString("6c2bc8d9-ee62-4222-be89-4a8e31770878"));
157
158 List<TaxonNode> taxonNodes = service.listRankSpecificRootNodes(null, null, null, null, NODE_INIT_STRATEGY);
159 Assert.assertEquals(1, taxonNodes.size());
160
161 taxonNodes = service.listRankSpecificRootNodes(classification, null, null, null, NODE_INIT_STRATEGY);
162 Assert.assertEquals(1, taxonNodes.size());
163
164 taxonNodes = service.listRankSpecificRootNodes(classification, Rank.SECTION_BOTANY(), null, null, NODE_INIT_STRATEGY);
165 Assert.assertEquals(2, taxonNodes.size());
166
167 }
168
169 /**
170 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#loadTreeBranch(eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.name.Rank, java.util.List)}.
171 */
172 // @Test
173 public final void testLoadTreeBranch() {
174 // fail("Not yet implemented");
175 }
176
177 /**
178 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#loadTreeBranchToTaxon(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.Classification, eu.etaxonomy.cdm.model.name.Rank, java.util.List)}.
179 */
180 // @Test
181 public final void testLoadTreeBranchToTaxon() {
182 // fail("Not yet implemented");
183 }
184
185 /**
186 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#loadChildNodesOfTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode, java.util.List)}.
187 */
188 // @Test
189 public final void testLoadChildNodesOfTaxonNode() {
190 // fail("Not yet implemented");
191 }
192
193 /**
194 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#loadChildNodesOfTaxon(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.Classification, java.util.List)}.
195 */
196 // @Test
197 public final void testLoadChildNodesOfTaxon() {
198 // fail("Not yet implemented");
199 }
200
201 /**
202 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#getTaxonNodeByUuid(java.util.UUID)}.
203 */
204 // @Test
205 public final void testGetTaxonNodeByUuid() {
206 // fail("Not yet implemented");
207 }
208
209 /**
210 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#getTreeNodeByUuid(java.util.UUID)}.
211 */
212 // @Test
213 public final void testGetTreeNodeByUuid() {
214 // fail("Not yet implemented");
215 }
216
217 /**
218 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#listClassifications(java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)}.
219 */
220 // @Test
221 public final void testListClassifications() {
222 // fail("Not yet implemented");
223 }
224
225 /**
226 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#getClassificationByUuid(java.util.UUID)}.
227 */
228 // @Test
229 public final void testGetClassificationByUuid() {
230 // fail("Not yet implemented");
231 }
232
233 /**
234 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#removeTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode)}.
235 */
236 // @Test
237 public final void testRemoveTaxonNode() {
238 // fail("Not yet implemented");
239 }
240
241 /**
242 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#removeTreeNode(eu.etaxonomy.cdm.model.taxon.ITreeNode)}.
243 */
244 // @Test
245 public final void testRemoveTreeNode() {
246 // fail("Not yet implemented");
247 }
248
249 /**
250 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#saveTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode)}.
251 */
252 // @Test
253 public final void testSaveTaxonNode() {
254 // fail("Not yet implemented");
255 }
256
257 /**
258 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#saveTaxonNodeAll(java.util.Collection)}.
259 */
260 // @Test
261 public final void testSaveTaxonNodeAll() {
262 // fail("Not yet implemented");
263 }
264
265 /**
266 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#saveTreeNode(eu.etaxonomy.cdm.model.taxon.ITreeNode)}.
267 */
268 // @Test
269 public final void testSaveTreeNode() {
270 // fail("Not yet implemented");
271 }
272
273 /**
274 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(eu.etaxonomy.cdm.model.taxon.Classification)}.
275 */
276 // @Test
277 public final void testGetTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification() {
278 // fail("Not yet implemented");
279 }
280
281 /**
282 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#getUuidAndTitleCache()}.
283 */
284 // @Test
285 public final void testGetUuidAndTitleCache() {
286 // fail("Not yet implemented");
287 }
288
289 /**
290 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#getAllMediaForChildNodes(eu.etaxonomy.cdm.model.taxon.TaxonNode, java.util.List, int, int, int, java.lang.String[])}.
291 */
292 // @Test
293 public final void testGetAllMediaForChildNodesTaxonNodeListOfStringIntIntIntStringArray() {
294 // fail("Not yet implemented");
295 }
296
297 /**
298 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#getAllMediaForChildNodes(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.Classification, java.util.List, int, int, int, java.lang.String[])}.
299 */
300 // @Test
301 public final void testGetAllMediaForChildNodesTaxonClassificationListOfStringIntIntIntStringArray() {
302 // fail("Not yet implemented");
303 }
304
305 /**
306 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#setDao(eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao)}.
307 */
308 @Test
309 public final void testSetDaoIClassificationDao() {
310 Assert.assertNotNull(service);
311 }
312
313 /**
314 * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#generateTitleCache()}.
315 */
316 // @Test
317 public final void testGenerateTitleCache() {
318 // fail("Not yet implemented");
319 }
320
321 /* (non-Javadoc)
322 * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
323 */
324 @Override
325 public void createTestDataSet() throws FileNotFoundException {
326 // TODO Auto-generated method stub
327
328 }
329 }