use of ddf.catalog.operation.impl.QueryResponseImpl 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.operation.impl.QueryResponseImpl 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.operation.impl.QueryResponseImpl 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.operation.impl.QueryResponseImpl 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));
}
use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class TestCswEndpoint method setUpBeforeClass.
@org.junit.Before
public void setUpBeforeClass() throws URISyntaxException, SourceUnavailableException, UnsupportedQueryException, FederationException, ParseException, IngestException {
URI mockUri = new URI("http://example.com/services/csw");
when(mockUriInfo.getBaseUri()).thenReturn(mockUri);
URL resourceUrl = TestCswEndpoint.class.getResource("/record.xsd");
URL resourceUrlDot = TestCswEndpoint.class.getClass().getResource(".");
when(mockBundle.getResource("record.xsd")).thenReturn(resourceUrl);
when(mockBundle.getResource("csw/2.0.2/record.xsd")).thenReturn(resourceUrl);
when(mockBundle.getResource("gmd/record_gmd.xsd")).thenReturn(resourceUrl);
when(mockBundle.getResource(".")).thenReturn(resourceUrlDot);
csw = new CswEndpointStub(catalogFramework, mockMimeTypeManager, mockSchemaManager, mockInputManager, validator, queryFactory, mockBundle);
csw.setUri(mockUriInfo);
when(mockMimeTypeManager.getAvailableMimeTypes()).thenReturn(Arrays.asList(MediaType.APPLICATION_XML));
when(mockSchemaManager.getAvailableSchemas()).thenReturn(new ArrayList<>(Arrays.asList(CswConstants.CSW_OUTPUT_SCHEMA)));
when(mockSchemaManager.getTransformerBySchema(CswConstants.CSW_OUTPUT_SCHEMA)).thenReturn(mockTransformer);
when(mockInputManager.getAvailableIds()).thenReturn(Arrays.asList(CswConstants.CSW_RECORD));
QueryResponseImpl response = new QueryResponseImpl(null, new LinkedList<>(), 0);
argument = ArgumentCaptor.forClass(QueryRequest.class);
reset(catalogFramework);
when(catalogFramework.query(argument.capture())).thenReturn(response);
when(catalogFramework.getSourceIds()).thenReturn(new HashSet<>(Arrays.asList("source1", "source2", "source3")));
CreateResponseImpl createResponse = new CreateResponseImpl(null, null, Arrays.asList(new MetacardImpl()));
when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
}
Aggregations