Project

General

Profile

Download (10.7 KB) Statistics
| Branch: | Tag: | Revision:
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 junit.framework.Assert;
20

    
21
import org.apache.log4j.Level;
22
import org.apache.log4j.Logger;
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
                logger.debug(node.getTaxon().getName().getTitleCache() );
123
            /*for (TaxonNode child : node.getChildNodes()){
124
                    logger.debug(child.getTaxon().getName().getTitleCache());
125
            }*/
126
        }
127
        }
128

    
129
        Assert.assertEquals("Acacia subg. Aculeiferum Pedley", taxonNodes.get(0).getTaxon().getName().getTitleCache());
130

    
131
        /*
132
        ((TaxonNodeByNameComparator)taxonNodeComparator).setSortInfraGenericFirst(false);
133
        Collections.sort(taxonNodes, taxonNodeComparator);
134

    
135
        Assert.assertEquals("Acacia cuspidifolia Maslin", taxonNodes.get(0).getTaxon().getName().getTitleCache());
136
        System.err.println();
137
        for (TaxonNode node: taxonNodes){
138
            System.err.println(node.getTaxon().getName().getTitleCache() );
139
            /*for (TaxonNode child : node.getChildNodes()){
140
                System.err.println(child.getTaxon().getName().getTitleCache());
141
            }
142
        }*/
143
//		fail("Not yet implemented");
144

    
145
    }
146

    
147

    
148
    /**
149
     * 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)}.
150
     */
151
    @Test
152
    @DataSet
153
    @Ignore
154
    public final void testloadRankSpecificRootNodes(){
155
        Classification classification = service.find(UUID.fromString("6c2bc8d9-ee62-4222-be89-4a8e31770878"));
156

    
157
        List<TaxonNode> taxonNodes = service.loadRankSpecificRootNodes(classification, Rank.SECTION_BOTANY(), NODE_INIT_STRATEGY);
158
        Assert.assertEquals(2, taxonNodes.size());
159

    
160
    }
161

    
162
    /**
163
     * 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)}.
164
     */
165
//    @Test
166
    public final void testLoadTreeBranch() {
167
//		fail("Not yet implemented");
168
    }
169

    
170
    /**
171
     * 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)}.
172
     */
173
//    @Test
174
    public final void testLoadTreeBranchToTaxon() {
175
//		fail("Not yet implemented");
176
    }
177

    
178
    /**
179
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#loadChildNodesOfTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode, java.util.List)}.
180
     */
181
//    @Test
182
    public final void testLoadChildNodesOfTaxonNode() {
183
//		fail("Not yet implemented");
184
    }
185

    
186
    /**
187
     * 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)}.
188
     */
189
//    @Test
190
    public final void testLoadChildNodesOfTaxon() {
191
//		fail("Not yet implemented");
192
    }
193

    
194
    /**
195
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#getTaxonNodeByUuid(java.util.UUID)}.
196
     */
197
//    @Test
198
    public final void testGetTaxonNodeByUuid() {
199
//		fail("Not yet implemented");
200
    }
201

    
202
    /**
203
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#getTreeNodeByUuid(java.util.UUID)}.
204
     */
205
//    @Test
206
    public final void testGetTreeNodeByUuid() {
207
//		fail("Not yet implemented");
208
    }
209

    
210
    /**
211
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#listClassifications(java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)}.
212
     */
213
//    @Test
214
    public final void testListClassifications() {
215
//		fail("Not yet implemented");
216
    }
217

    
218
    /**
219
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#getClassificationByUuid(java.util.UUID)}.
220
     */
221
//    @Test
222
    public final void testGetClassificationByUuid() {
223
//		fail("Not yet implemented");
224
    }
225

    
226
    /**
227
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#removeTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode)}.
228
     */
229
//    @Test
230
    public final void testRemoveTaxonNode() {
231
//		fail("Not yet implemented");
232
    }
233

    
234
    /**
235
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#removeTreeNode(eu.etaxonomy.cdm.model.taxon.ITreeNode)}.
236
     */
237
//    @Test
238
    public final void testRemoveTreeNode() {
239
//		fail("Not yet implemented");
240
    }
241

    
242
    /**
243
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#saveTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode)}.
244
     */
245
//    @Test
246
    public final void testSaveTaxonNode() {
247
//		fail("Not yet implemented");
248
    }
249

    
250
    /**
251
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#saveTaxonNodeAll(java.util.Collection)}.
252
     */
253
//    @Test
254
    public final void testSaveTaxonNodeAll() {
255
//		fail("Not yet implemented");
256
    }
257

    
258
    /**
259
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#saveTreeNode(eu.etaxonomy.cdm.model.taxon.ITreeNode)}.
260
     */
261
//    @Test
262
    public final void testSaveTreeNode() {
263
//		fail("Not yet implemented");
264
    }
265

    
266
    /**
267
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(eu.etaxonomy.cdm.model.taxon.Classification)}.
268
     */
269
//    @Test
270
    public final void testGetTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification() {
271
//		fail("Not yet implemented");
272
    }
273

    
274
    /**
275
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#getUuidAndTitleCache()}.
276
     */
277
//    @Test
278
    public final void testGetUuidAndTitleCache() {
279
//		fail("Not yet implemented");
280
    }
281

    
282
    /**
283
     * 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[])}.
284
     */
285
//    @Test
286
    public final void testGetAllMediaForChildNodesTaxonNodeListOfStringIntIntIntStringArray() {
287
//		fail("Not yet implemented");
288
    }
289

    
290
    /**
291
     * 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[])}.
292
     */
293
//    @Test
294
    public final void testGetAllMediaForChildNodesTaxonClassificationListOfStringIntIntIntStringArray() {
295
//		fail("Not yet implemented");
296
    }
297

    
298
    /**
299
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#setDao(eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao)}.
300
     */
301
    @Test
302
    public final void testSetDaoIClassificationDao() {
303
        Assert.assertNotNull(service);
304
    }
305

    
306
    /**
307
     * Test method for {@link eu.etaxonomy.cdm.api.service.ClassificationServiceImpl#generateTitleCache()}.
308
     */
309
//    @Test
310
    public final void testGenerateTitleCache() {
311
//		fail("Not yet implemented");
312
    }
313
}
(1-1/17)