use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class MetacardResourceStatus method isResourceCached.
private boolean isResourceCached(Metacard metacard, ResourceRequest resourceRequest) {
String key = getCacheKey(metacard, resourceRequest);
ReliableResource cachedResource = (ReliableResource) cache.getValid(key, metacard);
return cachedResource != null;
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class MetacardResourceSizePluginTest 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(), any())).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.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplTest method testPutThenGetNotPending.
/**
* Verifies that put() method works even if entry being added was never in the pending cache list.
*/
@Test
public void testPutThenGetNotPending() throws URISyntaxException {
MetacardImpl metacard = generateMetacard();
ReliableResource reliableResource = createCachedResource(metacard);
resourceCache.put(reliableResource);
assertFalse("cache should be noop", resourceCache.isPending(CACHED_RESOURCE_KEY));
assertNull("cache should be noop", resourceCache.getValid(CACHED_RESOURCE_KEY, metacard));
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplTest method testValidationNullMetacard.
@Test(expected = IllegalArgumentException.class)
public void testValidationNullMetacard() throws URISyntaxException {
MetacardImpl metacard = generateMetacard();
ReliableResource cachedResource = new ReliableResource("key", "", null, null, metacard);
resourceCache.validateCacheEntry(cachedResource, null);
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplTest method containsDefaultResourceInCache.
@Test
public void containsDefaultResourceInCache() {
ReliableResource cachedResource = createCachedResource(cachedMetacard);
resourceCache.put(cachedResource);
assertThat("cache should be noop", newResourceCache.contains(cachedMetacard), is(false));
}
Aggregations