use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project ddf by codice.
the class TestCswSource method testQueryWithSortByTemporal.
@Test
public void testQueryWithSortByTemporal() 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.TEMPORAL, 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.MODIFIED));
assertThat(cswQuery.getSortBy().getSortProperty().get(0).getSortOrder(), is(SortOrderType.DESC));
}
use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project ddf by codice.
the class TestCswSource method testQueryWithSorting.
@Test
public void testQueryWithSorting() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
final String TITLE = "title";
// 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(TITLE, 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(TITLE));
assertThat(cswQuery.getSortBy().getSortProperty().get(0).getSortOrder(), is(SortOrderType.DESC));
}
use of com.evolveum.prism.xml.ns._public.query_3.QueryType 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 com.evolveum.prism.xml.ns._public.query_3.QueryType 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 com.evolveum.prism.xml.ns._public.query_3.QueryType in project ddf by codice.
the class TestWfsSource method testSrsNameProvided.
@Test
public void testSrsNameProvided() throws Exception {
int pageSize = 10;
WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 10, false);
source.setSrsName(GeospatialUtil.EPSG_4326);
Filter filter = builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(SAMPLE_FEATURE_NAME + "0");
QueryImpl query = new QueryImpl(filter);
query.setPageSize(pageSize);
//Execute
GetFeatureType featureType = source.buildGetFeatureRequest(query);
QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
assertThat(queryType.getSrsName(), is(GeospatialUtil.EPSG_4326));
}
Aggregations