View Javadoc

1   package org.cateproject.model;
2   
3   import java.io.IOException;
4   import java.io.InputStreamReader;
5   import java.net.URI;
6   import java.net.URISyntaxException;
7   
8   import javax.xml.bind.JAXBException;
9   import javax.xml.parsers.ParserConfigurationException;
10  import javax.xml.transform.stream.StreamSource;
11  
12  import junit.framework.Assert;
13  
14  import org.cateproject.marshal.CateDocumentBuilder;
15  import org.junit.Test;
16  import org.springframework.core.io.ClassPathResource;
17  import org.springframework.core.io.Resource;
18  import org.springframework.oxm.jaxb.Jaxb2Marshaller;
19  import org.xml.sax.InputSource;
20  import org.xml.sax.SAXException;
21  
22  import eu.etaxonomy.cdm.io.jaxb.URIEncoder;
23  import eu.etaxonomy.cdm.jaxb.FormattedText;
24  import eu.etaxonomy.cdm.jaxb.MultilanguageTextElement;
25  import eu.etaxonomy.cdm.model.common.LSIDAuthority;
26  import eu.etaxonomy.cdm.model.taxon.TaxonBase;
27  
28  public class WebRevisionTest {
29  	
30  	private String resource = "/org/cateproject/model/WebRevisionTest.xml";    
31  	
32      /**
33       * Test getting WebRevision from the document
34       * @throws URISyntaxException 
35       * @throws ParserConfigurationException 
36       * @throws IOException 
37       * @throws JAXBException 
38       * @throws SAXException 
39       */
40  	@Test
41      public void testGetRevision() throws URISyntaxException, SAXException, JAXBException, IOException, ParserConfigurationException
42      {
43  		URI uri = new URI(URIEncoder.encode(this.getClass().getResource(resource).toString()));
44  		CateDocumentBuilder cateDocumentBuilder = new CateDocumentBuilder();
45  
46  		try {
47  			cateDocumentBuilder.afterPropertiesSet();
48  		} catch(Exception e) {
49  			System.out.println(e);
50  			for(StackTraceElement ste : e.getStackTrace()) {
51  				System.out.println(ste);
52  			}
53  		}
54  		StreamSource source = new StreamSource(new InputStreamReader(this.getClass().getResourceAsStream(resource)));
55  				
56  			
57  		DataSet dataSet = (DataSet)cateDocumentBuilder.unmarshal(source);
58  	
59          WebRevision webRevision = dataSet.getWebRevision();
60          Assert.assertNotNull(webRevision);
61          Assert.assertFalse(webRevision.getTaxonNameTopics().isEmpty());
62          Assert.assertFalse(webRevision.getTaxonTopics().isEmpty());
63          Assert.assertNotNull(webRevision.getAuthorities());
64          Assert.assertFalse(webRevision.getAuthorities().isEmpty());
65          LSIDAuthority authority = webRevision.getAuthorities().get(0);
66          Assert.assertNotNull(authority.getNamespaces());
67          Assert.assertFalse(authority.getNamespaces().isEmpty());
68          Assert.assertNotNull(authority.getNamespaces().get("taxonconcepts"));
69          Assert.assertEquals(TaxonBase.class, authority.getNamespaces().get("taxonconcepts"));
70          
71      }
72  }