1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.cdm.api.service;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
import static org.junit.Assert.assertFalse;
|
14
|
import static org.junit.Assert.assertNull;
|
15
|
import static org.junit.Assert.assertTrue;
|
16
|
|
17
|
import java.io.FileNotFoundException;
|
18
|
import java.lang.reflect.Field;
|
19
|
import java.net.URI;
|
20
|
import java.util.UUID;
|
21
|
|
22
|
import org.apache.log4j.Logger;
|
23
|
import org.junit.Assert;
|
24
|
import org.junit.Test;
|
25
|
import org.unitils.dbunit.annotation.DataSet;
|
26
|
import org.unitils.dbunit.annotation.DataSets;
|
27
|
import org.unitils.spring.annotation.SpringBeanByType;
|
28
|
|
29
|
import eu.etaxonomy.cdm.model.agent.Contact;
|
30
|
import eu.etaxonomy.cdm.model.agent.Person;
|
31
|
import eu.etaxonomy.cdm.model.agent.Team;
|
32
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
33
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
34
|
import eu.etaxonomy.cdm.model.location.Point;
|
35
|
import eu.etaxonomy.cdm.model.name.Rank;
|
36
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
37
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
38
|
import eu.etaxonomy.cdm.strategy.merge.MergeException;
|
39
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
40
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
41
|
|
42
|
/**
|
43
|
* @author a.mueller
|
44
|
* @since 2015-04-01
|
45
|
*/
|
46
|
public class AgentServiceImplTest extends CdmTransactionalIntegrationTest{
|
47
|
|
48
|
@SuppressWarnings("unused")
|
49
|
private static final Logger logger = Logger.getLogger(AgentServiceImplTest.class);
|
50
|
|
51
|
@SpringBeanByType
|
52
|
private IAgentService service;
|
53
|
|
54
|
@SpringBeanByType
|
55
|
private INameService nameSerivce;
|
56
|
|
57
|
|
58
|
@Test
|
59
|
@DataSets({
|
60
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
61
|
@DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
62
|
})
|
63
|
public void testConvertPerson2Team(){
|
64
|
String fullAuthor = "Original author";
|
65
|
String nomTitle = "Abrev. aut.";
|
66
|
Person person = Person.NewTitledInstance(fullAuthor);
|
67
|
person.setNomenclaturalTitle(nomTitle);
|
68
|
Annotation annotation = Annotation.NewDefaultLanguageInstance("Meine annotation");
|
69
|
person.setContact(getContact());
|
70
|
TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
71
|
name.setCombinationAuthorship(person);
|
72
|
person.addAnnotation(annotation);
|
73
|
|
74
|
service.save(person);
|
75
|
nameSerivce.save(name);
|
76
|
|
77
|
Team team = null;
|
78
|
UpdateResult result = null;
|
79
|
try {
|
80
|
result = service.convertPerson2Team(person);
|
81
|
team = (Team) result.getCdmEntity();
|
82
|
} catch (MergeException e) {
|
83
|
Assert.fail("No Merge exception should be thrown");
|
84
|
}
|
85
|
Assert.assertNotNull(team);
|
86
|
//Assert.assertEquals("Title cache must be equal", fullAuthor, team.getTitleCache());
|
87
|
//Assert.assertEquals("Nom. title must be equal", nomTitle, team.getNomenclaturalTitle());
|
88
|
Assert.assertEquals("Annotations should be moved", 1, team.getAnnotations().size());
|
89
|
Assert.assertNotNull("Contact must be copied too", team.getContact());
|
90
|
Assert.assertEquals("Team must be combination author now", team, name.getCombinationAuthorship());
|
91
|
|
92
|
}
|
93
|
|
94
|
private Contact getContact(){
|
95
|
URI uri = URI.create("a");
|
96
|
Contact contact = Contact.NewInstance("My street", "12345", null, null, null, "region", "a@bc.de", "030-445566", "030-12345", uri, Point.NewInstance(2d, 5d, null, null));
|
97
|
return contact;
|
98
|
}
|
99
|
|
100
|
|
101
|
@Test
|
102
|
@DataSets({
|
103
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
104
|
@DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
105
|
})
|
106
|
public void testConvertTeam2Person(){
|
107
|
String fullAuthor = "Original author";
|
108
|
String nomTitle = "Abrev. aut.";
|
109
|
Team team = Team.NewTitledInstance(fullAuthor, nomTitle);
|
110
|
Annotation annotation = Annotation.NewDefaultLanguageInstance("Meine annotation");
|
111
|
team.addAnnotation(annotation);
|
112
|
team.setContact(getContact());
|
113
|
TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
114
|
name.setCombinationAuthorship(team);
|
115
|
|
116
|
service.save(team);
|
117
|
nameSerivce.save(name);
|
118
|
|
119
|
UpdateResult result = null;
|
120
|
Person person = null;
|
121
|
try {
|
122
|
result = service.convertTeam2Person(team);
|
123
|
person = (Person)result.getCdmEntity();
|
124
|
} catch (IllegalArgumentException e) {
|
125
|
Assert.fail("No IllegalArgumentException should be thrown");
|
126
|
} catch (MergeException e) {
|
127
|
Assert.fail("No Merge exception should be thrown");
|
128
|
}
|
129
|
Assert.assertNotNull(person);
|
130
|
Assert.assertEquals("Title cache must be equal", fullAuthor, person.getTitleCache());
|
131
|
Assert.assertEquals("Nom. title must be equal", nomTitle, person.getNomenclaturalTitle());
|
132
|
Assert.assertEquals("Annotations should be moved", 1, person.getAnnotations().size());
|
133
|
Assert.assertNotNull("Contact must be copied too", person.getContact());
|
134
|
Assert.assertEquals("person must be combination author now", person, name.getCombinationAuthorship());
|
135
|
}
|
136
|
|
137
|
|
138
|
@Test
|
139
|
@DataSets({
|
140
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
141
|
@DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
142
|
})
|
143
|
public void testConvertTeam2PersonWithMember(){
|
144
|
String fullAuthor = "Original author";
|
145
|
String nomTitle = "Abrev. aut.";
|
146
|
Team team = Team.NewTitledInstance(fullAuthor, nomTitle);
|
147
|
Annotation annotation = Annotation.NewDefaultLanguageInstance("Meine annotation");
|
148
|
team.addAnnotation(annotation);
|
149
|
Annotation annotation2 = Annotation.NewDefaultLanguageInstance("Meine annotation2");
|
150
|
team.addAnnotation(annotation2);
|
151
|
team.setContact(getContact());
|
152
|
TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
153
|
name.setCombinationAuthorship(team);
|
154
|
Person member = Person.NewTitledInstance("Member person");
|
155
|
member.setNomenclaturalTitle("Memb. pers.");
|
156
|
Annotation annotation3 = Annotation.NewDefaultLanguageInstance("Meine annotation3");
|
157
|
member.addAnnotation(annotation3);
|
158
|
team.addTeamMember(member);
|
159
|
|
160
|
service.save(team);
|
161
|
|
162
|
nameSerivce.save(name);
|
163
|
|
164
|
Person person = null;
|
165
|
UpdateResult result = null;
|
166
|
try {
|
167
|
result = service.convertTeam2Person(team);
|
168
|
person = (Person) result.getCdmEntity();
|
169
|
} catch (IllegalArgumentException e) {
|
170
|
Assert.fail("No IllegalArgumentException should be thrown");
|
171
|
} catch (MergeException e) {
|
172
|
Assert.fail("No Merge exception should be thrown");
|
173
|
}
|
174
|
Assert.assertNotNull(person);
|
175
|
Assert.assertEquals("Convert result and 'member' must be equal'", member, person);
|
176
|
Assert.assertEquals("Title cache must be equal", "Member person", person.getTitleCache());
|
177
|
Assert.assertEquals("Nom. title must be equal", "Memb. pers.", person.getNomenclaturalTitle());
|
178
|
//FIXME should annotations be taken only from member ??
|
179
|
// Assert.assertEquals("Annotations should be moved", 1, person.getAnnotations().size());
|
180
|
String annotationText = person.getAnnotations().iterator().next().getText();
|
181
|
// Assert.assertEquals("The only annotation should be annotation 3", annotation3.getText(), annotationText);
|
182
|
//FIXME currently merge mode is still MERGE for user defined fields
|
183
|
// Assert.assertNull("Contact must not be copied", person.getContact());
|
184
|
Assert.assertEquals("person must be combination author now", person, name.getCombinationAuthorship());
|
185
|
}
|
186
|
|
187
|
|
188
|
@Test //7874
|
189
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="AgentServiceImplTest.testUpdateTitleCache.xml")
|
190
|
public final void testUpdateNomTitle() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
191
|
|
192
|
Field nomenclaturalTitleField = TeamOrPersonBase.class.getDeclaredField("nomenclaturalTitle");
|
193
|
nomenclaturalTitleField.setAccessible(true);
|
194
|
|
195
|
Person turland = (Person) service.load(UUID.fromString("a598ab3f-b33b-4b4b-b237-d616fcb6b5b1"));
|
196
|
Person monro = (Person) service.load(UUID.fromString("e7206bc5-61ab-468e-a9f5-dec118b46b7f"));
|
197
|
// TODO Add Assertion Person "Ehrenberg" must not be member of a team.
|
198
|
Person ehrenberg = (Person) service.load(UUID.fromString("6363ae88-ec57-4b23-8235-6c86fbe59446"));
|
199
|
|
200
|
|
201
|
Team turland_monro_protected = (Team) service.load(UUID.fromString("5bff55de-f7cc-44d9-baac-908f52ad0cb8"));
|
202
|
Team turland_monro = (Team) service.load(UUID.fromString("30ca93d6-b543-4bb9-b6ff-e9ededa65af7"));
|
203
|
Team turland_monro_null = (Team) service.load(UUID.fromString("a4ca0d37-d78b-4bcc-875e-d4ea5a031089"));
|
204
|
|
205
|
// Person has no flag for protecting the nomenclaturalTitle
|
206
|
assertNull(nomenclaturalTitleField.get(turland));
|
207
|
assertNull(nomenclaturalTitleField.get(ehrenberg));
|
208
|
assertTrue(ehrenberg.isProtectedTitleCache());
|
209
|
assertEquals("A.M. Monro", nomenclaturalTitleField.get(monro).toString());
|
210
|
|
211
|
// Team has a flag for protectedNomenclaturalTitle flag
|
212
|
assertEquals("Turland, Monro", nomenclaturalTitleField.get(turland_monro_protected));
|
213
|
assertTrue(turland_monro_protected.isProtectedNomenclaturalTitleCache());
|
214
|
assertEquals("--to be updated--", nomenclaturalTitleField.get(turland_monro).toString());
|
215
|
assertFalse(turland_monro.isProtectedNomenclaturalTitleCache());
|
216
|
assertNull(nomenclaturalTitleField.get(turland_monro_null));
|
217
|
assertFalse(turland_monro_null.isProtectedNomenclaturalTitleCache());
|
218
|
|
219
|
service.updateTitleCache();
|
220
|
|
221
|
turland_monro_protected = (Team) service.load(UUID.fromString("5bff55de-f7cc-44d9-baac-908f52ad0cb8"));
|
222
|
turland_monro = (Team) service.load(UUID.fromString("30ca93d6-b543-4bb9-b6ff-e9ededa65af7"));
|
223
|
|
224
|
assertEquals("Expecting nomenclaturalTitle to be set since it was NULL", "Turland, N.J.", nomenclaturalTitleField.get(turland));
|
225
|
assertEquals("Expecting nomenclaturalTitle to be set since it was NULL", "Ehrenberg, C.G.", nomenclaturalTitleField.get(ehrenberg));
|
226
|
assertEquals("Expecting titleChache to be unchaged since it was protecetd", "Ehrenb.", ehrenberg.getTitleCache());
|
227
|
assertEquals("Expecting nomenclaturalTitle to be unchanged", "A.M. Monro", nomenclaturalTitleField.get(monro).toString());
|
228
|
|
229
|
assertEquals("Turland, Monro", nomenclaturalTitleField.get(turland_monro_protected));
|
230
|
assertEquals("Turland, N.J. & A.M. Monro", nomenclaturalTitleField.get(turland_monro).toString());
|
231
|
assertEquals("Expecting nomenclaturalTitle to be set since it was NULL", "Turland, N.J. & A.M. Monro", nomenclaturalTitleField.get(turland_monro_null).toString());
|
232
|
|
233
|
}
|
234
|
|
235
|
|
236
|
@Override
|
237
|
public void createTestDataSet() throws FileNotFoundException {}
|
238
|
}
|