Search in sources :

Example 11 with StorageConnector

use of org.apache.sis.storage.StorageConnector in project sis by apache.

the class NetcdfStoreProviderTest method testProbeContentFromStream.

/**
 * Tests {@link NetcdfStoreProvider#probeContent(StorageConnector)} for an input stream which shall
 * be recognized as a classic netCDF file.
 *
 * @throws DataStoreException if a logical error occurred.
 */
@Test
public void testProbeContentFromStream() throws DataStoreException {
    final StorageConnector c = new StorageConnector(IOTestCase.getResourceAsStream(NCEP));
    final NetcdfStoreProvider provider = new NetcdfStoreProvider();
    final ProbeResult probe = provider.probeContent(c);
    assertTrue("isSupported", probe.isSupported());
    assertEquals("getMimeType", NetcdfStoreProvider.MIME_TYPE, probe.getMimeType());
    assertEquals("getVersion", new Version("1"), probe.getVersion());
    c.closeAllExcept(null);
}
Also used : StorageConnector(org.apache.sis.storage.StorageConnector) Version(org.apache.sis.util.Version) ProbeResult(org.apache.sis.storage.ProbeResult) ChannelDecoderTest(org.apache.sis.internal.netcdf.impl.ChannelDecoderTest) Test(org.junit.Test)

Example 12 with StorageConnector

use of org.apache.sis.storage.StorageConnector in project sis by apache.

the class NetcdfStoreProviderTest method testProbeContentFromUCAR.

/**
 * Tests {@link NetcdfStoreProvider#probeContent(StorageConnector)} for a UCAR {@link NetcdfFile} object.
 *
 * @throws IOException if an error occurred while opening the netCDF file.
 * @throws DataStoreException if a logical error occurred.
 */
@Test
public void testProbeContentFromUCAR() throws IOException, DataStoreException {
    try (NetcdfFile file = open(NCEP)) {
        final StorageConnector c = new StorageConnector(file);
        final NetcdfStoreProvider provider = new NetcdfStoreProvider();
        final ProbeResult probe = provider.probeContent(c);
        assertTrue("isSupported", probe.isSupported());
        assertEquals("getMimeType", NetcdfStoreProvider.MIME_TYPE, probe.getMimeType());
        assertNull("getVersion", probe.getVersion());
    }
}
Also used : NetcdfFile(ucar.nc2.NetcdfFile) StorageConnector(org.apache.sis.storage.StorageConnector) ProbeResult(org.apache.sis.storage.ProbeResult) ChannelDecoderTest(org.apache.sis.internal.netcdf.impl.ChannelDecoderTest) Test(org.junit.Test)

Example 13 with StorageConnector

use of org.apache.sis.storage.StorageConnector in project sis by apache.

the class StoreTest method testFromInputStream.

/**
 * Tests {@link StoreProvider#probeContent(StorageConnector)} followed by {@link Store#getMetadata()}
 * reading from an {@link java.io.InputStream}. This method tests indirectly {@link StorageConnector}
 * capability to reset the {@code InputStream} to its original position after {@code probeContent(…)}.
 *
 * @throws DataStoreException if en error occurred while reading the WKT.
 */
@Test
public void testFromInputStream() throws DataStoreException {
    final Metadata metadata;
    final StoreProvider p = new StoreProvider();
    final StorageConnector c = new StorageConnector(new ByteArrayInputStream(StoreTest.WKT.getBytes(StandardCharsets.US_ASCII)));
    assertTrue("isSupported", p.probeContent(c).isSupported());
    try (Store store = new Store(null, c)) {
        metadata = store.getMetadata();
        assertSame("Expected cached value.", metadata, store.getMetadata());
    }
    validate((GeographicCRS) TestUtilities.getSingleton(metadata.getReferenceSystemInfo()));
}
Also used : StorageConnector(org.apache.sis.storage.StorageConnector) ByteArrayInputStream(java.io.ByteArrayInputStream) Metadata(org.opengis.metadata.Metadata) Test(org.junit.Test)

Example 14 with StorageConnector

use of org.apache.sis.storage.StorageConnector in project sis by apache.

the class StoreProviderTest method testProbeContentFromReader.

/**
 * Tests {@link StoreProvider#probeContent(StorageConnector)} method from a {@link java.io.Reader} object.
 *
 * @throws DataStoreException if en error occurred while reading the XML.
 */
@Test
public void testProbeContentFromReader() throws DataStoreException {
    final StoreProvider p = new StoreProvider();
    final StorageConnector c = new StorageConnector(new StringReader(StoreTest.XML));
    final ProbeResult r = p.probeContent(c);
    c.closeAllExcept(null);
    assertTrue("isSupported", r.isSupported());
    assertEquals("mimeType", "application/vnd.iso.19139+xml", r.getMimeType());
}
Also used : StorageConnector(org.apache.sis.storage.StorageConnector) StringReader(java.io.StringReader) ProbeResult(org.apache.sis.storage.ProbeResult) Test(org.junit.Test)

Example 15 with StorageConnector

use of org.apache.sis.storage.StorageConnector in project sis by apache.

the class StoreTest method testMetadata.

/**
 * Tests {@link Store#getMetadata()}.
 *
 * @throws DataStoreException if en error occurred while reading the XML.
 */
@Test
public void testMetadata() throws DataStoreException {
    final Metadata metadata;
    try (Store store = new Store(null, new StorageConnector(new StringReader(XML)))) {
        metadata = store.getMetadata();
        assertSame("Expected cached value.", metadata, store.getMetadata());
    }
    final ResponsibleParty resp = getSingleton(metadata.getContacts());
    final Contact contact = resp.getContactInfo();
    final OnlineResource resource = contact.getOnlineResource();
    assertEquals(Locale.ENGLISH, metadata.getLanguage());
    if (!REGRESSION)
        assertEquals(CharacterSet.UTF_8, metadata.getCharacterSet());
    assertEquals(Role.PRINCIPAL_INVESTIGATOR, resp.getRole());
    assertEquals("Apache SIS", String.valueOf(resp.getOrganisationName()));
    assertEquals("http://sis.apache.org", String.valueOf(resource.getLinkage()));
    assertEquals(OnLineFunction.INFORMATION, resource.getFunction());
}
Also used : StorageConnector(org.apache.sis.storage.StorageConnector) Metadata(org.opengis.metadata.Metadata) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

StorageConnector (org.apache.sis.storage.StorageConnector)18 Test (org.junit.Test)11 StringReader (java.io.StringReader)4 ProbeResult (org.apache.sis.storage.ProbeResult)4 Path (java.nio.file.Path)3 DataStore (org.apache.sis.storage.DataStore)3 Metadata (org.opengis.metadata.Metadata)3 ChannelDecoderTest (org.apache.sis.internal.netcdf.impl.ChannelDecoderTest)2 Parameters (org.apache.sis.parameter.Parameters)2 DataStoreException (org.apache.sis.storage.DataStoreException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 DirectoryIteratorException (java.nio.file.DirectoryIteratorException)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AbstractFeature (org.apache.sis.feature.AbstractFeature)1 URIDataStore (org.apache.sis.internal.storage.URIDataStore)1 UnmodifiableArrayList (org.apache.sis.internal.util.UnmodifiableArrayList)1