1
|
/**
|
2
|
* Copyright (C) 2009 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.io.jaxb;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
import static org.junit.Assert.assertFalse;
|
13
|
import static org.junit.Assert.assertNotNull;
|
14
|
|
15
|
import java.io.InputStreamReader;
|
16
|
import eu.etaxonomy.cdm.common.URI;
|
17
|
|
18
|
import org.junit.Test;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
21
|
import eu.etaxonomy.cdm.model.description.TextData;
|
22
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
23
|
|
24
|
public class DescriptionTest {
|
25
|
|
26
|
private String resource = "/eu/etaxonomy/cdm/io/jaxb/DescriptionTest.xml";
|
27
|
|
28
|
@Test
|
29
|
public void testUnmarshalDescription() throws Exception {
|
30
|
CdmDocumentBuilder cdmDocumentBuilder = new CdmDocumentBuilder();
|
31
|
URI uri = new URI(URIEncoder.encode(this.getClass().getResource(resource).toString()));
|
32
|
DataSet dataSet = cdmDocumentBuilder.unmarshal(DataSet.class, new InputStreamReader(this.getClass().getResourceAsStream(resource)),uri.toString());
|
33
|
|
34
|
Taxon taxon = (Taxon)dataSet.getTaxonBases().get(0);
|
35
|
assertNotNull("Taxon must not be null",taxon);
|
36
|
assertNotNull("Taxon.descriptions must not be null",taxon.getDescriptions());
|
37
|
assertFalse("Taxon.descriptions must not be empty",taxon.getDescriptions().isEmpty());
|
38
|
assertEquals("Taxon.descriptions must contain one description",1,taxon.getDescriptions().size());
|
39
|
|
40
|
TaxonDescription taxonDescription = taxon.getDescriptions().iterator().next();
|
41
|
|
42
|
assertNotNull("TaxonDescription.descriptionElements must not be null",taxonDescription.getElements());
|
43
|
assertFalse("TaxonDescription.descriptionElements must not be empty",taxonDescription.getElements().isEmpty());
|
44
|
assertEquals("TaxonDescription.descriptionElements should contain one DescriptionElement",1,taxonDescription.getElements().size());
|
45
|
|
46
|
TextData textData = (TextData)taxonDescription.getElements().iterator().next();
|
47
|
assertEquals("TaxonDescription should equal TextData.inDescription",taxonDescription,textData.getInDescription());
|
48
|
}
|
49
|
}
|