use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplTest method testValidationEqualMetacards.
@Test
public void testValidationEqualMetacards() throws URISyntaxException {
MetacardImpl metacard = generateMetacard();
MetacardImpl metacard1 = generateMetacard();
ReliableResource cachedResource = new ReliableResource("key", "", null, null, metacard);
assertFalse("cache should be noop", resourceCache.validateCacheEntry(cachedResource, metacard1));
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplTest method containsSpecificResourceInCache.
@Test
public void containsSpecificResourceInCache() {
ReliableResource cachedResource = createCachedResource(cachedMetacard);
resourceCache.put(cachedResource);
assertThat("cache should be noop", newResourceCache.contains(cachedMetacard, new ResourceRequestById(METACARD_ID)), is(false));
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplTest method assertReliableResourceEquals.
/**
* Check the values of the ReliableResource objects since equals fails once they've been
* serialized and reconstituted.
*/
private boolean assertReliableResourceEquals(ReliableResource expected, Resource actual) {
ReliableResource rrActual = null;
boolean result = false;
if (actual instanceof ReliableResource) {
rrActual = (ReliableResource) actual;
result = true;
}
if (result) {
result = rrActual.getFilePath().equals(expected.getFilePath());
if (result) {
result = rrActual.getMimeTypeValue().equals((expected.getMimeTypeValue()));
if (result) {
result = rrActual.getName().equals(expected.getName());
if (result) {
result = rrActual.getSize() == expected.getSize();
if (result) {
result = rrActual.getLastTouchedMillis() == expected.getLastTouchedMillis();
}
}
}
}
}
return result;
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplTest method testContainsTrueInvalid.
@Test
public void testContainsTrueInvalid() throws URISyntaxException, IOException {
MetacardImpl cachedMetacard = generateMetacard();
MetacardImpl latestMetacard = generateMetacard();
latestMetacard.setId("different-id");
String fileName = "10bytes.txt";
simulateAddFileToCacheDir(fileName);
String cachedResourceMetacardKey = "keyA1";
Path cachedResourceFilePath = Paths.get(defaultProductCacheDirectory.toString(), fileName);
File cachedResourceFile = cachedResourceFilePath.toFile();
assertTrue(cachedResourceFile.exists());
resourceCache.put(new ReliableResource(cachedResourceMetacardKey, cachedResourceFilePath.toString(), null, "name", cachedMetacard));
assertFalse("cache should be noop", resourceCache.containsValid(cachedResourceMetacardKey, latestMetacard));
assertTrue("cache should be noop", cachedResourceFile.exists());
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplTest method testPutThenGet.
/**
* Verifies that put() method works.
*/
@Test
public void testPutThenGet() throws URISyntaxException {
Metacard metacard = generateMetacard();
ReliableResource reliableResource = createCachedResource(metacard);
resourceCache.addPendingCacheEntry(reliableResource);
assertFalse("cache should be noop", resourceCache.isPending(CACHED_RESOURCE_KEY));
resourceCache.put(reliableResource);
assertNull("cache should be noop", resourceCache.getValid(CACHED_RESOURCE_KEY, metacard));
assertFalse("cache should be noop", resourceCache.isPending(CACHED_RESOURCE_KEY));
}
Aggregations