Search in sources :

Example 16 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class CqlResultTest method distanceCheck.

private void distanceCheck(Double input, Double output) {
    MetacardImpl metacard = new MetacardImpl(BasicTypes.BASIC_METACARD);
    ResultImpl result = new ResultImpl(metacard);
    result.setDistanceInMeters(input);
    ActionRegistry actionRegistry = mock(ActionRegistry.class);
    when(actionRegistry.list(any())).thenReturn(Collections.emptyList());
    QueryRequest request = new QueryRequestImpl(new QueryImpl(filterBuilder.attribute("test").equalTo().text("value")));
    CqlResult cqlResult = new CqlResult(result, null, request, false, filterAdapter, actionRegistry);
    assertThat(cqlResult.getDistance(), is(output));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) ActionRegistry(ddf.action.ActionRegistry) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 17 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl 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 18 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class MigrationFileWriterTest method testWriteMetacardsWriteObjectFails.

@Test(expected = IOException.class)
public void testWriteMetacardsWriteObjectFails() throws Exception {
    whenNew(ObjectOutputStream.class).withAnyArguments().thenReturn(mockObjectOutputStream);
    doThrow(IOException.class).when(mockObjectOutputStream).writeObject(anyObject());
    List<Result> results = new ArrayList<>();
    results.add(new ResultImpl(new MetacardImpl()));
    mockFile = testFolder.newFile("mockFile");
    fileWriter.writeMetacards(mockFile, results);
}
Also used : ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class SolrMetacardClientImpl method createResult.

private ResultImpl createResult(SolrDocument doc) throws MetacardCreationException {
    ResultImpl result = new ResultImpl(createMetacard(doc));
    if (doc.get(RELEVANCE_SORT_FIELD) != null) {
        result.setRelevanceScore(((Float) (doc.get(RELEVANCE_SORT_FIELD))).doubleValue());
    }
    if (doc.get(DISTANCE_SORT_FIELD) != null) {
        Object distance = doc.getFieldValue(DISTANCE_SORT_FIELD);
        if (distance != null) {
            LOGGER.debug("Distance returned from Solr [{}]", distance);
            double convertedDistance = new Distance(Double.valueOf(distance.toString()), Distance.LinearUnit.KILOMETER).getAs(Distance.LinearUnit.METER);
            result.setDistanceInMeters(convertedDistance);
        }
    }
    return result;
}
Also used : ResultImpl(ddf.catalog.data.impl.ResultImpl) Distance(ddf.measure.Distance)

Example 20 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class Jpeg2000ThumbnailConverterTest method testEmptyThumbnail.

@Test
public void testEmptyThumbnail() throws Exception {
    Metacard metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, new byte[0]));
    List<Result> resultList = new ArrayList<>();
    resultList.add(new ResultImpl(metacard));
    QueryResponseImpl queryResponse = new QueryResponseImpl(null, resultList, 1);
    jpeg2000ThumbnailConverter.process(queryResponse);
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Aggregations

ResultImpl (ddf.catalog.data.impl.ResultImpl)114 Result (ddf.catalog.data.Result)74 Test (org.junit.Test)73 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)61 Metacard (ddf.catalog.data.Metacard)47 ArrayList (java.util.ArrayList)45 QueryRequest (ddf.catalog.operation.QueryRequest)33 SourceResponse (ddf.catalog.operation.SourceResponse)30 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)23 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)21 QueryResponse (ddf.catalog.operation.QueryResponse)20 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)18 DAG (org.codice.alliance.nsili.common.UCO.DAG)17 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)15 BinaryContent (ddf.catalog.data.BinaryContent)10 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)9 Product (org.codice.alliance.nsili.common.UID.Product)9 Query (ddf.catalog.operation.Query)7 PolicyResponse (ddf.catalog.plugin.PolicyResponse)7