use of ddf.catalog.operation.QueryResponse in project ddf by codice.
the class CatalogFrameworkImplTest method testDeleteWithStores.
// TODO (DDF-2436) -
@Ignore
@Test
public void testDeleteWithStores() throws Exception {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
List<CatalogStore> storeList = new ArrayList<>();
List<FederatedSource> sourceList = new ArrayList<>();
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
storeList.add(store);
sourceList.add(store);
CatalogFramework framework = createDummyCatalogFramework(provider, storeList, sourceList, eventAdmin);
FilterFactory filterFactory = new FilterFactoryImpl();
Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "*", "*", "?", "/", false);
List<Metacard> metacards = new ArrayList<>();
String id = UUID.randomUUID().toString().replaceAll("-", "");
MetacardImpl newCard = new MetacardImpl();
newCard.setId(id);
newCard.setAttribute("myKey", "myValue1");
metacards.add(newCard);
Map<String, Serializable> reqProps = new HashMap<>();
HashSet<String> destinations = new HashSet<>();
destinations.add("mockMemoryProvider");
destinations.add("catalogStoreId-1");
framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
DeleteRequest deleteRequest = new DeleteRequestImpl(Collections.singletonList(id), Metacard.ID, new HashMap<>(), destinations);
DeleteResponse response = framework.delete(deleteRequest);
assertThat(response.getDeletedMetacards().size(), is(1));
QueryResponse queryResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), true));
assertThat(queryResponse.getResults().size(), is(0));
}
use of ddf.catalog.operation.QueryResponse in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateWithDefaults.
@Test
public void testUpdateWithDefaults() throws Exception {
final String title = "some title";
final Date expiration = new Date();
List<Metacard> metacards = getMetacards(title, expiration);
CreateRequest createRequest = new CreateRequestImpl(metacards);
CreateResponse createResponse = framework.create(createRequest);
verifyDefaults(createResponse.getCreatedMetacards(), title, expiration, null, null, null, null);
registerDefaults();
List<Result> mockFederationResults = metacards.stream().map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), any())).thenReturn(queryResponse);
UpdateRequest updateRequest = new UpdateRequestImpl(new String[] { "1", "2", "3", "4", "5" }, createResponse.getCreatedMetacards());
UpdateResponse updateResponse = framework.update(updateRequest);
List<Metacard> updatedMetacards = updateResponse.getUpdatedMetacards().stream().map(Update::getNewMetacard).collect(Collectors.toList());
verifyDefaults(updatedMetacards, title, expiration, DEFAULT_TITLE, DEFAULT_EXPIRATION, DEFAULT_TITLE_CUSTOM, DEFAULT_EXPIRATION_CUSTOM);
}
use of ddf.catalog.operation.QueryResponse in project ddf by codice.
the class FanoutCatalogFrameworkTest method testReplaceDistance.
@Test
public void testReplaceDistance() {
QueryRequest request = new QueryRequestImpl(null);
List<Result> results = new ArrayList<Result>();
MetacardImpl newCard1 = new MetacardImpl();
ResultImpl result1 = new ResultImpl(newCard1);
result1.setRelevanceScore(RELEVANCE_SCORE);
result1.setDistanceInMeters(DISTANCE_SCORE);
MetacardImpl newCard2 = new MetacardImpl();
ResultImpl result2 = new ResultImpl(newCard2);
result2.setRelevanceScore(RELEVANCE_SCORE);
result2.setDistanceInMeters(DISTANCE_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(newResults);
assertEquals(2, newResults.size());
Metacard card = new MetacardImpl();
// Make sure the relevance and distance score was copied over
for (Result newResult : newResults) {
card = newResult.getMetacard();
assertNotNull(card);
assertEquals(RELEVANCE_SCORE, newResult.getRelevanceScore());
assertEquals(DISTANCE_SCORE, newResult.getDistanceInMeters());
}
}
use of ddf.catalog.operation.QueryResponse in project ddf by codice.
the class FanoutCatalogFrameworkTest method testQueryReplacesSourceId.
@Test
public void testQueryReplacesSourceId() throws Exception {
ConnectedSource source1 = mock(ConnectedSource.class);
when(source1.getId()).thenReturn("source1");
when(source1.isAvailable()).thenReturn(true);
ConnectedSource source2 = mock(ConnectedSource.class);
when(source2.getId()).thenReturn("source2");
when(source2.isAvailable()).thenReturn(true);
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.operation.QueryResponse 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());
}
}
Aggregations