Search in sources :

Example 16 with Resource

use of ddf.catalog.resource.Resource in project alliance by codice.

the class CatalogOutputAdapterTest method testGetNitfSegmentsFlow.

@Test
public void testGetNitfSegmentsFlow() throws IOException, NitfFormatException {
    Resource resource = mock(Resource.class);
    when(resource.getInputStream()).thenReturn(getInputStream("/i_3001a.ntf"));
    ResourceResponse resourceResponse = mock(ResourceResponse.class);
    when(resourceResponse.getResource()).thenReturn(resource);
    NitfSegmentsFlow nitfSegmentsFlow = catalogOutputAdapter.getNitfSegmentsFlow(resourceResponse);
    assertThat(nitfSegmentsFlow, notNullValue());
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Resource(ddf.catalog.resource.Resource) NitfSegmentsFlow(org.codice.imaging.nitf.fluent.NitfSegmentsFlow) Test(org.junit.Test)

Example 17 with Resource

use of ddf.catalog.resource.Resource in project ddf by codice.

the class ReliableResourceDownloaderTest method getMockResourceResponse.

private ResourceResponse getMockResourceResponse(InputStream stream) throws Exception {
    ResourceRequest resourceRequest = mock(ResourceRequest.class);
    Map<String, Serializable> requestProperties = new HashMap<String, Serializable>();
    when(resourceRequest.getPropertyNames()).thenReturn(requestProperties.keySet());
    mockResource = mock(Resource.class);
    when(mockResource.getInputStream()).thenReturn(stream);
    when(mockResource.getName()).thenReturn("test-resource");
    when(mockResource.getMimeType()).thenReturn(new MimeType("text/plain"));
    mockResponse = mock(ResourceResponse.class);
    when(mockResponse.getRequest()).thenReturn(resourceRequest);
    when(mockResponse.getResource()).thenReturn(mockResource);
    Map<String, Serializable> responseProperties = new HashMap<String, Serializable>();
    when(mockResponse.getProperties()).thenReturn(responseProperties);
    return mockResponse;
}
Also used : Serializable(java.io.Serializable) ResourceResponse(ddf.catalog.operation.ResourceResponse) HashMap(java.util.HashMap) ReliableResource(ddf.catalog.resource.data.ReliableResource) Resource(ddf.catalog.resource.Resource) ResourceRequest(ddf.catalog.operation.ResourceRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MimeType(javax.activation.MimeType)

Example 18 with Resource

use of ddf.catalog.resource.Resource in project ddf by codice.

the class ReliableResourceDownloadManagerTest method getMockResourceResponse.

private ResourceResponse getMockResourceResponse() throws Exception {
    resourceRequest = mock(ResourceRequest.class);
    Map<String, Serializable> requestProperties = new HashMap<String, Serializable>();
    when(resourceRequest.getPropertyNames()).thenReturn(requestProperties.keySet());
    resource = mock(Resource.class);
    when(resource.getInputStream()).thenReturn(mis);
    when(resource.getName()).thenReturn("test-resource");
    when(resource.getMimeType()).thenReturn(new MimeType("text/plain"));
    resourceResponse = mock(ResourceResponse.class);
    when(resourceResponse.getRequest()).thenReturn(resourceRequest);
    when(resourceResponse.getResource()).thenReturn(resource);
    Map<String, Serializable> responseProperties = new HashMap<String, Serializable>();
    when(resourceResponse.getProperties()).thenReturn(responseProperties);
    return resourceResponse;
}
Also used : Serializable(java.io.Serializable) ResourceResponse(ddf.catalog.operation.ResourceResponse) HashMap(java.util.HashMap) ReliableResource(ddf.catalog.resource.data.ReliableResource) Resource(ddf.catalog.resource.Resource) ResourceRequest(ddf.catalog.operation.ResourceRequest) MimeType(javax.activation.MimeType)

Example 19 with Resource

use of ddf.catalog.resource.Resource in project ddf by codice.

the class ResourceOperationsTest method testGetResource.

@Test
public void testGetResource() throws Exception {
    ArrayList<Result> mockResultList = new ArrayList<>();
    mockResultList.add(resultMock);
    setGetResourceMocks();
    when(queryResponseMock.getResults()).thenReturn(mockResultList);
    when(queryResponseMock.getResults().get(0).getMetacard()).thenReturn(metacard);
    when(reliableResourceDownloadManagerMock.download(any(ResourceRequest.class), any(MetacardImpl.class), isNull())).thenReturn(resourceResponseMock);
    Resource resourceMock = mock(Resource.class);
    when(resourceResponseMock.getResource()).thenReturn(resourceMock);
    frameworkProperties.setReliableResourceDownloadManager(reliableResourceDownloadManagerMock);
    resourceOperations.getResource(resourceRequestMock, isEnterprise, resourceName, fanoutEnabled);
    verify(resourceResponseMock).getResource();
}
Also used : ArrayList(java.util.ArrayList) Resource(ddf.catalog.resource.Resource) ResourceRequest(ddf.catalog.operation.ResourceRequest) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 20 with Resource

use of ddf.catalog.resource.Resource in project ddf by codice.

the class DumpCommand method createZip.

private void createZip(CatalogFacade catalog, QueryRequest queryRequest, File outputFile, AtomicLong resultCount) throws CatalogTransformerException {
    try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
        ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream)) {
        // write the metacards to the zip
        ResultIterable.resultIterable(catalog::query, queryRequest).stream().map(Result::getMetacard).forEach(metacard -> {
            writeMetacardToZip(zipOutputStream, metacard);
            if (hasLocalResources(metacard)) {
                // write the resources to the zip
                Map<String, Resource> resourceMap = getAllMetacardContent(metacard);
                resourceMap.forEach((filename, resource) -> writeResourceToZip(zipOutputStream, filename, resource));
            }
            resultCount.incrementAndGet();
        });
    } catch (IOException e) {
        throw new CatalogTransformerException(String.format("Error occurred when initializing/closing ZipOutputStream with path %s.", outputFile.getAbsoluteFile()), e);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) Resource(ddf.catalog.resource.Resource) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException)

Aggregations

Resource (ddf.catalog.resource.Resource)59 ResourceResponse (ddf.catalog.operation.ResourceResponse)29 Test (org.junit.Test)21 ByteArrayInputStream (java.io.ByteArrayInputStream)16 ResourceRequest (ddf.catalog.operation.ResourceRequest)14 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)13 URI (java.net.URI)11 HashMap (java.util.HashMap)11 InputStream (java.io.InputStream)10 Serializable (java.io.Serializable)10 MimeType (javax.activation.MimeType)10 Result (ddf.catalog.data.Result)9 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)9 ResourceImpl (ddf.catalog.resource.impl.ResourceImpl)9 IOException (java.io.IOException)9 Map (java.util.Map)9 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 ResourceResponseImpl (ddf.catalog.operation.impl.ResourceResponseImpl)8 Metacard (ddf.catalog.data.Metacard)7