Project

General

Profile

Download (5.94 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.Set;
15
import java.util.UUID;
16

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

    
25
import com.vaadin.data.util.sqlcontainer.RowId;
26

    
27
import eu.etaxonomy.cdm.model.common.CdmBase;
28
import eu.etaxonomy.cdm.model.taxon.Synonym;
29
import eu.etaxonomy.cdm.model.taxon.Taxon;
30
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
31
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest;
32
import eu.etaxonomy.cdm.vaadin.component.taxon.INewTaxonBaseComponentListener;
33
import eu.etaxonomy.cdm.vaadin.component.taxon.INewTaxonBaseComposite;
34
import eu.etaxonomy.cdm.vaadin.component.taxon.NewTaxonBasePresenter;
35
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
36

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

    
47
    @SuppressWarnings("unused")
48
    private static final Logger logger = LogManager.getLogger();
49

    
50
    private static NewTaxonBasePresenter newTaxonBasePresenter;
51

    
52
    @BeforeClass
53
    public static void init() throws SQLException {
54
        newTaxonBasePresenter = new NewTaxonBasePresenter();
55
    }
56

    
57
    @Test
58
    //NOTE by AM: I fixed property path sec=>secSource.citation (#9327), not sure if this is correct
59
    //            but as the test does not say what is meant to be tested I can't proof it
60
    public void testNewTaxonBase(){
61
        RowId refId20 = new RowId(20);
62
        RowId refId21 = new RowId(21);
63
        UUID newTaxonUuid = newTaxonBasePresenter.newTaxon("Taxon  h", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
64
        List<String> ACC_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
65
                "secSource.citation",
66
                "synonyms"
67
        });
68
        Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
69

    
70
        UUID newSynonymUuid = newTaxonBasePresenter.newSynonym("Synonym ofe", refId20, refId21, newTaxonUuid).getUuid();
71
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
72

    
73
        Set<Synonym> synonyms = taxon.getSynonyms();
74
        Assert.assertEquals(1,synonyms.size());
75
        Synonym synonymOfTaxon = synonyms.iterator().next();
76
        List<String> SYN_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
77
                "secSource.citation"
78
        });
79
        Synonym synonym = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newSynonymUuid, SYN_TAXON_INIT_STRATEGY),Synonym.class);
80
        Assert.assertEquals(synonym, synonymOfTaxon);
81

    
82
        Assert.assertEquals(synonym.getSec().getId(), 20);
83

    
84
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
85

    
86
        Assert.assertEquals(taxon.getSec().getId(), 21);
87
    }
88

    
89
    @Test
90
    public void testNewTaxonBaseWhenNameAlreadyExists() {
91
        RowId refId20 = new RowId(20);
92
        // test taxa
93
        try {
94
            newTaxonBasePresenter.newTaxon("Taxon e", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
95
            Assert.fail("Exception should be thrown as name already exists");
96
        } catch (IllegalArgumentException iae) {
97

    
98
        }
99

    
100
        try {
101
            newTaxonBasePresenter.newTaxon("Taxon  e", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
102
            Assert.fail("Exception should be thrown as name already exists");
103
        } catch (IllegalArgumentException iae) {
104

    
105
        }
106
        try{
107
            newTaxonBasePresenter.newTaxon("Taxon e Me.", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
108
            Assert.fail("Exception should be thrown as name already exists");
109
        } catch (IllegalArgumentException iae) {
110

    
111
        }
112

    
113
        // test synonym
114
        RowId refId21 = new RowId(21);
115
        UUID newTaxonUuid = newTaxonBasePresenter.newTaxon("Taxon  h", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
116
        List<String> ACC_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
117
                "secSource.citation",
118
                "synonymRelations"
119
        });
120
        Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
121
        try {
122
            newTaxonBasePresenter.newSynonym("Htsynonym bofa", refId20, refId21, newTaxonUuid);
123
            Assert.fail("Exception should be thrown as name already exists");
124
        } catch (IllegalArgumentException iae) {
125

    
126
        }
127

    
128
        try {
129
            newTaxonBasePresenter.newSynonym("Htsynonym  bofa", refId20, refId21, newTaxonUuid);
130
            Assert.fail("Exception should be thrown as name already exists");
131
        } catch (IllegalArgumentException iae) {
132

    
133
        }
134
        try{
135
            newTaxonBasePresenter.newSynonym("Htsynonym bofa Me.", refId20, refId21, newTaxonUuid);
136
            Assert.fail("Exception should be thrown as name already exists");
137
        } catch (IllegalArgumentException iae) {
138

    
139
        }
140
    }
141

    
142
    public static class MockNewTaxonBaseComposite implements INewTaxonBaseComposite {
143

    
144
        @Override
145
        public void setListener(INewTaxonBaseComponentListener listener) {
146
            // TODO Auto-generated method stub
147
        }
148
    }
149
}
(4-4/5)