Search in sources :

Example 21 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project ddf by codice.

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionGetBrief.

@Ignore
public void testMarshalRecordCollectionGetBrief() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
    GetRecordsType getRecords = new GetRecordsType();
    QueryType query = new QueryType();
    ElementSetNameType set = new ElementSetNameType();
    set.setValue(ElementSetType.BRIEF);
    query.setElementSetName(set);
    ObjectFactory objectFactory = new ObjectFactory();
    getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
    CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
    collection.setElementSetType(ElementSetType.BRIEF);
    ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
    String xml = xstream.toXML(collection);
    // Verify the context arguments were set correctly
    verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
    MarshallingContext context = captor.getValue();
    assertThat(context, not(nullValue()));
    assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
    assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.BRIEF));
    JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    GetRecordsResponseType response = jaxb.getValue();
    // Assert the GetRecordsResponse elements and attributes
    assertThat(response, not(nullValue()));
    SearchResultsType resultsType = response.getSearchResults();
    assertThat(resultsType, not(nullValue()));
    assertThat(resultsType.getElementSet(), is(ElementSetType.BRIEF));
    assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
    assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
    assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Also used : HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(jdk.nashorn.internal.ir.annotations.Ignore)

Example 22 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project ddf by codice.

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionGetFull.

@Ignore
public void testMarshalRecordCollectionGetFull() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
    GetRecordsType getRecords = new GetRecordsType();
    QueryType query = new QueryType();
    ElementSetNameType set = new ElementSetNameType();
    set.setValue(ElementSetType.FULL);
    query.setElementSetName(set);
    ObjectFactory objectFactory = new ObjectFactory();
    getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
    CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
    collection.setElementSetType(ElementSetType.FULL);
    ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
    String xml = xstream.toXML(collection);
    // Verify the context arguments were set correctly
    verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
    MarshallingContext context = captor.getValue();
    assertThat(context, not(nullValue()));
    assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
    assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.FULL));
    JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    GetRecordsResponseType response = jaxb.getValue();
    // Assert the GetRecordsResponse elements and attributes
    assertThat(response, not(nullValue()));
    SearchResultsType resultsType = response.getSearchResults();
    assertThat(resultsType, not(nullValue()));
    assertThat(resultsType.getElementSet(), is(ElementSetType.FULL));
    assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
    assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
    assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Also used : HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(jdk.nashorn.internal.ir.annotations.Ignore)

Example 23 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project ddf by codice.

the class TestWfsSource method testTwoPropertyQuery.

@Test
public void testTwoPropertyQuery() throws UnsupportedQueryException, WfsException, SecurityServiceException {
    setUp(TWO_TEXT_PROPERTY_SCHEMA, null, null, ONE_FEATURE, null);
    QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL));
    propertyIsLikeQuery.setPageSize(MAX_FEATURES);
    ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
    source.query(new QueryRequestImpl(propertyIsLikeQuery));
    verify(mockWfs).getFeature(captor.capture());
    GetFeatureType getFeatureType = captor.getValue();
    assertMaxFeatures(getFeatureType, propertyIsLikeQuery);
    assertTrue(getFeatureType.getQuery().size() == ONE_FEATURE);
    QueryType query = getFeatureType.getQuery().get(0);
    assertTrue(query.getTypeName().equals(sampleFeatures.get(0)));
    // The Text Properties should be ORed
    assertTrue(query.getFilter().isSetLogicOps());
    assertTrue(query.getFilter().getLogicOps().getValue() instanceof BinaryLogicOpType);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) BinaryLogicOpType(ogc.schema.opengis.filter.v_1_0_0.BinaryLogicOpType) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Example 24 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project ddf by codice.

the class TestWfsSource method testIntersectQuery.

@Test
public void testIntersectQuery() throws UnsupportedQueryException, WfsException, SecurityServiceException {
    setUp(ONE_GML_PROPERTY_SCHEMA, Arrays.asList(new Intersect(), new BBOX()), SRS_NAME, ONE_FEATURE, null);
    Filter intersectFilter = builder.attribute(Metacard.ANY_GEO).is().intersecting().wkt(POLYGON_WKT);
    QueryImpl intersectQuery = new QueryImpl(intersectFilter);
    intersectQuery.setPageSize(MAX_FEATURES);
    ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
    source.query(new QueryRequestImpl(intersectQuery));
    verify(mockWfs).getFeature(captor.capture());
    GetFeatureType getFeatureType = captor.getValue();
    assertMaxFeatures(getFeatureType, intersectQuery);
    assertTrue(getFeatureType.getQuery().size() == ONE_FEATURE);
    QueryType query = getFeatureType.getQuery().get(0);
    assertTrue(query.getTypeName().equals(sampleFeatures.get(0)));
    assertTrue(query.getFilter().isSetSpatialOps());
    assertTrue(query.getFilter().getSpatialOps().getValue() instanceof SpatialOpsType);
}
Also used : Intersect(ogc.schema.opengis.filter_capabilities.v_1_0_0.Intersect) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) BBOX(ogc.schema.opengis.filter_capabilities.v_1_0_0.BBOX) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SpatialOpsType(ogc.schema.opengis.filter.v_1_0_0.SpatialOpsType) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Example 25 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project ddf by codice.

the class TestWfsSource method testPropertyIsLikeQuery.

@Test
public void testPropertyIsLikeQuery() throws UnsupportedQueryException, WfsException, SecurityServiceException {
    setUp(ONE_TEXT_PROPERTY_SCHEMA, null, null, ONE_FEATURE, null);
    QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("literal"));
    propertyIsLikeQuery.setPageSize(MAX_FEATURES);
    ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
    source.query(new QueryRequestImpl(propertyIsLikeQuery));
    verify(mockWfs).getFeature(captor.capture());
    GetFeatureType getFeatureType = captor.getValue();
    assertMaxFeatures(getFeatureType, propertyIsLikeQuery);
    assertTrue(getFeatureType.getQuery().size() == ONE_FEATURE);
    QueryType query = getFeatureType.getQuery().get(0);
    assertTrue(query.getTypeName().equals(sampleFeatures.get(0)));
    assertTrue(query.getFilter().isSetComparisonOps());
    assertTrue(query.getFilter().getComparisonOps().getValue() instanceof PropertyIsLikeType);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) PropertyIsLikeType(ogc.schema.opengis.filter.v_1_0_0.PropertyIsLikeType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Aggregations

QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)91 Test (org.junit.Test)89 QueryImpl (ddf.catalog.operation.impl.QueryImpl)71 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)67 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)58 Test (org.testng.annotations.Test)52 QName (javax.xml.namespace.QName)50 JAXBElement (javax.xml.bind.JAXBElement)44 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)38 ArrayList (java.util.ArrayList)37 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)34 Filter (org.opengis.filter.Filter)32 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)23 SortBy (org.opengis.filter.sort.SortBy)22 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)21 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)21 SortByImpl (ddf.catalog.filter.impl.SortByImpl)20 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)19 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)19 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)18