use of org.apache.sis.xml.MarshallerPool in project sis by apache.
the class CodeListMarshallingTest method testISO_URL.
/**
* Tests marshaling using the ISO URL.
*
* @throws JAXBException if an error occurred while marshaling the XML.
*/
@Test
public void testISO_URL() throws JAXBException {
final String expected = getResponsiblePartyXML("http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/");
final ResponsibleParty rp = unmarshal(ResponsibleParty.class, expected);
assertEquals(Role.PRINCIPAL_INVESTIGATOR, rp.getRole());
final MarshallerPool pool = getMarshallerPool();
final Marshaller marshaller = pool.acquireMarshaller();
marshaller.setProperty(XML.METADATA_VERSION, VERSION_2007);
marshaller.setProperty(XML.SCHEMAS, Collections.singletonMap("gmd", // Intentionally omit trailing '/'.
"http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas"));
final String actual = marshal(marshaller, rp);
pool.recycle(marshaller);
assertXmlEquals(expected, actual, "xmlns:*");
}
use of org.apache.sis.xml.MarshallerPool in project sis by apache.
the class DefaultBrowseGraphicTest method testStringSubstitution.
/**
* Tests XML marshalling of filename substituted by {@code <gco:CharacterString>}
* inside {@code <mcc:MD_BrowseGraphic>}.
*
* @throws JAXBException if an error occurred while (un)marshalling the {@code BrowseGraphic}.
*/
@Test
@DependsOnMethod("testFileNameAndType")
public void testStringSubstitution() throws JAXBException {
final DefaultBrowseGraphic browse = new DefaultBrowseGraphic(URI.create("file:/catalog/image.png"));
browse.setFileType("image/tiff");
final MarshallerPool pool = getMarshallerPool();
final Marshaller marshaller = pool.acquireMarshaller();
marshaller.setProperty(XML.STRING_SUBSTITUTES, new String[] { "filename", "mimetype" });
final String xml = marshal(marshaller, browse);
pool.recycle(marshaller);
assertXmlEquals("<mcc:MD_BrowseGraphic xmlns:mcc=\"" + Namespaces.MCC + '"' + " xmlns:gco=\"" + Namespaces.GCO + "\">\n" + " <mcc:fileName>\n" + " <gco:CharacterString>file:/catalog/image.png</gco:CharacterString>\n" + " </mcc:fileName>\n" + " <mcc:fileType>\n" + " <gco:CharacterString>image/tiff</gco:CharacterString>\n" + " </mcc:fileType>\n" + "</mcc:MD_BrowseGraphic>", xml, "xmlns:*");
/*
* Unmarshal the element back to a Java object and compare to the original.
*/
assertEquals(browse, unmarshal(BrowseGraphic.class, xml));
}
use of org.apache.sis.xml.MarshallerPool in project sis by apache.
the class XMLTestCase method marshal.
/**
* Marshals the given object using the {@linkplain #getMarshallerPool() test marshaller pool}.
* The XML schema identified by the given version is used.
*
* @param object the object to marshal.
* @param metadataVersion whether to marshal legacy 19139:2007 or newer ISO 19115-3 document. Can be {@code null}.
* @return the marshalled object.
* @throws JAXBException if an error occurred while marshalling the object.
*
* @since 1.0
*/
protected final String marshal(final Object object, final Version metadataVersion) throws JAXBException {
final MarshallerPool pool = getMarshallerPool();
final Marshaller marshaller = pool.acquireMarshaller();
marshaller.setProperty(XML.METADATA_VERSION, metadataVersion);
final String xml = marshal(marshaller, object);
pool.recycle(marshaller);
return xml;
}
use of org.apache.sis.xml.MarshallerPool in project sis by apache.
the class TimePeriodTest method createMarshallerPool.
/**
* Creates the XML (un)marshaller pool to be shared by all test methods.
* The (un)marshallers locale and timezone will be set to fixed values.
*
* @throws JAXBException if an error occurred while creating the pool.
*
* @see #disposeMarshallerPool()
*/
@BeforeClass
public static void createMarshallerPool() throws JAXBException {
final Map<String, Object> properties = new HashMap<>(4);
assertNull(properties.put(XML.LOCALE, Locale.FRANCE));
assertNull(properties.put(XML.TIMEZONE, "CET"));
pool = new MarshallerPool(JAXBContext.newInstance(TimeInstant.class, TimePeriod.class), properties);
}
use of org.apache.sis.xml.MarshallerPool in project sis by apache.
the class LanguageCodeTest method createMarshallerPool.
/**
* Creates the XML (un)marshaller pool to be shared by all test methods.
* The (un)marshallers locale and timezone will be set to fixed values.
*
* <p>This test uses its own pool instead of {@link XMLTestCase#getMarshallerPool()} because it
* uses {@link MetadataMock} instead of {@link org.apache.sis.metadata.iso.DefaultMetadata}.</p>
*
* @throws JAXBException if an error occurred while creating the pool.
*
* @see #disposeMarshallerPool()
*/
@BeforeClass
public static void createMarshallerPool() throws JAXBException {
final Map<String, Object> properties = new HashMap<>(4);
assertNull(properties.put(XML.LOCALE, Locale.UK));
assertNull(properties.put(XML.TIMEZONE, UTC));
pool = new MarshallerPool(JAXBContext.newInstance(MetadataMock.class), properties);
}
Aggregations