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