Project

General

Profile

Download (2.55 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
import static org.junit.Assert.assertNotSame;
14

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

    
18
import org.junit.Test;
19

    
20
import eu.etaxonomy.cdm.model.reference.IArticle;
21
import eu.etaxonomy.cdm.model.reference.IGeneric;
22
import eu.etaxonomy.cdm.model.reference.IJournal;
23
import eu.etaxonomy.cdm.model.reference.Reference;
24

    
25
public class ReferenceTest {
26

    
27
        private String resource = "/eu/etaxonomy/cdm/io/jaxb/ReferenceTest.xml";
28

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

    
35
            assertNotSame("Reference list should not be empty", 0, dataSet.getReferences().size());
36

    
37
            IArticle article = dataSet.getReferences().get(0);
38
            assertNotNull("Article must not be null",article);
39

    
40
            IJournal journal = dataSet.getReferences().get(1);
41
            assertNotNull("Journal must not be null", journal);
42
            assertEquals("Journal must equal Article.inJournal",journal,article.getInJournal());
43
        }
44

    
45
        @Test
46
        public void testCastReferences() throws Exception{
47
            CdmDocumentBuilder cdmDocumentBuilder = new CdmDocumentBuilder();
48
            URI uri = new URI(URIEncoder.encode(this.getClass().getResource(resource).toString()));
49
            DataSet dataSet = cdmDocumentBuilder.unmarshal(DataSet.class, new InputStreamReader(this.getClass().getResourceAsStream(resource)),uri.toString());
50

    
51
            IArticle article = dataSet.getReferences().get(0);
52
            assertNotNull("Article must not be null",article);
53

    
54
            IJournal journal = ((Reference)article).castReferenceToJournal();
55
            assertEquals("Journal", journal.getType().name());
56

    
57
            IGeneric generic = ((Reference)journal).castReferenceToGeneric();
58
            assertEquals("Generic", generic.getType().name());
59

    
60

    
61
        }
62
}
(10-10/17)