Project

General

Profile

Download (5.56 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.log4j.Logger;
18
import org.junit.Assert;
19
import org.junit.BeforeClass;
20
import org.junit.Test;
21
import org.unitils.dbunit.annotation.DataSet;
22
import org.unitils.dbunit.annotation.DataSets;
23

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

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

    
36
/**
37
 * @author cmathew
38
 * @date 2 Apr 2015
39
 *
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 = Logger.getLogger(NewTaxonBasePresenterTest.class);
49

    
50
    private static NewTaxonBasePresenter ntbp;
51

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

    
57

    
58
    @Test
59
    public void testNewTaxonBase(){
60
        RowId refId20 = new RowId(20);
61
        RowId refId21 = new RowId(21);
62
        UUID newTaxonUuid = ntbp.newTaxon("Taxon  h", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
63
        List<String> ACC_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
64
                "sec",
65
                "synonyms"
66
        });
67
        Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
68

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

    
72
        Set<Synonym> synonyms = taxon.getSynonyms();
73
        Assert.assertEquals(1,synonyms.size());
74
        Synonym synonymOfTaxon = synonyms.iterator().next();
75

    
76
        Synonym synonym = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newSynonymUuid),Synonym.class);
77
        Assert.assertEquals(synonym, synonymOfTaxon);
78

    
79
        Assert.assertEquals(synonym.getSec().getId(), 20);
80

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

    
83
        Assert.assertEquals(taxon.getSec().getId(), 21);
84
    }
85

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

    
95
        }
96

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

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

    
108
        }
109

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

    
123
        }
124

    
125
        try {
126
            ntbp.newSynonym("Htsynonym  bofa", refId20, refId21, newTaxonUuid);
127
            Assert.fail("Exception should be thrown as name already exists");;
128
        } catch (IllegalArgumentException iae) {
129

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

    
136
        }
137

    
138
    }
139

    
140
    public static class MockNewTaxonBaseComposite implements INewTaxonBaseComposite {
141

    
142
        /* (non-Javadoc)
143
         * @see eu.etaxonomy.cdm.vaadin.view.INewTaxonBaseComposite#setListener(eu.etaxonomy.cdm.vaadin.view.INewTaxonBaseComponentListener)
144
         */
145
        @Override
146
        public void setListener(INewTaxonBaseComponentListener listener) {
147
            // TODO Auto-generated method stub
148

    
149
        }
150

    
151

    
152

    
153
    }
154
}
(4-4/5)