use of javax.activation.MimeType 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;
}
use of javax.activation.MimeType in project ddf by codice.
the class TestCswTransformProvider 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()), 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));
}
use of javax.activation.MimeType in project ddf by codice.
the class CswRecordCollectionMessageBodyWriterTest method testWriteToProductData.
@Test
public void testWriteToProductData() throws MimeTypeParseException, IOException {
CswRecordCollectionMessageBodyWriter writer = new CswRecordCollectionMessageBodyWriter(mockManager);
byte[] data = "SampleData".getBytes();
ByteArrayInputStream productData = new ByteArrayInputStream(data);
MimeType mimeType = new MimeType("text", "plain");
MultivaluedMap<String, Object> httpHeaders = new MultivaluedHashMap<>();
Resource resource = new ResourceImpl(productData, mimeType, "ResourceName");
CswRecordCollection collection = new CswRecordCollection();
collection.setMimeType(mimeType.toString());
collection.setResource(resource);
collection.setOutputSchema("http://www.iana.org/assignments/media-types/application/octet-stream");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
writer.writeTo(collection, null, null, null, null, httpHeaders, stream);
assertThat(stream.toByteArray(), is(equalTo(resource.getByteArray())));
}
use of javax.activation.MimeType in project ddf by codice.
the class TestCswQueryResponseTransformer 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() + ","), 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 TestResourceMetacardTransformer method testGetResourceJpeg.
@Test
public void testGetResourceJpeg() throws Exception {
String filePath = ABSOLUTE_PATH + TEST_PATH + JPEG_FILE_NAME_1;
URI uri = getUri(filePath);
Metacard metacard = getMockMetacard(uri);
boolean expectSuccess = true;
MimeType mimeType = getMimeType(JPEG_MIME_TYPE);
CatalogFramework framework = getFramework(getResourceResponse(getResource(mimeType, uri)));
testGetResource(metacard, filePath, mimeType, framework, expectSuccess);
}
Aggregations