GetFeatureXMLAdapter extends QueryXMLAdapter { public GetFeature parse() throws Exception { Version version = determineVersion110Safe(); GetFeature result = null; if ( VERSION_100.equals( version ) ) { result = parse100(); } else if ( VERSION_110.equals( version ) ) { result = parse110(); } else if ( VERSION_200.equals( version ) ) { result = parse200(); } else { String msg = "Version '" + version + "' is not supported. Supported versions are 1.0.0, 1.1.0 and 2.0.0."; throw new Exception( msg ); } return result; }  GetFeature parse(); GetFeature parse100(); GetFeature parse110(); GetFeature parse200();  }
@Test public void test_V110_EXAMPLE01() throws Exception { URL exampleURL = this.getClass().getResource( V110_EXAMPLE01 ); XMLAdapter xmlAdapter = new XMLAdapter( exampleURL ); GetFeatureXMLAdapter getFeatureAdapter = new GetFeatureXMLAdapter(); getFeatureAdapter.setRootElement( xmlAdapter.getRootElement() ); GetFeature getFeature = getFeatureAdapter.parse(); List<Query> queries = getFeature.getQueries(); FilterQuery filterQuery = (FilterQuery) queries.get( 0 ); TypeName[] typeNames = filterQuery.getTypeNames(); assertEquals( typeNames.length, 1 ); assertEquals( typeNames[0].getFeatureTypeName(), new QName( "http: IdFilter filter = (IdFilter) filterQuery.getFilter(); Set<String> ids = filter.getMatchingIds(); assertEquals( ids.size(), 1 ); assertTrue( ids.contains( "InWaterA_1M.1234" ) ); }
@Test public void test_V110_EXAMPLE02() throws Exception { URL exampleURL = this.getClass().getResource( V110_EXAMPLE02 ); XMLAdapter xmlAdapter = new XMLAdapter( exampleURL ); GetFeatureXMLAdapter getFeatureAdapter = new GetFeatureXMLAdapter(); getFeatureAdapter.setRootElement( xmlAdapter.getRootElement() ); GetFeature getFeature = getFeatureAdapter.parse(); List<Query> queries = getFeature.getQueries(); FilterQuery filterQuery = (FilterQuery) queries.get( 0 ); ProjectionClause[] propNames = filterQuery.getProjectionClauses(); assertEquals( propNames.length, 3 ); assertEquals( ( (PropertyName) propNames[0] ).getPropertyName().getAsText(), "myns:wkbGeom" ); assertEquals( ( (PropertyName) propNames[1] ).getPropertyName().getAsText(), "myns:tileId" ); assertEquals( ( (PropertyName) propNames[2] ).getPropertyName().getAsText(), "myns:facId" ); IdFilter filter = (IdFilter) filterQuery.getFilter(); Set<String> ids = filter.getMatchingIds(); assertEquals( ids.size(), 1 ); assertTrue( ids.contains( "InWaterA1M.1013" ) ); }
@Test public void test_V110_EXAMPLE03() throws Exception { URL exampleURL = this.getClass().getResource( V110_EXAMPLE03 ); XMLAdapter xmlAdapter = new XMLAdapter( exampleURL ); GetFeatureXMLAdapter getFeatureAdapter = new GetFeatureXMLAdapter(); getFeatureAdapter.setRootElement( xmlAdapter.getRootElement() ); GetFeature getFeature = getFeatureAdapter.parse(); List<Query> queries = getFeature.getQueries(); FilterQuery filterQuery = (FilterQuery) queries.get( 0 ); IdFilter filter = (IdFilter) filterQuery.getFilter(); Set<String> ids = filter.getMatchingIds(); assertEquals( ids.size(), 3 ); assertTrue( ids.contains( "InWaterA1M.1013" ) ); assertTrue( ids.contains( "InWaterA1M.1014" ) ); assertTrue( ids.contains( "InWaterA1M.1015" ) ); }
@Test public void test_V110_EXAMPLE04() throws Exception { URL exampleURL = this.getClass().getResource( V110_EXAMPLE04 ); XMLAdapter xmlAdapter = new XMLAdapter( exampleURL ); GetFeatureXMLAdapter getFeatureAdapter = new GetFeatureXMLAdapter(); getFeatureAdapter.setRootElement( xmlAdapter.getRootElement() ); GetFeature getFeature = getFeatureAdapter.parse(); List<Query> queries = getFeature.getQueries(); FilterQuery filterQuery = (FilterQuery) queries.get( 0 ); ProjectionClause[] propNames = filterQuery.getProjectionClauses(); assertEquals( propNames.length, 2 ); assertEquals( ( (PropertyName) propNames[0] ).getPropertyName().getAsText(), "myns:wkbGeom" ); assertEquals( ( (PropertyName) propNames[1] ).getPropertyName().getAsText(), "myns:tileId" ); IdFilter filter = (IdFilter) filterQuery.getFilter(); Set<String> ids = filter.getMatchingIds(); assertEquals( ids.size(), 3 ); assertTrue( ids.contains( "InWaterA1M.1013" ) ); assertTrue( ids.contains( "InWaterA1M.1014" ) ); assertTrue( ids.contains( "InWaterA1M.1015" ) ); }
@Test public void test_V110_EXAMPLE09() throws Exception { URL exampleURL = this.getClass().getResource( V110_EXAMPLE09 ); XMLAdapter xmlAdapter = new XMLAdapter( exampleURL ); GetFeatureXMLAdapter getFeatureAdapter = new GetFeatureXMLAdapter(); getFeatureAdapter.setRootElement( xmlAdapter.getRootElement() ); GetFeature getFeature = getFeatureAdapter.parse(); List<Query> queries = getFeature.getQueries(); FilterQuery filterQuery = (FilterQuery) queries.get( 0 ); TypeName[] typeNames = filterQuery.getTypeNames(); assertEquals( typeNames.length, 1 ); assertEquals( new QName( "Person" ), typeNames[0].getFeatureTypeName() ); OperatorFilter opFilter = (OperatorFilter) filterQuery.getFilter(); assertEquals( opFilter.getOperator().getType(), LOGICAL ); LogicalOperator logOp = (LogicalOperator) opFilter.getOperator(); assertEquals( logOp.getSubType(), AND ); And andOp = (And) logOp; Operator op1 = andOp.getParameter( 0 ); assertEquals( op1.getType(), LOGICAL ); LogicalOperator logOp1 = (LogicalOperator) op1; assertEquals( logOp1.getSubType(), AND ); And andOp1 = (And) logOp1; Operator op11 = andOp1.getParameter( 0 ); assertEquals( op11.getType(), COMPARISON ); BinaryComparisonOperator compOp11 = (BinaryComparisonOperator) op11; assertTrue( compOp11 instanceof PropertyIsGreaterThanOrEqualTo ); assertTrue( ( (PropertyIsGreaterThanOrEqualTo) op11 ).getParameter1() instanceof ValueReference ); assertEquals( ( (ValueReference) ( (PropertyIsGreaterThanOrEqualTo) op11 ).getParameter1() ).getAsText(), "myns:Person/myns:mailAddress/myns:Address/myns:streetNumber" ); assertTrue( ( (PropertyIsGreaterThanOrEqualTo) op11 ).getParameter2() instanceof Literal<?> ); assertEquals( ( (Literal<?>) ( (PropertyIsGreaterThanOrEqualTo) op11 ).getParameter2() ).getValue().toString(), "10000" ); Operator op12 = andOp1.getParameter( 1 ); assertEquals( op12.getType(), COMPARISON ); BinaryComparisonOperator compOp12 = (BinaryComparisonOperator) op12; assertTrue( compOp12 instanceof PropertyIsLessThanOrEqualTo ); assertTrue( ( (PropertyIsLessThanOrEqualTo) op12 ).getParameter1() instanceof ValueReference ); assertEquals( ( (ValueReference) ( (PropertyIsLessThanOrEqualTo) op12 ).getParameter1() ).getAsText(), "myns:Person/myns:mailAddress/myns:Address/myns:streetNumber" ); assertTrue( ( (PropertyIsLessThanOrEqualTo) op12 ).getParameter2() instanceof Literal<?> ); assertEquals( ( (Literal<?>) ( (PropertyIsLessThanOrEqualTo) op12 ).getParameter2() ).getValue().toString(), "10999" ); Operator op2 = andOp.getParameter( 1 ); assertEquals( op2.getType(), LOGICAL ); LogicalOperator logOp2 = (LogicalOperator) op2; assertEquals( logOp2.getSubType(), AND ); And andOp2 = (And) logOp2; Operator op21 = andOp2.getParameter( 0 ); assertEquals( op21.getType(), COMPARISON ); BinaryComparisonOperator compOp21 = (BinaryComparisonOperator) op21; assertTrue( compOp21 instanceof PropertyIsEqualTo ); assertTrue( ( (PropertyIsEqualTo) op21 ).getParameter1() instanceof ValueReference ); assertEquals( ( (ValueReference) ( (PropertyIsEqualTo) op21 ).getParameter1() ).getAsText(), "myns:Person/myns:mailAddress/myns:Address/myns:streetName" ); assertTrue( ( (PropertyIsEqualTo) op21 ).getParameter2() instanceof Literal<?> ); assertEquals( ( (Literal<?>) ( (PropertyIsEqualTo) op21 ).getParameter2() ).getValue().toString(), "Main St." ); Operator op22 = andOp2.getParameter( 1 ); assertEquals( op22.getType(), COMPARISON ); BinaryComparisonOperator compOp22 = (BinaryComparisonOperator) op22; assertTrue( compOp22 instanceof PropertyIsEqualTo ); assertTrue( ( (PropertyIsEqualTo) op22 ).getParameter1() instanceof ValueReference ); assertEquals( ( (ValueReference) ( (PropertyIsEqualTo) op22 ).getParameter1() ).getAsText(), "myns:Person/myns:mailAddress/myns:Address/myns:city" ); assertTrue( ( (PropertyIsEqualTo) op22 ).getParameter2() instanceof Literal<?> ); assertEquals( ( (Literal<?>) ( (PropertyIsEqualTo) op22 ).getParameter2() ).getValue().toString(), "SomeTown" ); Operator op23 = andOp2.getParameter( 2 ); assertEquals( op23.getType(), COMPARISON ); BinaryComparisonOperator compOp23 = (BinaryComparisonOperator) op23; assertTrue( compOp23 instanceof PropertyIsEqualTo ); assertTrue( ( (PropertyIsEqualTo) op23 ).getParameter1() instanceof ValueReference ); assertEquals( ( (ValueReference) ( (PropertyIsEqualTo) op23 ).getParameter1() ).getAsText(), "myns:Person/myns:sex" ); assertTrue( ( (PropertyIsEqualTo) op23 ).getParameter2() instanceof Literal<?> ); assertEquals( ( (Literal<?>) ( (PropertyIsEqualTo) op23 ).getParameter2() ).getValue().toString(), "Female" ); Operator op24 = andOp2.getParameter( 3 ); assertEquals( op24.getType(), COMPARISON ); BinaryComparisonOperator compOp24 = (BinaryComparisonOperator) op24; assertTrue( compOp24 instanceof PropertyIsGreaterThan ); assertTrue( ( (PropertyIsGreaterThan) op24 ).getParameter1() instanceof ValueReference ); assertEquals( ( (ValueReference) ( (PropertyIsGreaterThan) op24 ).getParameter1() ).getAsText(), "myns:Person/myns:salary" ); assertTrue( ( (PropertyIsGreaterThan) op24 ).getParameter2() instanceof Literal<?> ); assertEquals( ( (Literal<?>) ( (PropertyIsGreaterThan) op24 ).getParameter2() ).getValue().toString(), "35000" ); }
@Test public void test_V110_EXAMPLE10() throws Exception { URL exampleURL = this.getClass().getResource( V110_EXAMPLE10 ); XMLAdapter xmlAdapter = new XMLAdapter( exampleURL ); GetFeatureXMLAdapter getFeatureAdapter = new GetFeatureXMLAdapter(); getFeatureAdapter.setRootElement( xmlAdapter.getRootElement() ); GetFeature getFeature = getFeatureAdapter.parse(); List<Query> queries = getFeature.getQueries(); FilterQuery filterQuery = (FilterQuery) queries.get( 0 ); ProjectionClause[] propNames = filterQuery.getProjectionClauses(); assertEquals( propNames.length, 2 ); assertEquals( ( (PropertyName) propNames[0] ).getPropertyName().getAsText(), "gml:name" ); assertEquals( ( (PropertyName) propNames[1] ).getPropertyName().getAsText(), "gml:directedNode" ); IdFilter filter = (IdFilter) filterQuery.getFilter(); Set<String> ids = filter.getMatchingIds(); assertEquals( ids.size(), 1 ); assertTrue( ids.contains( "t1" ) ); }
@Test public void test_V110_EXAMPLE11() throws Exception { URL exampleURL = this.getClass().getResource( V110_EXAMPLE11 ); XMLAdapter xmlAdapter = new XMLAdapter( exampleURL ); GetFeatureXMLAdapter getFeatureAdapter = new GetFeatureXMLAdapter(); getFeatureAdapter.setRootElement( xmlAdapter.getRootElement() ); GetFeature getFeature = getFeatureAdapter.parse(); List<Query> queries = getFeature.getQueries(); FilterQuery filterQuery = (FilterQuery) queries.get( 0 ); ProjectionClause[] propNames = filterQuery.getProjectionClauses(); assertEquals( propNames.length, 2 ); assertEquals( ( (PropertyName) propNames[0] ).getPropertyName().getAsText(), "gml:name" ); assertEquals( ( (PropertyName) propNames[1] ).getPropertyName().getAsText(), "gml:directedNode" ); IdFilter filter = (IdFilter) filterQuery.getFilter(); Set<String> ids = filter.getMatchingIds(); assertEquals( ids.size(), 1 ); assertTrue( ids.contains( "t1" ) ); }