use of ddf.catalog.resource.Resource in project ddf by codice.
the class TestRestEndpoint method headTest.
private Response headTest(boolean local) throws CatalogTransformerException, URISyntaxException, UnsupportedEncodingException, UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
MetacardImpl metacard = null;
List<Result> list = new ArrayList<Result>();
Result result = mock(Result.class);
InputStream inputStream = null;
UriInfo uriInfo;
Response response;
CatalogFramework framework = givenCatalogFramework(SAMPLE_ID);
list.add(result);
QueryResponse queryResponse = mock(QueryResponse.class);
when(queryResponse.getResults()).thenReturn(list);
when(framework.query(isA(QueryRequest.class), isNull(FederationStrategy.class))).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);
RESTEndpoint restEndpoint = new RESTEndpoint(framework);
restEndpoint.setTikaMimeTypeResolver(new TikaMimeTypeResolver());
FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
restEndpoint.setFilterBuilder(filterBuilder);
uriInfo = createSpecificUriInfo(LOCAL_RETRIEVE_ADDRESS);
if (local) {
response = restEndpoint.getHeaders(GET_ID, uriInfo, null);
} else {
response = restEndpoint.getHeaders(null, GET_ID, uriInfo, null);
}
return response;
}
use of ddf.catalog.resource.Resource in project ddf by codice.
the class TestGetRecordsMessageBodyReader method testPartialContentResponseHandling.
@Test
public void testPartialContentResponseHandling() throws Exception {
CswSourceConfiguration config = new CswSourceConfiguration(encryptionService);
config.setMetacardCswMappings(DefaultCswRecordMap.getCswToMetacardAttributeNames());
config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
String sampleData = "SampleData";
byte[] data = sampleData.getBytes();
ByteArrayInputStream dataInputStream = new ByteArrayInputStream(data);
MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
httpHeaders.add(CswConstants.PRODUCT_RETRIEVAL_HTTP_HEADER, "TRUE");
httpHeaders.add(HttpHeaders.CONTENT_DISPOSITION, String.format("inline; filename=ResourceName"));
httpHeaders.add(HttpHeaders.CONTENT_RANGE, String.format("bytes 1-%d/%d", sampleData.length() - 1, sampleData.length()));
MediaType mediaType = new MediaType("text", "plain");
CswRecordCollection cswRecords = reader.readFrom(CswRecordCollection.class, null, null, mediaType, httpHeaders, dataInputStream);
Resource resource = cswRecords.getResource();
// assert that the CswRecordCollection properly extracted the bytes skipped from the Partial Content response
assertThat(cswRecords.getResourceProperties().get(GetRecordsMessageBodyReader.BYTES_SKIPPED), is(1L));
// assert that the input stream has not been skipped at this stage. Since AbstractCswSource has the number
// of bytes that was attempted to be skipped, the stream must be aligned there instead.
assertThat(resource.getByteArray(), is(data));
}
use of ddf.catalog.resource.Resource in project alliance by codice.
the class CatalogOutputAdapterTest method testGetImage.
@Test
public void testGetImage() throws IOException {
InputStream is = getInputStream(I_3001A);
ResourceResponse resourceResponse = mock(ResourceResponse.class);
Resource resource = mock(Resource.class);
when(resourceResponse.getResource()).thenReturn(resource);
when(resource.getInputStream()).thenReturn(is);
BufferedImage image = catalogOutputAdapter.getImage(resourceResponse);
assertThat(image, is(notNullValue()));
assertThat(image.getWidth(), is(1024));
assertThat(image.getHeight(), is(1024));
}
use of ddf.catalog.resource.Resource in project alliance by codice.
the class CatalogOutputAdapterTest method testGetImageNullInputStream.
@Test(expected = IllegalStateException.class)
public void testGetImageNullInputStream() throws IOException {
ResourceResponse resourceResponse = mock(ResourceResponse.class);
Resource resource = mock(Resource.class);
when(resourceResponse.getResource()).thenReturn(resource);
when(resource.getInputStream()).thenReturn(null);
catalogOutputAdapter.getImage(resourceResponse);
}
use of ddf.catalog.resource.Resource in project ddf by codice.
the class DumpCommand method getDerivedResources.
@Nullable
private Map.Entry<String, Resource> getDerivedResources(Metacard metacard, Serializable serializable) {
if (!(serializable instanceof String)) {
LOGGER.debug("Input ({}) should have been a string but was a {}", serializable, serializable.getClass());
return null;
}
URI uri = null;
try {
uri = new URI((String) serializable);
} catch (URISyntaxException e) {
LOGGER.debug("Invalid Derived Resource URI Syntax for metacard : {}", metacard.getId(), e);
return null;
}
String derivedResourceFragment = uri.getFragment();
if (!ContentItem.CONTENT_SCHEME.equals(uri.getScheme()) || StringUtils.isBlank(derivedResourceFragment)) {
return null;
}
String fragment = CONTENT + File.separator + derivedResourceFragment + File.separator;
Resource resource = getResource(metacard);
if (resource == null) {
return null;
}
return new SimpleEntry<>(fragment + uri.getSchemeSpecificPart() + "-" + resource.getName(), resource);
}
Aggregations