Revision 2ba67e3f
Added by Cherian Mathew about 9 years ago
src/test/java/eu/etaxonomy/cdm/vaadin/presenter/ConceptRelationshipPresenterTest.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.vaadin.presenter; |
11 | 11 |
|
12 |
import java.util.Arrays; |
|
13 |
import java.util.List; |
|
14 | 12 |
import java.util.UUID; |
15 | 13 |
|
16 | 14 |
import org.apache.log4j.Logger; |
... | ... | |
21 | 19 |
import org.junit.Test; |
22 | 20 |
import org.unitils.dbunit.annotation.DataSet; |
23 | 21 |
|
24 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
25 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
26 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
|
27 | 22 |
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest; |
28 | 23 |
import eu.etaxonomy.cdm.vaadin.container.IdUuidName; |
29 | 24 |
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree; |
30 |
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper; |
|
31 | 25 |
|
32 | 26 |
/** |
33 | 27 |
* @author cmathew |
... | ... | |
42 | 36 |
private static ConceptRelationshipPresenter crp; |
43 | 37 |
private static D3ConceptRelationshipTree crTree; |
44 | 38 |
|
45 |
private static List<String> FROM_TAXON_INIT_STRATEGY = Arrays.asList(new String []{ |
|
46 |
"relationsFromThisTaxon" |
|
47 |
}); |
|
48 |
|
|
49 | 39 |
@BeforeClass |
50 | 40 |
public static void init() { |
51 | 41 |
crTree = new D3ConceptRelationshipTree(); |
... | ... | |
56 | 46 |
@Test |
57 | 47 |
public void testRefreshRelationshipView() throws JSONException { |
58 | 48 |
UUID taxonUuid = UUID.fromString("5f713f69-e03e-4a11-8a55-700fbbf44805"); |
59 |
crp.refreshRelationshipView(taxonUuid);
|
|
49 |
crp.refreshRelationshipView(new IdUuidName(null, taxonUuid, null));
|
|
60 | 50 |
String expected = "{\"name\":\"Taxon D sec. ???\",\"children\":[{\"name\":\"Includes\",\"children\":[{\"name\":\"Taxon A sec. Journal Reference 1\",\"uuid\":\"eaac797e-cac7-4649-97cf-c7b580076895\"},{\"name\":\"Taxon B sec. ???\",\"uuid\":\"77e7d93e-75c6-4dd4-850d-7b5809654378\"}],\"uuid\":\"0501c385-cab1-4fbe-b945-fc747419bb13\"},{\"name\":\"Excludes\",\"children\":[{\"name\":\"Taxon C sec. ???\",\"uuid\":\"3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9\"}],\"uuid\":\"4535a63c-4a3f-4d69-9350-7bf02e2c23be\"}],\"uuid\":\"5f713f69-e03e-4a11-8a55-700fbbf44805\"}"; |
61 | 51 |
Assert.assertEquals(expected, crTree.getState().getConceptRelationshipTree()); |
62 | 52 |
|
63 | 53 |
taxonUuid = UUID.fromString("3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9"); |
64 |
crp.refreshRelationshipView(taxonUuid);
|
|
54 |
crp.refreshRelationshipView(new IdUuidName(null, taxonUuid, null));
|
|
65 | 55 |
expected = "{\"name\":\"Taxon C sec. ???\",\"uuid\":\"3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9\"}"; |
66 | 56 |
Assert.assertEquals(expected, crTree.getState().getConceptRelationshipTree()); |
67 | 57 |
} |
68 | 58 |
|
69 |
@Test |
|
70 |
public void testCreateRelationship() { |
|
71 |
UUID fromTaxonUuid = UUID.fromString("77e7d93e-75c6-4dd4-850d-7b5809654378"); |
|
72 |
UUID toTaxonUuid = UUID.fromString("5004a8e7-b907-4744-b67e-44ccb057ab3b"); |
|
73 |
UUID relTypeUuid = UUID.fromString("60974c98-64ab-4574-bb5c-c110f6db634d"); |
|
74 |
|
|
75 |
IdUuidName trId = crp.createRelationship(fromTaxonUuid, relTypeUuid, toTaxonUuid); |
|
76 |
|
|
77 |
Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class); |
|
78 |
Assert.assertEquals(1, taxon.getRelationsFromThisTaxon().size()); |
|
79 |
|
|
80 |
Assert.assertEquals(trId.getUuid(),taxon.getRelationsFromThisTaxon().iterator().next().getUuid()); |
|
81 |
} |
|
82 |
|
|
83 |
@Test |
|
84 |
public void testUpdateRelationship() { |
|
85 |
UUID fromTaxonUuid = UUID.fromString("666b484f-dc1e-4578-b404-86bc6d2e47fa"); |
|
86 |
UUID taxonRelUuid = UUID.fromString("9634d870-bab1-4fdc-8845-c7e71aa8dc6b"); |
|
87 |
UUID newToTaxonUuid = UUID.fromString("5004a8e7-b907-4744-b67e-44ccb057ab3b"); |
|
88 |
UUID newRelTypeUuid = UUID.fromString("a8f03491-2ad6-4fae-a04c-2a4c117a2e9b"); |
|
89 |
|
|
90 |
Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class); |
|
91 |
TaxonRelationship tr = getFromRelwithUuid(taxon, taxonRelUuid); |
|
92 |
|
|
93 |
UUID oldToTaxonUuid = tr.getToTaxon().getUuid(); |
|
94 |
UUID oldRelTypeUuid = tr.getType().getUuid(); |
|
95 |
|
|
96 |
Assert.assertNotNull(tr); |
|
97 |
Assert.assertNotEquals(newToTaxonUuid, oldToTaxonUuid); |
|
98 |
Assert.assertNotEquals(newRelTypeUuid, oldRelTypeUuid); |
|
99 |
|
|
100 |
// change both to taxon and relationship type |
|
101 |
crp.updateRelationship(fromTaxonUuid, taxonRelUuid, newRelTypeUuid, newToTaxonUuid); |
|
102 |
taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class); |
|
103 |
tr = getFromRelwithUuid(taxon, taxonRelUuid); |
|
104 |
|
|
105 |
Assert.assertNotNull(tr); |
|
106 |
Assert.assertEquals(newToTaxonUuid, tr.getToTaxon().getUuid()); |
|
107 |
Assert.assertEquals(newRelTypeUuid, tr.getType().getUuid()); |
|
108 |
|
|
109 |
// reset old values |
|
110 |
crp.updateRelationship(fromTaxonUuid, taxonRelUuid, oldRelTypeUuid, oldToTaxonUuid); |
|
111 |
|
|
112 |
// change only relationship type |
|
113 |
crp.updateRelationship(fromTaxonUuid, taxonRelUuid, newRelTypeUuid, null); |
|
114 |
taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class); |
|
115 |
tr = getFromRelwithUuid(taxon, taxonRelUuid); |
|
116 |
|
|
117 |
Assert.assertNotNull(tr); |
|
118 |
Assert.assertEquals(oldToTaxonUuid, tr.getToTaxon().getUuid()); |
|
119 |
Assert.assertEquals(newRelTypeUuid, tr.getType().getUuid()); |
|
120 |
|
|
121 |
// reset old values |
|
122 |
crp.updateRelationship(fromTaxonUuid, taxonRelUuid, oldRelTypeUuid, oldToTaxonUuid); |
|
123 |
|
|
124 |
// change only to taxon |
|
125 |
crp.updateRelationship(fromTaxonUuid, taxonRelUuid, null, newToTaxonUuid); |
|
126 |
taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class); |
|
127 |
tr = getFromRelwithUuid(taxon, taxonRelUuid); |
|
128 |
|
|
129 |
Assert.assertNotNull(tr); |
|
130 |
Assert.assertEquals(newToTaxonUuid, tr.getToTaxon().getUuid()); |
|
131 |
Assert.assertEquals(oldRelTypeUuid, tr.getType().getUuid()); |
|
132 |
|
|
133 |
} |
|
134 |
|
|
135 |
@Test |
|
136 |
public void testDeleteRelationship() { |
|
137 |
UUID fromTaxonUuid = UUID.fromString("5f713f69-e03e-4a11-8a55-700fbbf44805"); |
|
138 |
UUID taxonRelUuid = UUID.fromString("cac9fa65-9b15-445f-80e4-56f77952f7ec"); |
|
139 |
|
|
140 |
crp.deleteRelationship(fromTaxonUuid, taxonRelUuid); |
|
141 |
Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class); |
|
142 |
Assert.assertEquals(3, taxon.getRelationsFromThisTaxon().size()); |
|
143 |
|
|
144 |
TaxonRelationship tr = getFromRelwithUuid(taxon, taxonRelUuid); |
|
145 |
Assert.assertNull(tr); |
|
146 |
|
|
147 |
fromTaxonUuid = UUID.fromString("666b484f-dc1e-4578-b404-86bc6d2e47fa"); |
|
148 |
taxonRelUuid = UUID.fromString("9634d870-bab1-4fdc-8845-c7e71aa8dc6b"); |
|
149 |
|
|
150 |
crp.deleteRelationship(fromTaxonUuid, taxonRelUuid); |
|
151 |
taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class); |
|
152 |
Assert.assertEquals(0, taxon.getRelationsFromThisTaxon().size()); |
|
153 |
} |
|
154 |
|
|
155 |
public TaxonRelationship getFromRelwithUuid(Taxon taxon, UUID taxonRelUuid) { |
|
156 |
for(TaxonRelationship tr : taxon.getRelationsFromThisTaxon()) { |
|
157 |
if(tr.getUuid().equals(taxonRelUuid)) { |
|
158 |
return tr; |
|
159 |
} |
|
160 |
} |
|
161 |
return null; |
|
162 |
} |
|
163 | 59 |
} |
Also available in: Unified diff
EditConceptRelationshipComposite : updated ui, added save + cancel + drag&drop functionality
ConceptRelationshipComposite : using the EditConceptRelationshipComposite
StatusComposite : set drag&drop mode
ConceptRelationshipPresenter, EditConceptRelationshipPresenter : moved create, update, edit methods to EditConceptRelationshipPresenter
ConceptRelationshipPresenterTest, EditConceptRelationshipPresenterTest(xml) : moved tests to EditConceptRelationshipPresenterTest