Project

General

Profile

Download (4.15 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2015 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
package eu.etaxonomy.cdm.vaadin.presenter;
11

    
12
import java.util.UUID;
13

    
14
import org.apache.log4j.Logger;
15
import org.json.JSONException;
16
import org.junit.Assert;
17
import org.junit.BeforeClass;
18
import org.junit.Test;
19
import org.springframework.transaction.TransactionStatus;
20
import org.unitils.dbunit.annotation.DataSet;
21

    
22
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
23
import eu.etaxonomy.cdm.api.service.INameService;
24
import eu.etaxonomy.cdm.model.common.CdmBase;
25
import eu.etaxonomy.cdm.model.name.BotanicalName;
26
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest;
27
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
28
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree;
29
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree.Direction;
30
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
31

    
32
/**
33
 * @author cmathew
34
 * @date 9 Apr 2015
35
 *
36
 */
37
@DataSet
38
public class ConceptRelationshipPresenterTest extends CdmVaadinBaseTest {
39

    
40
    private static final Logger logger = Logger.getLogger(ConceptRelationshipPresenterTest.class);
41

    
42
    private static ConceptRelationshipPresenter crp;
43
    private static D3ConceptRelationshipTree crTree;
44

    
45
    private static INameService nameService;
46

    
47
    private static ICdmApplicationConfiguration app;
48

    
49
    @BeforeClass
50
    public static void init() {
51
        crTree = new D3ConceptRelationshipTree();
52
        crp = new ConceptRelationshipPresenter(crTree);
53

    
54
        nameService = CdmSpringContextHelper.getNameService();
55
        app = CdmSpringContextHelper.getApplicationConfiguration();
56
    }
57

    
58

    
59
    @Test
60
    @Ignore
61
    public void testRefreshRelationshipView() throws JSONException {
62
        UUID taxonUuid = UUID.fromString("5f713f69-e03e-4a11-8a55-700fbbf44805");
63
        crp.refreshRelationshipView(new IdUuidName(30, taxonUuid, null), Direction.LEFT_RIGHT);
64
        String expected = "{\"direction\":\"left-right\",\"name\":\"T. d\",\"children\":[{\"name\":\"Congruent to\",\"children\":[{\"name\":\"Taxon e\",\"uuid\":\"84e99e24-f50a-4726-92d0-6088430c492a\",\"type\":\"ttaxon\"}],\"uuid\":\"511f504b-ae3b-4f04-b7b9-35c222f06e10\",\"type\":\"conceptr\"},{\"name\":\"Includes\",\"children\":[{\"name\":\"Taxon a\",\"uuid\":\"eaac797e-cac7-4649-97cf-c7b580076895\",\"type\":\"ttaxon\"}],\"uuid\":\"0e8b7922-974d-4389-b71e-af6fc9f98c56\",\"type\":\"conceptr\"},{\"name\":\"Includes\",\"children\":[{\"name\":\"Taxon b\",\"uuid\":\"5004a8e7-b907-4744-b67e-44ccb057ab3b\",\"type\":\"ttaxon\"}],\"uuid\":\"6fd9947e-21c3-4190-8748-57d9661e8659\",\"type\":\"conceptr\"},{\"name\":\"Excludes\",\"children\":[{\"name\":\"Taxon c\",\"uuid\":\"3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9\",\"type\":\"ttaxon\"}],\"uuid\":\"cc761030-38d2-4b5d-954d-32329c0ea106\",\"type\":\"conceptr\"}],\"uuid\":\"5f713f69-e03e-4a11-8a55-700fbbf44805\",\"type\":\"ftaxon\"}";
65
        logger.warn(crTree.getState().getConceptRelationshipTree());
66
        Assert.assertEquals(expected, crTree.getState().getConceptRelationshipTree());
67

    
68
        taxonUuid = UUID.fromString("3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9");
69
        crp.refreshRelationshipView(new IdUuidName(20, taxonUuid, null), Direction.RIGHT_LEFT);
70
        expected = "{\"direction\":\"right-left\",\"name\":\"T. c\",\"children\":[],\"uuid\":\"3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9\",\"type\":\"ftaxon\"}";
71
        logger.warn(crTree.getState().getConceptRelationshipTree());
72
        Assert.assertEquals(expected, crTree.getState().getConceptRelationshipTree());
73
    }
74

    
75
    @Test
76
    public void testAbbreviatedNameGeneration() {
77
        TransactionStatus tx = app.startTransaction();
78
        UUID nameUuid = UUID.fromString("7ebe3f1f-c383-4611-95da-4ee633a12d3a");
79
        BotanicalName name = CdmBase.deproxy(nameService.load(nameUuid), BotanicalName.class);
80

    
81
        String abbreviatedName = crTree.getAbbreviatedName(name);
82
        Assert.assertEquals("T. × withverylongspecificepithet subsp.", abbreviatedName);
83
        app.commitTransaction(tx);
84

    
85
    }
86

    
87

    
88
}
(2-2/5)