Revision 0f6bc0c7
Added by Andreas Müller about 3 years ago
cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/dto/assembler/lsid/AssemblerTest.java | ||
---|---|---|
11 | 11 |
import static org.junit.Assert.assertEquals; |
12 | 12 |
import static org.junit.Assert.assertNotNull; |
13 | 13 |
import static org.junit.Assert.assertNull; |
14 |
import static org.junit.Assert.assertTrue; |
|
15 | 14 |
|
16 | 15 |
import java.io.Serializable; |
17 | 16 |
import java.lang.reflect.Field; |
... | ... | |
67 | 66 |
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference; |
68 | 67 |
import eu.etaxonomy.cdm.model.reference.Reference; |
69 | 68 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
69 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
|
70 | 70 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
71 | 71 |
import eu.etaxonomy.cdm.model.taxon.SynonymType; |
72 | 72 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
73 | 73 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
74 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
74 | 75 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
75 | 76 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
76 | 77 |
import eu.etaxonomy.cdm.model.term.DefaultTermInitializer; |
... | ... | |
79 | 80 |
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.Relationship; |
80 | 81 |
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.SpeciesProfileModel; |
81 | 82 |
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonConcept; |
83 |
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonRelationshipTerm; |
|
82 | 84 |
import eu.etaxonomy.cdm.remote.view.OaiPmhViewTest; |
83 | 85 |
import net.sf.cglib.proxy.Enhancer; |
84 | 86 |
import net.sf.cglib.proxy.MethodInterceptor; |
... | ... | |
135 | 137 |
taxon.setTitleCache("titleCache", true); |
136 | 138 |
taxon.setLsid(lsid); |
137 | 139 |
|
138 |
for(int i = 2; i < 2+10; i++) {
|
|
140 |
for(int i = 2; i < 2+1; i++) { |
|
139 | 141 |
Taxon child = Taxon.NewInstance(name, (Reference)sec); |
140 |
child.setLsid(new LSID("urn:lsid:example.org:taxonconcepts:r" + i )); |
|
142 |
child.setLsid(new LSID("urn:lsid:example.org:taxonconcepts:r0" + i ));
|
|
141 | 143 |
child.addTaxonRelation(taxon, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(), null, null); |
142 | 144 |
} |
143 | 145 |
|
... | ... | |
194 | 196 |
} |
195 | 197 |
|
196 | 198 |
@Test |
197 |
public void testDeepMapping() { |
|
199 |
public void testDeepMapping() throws MalformedLSIDException {
|
|
198 | 200 |
|
199 | 201 |
if(!OaiPmhViewTest.dozerXsdIsAvailable()){ |
200 | 202 |
return; |
201 | 203 |
} |
202 | 204 |
|
205 |
//synonyms |
|
203 | 206 |
for(int i = 1; i < 1+3; i++) { |
204 | 207 |
Synonym synonym = Synonym.NewInstance(name,(Reference)sec); |
205 |
try { |
|
206 |
synonym.setLsid(new LSID("urn:lsid:example.org:synyonms:" + i )); |
|
207 |
} catch (MalformedLSIDException e) {} |
|
208 |
synonym.setLsid(new LSID("urn:lsid:example.org:synyonms:" + i )); |
|
208 | 209 |
taxon.addSynonym(synonym, SynonymType.SYNONYM_OF()); |
209 | 210 |
} |
210 | 211 |
|
212 |
//taxon nodes |
|
213 |
TaxonNode rootNode = Classification.NewInstance("Classification").getRootNode(); |
|
214 |
TaxonNode parentNode = rootNode.addChildTaxon(taxon, null); |
|
215 |
for(int i = 11; i < 11+2; i++) { |
|
216 |
Taxon child = Taxon.NewInstance(name, (Reference)sec); |
|
217 |
child.setLsid(new LSID("urn:lsid:example.org:taxonconcepts:p" + i )); |
|
218 |
parentNode.addChildTaxon(child, null); |
|
219 |
} |
|
220 |
|
|
211 | 221 |
TaxonConcept taxonConcept = mapper.map(taxon, TaxonConcept.class); |
212 | 222 |
|
213 | 223 |
assertNotNull("map() should return an object", taxonConcept); |
... | ... | |
223 | 233 |
assertNotNull("TaxonBase.name should be mapped to TaxonConcept.hasName",taxonConcept.getHasName()); |
224 | 234 |
assertEquals("NonViralName.nameCache should be mapped to TaxonName.nameComplete",name.getNameCache(),taxonConcept.getHasName().getNameComplete()); |
225 | 235 |
assertNotNull("Taxon.relationsToThisTaxon should be copied into TaxonConcept.hasRelationship",taxonConcept.getHasRelationship()); |
226 |
assertEquals("There should be 13 relations in TaxonConcept.hasRelationship",
|
|
227 |
13, taxonConcept.getHasRelationship().size());
|
|
236 |
assertEquals("There should be 6 relations in TaxonConcept.hasRelationship",
|
|
237 |
6, taxonConcept.getHasRelationship().size());
|
|
228 | 238 |
int nSynonyms = 0; |
229 |
int nTaxa = 0; |
|
239 |
int nIncludedInTaxa = 0; |
|
240 |
int pnParentTaxa = 0; |
|
230 | 241 |
for (Relationship rel : taxonConcept.getHasRelationship()){ |
231 | 242 |
Assert.assertNotNull(rel.getFromTaxon()); |
232 | 243 |
System.out.println(rel.getFromTaxon().getIdentifier().toString()); |
233 | 244 |
if (rel.getFromTaxon().getIdentifier().toString().startsWith("urn:lsid:example.org:synyonms:")){ |
234 | 245 |
nSynonyms++; |
235 |
}else if (rel.getFromTaxon().getIdentifier().toString().startsWith("urn:lsid:example.org:taxonconcepts:")){ |
|
236 |
nTaxa++; |
|
246 |
}else if (rel.getFromTaxon().getIdentifier().toString().startsWith("urn:lsid:example.org:taxonconcepts:r")){ |
|
247 |
nIncludedInTaxa++; |
|
248 |
}else if (rel.getFromTaxon().getIdentifier().toString().startsWith("urn:lsid:example.org:taxonconcepts:p")){ |
|
249 |
TaxonRelationshipTerm category = rel.getRelationshipCategory(); |
|
250 |
Assert.assertEquals("is taxonomically included in", category.getTitle()); |
|
251 |
pnParentTaxa++; |
|
237 | 252 |
} |
238 | 253 |
// System.out.println(rel); |
239 | 254 |
} |
240 | 255 |
Assert.assertEquals(3, nSynonyms); |
241 |
Assert.assertEquals(10, nTaxa); |
|
256 |
Assert.assertEquals(1, nIncludedInTaxa); |
|
257 |
Assert.assertEquals(2, pnParentTaxa); |
|
242 | 258 |
} |
243 | 259 |
|
244 | 260 |
@Test |
... | ... | |
275 | 291 |
relationsToThisTaxonField.set(taxon, proxy); |
276 | 292 |
|
277 | 293 |
TaxonConcept taxonConcept = mapper.map(taxon, TaxonConcept.class); |
278 |
assertTrue("TaxonBase.relationsToThisTaxon was uninitialized, so TaxonConcept.hasRelationship should be null", |
|
279 |
taxonConcept.getHasRelationship().isEmpty());
|
|
294 |
Assert.assertTrue("TaxonBase.relationsToThisTaxon was uninitialized, so TaxonConcept.hasRelationship should be null",
|
|
295 |
taxonConcept.getHasRelationship() == null || taxonConcept.getHasRelationship().isEmpty()); //with taxonNode mapping included this results in null, otherwise empty, not yet checked why
|
|
280 | 296 |
} |
281 | 297 |
|
282 | 298 |
@Test |
... | ... | |
347 | 363 |
}else if("initListener".equals(method.getName())) { |
348 | 364 |
return null; |
349 | 365 |
} else { |
350 |
|
|
351 | 366 |
throw new LazyInitializationException(null); |
352 | 367 |
} |
353 |
|
|
354 | 368 |
} |
355 | 369 |
}); |
356 | 370 |
|
Also available in: Unified diff
fix #6324 fix taxon node dozer mapping for TDWG Ontology