Project

General

Profile

Download (5.1 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.util.Arrays;
12
import java.util.List;
13
import java.util.Set;
14
import java.util.UUID;
15

    
16
import org.apache.log4j.Logger;
17
import org.junit.Assert;
18
import org.junit.Test;
19
import org.unitils.dbunit.annotation.DataSet;
20
import org.unitils.spring.annotation.SpringBeanByType;
21

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

    
24
import eu.etaxonomy.cdm.api.application.CdmRepository;
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.view.INewTaxonBaseComponentListener;
30
import eu.etaxonomy.cdm.vaadin.view.INewTaxonBaseComposite;
31

    
32
/**
33
 * @author cmathew
34
 * @date 2 Apr 2015
35
 *
36
 */
37

    
38
@DataSet
39
public class NewTaxonBasePresenterTest extends CdmVaadinBaseTest {
40

    
41
    @SpringBeanByType
42
    private CdmRepository cdmRepo = null;
43

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

    
47
    @SpringBeanByType
48
    private NewTaxonBasePresenter ntbp = null;
49

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

    
61
        UUID newSynonymUuid = ntbp.newSynonym("Synonym ofe", refId20, refId21, newTaxonUuid).getUuid();
62
        taxon = CdmBase.deproxy(cdmRepo.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
63

    
64
        Set<Synonym> synonyms = taxon.getSynonyms();
65
        Assert.assertEquals(1,synonyms.size());
66
        Synonym synonymOfTaxon = synonyms.iterator().next();
67

    
68
        Synonym synonym = CdmBase.deproxy(cdmRepo.getTaxonService().load(newSynonymUuid),Synonym.class);
69
        Assert.assertEquals(synonym, synonymOfTaxon);
70

    
71
        Assert.assertEquals(synonym.getSec().getId(), 20);
72

    
73
        taxon = CdmBase.deproxy(cdmRepo.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
74

    
75
        Assert.assertEquals(taxon.getSec().getId(), 21);
76
    }
77

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

    
87
        }
88

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

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

    
100
        }
101

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

    
115
        }
116

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

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

    
128
        }
129

    
130
    }
131

    
132
    public static class MockNewTaxonBaseComposite implements INewTaxonBaseComposite {
133

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

    
141
        }
142

    
143

    
144

    
145
    }
146
}
(4-4/5)