Project

General

Profile

Download (5.31 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

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

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

    
34
/**
35
 * @author cmathew
36
 * @date 2 Apr 2015
37
 *
38
 */
39
@DataSet
40
public class NewTaxonBasePresenterTest extends CdmVaadinBaseTest {
41

    
42
    @SuppressWarnings("unused")
43
    private static final Logger logger = Logger.getLogger(NewTaxonBasePresenterTest.class);
44

    
45
    private static NewTaxonBasePresenter ntbp;
46

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

    
52

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

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

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

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

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

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

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

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

    
90
        }
91

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

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

    
103
        }
104

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

    
118
        }
119

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

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

    
131
        }
132

    
133
    }
134

    
135
    public static class MockNewTaxonBaseComposite implements INewTaxonBaseComposite {
136

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

    
144
        }
145

    
146

    
147

    
148
    }
149
}
(4-4/5)