1
|
/**
|
2
|
* Copyright (C) 2017 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.service;
|
10
|
|
11
|
import java.io.FileNotFoundException;
|
12
|
import java.net.URI;
|
13
|
import java.net.URISyntaxException;
|
14
|
|
15
|
import org.junit.Assert;
|
16
|
import org.junit.BeforeClass;
|
17
|
import org.junit.Test;
|
18
|
import org.unitils.database.annotations.Transactional;
|
19
|
import org.unitils.database.util.TransactionMode;
|
20
|
import org.unitils.dbunit.annotation.DataSet;
|
21
|
import org.unitils.spring.annotation.SpringBeanByName;
|
22
|
import org.unitils.spring.annotation.SpringBeanByType;
|
23
|
|
24
|
import eu.etaxonomy.cdm.CdmVaadinIntegrationTest;
|
25
|
import eu.etaxonomy.cdm.api.application.CdmRepository;
|
26
|
import eu.etaxonomy.cdm.api.utility.DerivedUnitConversionException;
|
27
|
import eu.etaxonomy.cdm.model.agent.Team;
|
28
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
29
|
import eu.etaxonomy.cdm.model.common.Language;
|
30
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
31
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
32
|
import eu.etaxonomy.cdm.model.name.Rank;
|
33
|
import eu.etaxonomy.cdm.model.name.Registration;
|
34
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
35
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
36
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
37
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
38
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
39
|
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
|
40
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
41
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
42
|
import eu.etaxonomy.cdm.vaadin.model.registration.KindOfUnitTerms;
|
43
|
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationDTO;
|
44
|
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
|
45
|
|
46
|
/**
|
47
|
* @author a.kohlbecker
|
48
|
* @since Nov 17, 2017
|
49
|
*
|
50
|
*/
|
51
|
@Transactional(TransactionMode.DISABLED)
|
52
|
public class SpecimenTypeDesignationWorkingSetServiceImplTest extends CdmVaadinIntegrationTest{
|
53
|
|
54
|
@SpringBeanByName
|
55
|
private CdmRepository cdmRepository;
|
56
|
|
57
|
@SpringBeanByType
|
58
|
private ISpecimenTypeDesignationWorkingSetService service;
|
59
|
|
60
|
@BeforeClass
|
61
|
public static void setupLoggers() {
|
62
|
// Logger.getLogger("org.dbunit").setLevel(Level.DEBUG);
|
63
|
}
|
64
|
|
65
|
int registrationId = 5000;
|
66
|
|
67
|
private Integer publicationId = 5000;
|
68
|
|
69
|
private Integer typifiedNameId = 5000;
|
70
|
|
71
|
private final String[] includeTableNames_create = new String[]{"TAXONNAME", "REFERENCE", "AGENTBASE", "HOMOTYPICALGROUP", "REGISTRATION",
|
72
|
"HIBERNATE_SEQUENCES"};
|
73
|
|
74
|
private final String[] includeTableNames_delete = new String[]{"TAXONNAME", "REFERENCE", "AGENTBASE", "HOMOTYPICALGROUP", "REGISTRATION",
|
75
|
"DERIVATIONEVENT", "GATHERINGEVENT", "LANGUAGESTRING", "SPECIMENOROBSERVATIONBASE", "TYPEDESIGNATIONBASE",
|
76
|
"REGISTRATION_TYPEDESIGNATIONBASE", "TAXONNAME_TYPEDESIGNATIONBASE", "SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT",
|
77
|
"MEDIA", "MEDIA_REPRESENTATION", "MEDIAREPRESENTATION", "MEDIAREPRESENTATIONPART",
|
78
|
"AUDITEVENT",
|
79
|
"HIBERNATE_SEQUENCES"
|
80
|
};
|
81
|
|
82
|
|
83
|
@Test
|
84
|
@DataSet("SpecimenTypeDesignationWorkingSetServiceImplTest.xml")
|
85
|
public void createAndEditTest() throws DerivedUnitConversionException, URISyntaxException, FileNotFoundException {
|
86
|
|
87
|
// printDataSetWithNull(System.err, new String[]{"USERACCOUNT", "GROUPS", "USERACCOUNT_GRANTEDAUTHORITYIMPL", "USERACCOUNT_PERMISSIONGROUP"
|
88
|
// , "PERMISSIONGROUP", "PERMISSIONGROUP_GRANTEDAUTHORITYIMPL", "GRANTEDAUTHORITYIMPL"});
|
89
|
|
90
|
//printDataSetWithNull(System.err, debugTables);
|
91
|
// writeDbUnitDataSetFile(new String[]{"AUDITEVENT", "DEFINEDTERMBASE", "DEFINEDTERMBASE_AUD", "DEFINEDTERMBASE_REPRESENTATION", "DEFINEDTERMBASE_REPRESENTATION_AUD",
|
92
|
// "REPRESENTATION", "REPRESENTATION_AUD", "HIBERNATE_SEQUENCES"},
|
93
|
// "RegistrationTerms");
|
94
|
|
95
|
SpecimenTypeDesignationWorkingSetDTO<Registration> workingset = service.create(registrationId, publicationId, typifiedNameId);
|
96
|
|
97
|
Assert.assertNotNull(workingset.getOwner());
|
98
|
Assert.assertEquals(Registration.class, workingset.getOwner().getClass());
|
99
|
|
100
|
workingset.getFieldUnit().setFieldNotes("FieldNotes");
|
101
|
workingset.getFieldUnit().setFieldNumber("FieldNumber");
|
102
|
workingset.getFieldUnit().getGatheringEvent().setLocality(LanguageString.NewInstance("Somewhere", Language.ENGLISH()));
|
103
|
|
104
|
SpecimenTypeDesignationDTO specimenTypeDesignationDTO = new SpecimenTypeDesignationDTO();
|
105
|
specimenTypeDesignationDTO.setKindOfUnit((DefinedTerm)cdmRepository.getTermService().load(KindOfUnitTerms.PUBLISHED_IMAGE().getUuid()));
|
106
|
specimenTypeDesignationDTO.setMediaUri(new URI("http://foo.bar.com/image1"));
|
107
|
specimenTypeDesignationDTO.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
|
108
|
specimenTypeDesignationDTO.setAccessionNumber("TEST_1");
|
109
|
|
110
|
workingset.getSpecimenTypeDesignationDTOs().add(specimenTypeDesignationDTO);
|
111
|
|
112
|
service.save(workingset);
|
113
|
|
114
|
//printDataSetWithNull(System.err, new String[]{"TYPEDESIGNATIONBASE", "SPECIMENOROBSERVATIONBASE"});
|
115
|
|
116
|
workingset = service.loadDtoByIds(registrationId, 0);
|
117
|
|
118
|
Assert.assertNotNull(specimenTypeDesignationDTO.asSpecimenTypeDesignation().getTypeSpecimen());
|
119
|
Assert.assertEquals(MediaSpecimen.class, specimenTypeDesignationDTO.asSpecimenTypeDesignation().getTypeSpecimen().getClass());
|
120
|
Assert.assertNotNull(specimenTypeDesignationDTO.asSpecimenTypeDesignation().getTypeSpecimen().getOriginals().iterator().next());
|
121
|
Assert.assertEquals(FieldUnit.class, specimenTypeDesignationDTO.asSpecimenTypeDesignation().getTypeSpecimen().getOriginals().iterator().next().getClass());
|
122
|
Assert.assertEquals("FieldNumber", ((FieldUnit)specimenTypeDesignationDTO.asSpecimenTypeDesignation().getTypeSpecimen().getOriginals().iterator().next()).getFieldNumber());
|
123
|
|
124
|
SpecimenTypeDesignationDTO specimenTypeDesignationDTO2 = new SpecimenTypeDesignationDTO();
|
125
|
specimenTypeDesignationDTO2.setKindOfUnit((DefinedTerm)cdmRepository.getTermService().load(KindOfUnitTerms.SPECIMEN().getUuid()));
|
126
|
specimenTypeDesignationDTO2.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
|
127
|
specimenTypeDesignationDTO2.setAccessionNumber("TEST_2");
|
128
|
|
129
|
workingset.getSpecimenTypeDesignationDTOs().add(specimenTypeDesignationDTO2);
|
130
|
|
131
|
service.save(workingset);
|
132
|
|
133
|
workingset = service.loadDtoByIds(registrationId, 0);
|
134
|
Assert.assertTrue(workingset.getSpecimenTypeDesignationDTOs().size() == 2);
|
135
|
|
136
|
|
137
|
//FIXME this fails: Assert.assertEquals("There must only be one FieldUnit and one MediaSpecimen", 2, cdmRepository.getOccurrenceService().count(DerivedUnit.class));
|
138
|
|
139
|
// write test data for delete test
|
140
|
/*
|
141
|
// printDataSetWithNull(System.err, includeTableNames_delete);
|
142
|
writeDbUnitDataSetFile(includeTableNames_delete, "deleteTest");
|
143
|
*/
|
144
|
/* The following audit table fix needs also to be added to the test data:
|
145
|
<!-- Test data is being used by more than one test - need to reset a couple of *_AUD tables -->
|
146
|
<AUDITEVENT />
|
147
|
<TAXONNAME_AUD />
|
148
|
<DERIVATIONEVENT_AUD />
|
149
|
<TYPEDESIGNATIONBASE_AUD />
|
150
|
<SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT_AUD />
|
151
|
<REGISTRATION_AUD />
|
152
|
<SPECIMENOROBSERVATIONBASE_AUD />
|
153
|
<TAXONNAME_TYPEDESIGNATIONBASE_AUD />
|
154
|
*/
|
155
|
|
156
|
}
|
157
|
|
158
|
@Test
|
159
|
@DataSet("SpecimenTypeDesignationWorkingSetServiceImplTest-deleteTest.xml")
|
160
|
// @Ignore
|
161
|
public void deleteTypeDesignationTest() {
|
162
|
|
163
|
printDataSetWithNull(System.err, includeTableNames_delete); // new String[]{"TAXONNAME", "REFERENCE", "AGENTBASE", "HOMOTYPICALGROUP", "REGISTRATION"});
|
164
|
|
165
|
SpecimenTypeDesignationWorkingSetDTO<Registration> workingset = service.loadDtoByIds(registrationId, 0);
|
166
|
Assert.assertTrue(workingset.getSpecimenTypeDesignationDTOs().size() == 2);
|
167
|
|
168
|
SpecimenTypeDesignationDTO deleteDTO = null;
|
169
|
for(SpecimenTypeDesignationDTO stdDTO : workingset.getSpecimenTypeDesignationDTOs()){
|
170
|
if(stdDTO.getAccessionNumber().equals("TEST_1")){
|
171
|
deleteDTO = stdDTO;
|
172
|
break;
|
173
|
}
|
174
|
}
|
175
|
workingset.getSpecimenTypeDesignationDTOs().remove(deleteDTO);
|
176
|
|
177
|
// TODO once https://dev.e-taxonomy.eu/redmine/issues/7077 is fixed dissociating from the Registration could be removed here
|
178
|
Registration reg = workingset.getOwner();
|
179
|
SpecimenTypeDesignation std = deleteDTO.asSpecimenTypeDesignation();
|
180
|
reg.getTypeDesignations().remove(std);
|
181
|
|
182
|
|
183
|
//printDataSetWithNull(System.err, includeTableNames_delete);
|
184
|
|
185
|
service.save(workingset);
|
186
|
|
187
|
printDataSetWithNull(System.err, includeTableNames_delete);
|
188
|
|
189
|
workingset = service.loadDtoByIds(registrationId, 0);
|
190
|
Assert.assertEquals(1, workingset.getSpecimenTypeDesignationDTOs().size());
|
191
|
reg = workingset.getOwner();
|
192
|
Assert.assertEquals(1, reg.getTypeDesignations().size());
|
193
|
}
|
194
|
|
195
|
@Test
|
196
|
@DataSet("SpecimenTypeDesignationWorkingSetServiceImplTest-deleteTest.xml")
|
197
|
public void deleteWorkingsetTest() {
|
198
|
|
199
|
//printDataSetWithNull(System.err, includeTableNames_delete);
|
200
|
|
201
|
SpecimenTypeDesignationWorkingSetDTO<Registration> workingset = service.loadDtoByIds(registrationId, 0);
|
202
|
Assert.assertNotNull(workingset.getOwner());
|
203
|
Assert.assertEquals(2, workingset.getSpecimenTypeDesignationDTOs().size());
|
204
|
service.delete(workingset, true);
|
205
|
|
206
|
// UUID gatheringEventUUID = UUID.fromString("23d40440-38bb-46c1-af11-6e25dcfa0145");
|
207
|
// UUID fieldUnitUUID = UUID.fromString("22be718a-6f21-4b74-aae3-bb7d7d659e1c");
|
208
|
// UUID mediaSpecimenUUID = UUID.fromString("10eceb2c-9b51-458e-8dcd-2cb92cc558a9");
|
209
|
// UUID specimenUUID = UUID.fromString("2e384f8e-fbb0-44eb-9d5f-1b7235493932");
|
210
|
// UUID typeDesignation1UUID = UUID.fromString("a1896ae2-4396-4243-988e-3d74058b44ab");
|
211
|
// UUID typeDesignation2UUID = UUID.fromString("a1896ae2-4396-4243-988e-3d74058b44ab");
|
212
|
|
213
|
|
214
|
Assert.assertEquals("All TypeDesignations should have been deleted", 0, cdmRepository.getNameService().getAllTypeDesignations(10, 0).size());
|
215
|
Assert.assertEquals("All derived units should have been deleted", 0, cdmRepository.getOccurrenceService().count(DerivedUnit.class));
|
216
|
Assert.assertEquals("FieldUnit should have been deleted", 0, cdmRepository.getOccurrenceService().count(FieldUnit.class));
|
217
|
// FIXME Assert.assertEquals("Gathering event should have been deleted by orphan remove", 0, cdmRepository.getEventBaseService().count(GatheringEvent.class));
|
218
|
// FIXME Assert.assertEquals("Media should have been deleted ", 0, cdmRepository.getMediaService().count(null));
|
219
|
|
220
|
// printDataSetWithNull(System.err, includeTableNames_delete);
|
221
|
}
|
222
|
|
223
|
// ---------------------- TestData -------------------------------------------
|
224
|
|
225
|
|
226
|
@Override
|
227
|
// @Test
|
228
|
public void createTestDataSet() throws FileNotFoundException {
|
229
|
createRegistration();
|
230
|
}
|
231
|
|
232
|
private void createRegistration() throws FileNotFoundException {
|
233
|
|
234
|
Team team = Team.NewTitledInstance("Novis, Braidwood & Kilroy", "Novis, Braidwood & Kilroy");
|
235
|
Reference nomRef = ReferenceFactory.newArticle();
|
236
|
nomRef = cdmRepository.getReferenceService().save(nomRef);
|
237
|
publicationId = nomRef.getId();
|
238
|
|
239
|
nomRef.setAuthorship(team);
|
240
|
nomRef.setTitle("P.M. Novis, J. Braidwood & C. Kilroy, Small diatoms (Bacillariophyta) in cultures from the Styx River, New Zealand, including descriptions of three new species in Phytotaxa 64");
|
241
|
TaxonName name = TaxonName.NewInstance(NomenclaturalCode.ICNAFP, Rank.SPECIES(), "Planothidium", null, "victori", null, null, nomRef, "11-45", null);
|
242
|
name = cdmRepository.getNameService().save(name);
|
243
|
typifiedNameId = name.getId();
|
244
|
|
245
|
Registration reg = Registration.NewInstance();
|
246
|
reg.setName(name);
|
247
|
reg = cdmRepository.getRegistrationService().save(reg);
|
248
|
registrationId = reg.getId();
|
249
|
|
250
|
|
251
|
printDataSetWithNull(System.err, includeTableNames_create);
|
252
|
|
253
|
writeDbUnitDataSetFile(includeTableNames_create);
|
254
|
}
|
255
|
|
256
|
|
257
|
|
258
|
|
259
|
|
260
|
|
261
|
|
262
|
}
|