Search in sources :

Example 31 with Resource

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

the class RESTEndpointTest method mockTestSetup.

/**
 * Creates the mock setup for the GET tests above. Parameters provide the CatalogFramework, which
 * will be setup for the test, and also specify which test case is being run.
 */
@SuppressWarnings({ "unchecked" })
private String mockTestSetup(CatalogFramework framework, TestType testType) throws Exception {
    String transformer = null;
    QueryResponse queryResponse = mock(QueryResponse.class);
    when(framework.query(isA(QueryRequest.class), isNull())).thenReturn(queryResponse);
    List<Result> list = null;
    MetacardImpl metacard = null;
    Result result = mock(Result.class);
    InputStream inputStream;
    switch(testType) {
        case QUERY_RESPONSE_TEST:
            when(queryResponse.getResults()).thenReturn(list);
            break;
        case METACARD_TEST:
            list = new ArrayList<>();
            list.add(result);
            when(queryResponse.getResults()).thenReturn(list);
            when(result.getMetacard()).thenReturn(metacard);
            break;
        case RESOURCE_TEST:
            transformer = "resource";
        // fall through
        case SUCCESS_TEST:
            list = new ArrayList<>();
            list.add(result);
            when(queryResponse.getResults()).thenReturn(list);
            metacard = new MetacardImpl();
            metacard.setSourceId(GET_SITENAME);
            when(result.getMetacard()).thenReturn(metacard);
            Resource resource = mock(Resource.class);
            inputStream = new ByteArrayInputStream(GET_STREAM.getBytes(GET_OUTPUT_TYPE));
            when(resource.getInputStream()).thenReturn(inputStream);
            when(resource.getMimeTypeValue()).thenReturn(GET_MIME_TYPE);
            when(resource.getName()).thenReturn(GET_FILENAME);
            when(framework.transform(isA(Metacard.class), anyString(), isA(Map.class))).thenReturn(resource);
            break;
        case KML_TEST:
            transformer = "kml";
            list = new ArrayList<>();
            list.add(result);
            when(queryResponse.getResults()).thenReturn(list);
            metacard = new MetacardImpl();
            metacard.setSourceId(GET_SITENAME);
            when(result.getMetacard()).thenReturn(metacard);
            BinaryContent content = mock(BinaryContent.class);
            inputStream = new ByteArrayInputStream(GET_STREAM.getBytes(GET_OUTPUT_TYPE));
            when(content.getInputStream()).thenReturn(inputStream);
            when(content.getMimeTypeValue()).thenReturn(GET_KML_MIME_TYPE);
            when(framework.transform(isA(Metacard.class), anyString(), isA(Map.class))).thenReturn(content);
            break;
    }
    return transformer;
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Resource(ddf.catalog.resource.Resource) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) QueryResponse(ddf.catalog.operation.QueryResponse) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 32 with Resource

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

the class ResourceMetacardTransformerTest method getResource.

private Resource getResource(MimeType mimeType, URI uri) throws Exception {
    Resource resource = mock(Resource.class);
    when(resource.getMimeType()).thenReturn(mimeType);
    when(resource.getMimeTypeValue()).thenReturn((mimeType == null) ? null : mimeType.getBaseType());
    when(resource.getInputStream()).thenReturn(uri.toURL().openConnection().getInputStream());
    return resource;
}
Also used : Resource(ddf.catalog.resource.Resource)

Example 33 with Resource

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

the class TestCswEndpoint method setUpMocksForProductRetrieval.

private void setUpMocksForProductRetrieval(boolean includeMimeType) throws ResourceNotFoundException, IOException, ResourceNotSupportedException {
    ResourceResponse resourceResponse = mock(ResourceResponse.class);
    Resource resource = mock(Resource.class);
    if (includeMimeType) {
        MimeType mimeType = mock(MimeType.class);
        when(resource.getMimeType()).thenReturn(mimeType);
    }
    when(resourceResponse.getResource()).thenReturn(resource);
    when(catalogFramework.getLocalResource(any(ResourceRequest.class))).thenReturn(resourceResponse);
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Resource(ddf.catalog.resource.Resource) ResourceRequest(ddf.catalog.operation.ResourceRequest) MimeType(javax.activation.MimeType)

Example 34 with Resource

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

the class TestResourceReader method getMockResourceResponse.

private ResourceResponse getMockResourceResponse(MimeType mimeType) {
    Resource mockResource = mock(Resource.class);
    when(mockResource.getMimeType()).thenReturn(mimeType);
    ResourceResponse mockResourceResponse = mock(ResourceResponse.class);
    when(mockResourceResponse.getResource()).thenReturn(mockResource);
    return mockResourceResponse;
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Resource(ddf.catalog.resource.Resource)

Example 35 with Resource

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

the class TestRestEndpoint method mockTestSetup.

/**
     * Creates the mock setup for the GET tests above. Parameters provide the CatalogFramework, which will be
     * setup for the test, and also specify which test case is being run.
     *
     * @param framework
     * @param testType
     * @return
     * @throws Exception
     */
protected String mockTestSetup(CatalogFramework framework, TestType testType) throws Exception, ResourceNotSupportedException {
    String transformer = null;
    QueryResponse queryResponse = mock(QueryResponse.class);
    when(framework.query(isA(QueryRequest.class), isNull(FederationStrategy.class))).thenReturn(queryResponse);
    List<Result> list = null;
    MetacardImpl metacard = null;
    Result result = mock(Result.class);
    InputStream inputStream = null;
    switch(testType) {
        case QUERY_RESPONSE_TEST:
            when(queryResponse.getResults()).thenReturn(list);
            break;
        case METACARD_TEST:
            list = new ArrayList<Result>();
            list.add(result);
            when(queryResponse.getResults()).thenReturn(list);
            when(result.getMetacard()).thenReturn(metacard);
            break;
        case RESOURCE_TEST:
            transformer = "resource";
        case SUCCESS_TEST:
            list = new ArrayList<Result>();
            list.add(result);
            when(queryResponse.getResults()).thenReturn(list);
            metacard = new MetacardImpl();
            metacard.setSourceId(GET_SITENAME);
            when(result.getMetacard()).thenReturn(metacard);
            Resource resource = mock(Resource.class);
            inputStream = new ByteArrayInputStream(GET_STREAM.getBytes(GET_OUTPUT_TYPE));
            when(resource.getInputStream()).thenReturn(inputStream);
            when(resource.getMimeTypeValue()).thenReturn(GET_MIME_TYPE);
            when(resource.getName()).thenReturn(GET_FILENAME);
            when(framework.transform(isA(Metacard.class), anyString(), isA(Map.class))).thenReturn(resource);
            break;
        case KML_TEST:
            transformer = "kml";
            list = new ArrayList<Result>();
            list.add(result);
            when(queryResponse.getResults()).thenReturn(list);
            metacard = new MetacardImpl();
            metacard.setSourceId(GET_SITENAME);
            when(result.getMetacard()).thenReturn(metacard);
            BinaryContent content = mock(BinaryContent.class);
            inputStream = new ByteArrayInputStream(GET_STREAM.getBytes(GET_OUTPUT_TYPE));
            when(content.getInputStream()).thenReturn(inputStream);
            when(content.getMimeTypeValue()).thenReturn(GET_KML_MIME_TYPE);
            when(framework.transform(isA(Metacard.class), anyString(), isA(Map.class))).thenReturn(content);
            break;
    }
    return transformer;
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) FederationStrategy(ddf.catalog.federation.FederationStrategy) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Resource(ddf.catalog.resource.Resource) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) QueryResponse(ddf.catalog.operation.QueryResponse) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

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