use of org.opengis.metadata.citation.Citation in project sis by apache.
the class CustomMetadataTest method testProxy.
/**
* Tests the marshalling of a metadata implemented by {@link Proxy}.
*
* @throws JAXBException if an error occurred during (un)marshalling.
*/
@Test
public void testProxy() throws JAXBException {
/*
* A trivial metadata implementation which return the method name
* for every attribute of type InternationalString.
*/
final InvocationHandler handler = (Object proxy, Method method, Object[] args) -> {
if (method.getReturnType() == InternationalString.class) {
return new SimpleInternationalString(method.getName());
}
return null;
};
Citation data = (Citation) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { Citation.class }, handler);
/*
* Wrap the metadata in a DefaultMetadata, and ensure
* we can marshall it without an exception being throw.
*/
data = new DefaultCitation(data);
final String xml = XML.marshal(data);
/*
* A few simple checks.
*/
assertTrue(xml.contains("title"));
assertTrue(xml.contains("edition"));
}
use of org.opengis.metadata.citation.Citation in project sis by apache.
the class DefaultServiceIdentificationTest method create.
/**
* Creates the service identification to use for testing purpose.
*/
private static DefaultServiceIdentification create() {
final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
final DefaultCoupledResource resource = DefaultCoupledResourceTest.create(factory);
resource.setResourceReferences(singleton(new DefaultCitation("WMS specification")));
final DefaultServiceIdentification id = new DefaultServiceIdentification(// serviceType
factory.createGenericName(null, "Web Map Server"), // citation
NilReason.MISSING.createNilObject(Citation.class), // abstract
"A dummy service for testing purpose.");
id.setServiceTypeVersions(singleton("1.0"));
id.setCoupledResources(singleton(resource));
id.setCouplingType(UnsupportedCodeList.valueOf("LOOSE"));
id.setContainsOperations(singleton(resource.getOperation()));
return id;
}
use of org.opengis.metadata.citation.Citation in project sis by apache.
the class NilReasonMarshallingTest method testMissing.
/**
* Tests a simple case for a missing data.
*
* @throws JAXBException if an error occurred during (un)marshalling.
*/
@Test
public void testMissing() throws JAXBException {
final String expected = "<cit:CI_Citation xmlns:cit=\"" + Namespaces.CIT + '"' + " xmlns:gco=\"" + Namespaces.GCO + "\">\n" + " <cit:title>\n" + " <gco:CharacterString>A title</gco:CharacterString>\n" + " </cit:title>\n" + " <cit:series gco:nilReason=\"missing\"/>\n" + "</cit:CI_Citation>";
final Citation citation = unmarshal(Citation.class, expected);
assertTitleEquals("citation", "A title", citation);
final Series series = citation.getSeries();
assertInstanceOf("Should have instantiated a proxy.", NilObject.class, series);
final NilReason reason = ((NilObject) series).getNilReason();
assertSame("nilReason", NilReason.MISSING, reason);
assertNull("NilReason.explanation", reason.getOtherExplanation());
assertNull("NilReason.URI", reason.getURI());
assertEquals("Series[missing]", series.toString());
assertNull("All attributes are expected to be null.", series.getName());
final String actual = marshal(citation);
assertXmlEquals(expected, actual, "xmlns:*");
assertEquals(citation, unmarshal(Citation.class, actual));
}
use of org.opengis.metadata.citation.Citation in project sis by apache.
the class UUIDMarshallingTest method testReference.
/**
* Tests (un)marshalling of an object referenced by a {@code uuidref} attribute.
* This test does not try to resolve the reference, but only check that the identifier is properly saved.
*
* <p>The element of interest for this test is the {@code "uuidref"} part
* in the {@code <gmd:series>} property of the following XML fragment:</p>
*
* {@preformat xml
* <cit:CI_Citation>
* <cit:title>
* <gco:CharacterString>My data</gco:CharacterString>
* </cit:title>
* <cit:series uuidref="f8f5fcb1-d57b-4013-b3a4-4eaa40df6dcf">
* <cit:CI_Series>
* <cit:name>
* <gco:CharacterString>My aggregate dataset</gco:CharacterString>
* </cit:name>
* </cit:CI_Series>
* </cit:series>
* </cit:CI_Citation>
* }
*
* On an implementation note, the {@code uuidref}, {@code xlink:href} and other attributes of the
* {@code <gmd:series>} element are handled by {@link org.apache.sis.internal.jaxb.gco.PropertyType}.
*
* @throws JAXBException if an error occurred during (un)marshalling.
*/
@Test
public void testReference() throws JAXBException {
final Citation citation = (Citation) XML.unmarshal(REFERENCED_XML_WITH_BODY);
assertTitleEquals("Citation.title", "My data", citation);
/*
* Programmatic verification of the Series properties,
* which is the main object of interest in this test.
*/
final Series series = citation.getSeries();
assertInstanceOf("Citation.series", IdentifiedObject.class, series);
assertFalse("Citation.series.isProxy", Proxy.isProxyClass(series.getClass()));
assertEquals("Citation.series.name", "My aggregate dataset", series.getName().toString());
final IdentifierMap map = ((IdentifiedObject) series).getIdentifierMap();
assertNull("href", map.get(IdentifierSpace.HREF));
assertEquals("uuid", UUID_VALUE, map.get(IdentifierSpace.UUID));
/*
* Marshal the object back to XML and compare with the expected result. The result shall be
* slightly different than the original XML, since the UUID in the <gmd:series> element shall
* move to the <gmd:CI_Series> element. This is the expected behavior because we have a fully
* constructed object, not a reference to an object defined elsewhere.
*/
final String actual = XML.marshal(citation);
assertXmlEquals(IDENTIFIED_XML, actual, "xmlns:*");
assertEquals(citation, XML.unmarshal(actual));
}
use of org.opengis.metadata.citation.Citation in project sis by apache.
the class DefaultMetadata method setMetadataStandard.
/**
* Implementation of legacy {@link #setMetadataStandardName(String)} and
* {@link #setMetadataStandardVersion(String)} methods.
*/
private void setMetadataStandard(final boolean version, final String newValue) {
checkWritePermission();
final InternationalString i18n = (newValue != null) ? new SimpleInternationalString(newValue) : null;
final List<Citation> newValues = (metadataStandards != null) ? new ArrayList<>(metadataStandards) : new ArrayList<>(1);
DefaultCitation citation = newValues.isEmpty() ? null : DefaultCitation.castOrCopy(newValues.get(0));
if (citation == null) {
citation = new DefaultCitation();
}
if (version) {
citation.setEdition(i18n);
} else {
citation.setTitle(i18n);
}
if (newValues.isEmpty()) {
newValues.add(citation);
} else {
newValues.set(0, citation);
}
setMetadataStandards(newValues);
}
Aggregations