use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class TestMetacardResourceSizePlugin method testWhenCachedResourceSizeIsZero.
@Test
public void testWhenCachedResourceSizeIsZero() throws Exception {
ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
ReliableResource cachedResource = mock(ReliableResource.class);
when(cachedResource.getSize()).thenReturn(0L);
when(cache.getValid(anyString(), (Metacard) anyObject())).thenReturn(cachedResource);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("abc123");
metacard.setSourceId("ddf-1");
metacard.setResourceSize("N/A");
Result result = new ResultImpl(metacard);
List<Result> results = new ArrayList<Result>();
results.add(result);
QueryResponse input = mock(QueryResponse.class);
when(input.getResults()).thenReturn(results);
MetacardResourceSizePlugin plugin = new MetacardResourceSizePlugin(cache);
QueryResponse queryResponse = plugin.process(input);
assertThat(queryResponse.getResults().size(), is(1));
Metacard resultMetacard = queryResponse.getResults().get(0).getMetacard();
assertThat(metacard, is(notNullValue()));
// Since using Metacard vs. MetacardImpl have to get resource-size as an
// Attribute vs. Long
Attribute resourceSizeAttr = resultMetacard.getAttribute(Metacard.RESOURCE_SIZE);
assertThat((String) resourceSizeAttr.getValue(), equalTo("N/A"));
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class MetacardResourceStatusTest method setupSingleResultResponseMock.
private void setupSingleResultResponseMock(MetacardImpl metacard) {
Result result = new ResultImpl(metacard);
List<Result> results = new ArrayList<>();
results.add(result);
when(queryResponse.getResults()).thenReturn(results);
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class TestMetacardResourceSizePlugin method testMetacardResourceSizePopulatedAndHasProduct.
@Test
public void testMetacardResourceSizePopulatedAndHasProduct() throws Exception {
ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
ReliableResource cachedResource = mock(ReliableResource.class);
when(cachedResource.getSize()).thenReturn(999L);
when(cachedResource.hasProduct()).thenReturn(true);
when(cache.getValid(anyString(), (Metacard) anyObject())).thenReturn(cachedResource);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("abc123");
metacard.setSourceId("ddf-1");
metacard.setResourceSize("N/A");
Result result = new ResultImpl(metacard);
List<Result> results = new ArrayList<Result>();
results.add(result);
QueryResponse input = mock(QueryResponse.class);
when(input.getResults()).thenReturn(results);
MetacardResourceSizePlugin plugin = new MetacardResourceSizePlugin(cache);
QueryResponse queryResponse = plugin.process(input);
assertThat(queryResponse.getResults().size(), is(1));
Metacard resultMetacard = queryResponse.getResults().get(0).getMetacard();
assertThat(metacard, is(notNullValue()));
// Since using Metacard vs. MetacardImpl have to get resource-size as an
// Attribute vs. Long
Attribute resourceSizeAttr = resultMetacard.getAttribute(Metacard.RESOURCE_SIZE);
assertThat((String) resourceSizeAttr.getValue(), is("999"));
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testGetResourceOptions.
/**
* Tests that you can get a resource's (product) options. Covers the case where the source ID
* specified is actually the local catalog provider's site name (so this reduces down to a
* getResourceOptions for local provider); and the case where a federated source is specified.
* <p>
* Test for DDF-1763.
*
* @throws Exception
*/
@Test
public void testGetResourceOptions() throws Exception {
String localProviderName = "ddf";
String federatedSite1Name = "fed-site-1";
String metacardId = "123";
// The resource's URI
URI metacardUri = new URI("http:///27+Nov+12+12%3A30%3A04?MyPhotograph%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc%2Fimages%2FActionable.jpg%0AMyAttachment%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc#abc.xyz.dao.URLResourceOptionDataAccessObject");
Set<String> supportedOptions = new HashSet<String>();
supportedOptions.add("MyPhotograph");
supportedOptions.add("MyAttachment");
// Catalog Provider
CatalogProvider provider = mock(CatalogProvider.class);
when(provider.getId()).thenReturn(localProviderName);
when(provider.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
when(provider.isAvailable()).thenReturn(true);
// Federated Source 1
FederatedSource federatedSource1 = mock(FederatedSource.class);
when(federatedSource1.getId()).thenReturn(federatedSite1Name);
when(federatedSource1.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
when(federatedSource1.isAvailable()).thenReturn(true);
when(federatedSource1.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);
List<FederatedSource> federatedSources = new ArrayList<FederatedSource>();
federatedSources.add(federatedSource1);
// Mock register the provider in the container
// Mock the source poller
SourcePoller mockPoller = mock(SourcePoller.class);
when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);
MetacardImpl metacard = new MetacardImpl(BASIC_METACARD);
metacard.setId(metacardId);
metacard.setResourceURI(metacardUri);
Result result = new ResultImpl(metacard);
List<Result> results = new ArrayList<>();
results.add(result);
QueryResponse queryResponse = mock(QueryResponse.class);
when(queryResponse.getResults()).thenReturn(results);
FederationStrategy strategy = mock(FederationStrategy.class);
when(strategy.federate(isA(federatedSources.getClass()), isA(QueryRequest.class))).thenReturn(queryResponse);
ResourceReader resourceReader = mock(ResourceReader.class);
Set<String> supportedSchemes = new HashSet<String>();
supportedSchemes.add("http");
when(resourceReader.getSupportedSchemes()).thenReturn(supportedSchemes);
when(resourceReader.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);
List<ResourceReader> resourceReaders = new ArrayList<ResourceReader>();
resourceReaders.add(resourceReader);
FrameworkProperties props = new FrameworkProperties();
props.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
props.setFederatedSources(Collections.singletonMap(federatedSite1Name, federatedSource1));
props.setResourceReaders(resourceReaders);
props.setFederationStrategy(strategy);
props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
props.setSourcePoller(mockPoller);
props.setFilterBuilder(new GeotoolsFilterBuilder());
props.setDefaultAttributeValueRegistry(defaultAttributeValueRegistry);
CatalogFrameworkImpl framework = createFramework(props);
framework.setId("ddf");
Set<String> ids = new HashSet<String>();
for (FederatedSource source : federatedSources) {
ids.add(source.getId());
}
ids.add(framework.getId());
// site name = local provider
Map<String, Set<String>> optionsMap = framework.getResourceOptions(metacardId, localProviderName);
LOGGER.debug("localProvider optionsMap = {}", optionsMap);
assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
// site name = federated site's name
optionsMap = framework.getResourceOptions(metacardId, federatedSite1Name);
LOGGER.debug("federatedSource optionsMap = {}", optionsMap);
assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
// site name = null (should default to local provider)
optionsMap = framework.getResourceOptions(metacardId, null);
LOGGER.debug("localProvider optionsMap = {}", optionsMap);
assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
// site name = empty string (should default to local provider)
optionsMap = framework.getResourceOptions(metacardId, "");
LOGGER.debug("localProvider optionsMap = {}", optionsMap);
assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class AbstractCswSource method createResults.
protected List<Result> createResults(CswRecordCollection cswRecordCollection) {
List<Result> results = new ArrayList<>();
LOGGER.debug("Found {} metacard(s) in the CswRecordCollection.", cswRecordCollection.getCswRecords().size());
String transformerId = getMetadataTransformerId();
MetadataTransformer transformer = lookupMetadataTransformer(transformerId);
for (Metacard metacard : cswRecordCollection.getCswRecords()) {
MetacardImpl wrappedMetacard = new MetacardImpl(metacard);
wrappedMetacard.setSourceId(getId());
if (wrappedMetacard.getAttribute(Core.RESOURCE_DOWNLOAD_URL) != null && wrappedMetacard.getAttribute(Core.RESOURCE_DOWNLOAD_URL).getValue() != null) {
wrappedMetacard.setAttribute(Core.RESOURCE_URI, wrappedMetacard.getAttribute(Core.RESOURCE_DOWNLOAD_URL).getValue());
}
if (wrappedMetacard.getAttribute(Core.DERIVED_RESOURCE_DOWNLOAD_URL) != null && !wrappedMetacard.getAttribute(Core.DERIVED_RESOURCE_DOWNLOAD_URL).getValues().isEmpty()) {
wrappedMetacard.setAttribute(new AttributeImpl(Core.DERIVED_RESOURCE_URI, wrappedMetacard.getAttribute(Core.DERIVED_RESOURCE_DOWNLOAD_URL).getValues()));
}
Metacard tranformedMetacard = wrappedMetacard;
if (transformer != null) {
tranformedMetacard = transform(metacard, transformer);
}
Result result = new ResultImpl(tranformedMetacard);
results.add(result);
}
return results;
}
Aggregations