use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.
the class TestCswSource method testQueryWithSortByRelevance.
@Test
public void testQueryWithSortByRelevance() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
// Setup
final String searchPhrase = "*";
final int pageSize = 1;
final int numRecordsReturned = 1;
final long numRecordsMatched = 1;
setupMockContextForMetacardTypeRegistrationAndUnregistration(getDefaultContentTypes());
try {
configureMockCsw(numRecordsReturned, numRecordsMatched, CswConstants.VERSION_2_0_2);
} catch (CswException e) {
fail("Could not configure Mock Remote CSW: " + e.getMessage());
}
QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
query.setPageSize(pageSize);
SortBy sortBy = new SortByImpl(Result.RELEVANCE, SortOrder.DESCENDING);
query.setSortBy(sortBy);
AbstractCswSource cswSource = getCswSource(mockCsw, mockContext);
cswSource.setCswUrl(URL);
cswSource.setId(ID);
// Perform test
SourceResponse response = cswSource.query(new QueryRequestImpl(query));
// Verify
Assert.assertNotNull(response);
assertThat(response.getResults().size(), is(numRecordsReturned));
assertThat(response.getHits(), is(numRecordsMatched));
ArgumentCaptor<GetRecordsType> captor = ArgumentCaptor.forClass(GetRecordsType.class);
try {
verify(mockCsw, atLeastOnce()).getRecords(captor.capture());
} catch (CswException e) {
fail("Could not verify mock CSW record count: " + e.getMessage());
}
GetRecordsType getRecordsType = captor.getValue();
QueryType cswQuery = (QueryType) getRecordsType.getAbstractQuery().getValue();
assertThat(cswQuery.getSortBy().getSortProperty().size(), is(1));
assertThat(cswQuery.getSortBy().getSortProperty().get(0).getPropertyName().getContent().get(0).toString(), equalTo(Core.TITLE));
assertThat(cswQuery.getSortBy().getSortProperty().get(0).getSortOrder(), is(SortOrderType.DESC));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.
the class TestCswSource method testQueryWitNaturalSorting.
@Test
public void testQueryWitNaturalSorting() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
// Setup
final String searchPhrase = "*";
final int pageSize = 1;
final int numRecordsReturned = 1;
final long numRecordsMatched = 1;
setupMockContextForMetacardTypeRegistrationAndUnregistration(getDefaultContentTypes());
try {
configureMockCsw(numRecordsReturned, numRecordsMatched, CswConstants.VERSION_2_0_2);
} catch (CswException e) {
fail("Could not configure Mock Remote CSW: " + e.getMessage());
}
QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
query.setPageSize(pageSize);
query.setSortBy(SortBy.NATURAL_ORDER);
AbstractCswSource cswSource = getCswSource(mockCsw, mockContext);
cswSource.setCswUrl(URL);
cswSource.setId(ID);
// Perform test
SourceResponse response = cswSource.query(new QueryRequestImpl(query));
// Verify
Assert.assertNotNull(response);
assertThat(response.getResults().size(), is(numRecordsReturned));
assertThat(response.getHits(), is(numRecordsMatched));
ArgumentCaptor<GetRecordsType> captor = ArgumentCaptor.forClass(GetRecordsType.class);
try {
verify(mockCsw, atLeastOnce()).getRecords(captor.capture());
} catch (CswException e) {
fail("Could not verify mock CSW record count: " + e.getMessage());
}
GetRecordsType getRecordsType = captor.getValue();
QueryType cswQuery = (QueryType) getRecordsType.getAbstractQuery().getValue();
assertThat(cswQuery.getSortBy(), nullValue());
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.
the class TestCswResponseExceptionMapper method testCswExceptionWithNullResponse.
@Test
public void testCswExceptionWithNullResponse() {
CswException cswException = new CswResponseExceptionMapper().fromResponse(null);
assertThat(cswException.getMessage(), is("Error handling response, response is null"));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.
the class TestCswResponseExceptionMapper method testInvalidCswException.
@Test
public void testInvalidCswException() {
String exceptionReportXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n" + "<ows:ExceptionReport version=\"1.2.0\" xmlns:ns16=\"http://www.opengis.net/ows/1.1\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cat=\"http://www.opengis.net/cat/csw\" xmlns:gco=\"http://www.isotc211.org/2005/gco\" xmlns:gmd=\"http://www.isotc211.org/2005/gmd\" xmlns:fra=\"http://www.cnig.gouv.fr/2005/fra\" xmlns:ins=\"http://www.inspire.org\" xmlns:gmx=\"http://www.isotc211.org/2005/gmx\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:dct=\"http://purl.org/dc/terms/\" xmlns:ows=\"http://www.opengis.net/ows\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\" xmlns:gmi=\"http://www.isotc211.org/2005/gmi\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n" + " <ows:Invalid exceptionCode=\"INVALID_PARAMETER_VALUE\" locator=\"QueryConstraint\">\r\n" + " <ows:ExceptionText>Only dc:title,dct:modified,dc:subject,dct:dateSubmitted,dct:alternative,dc:format,dct:created,dc:type,dct:abstract,dc:identifier,dc:creator are currently supported</ows:ExceptionText>\r\n" + " </ows:Exception>\r\n" + "</ows:ExceptionReport>";
CswException cswException = createCswException(exceptionReportXml);
assertThat(cswException.getMessage(), containsString("Error received from remote Csw server"));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.
the class TestCswEndpoint method testCapabilitiesRequestOperationsMetadata.
@Test
public void testCapabilitiesRequestOperationsMetadata() {
// Should only return the OperationsMetadata section
GetCapabilitiesRequest gcr = createDefaultGetCapabilitiesRequest();
gcr.setSections(CswEndpoint.OPERATIONS_METADATA);
CapabilitiesType ct = null;
try {
ct = csw.getCapabilities(gcr);
} catch (CswException e) {
fail("CswException caught during getCapabilities GET request: " + e.getMessage());
}
assertThat(ct, notNullValue());
verifyFilterCapabilities(ct);
assertThat(ct.getServiceIdentification(), nullValue());
assertThat(ct.getServiceProvider(), nullValue());
verifyOperationsMetadata(ct);
}
Aggregations