Search in sources :

Example 1 with ResourceCacheInterface

use of ddf.catalog.cache.ResourceCacheInterface in project ddf by codice.

the class TestMetacardResourceSizePlugin method testWhenNoCachedResourceFound.

@Test
public void testWhenNoCachedResourceFound() throws Exception {
    ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
    when(cache.getValid(anyString(), (Metacard) anyObject())).thenReturn(null);
    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"));
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ResourceCacheInterface(ddf.catalog.cache.ResourceCacheInterface) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 2 with ResourceCacheInterface

use of ddf.catalog.cache.ResourceCacheInterface in project ddf by codice.

the class MetacardResourceSizePluginTest method testWhenNoCachedResourceFound.

@Test
public void testWhenNoCachedResourceFound() throws Exception {
    ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
    when(cache.getValid(anyString(), any())).thenReturn(null);
    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"));
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ResourceCacheInterface(ddf.catalog.cache.ResourceCacheInterface) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 3 with ResourceCacheInterface

use of ddf.catalog.cache.ResourceCacheInterface in project ddf by codice.

the class MetacardResourceSizePluginTest 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(), 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(), is("999"));
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ResourceCacheInterface(ddf.catalog.cache.ResourceCacheInterface) ReliableResource(ddf.catalog.resource.data.ReliableResource) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 4 with ResourceCacheInterface

use of ddf.catalog.cache.ResourceCacheInterface in project ddf by codice.

the class MetacardResourceSizePluginTest method testMetacardResourceSizePopulatedButNoProduct.

/**
 * Verifies case where product has been cached previously but has since been deleted from the
 * product-cache directory, so there is still an entry in the cache map but no cache file on disk.
 *
 * @throws Exception
 */
@Test
public void testMetacardResourceSizePopulatedButNoProduct() throws Exception {
    ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
    ReliableResource cachedResource = mock(ReliableResource.class);
    when(cachedResource.getSize()).thenReturn(999L);
    when(cachedResource.hasProduct()).thenReturn(false);
    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. String
    Attribute resourceSizeAttr = resultMetacard.getAttribute(Metacard.RESOURCE_SIZE);
    assertThat((String) resourceSizeAttr.getValue(), equalTo("N/A"));
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ResourceCacheInterface(ddf.catalog.cache.ResourceCacheInterface) ReliableResource(ddf.catalog.resource.data.ReliableResource) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 5 with ResourceCacheInterface

use of ddf.catalog.cache.ResourceCacheInterface in project ddf by codice.

the class MetacardResourceSizePluginTest method testNullMetacard.

@Test
public void testNullMetacard() throws Exception {
    ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
    Result result = mock(Result.class);
    when(result.getMetacard()).thenReturn(null);
    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, equalTo(input));
}
Also used : QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResourceCacheInterface(ddf.catalog.cache.ResourceCacheInterface) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Aggregations

ResourceCacheInterface (ddf.catalog.cache.ResourceCacheInterface)10 Result (ddf.catalog.data.Result)10 QueryResponse (ddf.catalog.operation.QueryResponse)10 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 Attribute (ddf.catalog.data.Attribute)8 Metacard (ddf.catalog.data.Metacard)8 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 ResultImpl (ddf.catalog.data.impl.ResultImpl)8 ReliableResource (ddf.catalog.resource.data.ReliableResource)6