Example usage for javax.xml.bind JAXB marshal

List of usage examples for javax.xml.bind JAXB marshal

Introduction

In this page you can find the example usage for javax.xml.bind JAXB marshal.

Prototype

public static void marshal(Object jaxbObject, Result xml) 

Source Link

Document

Writes a Java object tree to XML and store it to the specified location.

Usage

From source file:org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.TestWfs10JTStoGML200Converter.java

@Test
public void testPointTypeToJAXB()
        throws JAXBException, SAXException, IOException, ParseException, NullPointerException {
    String pointGML = Wfs10JTStoGML200Converter.convertGeometryToGML(getGeometryFromWkt(POINT));
    PointType pointType = (PointType) Wfs10JTStoGML200Converter.convertGMLToGeometryType(pointGML,
            Wfs10Constants.POINT);//from  www.  ja  v a 2  s  .c  o  m
    JAXBElement<PointType> pointTypeJAXBElement = (JAXBElement<PointType>) Wfs10JTStoGML200Converter
            .convertGeometryTypeToJAXB(pointType);

    JAXB.marshal(pointTypeJAXBElement, writer);
    String xml = writer.toString();
    Diff diff = XMLUnit.compareXML(xml, POINT_GML);
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
    assertThat(diff.similar(), is(Boolean.TRUE));
    assertThat(diff.identical(), is(Boolean.FALSE));
}

From source file:org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.TestWfs10JTStoGML200Converter.java

@Test
public void testMultiPointTypeToJAXB()
        throws JAXBException, SAXException, IOException, ParseException, NullPointerException {

    String multiPointGML = Wfs10JTStoGML200Converter.convertGeometryToGML(getGeometryFromWkt(MULTIPOINT));
    MultiPointType multiPointType = (MultiPointType) Wfs10JTStoGML200Converter
            .convertGMLToGeometryType(multiPointGML, Wfs10Constants.MULTI_POINT);
    JAXBElement<MultiPointType> multiPointTypeJAXBElement = (JAXBElement<MultiPointType>) Wfs10JTStoGML200Converter
            .convertGeometryTypeToJAXB(multiPointType);

    JAXB.marshal(multiPointTypeJAXBElement, writer);
    String xml = writer.toString();
    Diff diff = XMLUnit.compareXML(xml, MULTIPOINT_GML);
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
    assertThat(diff.similar(), is(Boolean.TRUE));
    assertThat(diff.identical(), is(Boolean.FALSE));
}

From source file:org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.TestWfs10JTStoGML200Converter.java

@Test
public void testMultiLineStringTypeToJAXB()
        throws JAXBException, SAXException, IOException, ParseException, NullPointerException {

    String multiLineString = Wfs10JTStoGML200Converter
            .convertGeometryToGML(getGeometryFromWkt(MULTILINESTRING));
    MultiLineStringType multiLineStringType = (MultiLineStringType) Wfs10JTStoGML200Converter
            .convertGMLToGeometryType(multiLineString, Wfs10Constants.MULTI_LINESTRING);
    JAXBElement<MultiLineStringType> multiLineStringTypeJAXBElement = (JAXBElement<MultiLineStringType>) Wfs10JTStoGML200Converter
            .convertGeometryTypeToJAXB(multiLineStringType);

    JAXB.marshal(multiLineStringTypeJAXBElement, writer);
    String xml = writer.toString();
    Diff diff = XMLUnit.compareXML(xml, MULTILINESTRING_GML);
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
    assertThat(diff.similar(), is(Boolean.TRUE));
    assertThat(diff.identical(), is(Boolean.FALSE));

}

From source file:org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.TestWfs10JTStoGML200Converter.java

