Search in sources :

Example 1 with CatalogServiceImpl

use of org.codice.ddf.rest.service.impl.CatalogServiceImpl in project ddf by codice.

the class RESTEndpointTest method headTest.

@SuppressWarnings({ "unchecked" })
private Response headTest(boolean local) throws Exception {
    MetacardImpl metacard;
    List<Result> list = new ArrayList<>();
    Result result = mock(Result.class);
    InputStream inputStream;
    UriInfo uriInfo;
    Response response;
    CatalogFramework framework = givenCatalogFramework();
    list.add(result);
    QueryResponse queryResponse = mock(QueryResponse.class);
    when(queryResponse.getResults()).thenReturn(list);
    when(framework.query(isA(QueryRequest.class), isNull())).thenReturn(queryResponse);
    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);
    MimeTypeMapper mimeTypeMapper = mock(MimeTypeMapper.class);
    when(mimeTypeMapper.getMimeTypeForFileExtension("txt")).thenReturn("text/plain");
    when(mimeTypeMapper.getMimeTypeForFileExtension("xml")).thenReturn("text/xml");
    CatalogServiceImpl catalogServiceImpl = new CatalogServiceImpl(framework, new AttachmentParserImpl(mimeTypeMapper), mock(AttributeRegistry.class));
    catalogServiceImpl.setTikaMimeTypeResolver(new TikaMimeTypeResolver());
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    catalogServiceImpl.setFilterBuilder(filterBuilder);
    uriInfo = createSpecificUriInfo(LOCAL_RETRIEVE_ADDRESS);
    RESTEndpoint restEndpoint = new RESTEndpoint(catalogServiceImpl);
    if (local) {
        response = restEndpoint.getHeaders(GET_ID, uriInfo, null);
    } else {
        response = restEndpoint.getHeaders(null, GET_ID, uriInfo, null);
    }
    return response;
}
Also used : MimeTypeMapper(ddf.mime.MimeTypeMapper) QueryRequest(ddf.catalog.operation.QueryRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Resource(ddf.catalog.resource.Resource) TikaMimeTypeResolver(ddf.mime.tika.TikaMimeTypeResolver) CatalogServiceImpl(org.codice.ddf.rest.service.impl.CatalogServiceImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) AttributeRegistry(ddf.catalog.data.AttributeRegistry) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) CatalogFramework(ddf.catalog.CatalogFramework) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) UriInfo(javax.ws.rs.core.UriInfo) AttachmentParserImpl(org.codice.ddf.attachment.impl.AttachmentParserImpl)

Example 2 with CatalogServiceImpl

use of org.codice.ddf.rest.service.impl.CatalogServiceImpl in project ddf by codice.

the class RESTEndpointTest method executeTest.

private Response executeTest(CatalogFramework framework, String transformer, boolean local) throws Exception {
    MimeTypeMapper mimeTypeMapper = mock(MimeTypeMapper.class);
    when(mimeTypeMapper.getMimeTypeForFileExtension("txt")).thenReturn("text/plain");
    when(mimeTypeMapper.getMimeTypeForFileExtension("xml")).thenReturn("text/xml");
    CatalogServiceImpl catalogServiceImpl = new CatalogServiceImpl(framework, new AttachmentParserImpl(mimeTypeMapper), mock(AttributeRegistry.class));
    catalogServiceImpl.setTikaMimeTypeResolver(new TikaMimeTypeResolver());
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    catalogServiceImpl.setFilterBuilder(filterBuilder);
    RESTEndpoint restEndpoint = new RESTEndpoint(catalogServiceImpl);
    UriInfo uriInfo;
    Response response;
    if (local) {
        uriInfo = createSpecificUriInfo(LOCAL_RETRIEVE_ADDRESS);
        response = restEndpoint.getDocument(GET_ID, transformer, uriInfo, null);
    } else {
        uriInfo = createSpecificUriInfo(FED_RETRIEVE_ADDRESS);
        response = restEndpoint.getDocument(GET_SITENAME, GET_ID, transformer, uriInfo, null);
    }
    return response;
}
Also used : QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) MimeTypeMapper(ddf.mime.MimeTypeMapper) AttributeRegistry(ddf.catalog.data.AttributeRegistry) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) TikaMimeTypeResolver(ddf.mime.tika.TikaMimeTypeResolver) CatalogServiceImpl(org.codice.ddf.rest.service.impl.CatalogServiceImpl) AttachmentParserImpl(org.codice.ddf.attachment.impl.AttachmentParserImpl) UriInfo(javax.ws.rs.core.UriInfo)

Aggregations

AttributeRegistry (ddf.catalog.data.AttributeRegistry)2 FilterBuilder (ddf.catalog.filter.FilterBuilder)2 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)2 QueryResponse (ddf.catalog.operation.QueryResponse)2 MimeTypeMapper (ddf.mime.MimeTypeMapper)2 TikaMimeTypeResolver (ddf.mime.tika.TikaMimeTypeResolver)2 Response (javax.ws.rs.core.Response)2 UriInfo (javax.ws.rs.core.UriInfo)2 AttachmentParserImpl (org.codice.ddf.attachment.impl.AttachmentParserImpl)2 CatalogServiceImpl (org.codice.ddf.rest.service.impl.CatalogServiceImpl)2 CatalogFramework (ddf.catalog.CatalogFramework)1 Metacard (ddf.catalog.data.Metacard)1 Result (ddf.catalog.data.Result)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 Resource (ddf.catalog.resource.Resource)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1