Project

General

Profile

Download (4.01 KB) Statistics
| Branch: | Tag: | Revision:
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
import static org.junit.Assert.assertTrue;
15

    
16
import java.io.InputStreamReader;
17
import java.net.URI;
18

    
19
import org.junit.Test;
20

    
21
import eu.etaxonomy.cdm.model.agent.Institution;
22
import eu.etaxonomy.cdm.model.agent.Person;
23
import eu.etaxonomy.cdm.model.name.TaxonName;
24
import eu.etaxonomy.cdm.model.occurrence.Collection;
25
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
26
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
27
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
28
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
29
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
30
import eu.etaxonomy.cdm.model.taxon.Taxon;
31
import eu.etaxonomy.cdm.model.term.DefinedTerm;
32

    
33
public class SpecimenTest {
34

    
35
	    private String resource = "/eu/etaxonomy/cdm/io/jaxb/SpecimenTest.xml";
36

    
37
	    @Test
38
	    public void testUnmarshalSpecimen() throws Exception {
39
	        CdmDocumentBuilder cdmDocumentBuilder = new CdmDocumentBuilder();
40
	        URI uri = new URI(URIEncoder.encode(this.getClass().getResource(resource).toString()));
41
	        DataSet dataSet = cdmDocumentBuilder.unmarshal(DataSet.class, new InputStreamReader(this.getClass().getResourceAsStream(resource)),uri.toString());
42
//	        List<SpecimenOrObservationBase> occurrences = dataSet.getOccurrences();
43

    
44
			DerivedUnit specimen = (DerivedUnit)dataSet.getOccurrences().get(0);
45
			assertNotNull("Specimen must not be null",specimen);
46

    
47
			Institution institution = (Institution)dataSet.getAgents().get(0);
48
			assertNotNull("Institution must not be null",institution);
49
			Person person = (Person)dataSet.getAgents().get(1);
50
			assertNotNull("Person must not be null", person);
51
			Taxon taxon = (Taxon)dataSet.getTaxonBases().get(0);
52
			assertNotNull("Taxon must not be null",taxon);
53
			TaxonName name = dataSet.getTaxonomicNames().get(0);
54
			assertNotNull("TaxonName must not be null",name);
55
			DefinedTerm sex = (DefinedTerm)dataSet.getTerms().get(1);
56

    
57
			Collection collection = dataSet.getCollections().get(0);
58
			assertNotNull("Collection must not be null", collection);
59

    
60
			FieldUnit fieldUnit = (FieldUnit)dataSet.getOccurrences().get(1);
61
			assertNotNull("FieldUnit must not be null", fieldUnit);
62
			assertEquals("Specimen.collection must equal Collection",collection, specimen.getCollection());
63
			assertEquals("Collection.institute must equal Institution",institution,collection.getInstitute());
64

    
65
			assertEquals("TaxonName must equal Specimen.storedUnder",name,specimen.getStoredUnder());
66
			assertEquals("Sex must equal Specimen.sex",sex,specimen.getSex());
67

    
68
			assertNotNull("Specimen.determinations must not be null",specimen.getDeterminations());
69
			assertFalse("Specimen.determinations must not be empty",specimen.getDeterminations().isEmpty());
70
			DeterminationEvent determination = specimen.getDeterminations().iterator().next();
71
			assertEquals("Person must equal Determination.actor",person,determination.getActor());
72

    
73
			GatheringEvent gatheringEvent = (GatheringEvent)dataSet.getEventBases().get(0);
74
			assertNotNull("GatheringEvent must not be null",gatheringEvent);
75

    
76
			DerivationEvent derivationEvent = (DerivationEvent)dataSet.getEventBases().get(1);
77
			assertNotNull("DerivationEvent must not be null",derivationEvent);
78

    
79
			assertEquals("GatheringEvent must be equal to FieldUnit.getGatheringEvent()",gatheringEvent, fieldUnit.getGatheringEvent());
80
			assertTrue("DerivationEvent.derivatives must contain Specimen",derivationEvent.getDerivatives().contains(specimen));
81
			assertEquals("DerivationEvent must equal Specimen.derivedFrom",derivationEvent,specimen.getDerivedFrom());
82
	    }
83
}
(12-12/17)