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
    @SuppressWarnings("unused")
45
    private static final Logger logger = Logger.getLogger(NewTaxonBasePresenterTest.class);
46

    
47
    private static NewTaxonBasePresenter ntbp;
48

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

    
54

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

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

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

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

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

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

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

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

    
92
        }
93

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

    
99
        }
100
        try{
101
            ntbp.newTaxon("Taxon e Me.", 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

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

    
120
        }
121

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

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

    
133
        }
134

    
135
    }
136

    
137
    public static class MockNewTaxonBaseComposite implements INewTaxonBaseComposite {
138

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

    
146
        }
147

    
148

    
149

    
150
    }
151
}
(4-4/5)