1 |
73baaed9
|
Cherian Mathew
|
// $Id$
|
2 |
|
|
/**
|
3 |
|
|
* Copyright (C) 2015 EDIT
|
4 |
|
|
* European Distributed Institute of Taxonomy
|
5 |
|
|
* http://www.e-taxonomy.eu
|
6 |
|
|
*
|
7 |
|
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8 |
|
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9 |
|
|
*/
|
10 |
|
|
package eu.etaxonomy.cdm.vaadin.presenter;
|
11 |
|
|
|
12 |
|
|
import java.sql.SQLException;
|
13 |
|
|
import java.util.Arrays;
|
14 |
|
|
import java.util.List;
|
15 |
|
|
import java.util.Set;
|
16 |
|
|
import java.util.UUID;
|
17 |
|
|
|
18 |
|
|
import org.apache.log4j.Logger;
|
19 |
|
|
import org.junit.Assert;
|
20 |
|
|
import org.junit.BeforeClass;
|
21 |
|
|
import org.junit.Test;
|
22 |
|
|
import org.unitils.dbunit.annotation.DataSet;
|
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.vaadin.CdmVaadinBaseTest;
|
30 |
|
|
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
|
31 |
|
|
import eu.etaxonomy.cdm.vaadin.view.INewTaxonBaseComponentListener;
|
32 |
|
|
import eu.etaxonomy.cdm.vaadin.view.INewTaxonBaseComposite;
|
33 |
|
|
|
34 |
|
|
/**
|
35 |
|
|
* @author cmathew
|
36 |
|
|
* @date 2 Apr 2015
|
37 |
|
|
*
|
38 |
|
|
*/
|
39 |
|
|
|
40 |
b0491d5e
|
Cherian Mathew
|
@DataSet
|
41 |
73baaed9
|
Cherian Mathew
|
public class NewTaxonBasePresenterTest extends CdmVaadinBaseTest {
|
42 |
|
|
|
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 |
53c75a2d
|
Cherian Mathew
|
|
53 |
73baaed9
|
Cherian Mathew
|
@Test
|
54 |
|
|
public void testNewTaxonBase() throws SQLException {
|
55 |
|
|
RowId refId20 = new RowId(20);
|
56 |
29aeffbe
|
Cherian Mathew
|
RowId refId21 = new RowId(21);
|
57 |
10cc0e5e
|
Cherian Mathew
|
UUID newTaxonUuid = ntbp.newTaxon("Taxon h", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
|
58 |
73baaed9
|
Cherian Mathew
|
List<String> ACC_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
|
59 |
29aeffbe
|
Cherian Mathew
|
"sec",
|
60 |
73baaed9
|
Cherian Mathew
|
"synonymRelations"
|
61 |
|
|
});
|
62 |
|
|
Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
|
63 |
|
|
|
64 |
10cc0e5e
|
Cherian Mathew
|
UUID newSynonymUuid = ntbp.newSynonym("Synonym ofe", refId20, refId21, newTaxonUuid).getUuid();
|
65 |
73baaed9
|
Cherian Mathew
|
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 |
29aeffbe
|
Cherian Mathew
|
|
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 |
73baaed9
|
Cherian Mathew
|
}
|
80 |
|
|
|
81 |
10cc0e5e
|
Cherian Mathew
|
@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 |
73baaed9
|
Cherian Mathew
|
|
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 |
|
|
}
|