use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class CachingFederationStrategyTest method setup.
@Before
public void setup() throws Exception {
cacheExecutor = MoreExecutors.newDirectExecutorService();
queryExecutor = MoreExecutors.newDirectExecutorService();
preQueryPlugin = mock(PreFederatedQueryPlugin.class);
when(preQueryPlugin.process(any(), any())).thenAnswer(invocation -> invocation.getArguments()[1]);
clientAdaptor = mock(SolrClientAdaptor.class);
cache = mock(SolrCache.class);
cacheBulkProcessor = mock(CacheBulkProcessor.class);
cacheCommitPhaser = mock(CacheCommitPhaser.class);
cacheArgs = ArgumentCaptor.forClass((Class) List.class);
validationQueryFactory = mock(ValidationQueryFactory.class);
strategy = new CachingFederationStrategy(queryExecutor, Arrays.asList(preQueryPlugin), new ArrayList<>(), cache, cacheExecutor, validationQueryFactory, new CacheQueryFactory(new GeotoolsFilterBuilder()));
mockSortedQueryMonitorFactory = mock(SortedQueryMonitorFactory.class);
mockSortedQueryMonitor = mock(SortedQueryMonitor.class);
responseArgumentCaptor = ArgumentCaptor.forClass(QueryResponseImpl.class);
requestArgumentCaptor = ArgumentCaptor.forClass(QueryRequestImpl.class);
when(mockSortedQueryMonitorFactory.createMonitor(any(CompletionService.class), any(Map.class), responseArgumentCaptor.capture(), requestArgumentCaptor.capture(), any(List.class))).thenReturn(mockSortedQueryMonitor);
strategy.setSortedQueryMonitorFactory(mockSortedQueryMonitorFactory);
strategy.setCacheCommitPhaser(cacheCommitPhaser);
strategy.setCacheBulkProcessor(cacheBulkProcessor);
mockQuery = mock(Query.class);
when(mockQuery.getTimeoutMillis()).thenReturn(LONG_TIMEOUT);
when(mockQuery.getPageSize()).thenReturn(-1);
mockMetacard = new MetacardImpl();
mockMetacard.setId("mock metacard");
mockResult = new ResultImpl(mockMetacard);
mockResponse = mock(SourceResponse.class);
results = Arrays.asList(mockResult);
when(mockResponse.getResults()).thenReturn(results);
// Set general properties
properties = new HashMap<>();
properties.put(QUERY_MODE, NATIVE_QUERY_MODE);
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class FanoutCatalogFrameworkTest method testReplaceRelevance.
@Test
public void testReplaceRelevance() {
QueryRequest request = new QueryRequestImpl(null);
List<Result> results = new ArrayList<Result>();
MetacardImpl newCard1 = new MetacardImpl();
ResultImpl result1 = new ResultImpl(newCard1);
result1.setRelevanceScore(RELEVANCE_SCORE);
MetacardImpl newCard2 = new MetacardImpl();
ResultImpl result2 = new ResultImpl(newCard2);
result2.setRelevanceScore(RELEVANCE_SCORE);
results.add(result1);
results.add(result2);
QueryResponse response = new QueryResponseImpl(request, results, 2);
QueryResponse newResponse = framework.getQueryOperations().replaceSourceId(response);
assertNotNull(newResponse);
List<Result> newResults = newResponse.getResults();
assertNotNull(newResponse);
assertEquals(2, newResults.size());
Metacard card = new MetacardImpl();
// Make sure the relevance score was copied over
for (Result newResult : newResults) {
card = newResult.getMetacard();
assertNotNull(card);
assertEquals(RELEVANCE_SCORE, newResult.getRelevanceScore());
}
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class FanoutCatalogFrameworkTest method testQueryReplacesSourceId.
@Test
public void testQueryReplacesSourceId() throws Exception {
ConnectedSource source1 = mock(ConnectedSource.class);
ConnectedSource source2 = mock(ConnectedSource.class);
when(source1.getId()).thenReturn("source1");
when(source2.getId()).thenReturn("source2");
frameworkProperties.setConnectedSources(ImmutableList.of(source1, source2));
frameworkProperties.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
QueryRequestImpl queryRequest = new QueryRequestImpl(mock(Query.class));
MetacardImpl meta1 = new MetacardImpl();
MetacardImpl meta2 = new MetacardImpl();
meta1.setSourceId("source1");
meta2.setSourceId("source2");
ResultImpl result1 = new ResultImpl(meta1);
ResultImpl result2 = new ResultImpl(meta2);
List<Result> results = new ArrayList<>();
results.add(result1);
results.add(result2);
QueryResponseImpl queryResponse = new QueryResponseImpl(queryRequest, results, 2);
FederationStrategy strategy = mock(FederationStrategy.class);
when(strategy.federate(anyList(), any())).thenReturn(queryResponse);
QueryResponse response = framework.query(queryRequest, strategy);
for (Result result : response.getResults()) {
assertEquals(result.getMetacard().getSourceId(), NEW_SOURCE_ID);
}
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class TestCswEndpoint method testDeleteTransaction.
@Test
public void testDeleteTransaction() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
DeleteType deleteType = mock(DeleteType.class);
doReturn(CswConstants.CSW_RECORD).when(deleteType).getTypeName();
doReturn("").when(deleteType).getHandle();
QueryConstraintType queryConstraintType = new QueryConstraintType();
queryConstraintType.setCqlText("title = \"foo\"");
doReturn(queryConstraintType).when(deleteType).getConstraint();
List<Result> results = new ArrayList<>();
results.add(new ResultImpl(new MetacardImpl()));
results.add(new ResultImpl(new MetacardImpl()));
QueryResponse queryResponse = new QueryResponseImpl(null, results, results.size());
doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
List<Metacard> deletedMetacards = new ArrayList<>();
deletedMetacards.add(new MetacardImpl());
deletedMetacards.add(new MetacardImpl());
DeleteResponse deleteResponse = new DeleteResponseImpl(null, null, deletedMetacards);
doReturn(deleteResponse).when(catalogFramework).delete(any(DeleteRequest.class));
DeleteAction deleteAction = new DeleteAction(deleteType, DefaultCswRecordMap.getDefaultCswRecordMap().getPrefixToUriMapping());
CswTransactionRequest deleteRequest = new CswTransactionRequest();
deleteRequest.getDeleteActions().add(deleteAction);
deleteRequest.setVersion(CswConstants.VERSION_2_0_2);
deleteRequest.setService(CswConstants.CSW);
deleteRequest.setVerbose(false);
TransactionResponseType response = csw.transaction(deleteRequest);
assertThat(response, notNullValue());
TransactionSummaryType summary = response.getTransactionSummary();
assertThat(summary, notNullValue());
assertThat(summary.getTotalDeleted().intValue(), is(2));
assertThat(summary.getTotalInserted().intValue(), is(0));
assertThat(summary.getTotalUpdated().intValue(), is(0));
verifyMarshalResponse(response, "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1", cswQnameOutPutSchema);
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class TestCswEndpoint method testGetRecordById.
@Test
public void testGetRecordById() throws CswException, FederationException, SourceUnavailableException, UnsupportedQueryException {
final GetRecordByIdRequest getRecordByIdRequest = new GetRecordByIdRequest();
getRecordByIdRequest.setId("123");
getRecordByIdRequest.setOutputFormat(MediaType.APPLICATION_XML);
getRecordByIdRequest.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
getRecordByIdRequest.setElementSetName("full");
final Metacard metacard = new MetacardImpl();
final List<Result> mockResults = Collections.singletonList(new ResultImpl(metacard));
final QueryResponseImpl queryResponse = new QueryResponseImpl(null, mockResults, mockResults.size());
doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
final CswRecordCollection cswRecordCollection = csw.getRecordById(getRecordByIdRequest, null);
verifyCswRecordCollection(cswRecordCollection, metacard);
assertThat(cswRecordCollection.getElementSetType(), is(ElementSetType.FULL));
}
Aggregations