Search in sources :

Example 1 with Metadata

use of org.opengis.metadata.Metadata in project sis by apache.

the class LanguageCodeTest method testUnmarshalLanguageCode.

/**
 * Tests the unmarshalling using the {@code <gmd:LanguageCode>} construct. XML fragment:
 *
 * {@preformat xml
 *   <gmd:MD_Metadata>
 *     <gmd:language>
 *       <gmd:LanguageCode codeList="(snip)/gmxCodelists.xml#LanguageCode" codeListValue="jpn">Japanese</gmd:LanguageCode>
 *     </gmd:language>
 *   </gmd:MD_Metadata>
 * }
 *
 * @throws JAXBException if an error occurs while unmarshalling the language.
 *
 * @see #testMarshalLanguageCode()
 */
@Test
public void testUnmarshalLanguageCode() throws JAXBException {
    final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
    final String xml = getMetadataXML(LANGUAGE_CODE);
    final Metadata metadata = (Metadata) unmarshal(unmarshaller, xml);
    assertEquals(Locale.JAPANESE, metadata.getLanguage());
}
Also used : Metadata(org.opengis.metadata.Metadata) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 2 with Metadata

use of org.opengis.metadata.Metadata in project sis by apache.

the class LanguageCodeTest method testLanguageCodeWithoutAttributes.

/**
 * Tests the unmarshalling using the {@code <gmd:LanguageCode>} construct without attributes.
 * The adapter is expected to parse the element value. XML fragment:
 *
 * {@preformat xml
 *   <gmd:MD_Metadata>
 *     <gmd:language>
 *       <gmd:LanguageCode>jpn</gmd:LanguageCode>
 *     </gmd:language>
 *   </gmd:MD_Metadata>
 * }
 *
 * @throws JAXBException if an error occurs while unmarshalling the language.
 */
@Test
@DependsOnMethod("testMarshalLanguageCode")
public void testLanguageCodeWithoutAttributes() throws JAXBException {
    final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
    final String xml = getMetadataXML(LANGUAGE_CODE_WITHOUT_ATTRIBUTE);
    final Metadata metadata = (Metadata) unmarshal(unmarshaller, xml);
    assertEquals(Locale.JAPANESE, metadata.getLanguage());
    pool.recycle(unmarshaller);
}
Also used : Metadata(org.opengis.metadata.Metadata) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 3 with Metadata

use of org.opengis.metadata.Metadata in project sis by apache.

the class StoreTest method testFromReader.

/**
 * Tests {@link Store#getMetadata()} reading from a {@link java.io.Reader}.
 *
 * @throws DataStoreException if an error occurred while reading the metadata.
 */
@Test
public void testFromReader() throws DataStoreException {
    final Metadata metadata;
    try (Store store = new Store(null, new StorageConnector(new StringReader(WKT)))) {
        metadata = store.getMetadata();
        assertSame("Expected cached value.", metadata, store.getMetadata());
    }
    validate((GeographicCRS) TestUtilities.getSingleton(metadata.getReferenceSystemInfo()));
}
Also used : StorageConnector(org.apache.sis.storage.StorageConnector) Metadata(org.opengis.metadata.Metadata) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 4 with Metadata

use of org.opengis.metadata.Metadata in project sis by apache.

the class MetadataReaderTest method testEmbedded.

/**
 * Reads the metadata using the netCDF decoder embedded with SIS,
 * and compares its string representation with the expected one.
 *
 * @throws IOException if an I/O error occurred while opening the file.
 * @throws DataStoreException if a logical error occurred.
 */
@Test
public void testEmbedded() throws IOException, DataStoreException {
    final Metadata metadata;
    try (Decoder input = ChannelDecoderTest.createChannelDecoder(NCEP)) {
        metadata = new MetadataReader(input).read();
    }
    compareToExpected(metadata);
}
Also used : DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) Metadata(org.opengis.metadata.Metadata) Decoder(org.apache.sis.internal.netcdf.Decoder) ChannelDecoderTest(org.apache.sis.internal.netcdf.impl.ChannelDecoderTest) Test(org.junit.Test)

Example 5 with Metadata

use of org.opengis.metadata.Metadata in project sis by apache.

the class MetadataCommand method run.

/**
 * Prints metadata or CRS information.
 *
 * @return 0 on success, or an exit code if the command failed for a reason other than an uncaught Java exception.
 */
@Override
public int run() throws Exception {
    /*
         * Read metadata from the data storage only after we verified that the arguments are valid.
         * The input can be a file given on the command line, or the standard input stream.
         */
    Object metadata = readMetadataOrCRS();
    if (hasUnexpectedFileCount) {
        return Command.INVALID_ARGUMENT_EXIT_CODE;
    }
    if (metadata != null) {
        if (!(metadata instanceof Metadata)) {
            final DefaultMetadata md = new DefaultMetadata();
            md.setReferenceSystemInfo(Collections.singleton((ReferenceSystem) metadata));
            metadata = md;
        }
        format(metadata);
    }
    return 0;
}
Also used : DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) Metadata(org.opengis.metadata.Metadata) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) ReferenceSystem(org.opengis.referencing.ReferenceSystem)

Aggregations

Metadata (org.opengis.metadata.Metadata)14 Test (org.junit.Test)11 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)5 Unmarshaller (javax.xml.bind.Unmarshaller)3 StorageConnector (org.apache.sis.storage.StorageConnector)3 ReferenceSystem (org.opengis.referencing.ReferenceSystem)3 StringReader (java.io.StringReader)2 Decoder (org.apache.sis.internal.netcdf.Decoder)2 ChannelDecoderTest (org.apache.sis.internal.netcdf.impl.ChannelDecoderTest)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1 DecoderWrapper (org.apache.sis.internal.netcdf.ucar.DecoderWrapper)1 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)1 AbstractIdentifiedObject (org.apache.sis.referencing.AbstractIdentifiedObject)1 DataStore (org.apache.sis.storage.DataStore)1 DependsOnMethod (org.apache.sis.test.DependsOnMethod)1 Cache (org.apache.sis.util.collection.Cache)1 Identifier (org.opengis.metadata.Identifier)1 Extent (org.opengis.metadata.extent.Extent)1