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.springframework.transaction.TransactionStatus;
|
20
|
import org.unitils.dbunit.annotation.DataSet;
|
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.BotanicalName;
|
26
|
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest;
|
27
|
import eu.etaxonomy.cdm.vaadin.component.taxon.ConceptRelationshipPresenter;
|
28
|
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
|
29
|
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree;
|
30
|
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree.Direction;
|
31
|
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
|
32
|
|
33
|
/**
|
34
|
* @author cmathew
|
35
|
* @date 9 Apr 2015
|
36
|
*
|
37
|
*/
|
38
|
@DataSet
|
39
|
public class ConceptRelationshipPresenterTest extends CdmVaadinBaseTest {
|
40
|
|
41
|
private static final Logger logger = Logger.getLogger(ConceptRelationshipPresenterTest.class);
|
42
|
|
43
|
private static ConceptRelationshipPresenter crp;
|
44
|
private static D3ConceptRelationshipTree crTree;
|
45
|
|
46
|
private static INameService nameService;
|
47
|
|
48
|
private static ICdmRepository app;
|
49
|
|
50
|
@BeforeClass
|
51
|
public static void init() {
|
52
|
crTree = new D3ConceptRelationshipTree();
|
53
|
crp = new ConceptRelationshipPresenter(crTree);
|
54
|
|
55
|
nameService = CdmSpringContextHelper.getNameService();
|
56
|
app = CdmSpringContextHelper.getApplicationConfiguration();
|
57
|
}
|
58
|
|
59
|
|
60
|
@Test
|
61
|
@Ignore
|
62
|
public void testRefreshRelationshipView() throws JSONException {
|
63
|
UUID taxonUuid = UUID.fromString("5f713f69-e03e-4a11-8a55-700fbbf44805");
|
64
|
crp.refreshRelationshipView(new IdUuidName(30, taxonUuid, null), Direction.LEFT_RIGHT);
|
65
|
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\"}";
|
66
|
logger.warn(crTree.getState().getConceptRelationshipTree());
|
67
|
Assert.assertEquals(expected, crTree.getState().getConceptRelationshipTree());
|
68
|
|
69
|
taxonUuid = UUID.fromString("3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9");
|
70
|
crp.refreshRelationshipView(new IdUuidName(20, taxonUuid, null), Direction.RIGHT_LEFT);
|
71
|
expected = "{\"direction\":\"right-left\",\"name\":\"T. c\",\"children\":[],\"uuid\":\"3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9\",\"type\":\"ftaxon\"}";
|
72
|
logger.warn(crTree.getState().getConceptRelationshipTree());
|
73
|
Assert.assertEquals(expected, crTree.getState().getConceptRelationshipTree());
|
74
|
}
|
75
|
|
76
|
@Test
|
77
|
public void testAbbreviatedNameGeneration() {
|
78
|
TransactionStatus tx = app.startTransaction();
|
79
|
UUID nameUuid = UUID.fromString("7ebe3f1f-c383-4611-95da-4ee633a12d3a");
|
80
|
BotanicalName name = CdmBase.deproxy(nameService.load(nameUuid), BotanicalName.class);
|
81
|
|
82
|
String abbreviatedName = crTree.getAbbreviatedName(name);
|
83
|
Assert.assertEquals("T. × withverylongspecificepithet subsp.", abbreviatedName);
|
84
|
app.commitTransaction(tx);
|
85
|
|
86
|
}
|
87
|
|
88
|
|
89
|
}
|