opengeospatial / ets-sta10

Repository for the Executable Test Suite for OGC Sensor Things API
Other
6 stars 8 forks source link

compareTo on observation results #37

Closed tebben closed 7 years ago

tebben commented 7 years ago

I ran into a problem while running Capability3Tests.java

On line 1746 the observations with a result 2 and higher are requested and tested. The request is fired using the following url: "http://localhost:8080/v1.0/Observations?$filter=result ge '2'" which results in 11 correct observations. In the function checkPropertiesForFilter the result of the observation result gets converted to a string value and compared against a fixed string value "2". In case of the first observation the observation result is "12" the CompareTo method ("2".compareTo("12"))returns 1 which should have been a negative number, this results in the message "java.lang.AssertionError: result should be greate than or equal to 2. But the property value is 12 expected [true] but found [false]"

It seems like CompareTo on strings can't be used to compare these observation result values correctly.

Stacktrace: at org.testng.Assert.fail(Assert.java:94) at org.testng.Assert.failNotEquals(Assert.java:494) at org.testng.Assert.assertTrue(Assert.java:42) at org.opengis.cite.sta10.filteringExtension.Capability3Tests.checkPropertiesForFilter(Capability3Tests.java:1889) at org.opengis.cite.sta10.filteringExtension.Capability3Tests.checkFilterForEntityType(Capability3Tests.java:1746) at org.opengis.cite.sta10.filteringExtension.Capability3Tests.readEntitiesWithFilterQO(Capability3Tests.java:261)

hylkevds commented 7 years ago

The issue comes from comparing numbers and strings. The filter forces a string compare, by specifying '2' in the filter url instead of 2 and when doing a string compare, 9 is larger than 10.

Since the standard does not (yet) specify what to do when mixing types, we've made a change request to clarify this: https://github.com/opengeospatial/sensorthings/issues/7

(duplicate of https://github.com/opengeospatial/ets-sta10/issues/14 and https://github.com/opengeospatial/ets-sta10/issues/33)

tebben commented 7 years ago

Ok, thanks for clarifying.

taniakhalafbeigi commented 7 years ago

The query is applied to /Observations which means all the Observations. In general case Observations can have multiple types (numbers, categories, Strings). As a result, any $filter query on all Observations on 'result' is considered as String. But for /Datastreams(id)/Observations in case the observationType is some kind of number, the comparison is number comparison or as specified in the query (result gt 2 vs result gt '2').