use of org.codice.ddf.attachment.impl.AttachmentParserImpl 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;
}
use of org.codice.ddf.attachment.impl.AttachmentParserImpl in project ddf by codice.
the class CatalogServiceImplTest method setup.
@Before
public void setup() throws MimeTypeResolutionException {
MimeTypeMapper mimeTypeMapper = mock(MimeTypeMapper.class);
when(mimeTypeMapper.getMimeTypeForFileExtension("txt")).thenReturn("text/plain");
when(mimeTypeMapper.getMimeTypeForFileExtension("xml")).thenReturn("text/xml");
attachmentParser = new AttachmentParserImpl(mimeTypeMapper);
attributeRegistry = mock(AttributeRegistry.class);
}
use of org.codice.ddf.attachment.impl.AttachmentParserImpl 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;
}
Aggregations