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