@Test
public void testMultiPolygonTypeToJAXB()
        throws JAXBException, SAXException, IOException, ParseException, NullPointerException {

    String multiPolygonGML = Wfs10JTStoGML200Converter.convertGeometryToGML(getGeometryFromWkt(MULTIPOLYGON));
    MultiPolygonType multiPolygonType = (MultiPolygonType) Wfs10JTStoGML200Converter
            .convertGMLToGeometryType(multiPolygonGML, Wfs10Constants.MULTI_POLYGON);
    JAXBElement<MultiPolygonType> multiPolygonTypeJAXBElement = (JAXBElement<MultiPolygonType>) Wfs10JTStoGML200Converter
            .convertGeometryTypeToJAXB(multiPolygonType);

    JAXB.marshal(multiPolygonTypeJAXBElement, writer);
    String xml = writer.toString();
    Diff diff = XMLUnit.compareXML(xml, MULTIPOLYGON_GML);
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
    assertThat(diff.similar(), is(Boolean.TRUE));
    assertThat(diff.identical(), is(Boolean.FALSE));

}

From source file:org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.TestWfs10JTStoGML200Converter.java

@Test
public void testGeometryCollectionTypeToJAXB()
        throws JAXBException, SAXException, IOException, ParseException, NullPointerException {

    String geometryCollectionGML = Wfs10JTStoGML200Converter
            .convertGeometryToGML(getGeometryFromWkt(GEOMETRYCOLLECTION)).replaceAll("\n", "");
    GeometryCollectionType geometryCollectionType = (GeometryCollectionType) Wfs10JTStoGML200Converter
            .convertGMLToGeometryType(geometryCollectionGML, Wfs10Constants.GEOMETRY_COLLECTION);
    JAXBElement<GeometryCollectionType> geometryCollectionTypeJAXBElement = (JAXBElement<GeometryCollectionType>) Wfs10JTStoGML200Converter
            .convertGeometryTypeToJAXB(geometryCollectionType);

    JAXB.marshal(geometryCollectionTypeJAXBElement, writer);
    String xml = writer.toString().replaceAll("\n", "");
    Diff diff = XMLUnit.compareXML(xml, GEOMETRYCOLLECTION_NS1);
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
    assertThat(diff.similar(), is(Boolean.TRUE));
    assertThat(diff.identical(), is(Boolean.TRUE));

}

From source file:org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.Wfs10JTStoGML200ConverterTest.java

@Test
public void testMultiLineStringTypeToJAXB()
        throws JAXBException, SAXException, IOException, ParseException, NullPointerException {

    String multiLineString = Wfs10JTStoGML200Converter
            .convertGeometryToGML(getGeometryFromWkt(MULTILINESTRING));
    MultiLineStringType multiLineStringType = (MultiLineStringType) Wfs10JTStoGML200Converter
            .convertGMLToGeometryType(multiLineString, Wfs10Constants.MULTI_LINESTRING);
    JAXBElement<MultiLineStringType> multiLineStringTypeJAXBElement = (JAXBElement<MultiLineStringType>) Wfs10JTStoGML200Converter
            .convertGeometryTypeToJAXB(multiLineStringType);

    JAXB.marshal(multiLineStringTypeJAXBElement, writer);
    String xml = writer.toString();
    Diff diff = XMLUnit.compareXML(xml, MULTILINESTRING_GML);
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
    assertThat(diff.similar(), is(Boolean.TRUE));
    assertThat(diff.identical(), is(Boolean.FALSE));
}

From source file:org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.Wfs10JTStoGML200ConverterTest.java

@Test
public void testMultiPolygonTypeToJAXB()
        throws JAXBException, SAXException, IOException, ParseException, NullPointerException {

    String multiPolygonGML = Wfs10JTStoGML200Converter.convertGeometryToGML(getGeometryFromWkt(MULTIPOLYGON));
    MultiPolygonType multiPolygonType = (MultiPolygonType) Wfs10JTStoGML200Converter
            .convertGMLToGeometryType(multiPolygonGML, Wfs10Constants.MULTI_POLYGON);
    JAXBElement<MultiPolygonType> multiPolygonTypeJAXBElement = (JAXBElement<MultiPolygonType>) Wfs10JTStoGML200Converter
            .convertGeometryTypeToJAXB(multiPolygonType);

    JAXB.marshal(multiPolygonTypeJAXBElement, writer);
    String xml = writer.toString();
    Diff diff = XMLUnit.compareXML(xml, MULTIPOLYGON_GML);
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
    assertThat(diff.similar(), is(Boolean.TRUE));
    assertThat(diff.identical(), is(Boolean.FALSE));
}

