Project

General

Profile

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

    
11
import java.util.UUID;
12

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

    
22
import eu.etaxonomy.cdm.api.application.ICdmRepository;
23
import eu.etaxonomy.cdm.api.service.INameService;
24
import eu.etaxonomy.cdm.model.common.CdmBase;
25
import eu.etaxonomy.cdm.model.name.TaxonName;
26
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
27
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest;
28
import eu.etaxonomy.cdm.vaadin.component.taxon.ConceptRelationshipPresenter;
29
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
30
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree;
31
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree.Direction;
32
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
33

    
34
/**
35
 * @author cmathew
36
 * @since 9 Apr 2015
37
 *
38
 */
39
@DataSets({
40
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class),
41
    @DataSet("/eu/etaxonomy/cdm/database/FirstData_UsersAndPermissions.xml")
42
})
43
public class ConceptRelationshipPresenterTest extends CdmVaadinBaseTest {
44

    
45
    private static final Logger logger = Logger.getLogger(ConceptRelationshipPresenterTest.class);
46

    
47
    private static ConceptRelationshipPresenter crp;
48
    private static D3ConceptRelationshipTree crTree;
49

    
50
    private static INameService nameService;
51

    
52
    private static ICdmRepository app;
53

    
54
    @BeforeClass
55
    public static void init() {
56
        crTree = new D3ConceptRelationshipTree();
57
        crp = new ConceptRelationshipPresenter(crTree);
58

    
59
        nameService = CdmSpringContextHelper.getNameService();
60
        app = CdmSpringContextHelper.getApplicationConfiguration();
61
    }
62

    
63

    
64
    @Test
65
    @Ignore
66
    public void testRefreshRelationshipView() throws JSONException {
67
        UUID taxonUuid = UUID.fromString("5f713f69-e03e-4a11-8a55-700fbbf44805");
68
        crp.refreshRelationshipView(new IdUuidName(30, taxonUuid, null), Direction.LEFT_RIGHT);
69
        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\"}";
70
        logger.warn(crTree.getState().getConceptRelationshipTree());
71
        Assert.assertEquals(expected, crTree.getState().getConceptRelationshipTree());
72

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

    
80
    @Test
81
    public void testAbbreviatedNameGeneration() {
82

    
83
        // TransactionStatus tx = app.startTransaction();
84
        UUID nameUuid = UUID.fromString("7ebe3f1f-c383-4611-95da-4ee633a12d3a");
85
        TaxonName name = nameService.load(nameUuid);
86
        name = CdmBase.deproxy(name);
87

    
88
        String abbreviatedName = crTree.getAbbreviatedName(name);
89
        Assert.assertEquals("T. × withverylongspecificepithet subsp.", abbreviatedName);
90
        // app.commitTransaction(tx);
91

    
92
    }
93

    
94

    
95
}
(2-2/5)