use of javax.activation.MimeType in project ddf by codice.
the class VideoThumbnailPluginTest method createMockContentItemOfMimeType.
private ContentItem createMockContentItemOfMimeType(String mimeType) throws MimeTypeParseException {
final ContentItem mockContentItem = mock(ContentItem.class);
doReturn(new MimeType(mimeType)).when(mockContentItem).getMimeType();
doReturn(new MetacardImpl()).when(mockContentItem).getMetacard();
doReturn(UUID.randomUUID().toString()).when(mockContentItem).getId();
return mockContentItem;
}
use of javax.activation.MimeType in project ddf by codice.
the class ReliableResourceDownloader method setupDownload.
public ResourceResponse setupDownload(Metacard metacard, DownloadStatusInfo downloadStatusInfo) {
Resource resource = resourceResponse.getResource();
MimeType mimeType = resource.getMimeType();
String resourceName = resource.getName();
fbos = new FileBackedOutputStream(DEFAULT_FILE_BACKED_OUTPUT_STREAM_THRESHOLD);
countingFbos = new CountingOutputStream(fbos);
streamReadByClient = new ReliableResourceInputStream(fbos, countingFbos, downloadState, downloadIdentifier, resourceResponse);
this.metacard = metacard;
// Create new ResourceResponse to return that will encapsulate the
// ReliableResourceInputStream that will be read by the client simultaneously as the product
// is cached to disk (if caching is enabled)
ResourceImpl newResource = new ResourceImpl(streamReadByClient, mimeType, resourceName);
resourceResponse = new ResourceResponseImpl(resourceResponse.getRequest(), resourceResponse.getProperties(), newResource);
// Get handle to retrieved product's InputStream
resourceInputStream = resource.getInputStream();
eventListener.setDownloadMap(downloadIdentifier, resourceResponse);
downloadStatusInfo.addDownloadInfo(downloadIdentifier, this, resourceResponse);
if (downloaderConfig.isCacheEnabled()) {
CacheKey keyMaker = null;
String key = null;
try {
keyMaker = new CacheKey(metacard, resourceResponse.getRequest());
key = keyMaker.generateKey();
} catch (IllegalArgumentException e) {
LOGGER.info("Cannot create cache key for resource with metacard ID = {}", metacard.getId());
return resourceResponse;
}
if (!resourceCache.isPending(key)) {
// Fully qualified path to cache file that will be written to.
// Example:
// <INSTALL-DIR>/data/product-cache/<source-id>-<metacard-id>
// <INSTALL-DIR>/data/product-cache/ddf.distribution-abc123
filePath = FilenameUtils.concat(resourceCache.getProductCacheDirectory(), key);
if (filePath == null) {
LOGGER.info("Unable to create cache for cache directory {} and key {} - no caching will be done.", resourceCache.getProductCacheDirectory(), key);
return resourceResponse;
}
reliableResource = new ReliableResource(key, filePath, mimeType, resourceName, metacard);
resourceCache.addPendingCacheEntry(reliableResource);
try {
fos = FileUtils.openOutputStream(new File(filePath));
doCaching = true;
this.downloadState.setCacheEnabled(true);
} catch (IOException e) {
LOGGER.info("Unable to open cache file {} - no caching will be done.", filePath);
}
} else {
LOGGER.debug("Cache key {} is already pending caching", key);
}
}
return resourceResponse;
}
use of javax.activation.MimeType in project ddf by codice.
the class ResourceCacheImplTest method createCachedResource.
private ReliableResource createCachedResource(Metacard metacard) {
String fileName = "15bytes.txt";
String productLocation = this.getClass().getResource("/" + fileName).getFile();
File rrCachedFile = new File(productLocation);
return new ReliableResource(CACHED_RESOURCE_KEY, rrCachedFile.getAbsolutePath(), new MimeType(), fileName, metacard);
}
use of javax.activation.MimeType in project ddf by codice.
the class CswQueryResponseTransformerTest method verifyResultOrderIsMaintained.
@Test
public void verifyResultOrderIsMaintained() throws CatalogTransformerException, IOException {
// when
when(mockPrintWriterProvider.build((Class<Metacard>) notNull())).thenReturn(mockPrintWriter);
when(mockPrintWriter.makeString()).thenReturn(new String());
when(mockSourceResponse.getResults()).thenReturn(createResults(1, 10));
when(mockSourceResponse.getRequest()).thenReturn(mockQueryRequest);
when(mockQueryRequest.getQuery()).thenReturn(mockQuery);
when(mockArguments.get(CswConstants.RESULT_TYPE_PARAMETER)).thenReturn(ResultType.RESULTS);
when(mockTransformerManager.getTransformerBySchema(anyString())).thenReturn(mockMetacardTransformer);
when(mockMetacardTransformer.transform(any(Metacard.class), any(Map.class))).thenAnswer(invocationOnMock -> {
Metacard metacard = (Metacard) invocationOnMock.getArguments()[0];
BinaryContentImpl bci = new BinaryContentImpl(IOUtils.toInputStream(metacard.getId() + ",", StandardCharsets.UTF_8), new MimeType("application/xml"));
return bci;
});
// given
transformer.init();
transformer.transform(mockSourceResponse, mockArguments);
transformer.destroy();
// then
ArgumentCaptor<String> tmCaptor = ArgumentCaptor.forClass(String.class);
verify(mockTransformerManager, times(1)).getTransformerBySchema(tmCaptor.capture());
ArgumentCaptor<Map> mapCaptor = ArgumentCaptor.forClass(Map.class);
ArgumentCaptor<Metacard> mcCaptor = ArgumentCaptor.forClass(Metacard.class);
verify(mockMetacardTransformer, times(10)).transform(mcCaptor.capture(), mapCaptor.capture());
ArgumentCaptor<String> strCaptor = ArgumentCaptor.forClass(String.class);
verify(mockPrintWriter, times(2)).setRawValue(strCaptor.capture());
String order = strCaptor.getAllValues().get(1);
String[] ids = order.split(",");
for (int i = 1; i < ids.length; i++) {
assertThat(ids[i - 1], is(String.valueOf("id_" + i)));
}
}
use of javax.activation.MimeType in project ddf by codice.
the class CswTransformProviderTest method testMarshalOtherSchema.
@Test
public void testMarshalOtherSchema() throws Exception {
when(mockMetacardManager.getTransformerByProperty(TransformerManager.SCHEMA, OTHER_SCHEMA)).thenReturn(mockMetacardTransformer);
when(mockMetacardTransformer.transform(any(Metacard.class), any(Map.class))).thenReturn(new BinaryContentImpl(IOUtils.toInputStream(getRecord(), StandardCharsets.UTF_8), new MimeType(MediaType.APPLICATION_XML)));
StringWriter stringWriter = new StringWriter();
HierarchicalStreamWriter writer = new WstxDriver().createWriter(stringWriter);
CswTransformProvider provider = new CswTransformProvider(mockMetacardManager, null);
MarshallingContext context = new TreeMarshaller(writer, null, null);
context.put(CswConstants.TRANSFORMER_LOOKUP_KEY, TransformerManager.SCHEMA);
context.put(CswConstants.TRANSFORMER_LOOKUP_VALUE, OTHER_SCHEMA);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
provider.marshal(getMetacard(), writer, context);
// Verify the context arguments were set correctly
verify(mockMetacardManager, times(1)).getTransformerByProperty(captor.capture(), captor.capture());
String outputSchema = captor.getValue();
assertThat(outputSchema, is(OTHER_SCHEMA));
}
Aggregations