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.Ignore;
|
17
|
import org.junit.Test;
|
18
|
import org.unitils.dbunit.annotation.DataSet;
|
19
|
import org.unitils.spring.annotation.SpringBeanByName;
|
20
|
import org.unitils.spring.annotation.SpringBeanByType;
|
21
|
|
22
|
import eu.etaxonomy.cdm.CdmVaadinIntegrationTest;
|
23
|
import eu.etaxonomy.cdm.api.application.CdmRepository;
|
24
|
import eu.etaxonomy.cdm.api.utility.DerivedUnitConversionException;
|
25
|
import eu.etaxonomy.cdm.model.agent.Team;
|
26
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
27
|
import eu.etaxonomy.cdm.model.common.Language;
|
28
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
29
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
30
|
import eu.etaxonomy.cdm.model.name.Rank;
|
31
|
import eu.etaxonomy.cdm.model.name.Registration;
|
32
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
33
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
34
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
35
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
36
|
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
|
37
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
38
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
39
|
import eu.etaxonomy.cdm.vaadin.model.registration.KindOfUnitTerms;
|
40
|
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationDTO;
|
41
|
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
|
42
|
|
43
|
/**
|
44
|
* @author a.kohlbecker
|
45
|
* @since Nov 17, 2017
|
46
|
*
|
47
|
*/
|
48
|
public class SpecimenTypeDesignationWorkingsetEditorPresenterTest extends CdmVaadinIntegrationTest{
|
49
|
|
50
|
@SpringBeanByName
|
51
|
private CdmRepository cdmRepository;
|
52
|
|
53
|
@SpringBeanByType
|
54
|
private ISpecimenTypeDesignationWorkingSetService service;
|
55
|
|
56
|
int registrationId = 5000;
|
57
|
|
58
|
private Integer publicationId = 5000;
|
59
|
|
60
|
private Integer typifiedNameId = 5000;
|
61
|
|
62
|
String[] includeTableNames_create = new String[]{"TAXONNAME", "REFERENCE", "AGENTBASE", "HOMOTYPICALGROUP", "REGISTRATION",
|
63
|
"HIBERNATE_SEQUENCES"};
|
64
|
|
65
|
String[] includeTableNames_delete = new String[]{"TAXONNAME", "REFERENCE", "AGENTBASE", "HOMOTYPICALGROUP", "REGISTRATION",
|
66
|
"DERIVATIONEVENT", "GATHERINGEVENT", "LANGUAGESTRING", "SPECIMENOROBSERVATIONBASE", "TYPEDESIGNATIONBASE",
|
67
|
"REGISTRATION_TYPEDESIGNATIONBASE", "TAXONNAME_TYPEDESIGNATIONBASE", "SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT",
|
68
|
"MEDIA", "MEDIA_REPRESENTATION", "MEDIAREPRESENTATION", "MEDIAREPRESENTATIONPART",
|
69
|
"HIBERNATE_SEQUENCES"
|
70
|
};
|
71
|
|
72
|
|
73
|
@Test
|
74
|
@DataSet
|
75
|
public void createAndEditTest() throws DerivedUnitConversionException, URISyntaxException, FileNotFoundException {
|
76
|
|
77
|
//printDataSetWithNull(System.err, debugTables);
|
78
|
// writeDbUnitDataSetFile(new String[]{"AUDITEVENT", "DEFINEDTERMBASE", "DEFINEDTERMBASE_AUD", "DEFINEDTERMBASE_REPRESENTATION", "DEFINEDTERMBASE_REPRESENTATION_AUD",
|
79
|
// "REPRESENTATION", "REPRESENTATION_AUD", "HIBERNATE_SEQUENCES"},
|
80
|
// "RegistrationTerms");
|
81
|
|
82
|
SpecimenTypeDesignationWorkingSetDTO<Registration> workingset = service.create(registrationId, publicationId, typifiedNameId);
|
83
|
|
84
|
Assert.assertNotNull(workingset.getOwner());
|
85
|
Assert.assertEquals(Registration.class, workingset.getOwner().getClass());
|
86
|
|
87
|
workingset.getFieldUnit().setFieldNotes("FieldNotes");
|
88
|
workingset.getFieldUnit().setFieldNumber("FieldNumber");
|
89
|
workingset.getFieldUnit().getGatheringEvent().setLocality(LanguageString.NewInstance("Somewhere", Language.ENGLISH()));
|
90
|
|
91
|
SpecimenTypeDesignationDTO specimenTypeDesignationDTO = new SpecimenTypeDesignationDTO();
|
92
|
specimenTypeDesignationDTO.setKindOfUnit((DefinedTerm)cdmRepository.getTermService().load(KindOfUnitTerms.PUBLISHED_IMAGE().getUuid()));
|
93
|
specimenTypeDesignationDTO.setMediaUri(new URI("http://foo.bar.com/image1"));
|
94
|
specimenTypeDesignationDTO.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
|
95
|
specimenTypeDesignationDTO.setAccessionNumber("TEST_1");
|
96
|
|
97
|
workingset.getSpecimenTypeDesignationDTOs().add(specimenTypeDesignationDTO);
|
98
|
|
99
|
service.save(workingset);
|
100
|
|
101
|
//printDataSetWithNull(System.err, new String[]{"TYPEDESIGNATIONBASE", "SPECIMENOROBSERVATIONBASE"});
|
102
|
|
103
|
workingset = service.loadDtoByIds(registrationId, 0);
|
104
|
|
105
|
Assert.assertNotNull(specimenTypeDesignationDTO.asSpecimenTypeDesignation().getTypeSpecimen());
|
106
|
Assert.assertEquals(MediaSpecimen.class, specimenTypeDesignationDTO.asSpecimenTypeDesignation().getTypeSpecimen().getClass());
|
107
|
Assert.assertNotNull(specimenTypeDesignationDTO.asSpecimenTypeDesignation().getTypeSpecimen().getOriginals().iterator().next());
|
108
|
Assert.assertEquals(FieldUnit.class, specimenTypeDesignationDTO.asSpecimenTypeDesignation().getTypeSpecimen().getOriginals().iterator().next().getClass());
|
109
|
Assert.assertEquals("FieldNumber", ((FieldUnit)specimenTypeDesignationDTO.asSpecimenTypeDesignation().getTypeSpecimen().getOriginals().iterator().next()).getFieldNumber());
|
110
|
|
111
|
SpecimenTypeDesignationDTO specimenTypeDesignationDTO2 = new SpecimenTypeDesignationDTO();
|
112
|
specimenTypeDesignationDTO2.setKindOfUnit((DefinedTerm)cdmRepository.getTermService().load(KindOfUnitTerms.SPECIMEN().getUuid()));
|
113
|
specimenTypeDesignationDTO2.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
|
114
|
specimenTypeDesignationDTO2.setAccessionNumber("TEST_2");
|
115
|
|
116
|
workingset.getSpecimenTypeDesignationDTOs().add(specimenTypeDesignationDTO2);
|
117
|
|
118
|
service.save(workingset);
|
119
|
|
120
|
workingset = service.loadDtoByIds(registrationId, 0);
|
121
|
Assert.assertTrue(workingset.getSpecimenTypeDesignationDTOs().size() == 2);
|
122
|
|
123
|
|
124
|
//FIXME this fails: Assert.assertEquals("There must only be one FieldUnit and one MediaSpecimen", 2, cdmRepository.getOccurrenceService().count(DerivedUnit.class));
|
125
|
|
126
|
// write test data for delete test
|
127
|
/*
|
128
|
// printDataSetWithNull(System.err, includeTableNames_delete);
|
129
|
writeDbUnitDataSetFile(includeTableNames_delete, "deleteTest");
|
130
|
*/
|
131
|
|
132
|
}
|
133
|
|
134
|
@Test
|
135
|
@DataSet("SpecimenTypeDesignationWorkingsetEditorPresenterTest-deleteTest.xml")
|
136
|
@Ignore
|
137
|
public void deleteTypeDesignationTest() {
|
138
|
|
139
|
// printDataSetWithNull(System.err, includeTableNames_delete);
|
140
|
|
141
|
SpecimenTypeDesignationWorkingSetDTO<Registration> workingset = service.loadDtoByIds(registrationId, 0);
|
142
|
Assert.assertTrue(workingset.getSpecimenTypeDesignationDTOs().size() == 2);
|
143
|
|
144
|
SpecimenTypeDesignationDTO deleteDTO = null;
|
145
|
for(SpecimenTypeDesignationDTO stdDTO : workingset.getSpecimenTypeDesignationDTOs()){
|
146
|
if(stdDTO.getAccessionNumber().equals("TEST_1")){
|
147
|
deleteDTO = stdDTO;
|
148
|
break;
|
149
|
}
|
150
|
}
|
151
|
workingset.getSpecimenTypeDesignationDTOs().remove(deleteDTO);
|
152
|
|
153
|
// TODO once https://dev.e-taxonomy.eu/redmine/issues/7077 is fixed dissociating from the Registration could be removed here
|
154
|
Registration reg = workingset.getOwner();
|
155
|
SpecimenTypeDesignation std = deleteDTO.asSpecimenTypeDesignation();
|
156
|
reg.getTypeDesignations().remove(std);
|
157
|
|
158
|
service.save(workingset);
|
159
|
|
160
|
//printDataSetWithNull(System.err, new String[]{"TYPEDESIGNATIONBASE", "SPECIMENOROBSERVATIONBASE"});
|
161
|
|
162
|
workingset = service.loadDtoByIds(registrationId, 0);
|
163
|
Assert.assertEquals(1, workingset.getSpecimenTypeDesignationDTOs().size());
|
164
|
|
165
|
}
|
166
|
|
167
|
@Test
|
168
|
@DataSet("SpecimenTypeDesignationWorkingsetEditorPresenterTest-deleteTest.xml")
|
169
|
@Ignore
|
170
|
public void deleteWorkingsetTest() {
|
171
|
|
172
|
SpecimenTypeDesignationWorkingSetDTO<Registration> workingset = service.loadDtoByIds(registrationId, 0);
|
173
|
//TODO implement ...
|
174
|
|
175
|
|
176
|
}
|
177
|
|
178
|
// ---------------------- TestData -------------------------------------------
|
179
|
|
180
|
|
181
|
@Override
|
182
|
// @Test
|
183
|
public void createTestDataSet() throws FileNotFoundException {
|
184
|
createRegistration();
|
185
|
}
|
186
|
|
187
|
private void createRegistration() throws FileNotFoundException {
|
188
|
|
189
|
Team team = Team.NewTitledInstance("Novis, Braidwood & Kilroy", "Novis, Braidwood & Kilroy");
|
190
|
Reference nomRef = ReferenceFactory.newArticle();
|
191
|
nomRef = cdmRepository.getReferenceService().save(nomRef);
|
192
|
publicationId = nomRef.getId();
|
193
|
|
194
|
nomRef.setAuthorship(team);
|
195
|
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");
|
196
|
TaxonName name = TaxonName.NewInstance(NomenclaturalCode.ICNAFP, Rank.SPECIES(), "Planothidium", null, "victori", null, null, nomRef, "11-45", null);
|
197
|
name = cdmRepository.getNameService().save(name);
|
198
|
typifiedNameId = name.getId();
|
199
|
|
200
|
Registration reg = Registration.NewInstance();
|
201
|
reg.setName(name);
|
202
|
reg = cdmRepository.getRegistrationService().save(reg);
|
203
|
registrationId = reg.getId();
|
204
|
|
205
|
|
206
|
printDataSetWithNull(System.err, includeTableNames_create);
|
207
|
|
208
|
writeDbUnitDataSetFile(includeTableNames_create);
|
209
|
}
|
210
|
|
211
|
|
212
|
|
213
|
|
214
|
|
215
|
|
216
|
|
217
|
}
|