From source file:org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.Wfs10JTStoGML200ConverterTest.java

@Test
public void testGeometryCollectionTypeToJAXB()
        throws JAXBException, SAXException, IOException, ParseException, NullPointerException {

    String geometryCollectionGML = Wfs10JTStoGML200Converter
            .convertGeometryToGML(getGeometryFromWkt(GEOMETRYCOLLECTION)).replaceAll("\n", "");
    GeometryCollectionType geometryCollectionType = (GeometryCollectionType) Wfs10JTStoGML200Converter
            .convertGMLToGeometryType(geometryCollectionGML, Wfs10Constants.GEOMETRY_COLLECTION);
    JAXBElement<GeometryCollectionType> geometryCollectionTypeJAXBElement = (JAXBElement<GeometryCollectionType>) Wfs10JTStoGML200Converter
            .convertGeometryTypeToJAXB(geometryCollectionType);

    JAXB.marshal(geometryCollectionTypeJAXBElement, writer);
    String xml = writer.toString().replaceAll("\n", "");
    Diff diff = XMLUnit.compareXML(xml, GEOMETRYCOLLECTION_NS1);
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
    assertThat(diff.similar(), is(Boolean.TRUE));
    assertThat(diff.identical(), is(Boolean.TRUE));
}

From source file:org.ebayopensource.turmeric.services.monitoringservice.junit.AbstractSOAQueryMetricsTest.java

/**
 * Test get metrics metadata.//from  w ww  .  j  a v a2s.  c  om
 * 
 * @param requestXmlPath
 *            the request xml path
 * @param respXmlPath
 *            the resp xml path
 * @throws Exception
 *             the exception
 */
public void testGetMetricsMetadata(String requestXmlPath, String respXmlPath) throws Exception {
    init();
    ClassLoader cl = AbstractSOAQueryMetricsTest.class.getClassLoader();
    InputStreamReader requestis = new InputStreamReader(cl.getResourceAsStream(requestXmlPath));
    InputStreamReader responseis = new InputStreamReader(cl.getResourceAsStream(respXmlPath));

    GetMetricsMetadataRequest req = JAXB.unmarshal(requestis, GetMetricsMetadataRequest.class);

    GetMetricsMetadataResponse resp = consumer.getMetricsMetadata(req);

    ByteArrayOutputStream xmlResp = new ByteArrayOutputStream();
    JAXB.marshal(resp, xmlResp);
    StringReader str = new StringReader(xmlResp.toString());
    System.out.println(xmlResp.toString());
    assertXMLEqual(responseis, str);
}

From source file:org.ebayopensource.turmeric.services.monitoringservice.junit.AbstractSOAQueryMetricsTest.java

/**
 * Test get metric value./* w ww  .java2  s . c o  m*/
 * 
 * @param requestXmlPath
 *            the request xml path
 * @param respXmlPath
 *            the resp xml path
 * @throws Exception
 *             the exception
 */
public void testGetMetricValue(String requestXmlPath, String respXmlPath) throws Exception {
    ClassLoader cl = AbstractSOAQueryMetricsTest.class.getClassLoader();
    InputStreamReader requestis = new InputStreamReader(cl.getResourceAsStream(requestXmlPath));
    InputStreamReader responseis = new InputStreamReader(cl.getResourceAsStream(respXmlPath));

    GetMetricValueRequest req = JAXB.unmarshal(requestis, GetMetricValueRequest.class);

    GetMetricValueResponse resp = consumer.getMetricValue(req);
    ByteArrayOutputStream xmlResp = new ByteArrayOutputStream();
    JAXB.marshal(resp, xmlResp);
    StringReader str = new StringReader(xmlResp.toString());
    System.out.println(xmlResp.toString());
    assertXMLEqual(responseis, str);
}