Project

General

Profile

Download (2.49 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.assertNotNull;
13

    
14
import java.io.InputStreamReader;
15
import java.net.URI;
16

    
17
import org.joda.time.DateTimeFieldType;
18
import org.junit.Test;
19

    
20
import eu.etaxonomy.cdm.model.agent.InstitutionalMembership;
21
import eu.etaxonomy.cdm.model.agent.Person;
22

    
23
public class AgentsTest {
24

    
25
    private String resource = "/eu/etaxonomy/cdm/io/jaxb/AgentsTest.xml";
26

    
27
    @Test
28
    public void testUnmarshalAgents() throws Exception {
29
        CdmDocumentBuilder cdmDocumentBuilder = new CdmDocumentBuilder();
30
        URI uri = new URI(URIEncoder.encode(this.getClass().getResource(resource).toString()));
31
        DataSet dataSet = cdmDocumentBuilder.unmarshal(DataSet.class, new InputStreamReader(this.getClass().getResourceAsStream(resource)),uri.toString());
32

    
33
		Person person = (Person)dataSet.getAgents().get(0);
34
		assertNotNull("Persion should not be null",person);
35
		assertEquals("Person.getNomenclaturalTitle should return \'Mill.\'","Mill.",person.getNomenclaturalTitle());
36
		assertEquals("Person.getGivenName should return \'Philip\'","Philip",person.getGivenName());
37
		assertEquals("Person.getFamilyName should return \'Miller\'","Miller",person.getFamilyName());
38
		assertNotNull("Person.getLifespan should not be null",person.getLifespan());
39
		assertNotNull("Person.getLifespan.getStart should not be null",person.getLifespan().getStart());
40
		assertEquals("Person.getLifespan.getStart should equal 1691", person.getLifespan().getStart().get(DateTimeFieldType.year()),1691);
41
        assertNotNull("Person.getInstitutionalMemberships should not be null",person.getInstitutionalMemberships());
42
        assertEquals("There should be one institutional membership",1,person.getInstitutionalMemberships().size());
43
        InstitutionalMembership institutionalMembership = person.getInstitutionalMemberships().iterator().next();
44
        assertEquals("institutionalMembership.getInstitute should return Chelsea Physic Garden",institutionalMembership.getInstitute(),dataSet.getAgents().get(1));
45
        assertEquals("institutionalMembership.getPerson should return Philip Miller",institutionalMembership.getPerson(),dataSet.getAgents().get(0));
46

    
47
    }
48
}
(1-1/17)