Project

General

Profile

Download (6.97 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.sql.SQLException;
12
import java.util.Arrays;
13
import java.util.List;
14
import java.util.Map;
15
import java.util.UUID;
16

    
17
import org.apache.log4j.Logger;
18
import org.junit.Assert;
19
import org.junit.BeforeClass;
20
import org.junit.Ignore;
21
import org.junit.Test;
22
import org.unitils.dbunit.annotation.DataSet;
23

    
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
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest;
28
import eu.etaxonomy.cdm.vaadin.component.taxon.EditConceptRelationshipPresenter;
29
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
30
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
31
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
32

    
33
/**
34
 * @author cmathew
35
 * @date 13 Apr 2015
36
 *
37
 */
38
@Ignore
39
@DataSet
40
public class EditConceptRelationshipPresenterTest extends CdmVaadinBaseTest {
41

    
42
    private static final Logger logger = Logger.getLogger(EditConceptRelationshipPresenterTest.class);
43
    public static EditConceptRelationshipPresenter ecrp;
44

    
45
    private static List<String> FROM_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
46
            "relationsFromThisTaxon"
47
    });
48

    
49
    @BeforeClass
50
    public static void init() {
51
        ecrp = new EditConceptRelationshipPresenter();
52
    }
53

    
54
    @Test
55
    public void testLoadTaxonRelationshipTypeContainer() throws SQLException {
56
        CdmSQLContainer container = ecrp.loadTaxonRelationshipTypeContainer();
57
        Assert.assertEquals(30, container.size());
58
    }
59

    
60

    
61
    @Test
62
    public void testCreateRelationship() {
63
        UUID fromTaxonUuid = UUID.fromString("77e7d93e-75c6-4dd4-850d-7b5809654378");
64
        UUID toTaxonUuid = UUID.fromString("5004a8e7-b907-4744-b67e-44ccb057ab3b");
65
        UUID relTypeUuid = UUID.fromString("60974c98-64ab-4574-bb5c-c110f6db634d");
66

    
67
        IdUuidName trId =ecrp.createRelationship(fromTaxonUuid, relTypeUuid, toTaxonUuid);
68

    
69
        Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
70
        Assert.assertEquals(1, taxon.getRelationsFromThisTaxon().size());
71

    
72
        Assert.assertEquals(trId.getUuid(),taxon.getRelationsFromThisTaxon().iterator().next().getUuid());
73
    }
74

    
75
    @Test
76
    public void testUpdateRelationship() {
77
        UUID fromTaxonUuid = UUID.fromString("666b484f-dc1e-4578-b404-86bc6d2e47fa");
78
        UUID taxonRelUuid = UUID.fromString("9634d870-bab1-4fdc-8845-c7e71aa8dc6b");
79
        UUID newToTaxonUuid = UUID.fromString("5004a8e7-b907-4744-b67e-44ccb057ab3b");
80
        UUID newRelTypeUuid = UUID.fromString("a8f03491-2ad6-4fae-a04c-2a4c117a2e9b");
81

    
82
        Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
83
        TaxonRelationship tr = getFromRelwithUuid(taxon, taxonRelUuid);
84

    
85
        UUID oldToTaxonUuid = tr.getToTaxon().getUuid();
86
        UUID oldRelTypeUuid = tr.getType().getUuid();
87

    
88
        Assert.assertNotNull(tr);
89
        Assert.assertNotEquals(newToTaxonUuid, oldToTaxonUuid);
90
        Assert.assertNotEquals(newRelTypeUuid, oldRelTypeUuid);
91

    
92
        // change both to taxon and relationship type
93
        ecrp.updateRelationship(fromTaxonUuid, taxonRelUuid, newRelTypeUuid, newToTaxonUuid);
94
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
95
        tr = getFromRelwithUuid(taxon, taxonRelUuid);
96

    
97
        Assert.assertNotNull(tr);
98
        Assert.assertEquals(newToTaxonUuid, tr.getToTaxon().getUuid());
99
        Assert.assertEquals(newRelTypeUuid, tr.getType().getUuid());
100

    
101
        // reset old values
102
        ecrp.updateRelationship(fromTaxonUuid, taxonRelUuid, oldRelTypeUuid, oldToTaxonUuid);
103

    
104
        // change only relationship type
105
        ecrp.updateRelationship(fromTaxonUuid, taxonRelUuid, newRelTypeUuid, null);
106
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
107
        tr = getFromRelwithUuid(taxon, taxonRelUuid);
108

    
109
        Assert.assertNotNull(tr);
110
        Assert.assertEquals(oldToTaxonUuid, tr.getToTaxon().getUuid());
111
        Assert.assertEquals(newRelTypeUuid, tr.getType().getUuid());
112

    
113
        // reset old values
114
        ecrp.updateRelationship(fromTaxonUuid, taxonRelUuid, oldRelTypeUuid, oldToTaxonUuid);
115

    
116
        // change only to taxon
117
        ecrp.updateRelationship(fromTaxonUuid, taxonRelUuid, null, newToTaxonUuid);
118
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
119
        tr = getFromRelwithUuid(taxon, taxonRelUuid);
120

    
121
        Assert.assertNotNull(tr);
122
        Assert.assertEquals(newToTaxonUuid, tr.getToTaxon().getUuid());
123
        Assert.assertEquals(oldRelTypeUuid, tr.getType().getUuid());
124

    
125
    }
