Project

General

Profile

Download (1.96 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.ext.kml;
2

    
3
import static org.junit.Assert.assertTrue;
4

    
5
import java.io.File;
6
import java.io.FileWriter;
7
import java.io.IOException;
8
import java.io.StringWriter;
9

    
10
import javax.xml.bind.JAXBContext;
11
import javax.xml.bind.JAXBException;
12
import javax.xml.bind.Marshaller;
13

    
14
import org.apache.commons.io.FileUtils;
15
import org.apache.log4j.Level;
16
import org.apache.log4j.Logger;
17
import org.junit.Before;
18
import org.junit.Test;
19

    
20
import de.micromata.opengis.kml.v_2_2_0.Kml;
21
import eu.etaxonomy.cdm.ext.geo.kml.KMLDocumentBuilder;
22
import eu.etaxonomy.cdm.model.location.Point;
23
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
24
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
25

    
26
public class KmlJaxbMarshallerTest {
27
	
28
	Kml kml;
29
	
30
	Logger logger;
31
	
32
	@Before
33
	public void makeKML() {
34
		FieldUnit fu = FieldUnit.NewInstance();
35
		fu.setGatheringEvent(GatheringEvent.NewInstance());
36
		fu.getGatheringEvent().setExactLocation(Point.NewInstance(-112.292238941097, 36.09520916122063, null, null));
37
		
38
		KMLDocumentBuilder builder = new KMLDocumentBuilder();
39
		builder.addSpecimenOrObservationBase(fu);
40
		kml = builder.build();
41
		
42
		logger = Logger.getLogger(this.getClass());
43
		logger.setLevel(Level.DEBUG);
44
	}
45
	
46
	
47
	@Test
48
	public void marshallTest() throws JAXBException, IOException {
49

    
50
		JAXBContext jaxbContext = JAXBContext.newInstance(Kml.class);
51
		Marshaller marshaller = jaxbContext.createMarshaller();
52
		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
53
		StringWriter sw = new StringWriter();
54
		marshaller.marshal(kml, sw);
55
		String kml = sw.toString();
56
		if(logger.isDebugEnabled()) {
57
			logger.debug("kml:\n" + kml);
58
			FileUtils.write(new File("KmlJaxbMarshallerTest.kml"), kml);
59
		}
60
		assertTrue(kml.contains("<kml:Document>"));
61
		assertTrue(kml.contains("<kml:Point>"));
62
		assertTrue(kml.contains("<kml:coordinates>-112.292238941097,36.09520916122063</kml:coordinates>"));
63
		assertTrue(kml.contains("<kml:altitudeMode>absolute</kml:altitudeMode>"));
64
	}
65

    
66
}
    (1-1/1)