Project

General

Profile

Download (5.22 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
// $Id$
3
/**
4
* Copyright (C) 2015 EDIT
5
* European Distributed Institute of Taxonomy
6
* http://www.e-taxonomy.eu
7
*
8
* The contents of this file are subject to the Mozilla Public License Version 1.1
9
* See LICENSE.TXT at the top of this package for the full license terms.
10
*/
11
package eu.etaxonomy.cdm.vaadin.presenter;
12

    
13
import java.sql.SQLException;
14
import java.util.Arrays;
15
import java.util.List;
16
import java.util.Set;
17
import java.util.UUID;
18

    
19
import org.apache.log4j.Logger;
20
import org.junit.Assert;
21
import org.junit.BeforeClass;
22
import org.junit.Test;
23
import org.unitils.dbunit.annotation.DataSet;
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.vaadin.CdmVaadinBaseTest;
31
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
32
import eu.etaxonomy.cdm.vaadin.view.INewTaxonBaseComponentListener;
33
import eu.etaxonomy.cdm.vaadin.view.INewTaxonBaseComposite;
34

    
35
/**
36
 * @author cmathew
37
 * @date 2 Apr 2015
38
 *
39
 */
40

    
41
@DataSet
42
public class NewTaxonBasePresenterTest extends CdmVaadinBaseTest {
43

    
44
    private static final Logger logger = Logger.getLogger(NewTaxonBasePresenterTest.class);
45

    
46
    private static NewTaxonBasePresenter ntbp;
47

    
48
    @BeforeClass
49
    public static void init() throws SQLException {
50
        ntbp = new NewTaxonBasePresenter();
51
    }
52

    
53

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

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

    
68
        Set<Synonym> synonyms = taxon.getSynonyms();
69
        Assert.assertEquals(1,synonyms.size());
70
        Synonym synonymOfTaxon = synonyms.iterator().next();
71

    
72
        Synonym synonym = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newSynonymUuid),Synonym.class);
73
        Assert.assertEquals(synonym, synonymOfTaxon);
74

    
75
        Assert.assertEquals(synonym.getSec().getId(), 20);
76

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

    
79
        Assert.assertEquals(taxon.getSec().getId(), 21);
80
    }
81

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

    
91
        }
92

    
93
        try {
94
            ntbp.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
        try{
100
            ntbp.newTaxon("Taxon e Me.", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
101
            Assert.fail("Exception should be thrown as name already exists");;
102
        } catch (IllegalArgumentException iae) {
103

    
104
        }
105

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

    
119
        }
120

    
121
        try {
122
            ntbp.newSynonym("Htsynonym  bofa", refId20, refId21, newTaxonUuid);
123
            Assert.fail("Exception should be thrown as name already exists");;
124
        } catch (IllegalArgumentException iae) {
125

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

    
132
        }
133

    
134
    }
135

    
136
    public static class MockNewTaxonBaseComposite implements INewTaxonBaseComposite {
137

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

    
145
        }
146

    
147

    
148

    
149
    }
150
}
(4-4/5)