126

    
127
    @Test
128
    public void testDeleteRelationship() {
129
        UUID fromTaxonUuid = UUID.fromString("5f713f69-e03e-4a11-8a55-700fbbf44805");
130
        UUID taxonRelUuid = UUID.fromString("cac9fa65-9b15-445f-80e4-56f77952f7ec");
131

    
132
        ecrp.deleteRelationship(fromTaxonUuid, taxonRelUuid);
133
        Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
134
        Assert.assertEquals(4, taxon.getRelationsFromThisTaxon().size());
135

    
136
        TaxonRelationship tr = getFromRelwithUuid(taxon, taxonRelUuid);
137
        Assert.assertNull(tr);
138

    
139
        fromTaxonUuid = UUID.fromString("666b484f-dc1e-4578-b404-86bc6d2e47fa");
140
        taxonRelUuid = UUID.fromString("9634d870-bab1-4fdc-8845-c7e71aa8dc6b");
141

    
142
        ecrp.deleteRelationship(fromTaxonUuid, taxonRelUuid);
143
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
144
        Assert.assertEquals(0, taxon.getRelationsFromThisTaxon().size());
145
    }
146

    
147

    
148
    @Test
149
    public void testGetRelTypeToTaxonIunMap() {
150
        UUID fromTaxonUuid = UUID.fromString("5f713f69-e03e-4a11-8a55-700fbbf44805");
151
        UUID taxonRelUuid = UUID.fromString("cc761030-38d2-4b5d-954d-32329c0ea106");
152
        Map<String, IdUuidName> map = ecrp.getRelTypeToTaxonIunMap(fromTaxonUuid, taxonRelUuid);
153

    
154
        IdUuidName relTypeIun = map.get(EditConceptRelationshipPresenter.REL_TYPE_KEY);
155
        Assert.assertEquals(924, relTypeIun.getId());
156

    
157
        IdUuidName toTaxonIun = map.get(EditConceptRelationshipPresenter.TO_TAXON_KEY);
158
        Assert.assertEquals(20, toTaxonIun.getId());
159
    }
160

    
161
    public TaxonRelationship getFromRelwithUuid(Taxon taxon, UUID taxonRelUuid) {
162
        for(TaxonRelationship tr : taxon.getRelationsFromThisTaxon()) {
163
            if(tr.getUuid().equals(taxonRelUuid)) {
164
                return tr;
165
            }
166
        }
167
        return null;
168
    }
169
}
(3-3/5)