Search in sources :

Example 61 with Metacard

use of ddf.catalog.data.Metacard in project ddf by codice.

the class TikaInputTransformerTest method testTiff.

@Test
public void testTiff() throws Exception {
    InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("testTIFF.tif");
    Metacard metacard = transform(stream);
    assertNotNull(metacard);
    assertNotNull(metacard.getMetadata());
    assertThat(metacard.getMetadata(), containsString("<meta name=\"tiff:BitsPerSample\" content=\"8\"/>"));
    assertThat(metacard.getContentTypeName(), is("image/tiff"));
    assertThat(metacard.getAttribute(Core.DATATYPE).getValue(), is(IMAGE));
}
Also used : Metacard(ddf.catalog.data.Metacard) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 62 with Metacard

use of ddf.catalog.data.Metacard in project ddf by codice.

the class HistorianTest method testDeleteResponse.

@Test
public void testDeleteResponse() throws SourceUnavailableException, IngestException, StorageException {
    Metacard metacard = getMetacardUpdatePair().get(0);
    storeMetacard(metacard);
    // Send a delete request
    DeleteStorageRequest deleteStorageRequest = new DeleteStorageRequestImpl(Collections.singletonList(metacard), new HashMap<>());
    storageProvider.delete(deleteStorageRequest);
    // Version delete request
    DeleteRequest deleteRequest = new DeleteRequestImpl("deleteRequest");
    DeleteResponse deleteResponse = new DeleteResponseImpl(deleteRequest, new HashMap<>(), Collections.singletonList(metacard));
    historian.version(deleteResponse);
    // Only the version metacard is left
    assertThat(storageProvider.storageMap.size(), equalTo(1));
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 63 with Metacard

use of ddf.catalog.data.Metacard in project ddf by codice.

the class ReliableResourceDownloadManagerTest method getMockMetacard.

private Metacard getMockMetacard(String id, String source) {
    Metacard metacard = mock(Metacard.class);
    when(metacard.getId()).thenReturn(id);
    when(metacard.getSourceId()).thenReturn(source);
    when(metacard.getMetacardType()).thenReturn(BasicTypes.BASIC_METACARD);
    return metacard;
}
Also used : Metacard(ddf.catalog.data.Metacard)

Example 64 with Metacard

use of ddf.catalog.data.Metacard in project ddf by codice.

the class ReliableResourceDownloadManagerTest method testCacheFileExceptionDuringProductDownload.

/**
     * Tests that if exception with file being cached to occurs during a product retrieval, then the (partially) cached
     * file is deleted and it is not placed in the cache map, but the product continues to be streamed to the client until
     * the EOF is detected.
     *
     * @throws Exception
     */
@Test
@Ignore
public void testCacheFileExceptionDuringProductDownload() throws Exception {
    // Need the product InputStream (MockInputStream) to read slower so that client has time to
    // start reading from the ReliableResourceInputStream and close the FileOutputStream the
    // download manager is writing to, simulating a cache file exception during
    // the product download
    mis = new MockInputStream(productInputFilename, true);
    mis.setReadDelay(MONITOR_PERIOD - 2, TimeUnit.MILLISECONDS);
    Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
    resourceResponse = getMockResourceResponse();
    ResourceRetriever retriever = mock(ResourceRetriever.class);
    when(retriever.retrieveResource()).thenReturn(resourceResponse);
    int chunkSize = 2;
    startDownload(true, chunkSize, false, metacard, retriever);
    // On second chunk read by client it will close the download manager's cache file output stream
    // to simulate a cache file exception that should be detected by the ReliableResourceCallable
    executor = Executors.newCachedThreadPool();
    ProductDownloadClient productDownloadClient = new ProductDownloadClient(productInputStream, chunkSize);
    productDownloadClient.setSimulateCacheFileException(2, downloadMgr);
    future = executor.submit(productDownloadClient);
    ByteArrayOutputStream clientBytesRead = future.get();
    verifyClientBytesRead(clientBytesRead);
    // Verify product was not cached, i.e., its pending caching entry was removed
    String cacheKey = new CacheKey(metacard, resourceResponse.getRequest()).generateKey();
    verify(resourceCache, timeout(3000)).removePendingCacheEntry(cacheKey);
    cleanup();
}
Also used : MockInputStream(ddf.catalog.cache.MockInputStream) Metacard(ddf.catalog.data.Metacard) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheKey(ddf.catalog.cache.impl.CacheKey) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 65 with Metacard

use of ddf.catalog.data.Metacard in project ddf by codice.

the class ReliableResourceDownloadManagerTest method testDownloadWithEmptyMetacardId.

@Test(expected = DownloadException.class)
public void testDownloadWithEmptyMetacardId() throws Exception {
    Metacard metacard = getMockMetacard("", EXPECTED_METACARD_SOURCE_ID);
    resourceRequest = mock(ResourceRequest.class);
    ResourceRetriever retriever = mock(ResourceRetriever.class);
    downloadMgr.download(resourceRequest, metacard, retriever);
}
Also used : Metacard(ddf.catalog.data.Metacard) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) ResourceRequest(ddf.catalog.operation.ResourceRequest) Test(org.junit.Test)

Aggregations

Metacard (ddf.catalog.data.Metacard)746 Test (org.junit.Test)470 ArrayList (java.util.ArrayList)206 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)149 InputStream (java.io.InputStream)136 HashMap (java.util.HashMap)129 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)115 Result (ddf.catalog.data.Result)109 Serializable (java.io.Serializable)100 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)90 QueryRequest (ddf.catalog.operation.QueryRequest)84 QueryImpl (ddf.catalog.operation.impl.QueryImpl)80 QueryResponse (ddf.catalog.operation.QueryResponse)78 SourceResponse (ddf.catalog.operation.SourceResponse)76 IOException (java.io.IOException)75 List (java.util.List)74 Map (java.util.Map)67 Filter (org.opengis.filter.Filter)67 CreateResponse (ddf.catalog.operation.CreateResponse)66 HashSet (java.util.HashSet)65