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);
}
use of javax.activation.MimeType in project ddf by codice.
the class TestResourceMetacardTransformer method testGetResourceTransportStream.
@Test
public void testGetResourceTransportStream() throws Exception {
String filePath = ABSOLUTE_PATH + TEST_PATH + TS_FILE_NAME_1;
URI uri = getUri(filePath);
Metacard metacard = getMockMetacard(uri);
boolean expectSuccess = true;
MimeType mimeType = getMimeType(VIDEO_MIME_TYPE);
CatalogFramework framework = getFramework(getResourceResponse(getResource(mimeType, uri)));
testGetResource(metacard, filePath, mimeType, framework, expectSuccess);
}
use of javax.activation.MimeType in project ddf by codice.
the class TestResourceMetacardTransformer method testNullMetacardId.
@Test
public void testNullMetacardId() throws Exception {
thrown.expect(CatalogTransformerException.class);
thrown.expectMessage("Could not transform metacard to a resource because the metacard is not valid.");
String filePath = ABSOLUTE_PATH + TEST_PATH + TS_FILE_NAME_1;
URI uri = getUri(filePath);
Metacard metacard = getMockMetacard(uri);
when(metacard.getId()).thenReturn(null);
boolean expectSuccess = false;
MimeType mimeType = getMimeType(VIDEO_MIME_TYPE);
CatalogFramework framework = getFramework(getResourceResponse(getResource(mimeType, uri)));
testGetResource(metacard, filePath, mimeType, framework, expectSuccess);
}
use of javax.activation.MimeType in project ddf by codice.
the class TestResourceMetacardTransformer method testFrameworkThrowsIoException.
@Test
public void testFrameworkThrowsIoException() throws Exception {
String filePath = ABSOLUTE_PATH + TEST_PATH + JPEG_FILE_NAME_1;
URI uri = getUri(filePath);
Metacard metacard = getMockMetacard(uri);
thrown.expect(CatalogTransformerException.class);
thrown.expectMessage("Unable to retrieve resource.");
thrown.expectMessage("Metacard id: " + TEST_ID);
thrown.expectMessage("Uri: " + uri);
thrown.expectMessage("Source: " + TEST_SITE);
boolean expectSuccess = false;
MimeType mimeType = getMimeType(JPEG_MIME_TYPE);
CatalogFramework framework = getFrameworkException(new IOException("Test IO Exception"));
testGetResource(metacard, filePath, mimeType, framework, expectSuccess);
}
Aggregations