Search in sources :

Example 16 with ReliableResource

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));
}
Also used : MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ReliableResource(ddf.catalog.resource.data.ReliableResource) Test(org.junit.Test)

Example 17 with ReliableResource

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));
}
Also used : ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) ReliableResource(ddf.catalog.resource.data.ReliableResource) Test(org.junit.Test)

Example 18 with ReliableResource

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;
}
Also used : ReliableResource(ddf.catalog.resource.data.ReliableResource)

Example 19 with ReliableResource

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());
}
Also used : Path(java.nio.file.Path) File(java.io.File) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ReliableResource(ddf.catalog.resource.data.ReliableResource) Test(org.junit.Test)

Example 20 with ReliableResource

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));
}
Also used : Metacard(ddf.catalog.data.Metacard) ReliableResource(ddf.catalog.resource.data.ReliableResource) Test(org.junit.Test)

Aggregations

ReliableResource (ddf.catalog.resource.data.ReliableResource)44 Test (org.junit.Test)32 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 Metacard (ddf.catalog.data.Metacard)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 Attribute (ddf.catalog.data.Attribute)7 Result (ddf.catalog.data.Result)7 File (java.io.File)7 MockInputStream (ddf.catalog.cache.MockInputStream)6 ResourceCacheInterface (ddf.catalog.cache.ResourceCacheInterface)6 ResultImpl (ddf.catalog.data.impl.ResultImpl)6 QueryResponse (ddf.catalog.operation.QueryResponse)6 ResourceRetriever (ddf.catalog.resourceretriever.ResourceRetriever)6 ArrayList (java.util.ArrayList)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 CacheKey (ddf.catalog.cache.impl.CacheKey)4 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)3 Resource (ddf.catalog.resource.Resource)3 MimeType (javax.activation.MimeType)3 Ignore (org.junit.Ignore)3