use of ddf.catalog.resource.Resource in project ddf by codice.
the class RESTEndpointTest method mockTestSetup.
/**
* Creates the mock setup for the GET tests above. Parameters provide the CatalogFramework, which
* will be setup for the test, and also specify which test case is being run.
*/
@SuppressWarnings({ "unchecked" })
private String mockTestSetup(CatalogFramework framework, TestType testType) throws Exception {
String transformer = null;
QueryResponse queryResponse = mock(QueryResponse.class);
when(framework.query(isA(QueryRequest.class), isNull())).thenReturn(queryResponse);
List<Result> list = null;
MetacardImpl metacard = null;
Result result = mock(Result.class);
InputStream inputStream;
switch(testType) {
case QUERY_RESPONSE_TEST:
when(queryResponse.getResults()).thenReturn(list);
break;
case METACARD_TEST:
list = new ArrayList<>();
list.add(result);
when(queryResponse.getResults()).thenReturn(list);
when(result.getMetacard()).thenReturn(metacard);
break;
case RESOURCE_TEST:
transformer = "resource";
// fall through
case SUCCESS_TEST:
list = new ArrayList<>();
list.add(result);
when(queryResponse.getResults()).thenReturn(list);
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);
break;
case KML_TEST:
transformer = "kml";
list = new ArrayList<>();
list.add(result);
when(queryResponse.getResults()).thenReturn(list);
metacard = new MetacardImpl();
metacard.setSourceId(GET_SITENAME);
when(result.getMetacard()).thenReturn(metacard);
BinaryContent content = mock(BinaryContent.class);
inputStream = new ByteArrayInputStream(GET_STREAM.getBytes(GET_OUTPUT_TYPE));
when(content.getInputStream()).thenReturn(inputStream);
when(content.getMimeTypeValue()).thenReturn(GET_KML_MIME_TYPE);
when(framework.transform(isA(Metacard.class), anyString(), isA(Map.class))).thenReturn(content);
break;
}
return transformer;
}
use of ddf.catalog.resource.Resource in project ddf by codice.
the class ResourceMetacardTransformerTest method getResource.
private Resource getResource(MimeType mimeType, URI uri) throws Exception {
Resource resource = mock(Resource.class);
when(resource.getMimeType()).thenReturn(mimeType);
when(resource.getMimeTypeValue()).thenReturn((mimeType == null) ? null : mimeType.getBaseType());
when(resource.getInputStream()).thenReturn(uri.toURL().openConnection().getInputStream());
return resource;
}
use of ddf.catalog.resource.Resource in project ddf by codice.
the class TestCswEndpoint method setUpMocksForProductRetrieval.
private void setUpMocksForProductRetrieval(boolean includeMimeType) throws ResourceNotFoundException, IOException, ResourceNotSupportedException {
ResourceResponse resourceResponse = mock(ResourceResponse.class);
Resource resource = mock(Resource.class);
if (includeMimeType) {
MimeType mimeType = mock(MimeType.class);
when(resource.getMimeType()).thenReturn(mimeType);
}
when(resourceResponse.getResource()).thenReturn(resource);
when(catalogFramework.getLocalResource(any(ResourceRequest.class))).thenReturn(resourceResponse);
}
use of ddf.catalog.resource.Resource in project ddf by codice.
the class TestResourceReader method getMockResourceResponse.
private ResourceResponse getMockResourceResponse(MimeType mimeType) {
Resource mockResource = mock(Resource.class);
when(mockResource.getMimeType()).thenReturn(mimeType);
ResourceResponse mockResourceResponse = mock(ResourceResponse.class);
when(mockResourceResponse.getResource()).thenReturn(mockResource);
return mockResourceResponse;
}
use of ddf.catalog.resource.Resource in project ddf by codice.
the class TestRestEndpoint method mockTestSetup.
/**
* Creates the mock setup for the GET tests above. Parameters provide the CatalogFramework, which will be
* setup for the test, and also specify which test case is being run.
*
* @param framework
* @param testType
* @return
* @throws Exception
*/
protected String mockTestSetup(CatalogFramework framework, TestType testType) throws Exception, ResourceNotSupportedException {
String transformer = null;
QueryResponse queryResponse = mock(QueryResponse.class);
when(framework.query(isA(QueryRequest.class), isNull(FederationStrategy.class))).thenReturn(queryResponse);
List<Result> list = null;
MetacardImpl metacard = null;
Result result = mock(Result.class);
InputStream inputStream = null;
switch(testType) {
case QUERY_RESPONSE_TEST:
when(queryResponse.getResults()).thenReturn(list);
break;
case METACARD_TEST:
list = new ArrayList<Result>();
list.add(result);
when(queryResponse.getResults()).thenReturn(list);
when(result.getMetacard()).thenReturn(metacard);
break;
case RESOURCE_TEST:
transformer = "resource";
case SUCCESS_TEST:
list = new ArrayList<Result>();
list.add(result);
when(queryResponse.getResults()).thenReturn(list);
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);
break;
case KML_TEST:
transformer = "kml";
list = new ArrayList<Result>();
list.add(result);
when(queryResponse.getResults()).thenReturn(list);
metacard = new MetacardImpl();
metacard.setSourceId(GET_SITENAME);
when(result.getMetacard()).thenReturn(metacard);
BinaryContent content = mock(BinaryContent.class);
inputStream = new ByteArrayInputStream(GET_STREAM.getBytes(GET_OUTPUT_TYPE));
when(content.getInputStream()).thenReturn(inputStream);
when(content.getMimeTypeValue()).thenReturn(GET_KML_MIME_TYPE);
when(framework.transform(isA(Metacard.class), anyString(), isA(Map.class))).thenReturn(content);
break;
}
return transformer;
}
Aggregations