@@ -1828,4 +1828,215 @@ public void expectNoErrorOnSingleRadiusForMultipleCoordinates() {
1828
1828
.body ("any { it.key == 'routes' }" , is (true ))
1829
1829
.statusCode (200 );
1830
1830
}
1831
+ // when given a user speed limit on a surface property,
1832
+ // a route should be found and the user speed limit should be present in at least the returned query.
1833
+ @ Test
1834
+ public void expectPassOnSurfaceSpeed () {
1835
+ JSONObject userSpeedLimits = new JSONObject ();
1836
+ JSONObject surfaceSpeedLimits = new JSONObject ();
1837
+ surfaceSpeedLimits .put ("gravel" , 80 );
1838
+ userSpeedLimits .put ("roadSpeeds" , surfaceSpeedLimits );
1839
+
1840
+ JSONObject body = new JSONObject ();
1841
+ body .put ("coordinates" , getParameter ("coordinatesShort" ));
1842
+ body .put ("user_speed_limits" , userSpeedLimits );
1843
+
1844
+ given ()
1845
+ .header ("Accept" , "application/json" )
1846
+ .header ("Content-Type" , "application/json" )
1847
+ .pathParam ("profile" , getParameter ("profile" ))
1848
+ .body (body .toString ())
1849
+ .when ()
1850
+ .post (getEndPointPath () + "/{profile}" )
1851
+ .then ()
1852
+ .assertThat ()
1853
+ .body ("any { it.key == 'routes' }" , is (true ))
1854
+ .body ("metadata.query.containsKey('user_speed_limits')" , is (true ))
1855
+ .statusCode (200 );
1856
+ }
1857
+
1858
+ // when given a user speed limit on a road property,
1859
+ // a route should be found and the user speed limit should be present in at least the returned query.
1860
+ @ Test
1861
+ public void expectPassOnRoadSpeed () {
1862
+ JSONObject userSpeedLimits = new JSONObject ();
1863
+ JSONObject roadSpeedLimits = new JSONObject ();
1864
+ roadSpeedLimits .put ("motorway" , 80 );
1865
+ userSpeedLimits .put ("roadSpeeds" , roadSpeedLimits );
1866
+
1867
+ JSONObject body = new JSONObject ();
1868
+ body .put ("coordinates" , getParameter ("coordinatesShort" ));
1869
+ body .put ("user_speed_limits" , userSpeedLimits );
1870
+
1871
+ given ()
1872
+ .header ("Accept" , "application/json" )
1873
+ .header ("Content-Type" , "application/json" )
1874
+ .pathParam ("profile" , getParameter ("profile" ))
1875
+ .body (body .toString ())
1876
+ .when ()
1877
+ .post (getEndPointPath () + "/{profile}" )
1878
+ .then ()
1879
+ .assertThat ()
1880
+ .body ("any { it.key == 'routes' }" , is (true ))
1881
+ .body ("metadata.query.containsKey('user_speed_limits')" , is (true ))
1882
+ .statusCode (200 );
1883
+ }
1884
+
1885
+ // when given a user speed limit and a custom unit,
1886
+ // a route should be found and the user speed limit should be present in at least the returned query.
1887
+ @ Test
1888
+ public void expectPassOnUserUnit () {
1889
+ JSONObject userSpeedLimits = new JSONObject ();
1890
+ JSONObject roadSpeedLimits = new JSONObject ();
1891
+ roadSpeedLimits .put ("motorway" , 55 );
1892
+ userSpeedLimits .put ("roadSpeeds" , roadSpeedLimits );
1893
+ userSpeedLimits .put ("unit" , "mph" );
1894
+
1895
+ JSONObject body = new JSONObject ();
1896
+ body .put ("coordinates" , getParameter ("coordinatesShort" ));
1897
+ body .put ("user_speed_limits" , userSpeedLimits );
1898
+
1899
+ given ()
1900
+ .header ("Accept" , "application/json" )
1901
+ .header ("Content-Type" , "application/json" )
1902
+ .pathParam ("profile" , getParameter ("profile" ))
1903
+ .body (body .toString ())
1904
+ .when ()
1905
+ .post (getEndPointPath () + "/{profile}" )
1906
+ .then ()
1907
+ .assertThat ()
1908
+ .body ("any { it.key == 'routes' }" , is (true ))
1909
+ .body ("metadata.query.containsKey('user_speed_limits')" , is (true ))
1910
+ .body ("metadata.query.user_speed_limits.containsKey('unit')" , is (true ))
1911
+ .body ("metadata.query.user_speed_limits.unit" , is ("mph" ))
1912
+ .statusCode (200 );
1913
+ }
1914
+
1915
+ @ Test
1916
+ public void expect2012OnUnknownKey () {
1917
+ JSONObject userSpeedLimits = new JSONObject ();
1918
+ JSONObject roadSpeedLimits = new JSONObject ();
1919
+ roadSpeedLimits .put ("primary" , 80 );
1920
+ userSpeedLimits .put ("unknownKey" , roadSpeedLimits );
1921
+
1922
+ JSONObject body = new JSONObject ();
1923
+ body .put ("coordinates" , getParameter ("coordinatesShort" ));
1924
+ body .put ("user_speed_limits" , userSpeedLimits );
1925
+
1926
+ given ()
1927
+ .header ("Accept" , "application/json" )
1928
+ .header ("Content-Type" , "application/json" )
1929
+ .pathParam ("profile" , getParameter ("profile" ))
1930
+ .body (body .toString ())
1931
+ .when ()
1932
+ .post (getEndPointPath () + "/{profile}" )
1933
+ .then ()
1934
+ .assertThat ()
1935
+ .body ("any { it.key == 'routes' }" , is (false ))
1936
+ .body ("error.code" , is (2012 ))
1937
+ .statusCode (400 );
1938
+ }
1939
+
1940
+
1941
+ // when given a non-supported road type, an error should appear
1942
+ @ Test
1943
+ public void expect2012onUnknownRoadType () {
1944
+ JSONObject userSpeedLimits = new JSONObject ();
1945
+ JSONObject roadSpeedLimits = new JSONObject ();
1946
+ roadSpeedLimits .put ("unknownProperty" , 80 );
1947
+ userSpeedLimits .put ("roadSpeeds" , roadSpeedLimits );
1948
+
1949
+ JSONObject body = new JSONObject ();
1950
+ body .put ("coordinates" , getParameter ("coordinatesShort" ));
1951
+ body .put ("user_speed_limits" , userSpeedLimits );
1952
+
1953
+ given ()
1954
+ .header ("Accept" , "application/json" )
1955
+ .header ("Content-Type" , "application/json" )
1956
+ .pathParam ("profile" , getParameter ("profile" ))
1957
+ .body (body .toString ())
1958
+ .when ()
1959
+ .post (getEndPointPath () + "/{profile}" )
1960
+ .then ()
1961
+ .assertThat ()
1962
+ .body ("any { it.key == 'routes' }" , is (false ))
1963
+ .body ("error.code" , is (2012 ))
1964
+ .statusCode (400 );
1965
+ }
1966
+
1967
+ // when given a non-supported surface type, an error should appear
1968
+ @ Test
1969
+ public void expect2012onUnknownSurfaceType () {
1970
+ JSONObject userSpeedLimits = new JSONObject ();
1971
+ JSONObject surfaceSpeedLimits = new JSONObject ();
1972
+ surfaceSpeedLimits .put ("unknownProperty" , 80 );
1973
+ userSpeedLimits .put ("surfaceSpeeds" , surfaceSpeedLimits );
1974
+
1975
+ JSONObject body = new JSONObject ();
1976
+ body .put ("coordinates" , getParameter ("coordinatesShort" ));
1977
+ body .put ("user_speed_limits" , userSpeedLimits );
1978
+
1979
+ given ()
1980
+ .header ("Accept" , "application/json" )
1981
+ .header ("Content-Type" , "application/json" )
1982
+ .pathParam ("profile" , getParameter ("profile" ))
1983
+ .body (body .toString ())
1984
+ .when ()
1985
+ .post (getEndPointPath () + "/{profile}" )
1986
+ .then ()
1987
+ .assertThat ()
1988
+ .body ("any { it.key == 'routes' }" , is (false ))
1989
+ .body ("error.code" , is (2012 ))
1990
+ .statusCode (400 );
1991
+ }
1992
+
1993
+ // when given an invalid speed, an error should appear
1994
+ @ Test
1995
+ public void expect2003onInvalidSpeed () {
1996
+ JSONObject userSpeedLimits = new JSONObject ();
1997
+ JSONObject surfaceSpeedLimits = new JSONObject ();
1998
+ surfaceSpeedLimits .put ("gravel" , -80 );
1999
+ userSpeedLimits .put ("surfaceSpeeds" , surfaceSpeedLimits );
2000
+
2001
+ JSONObject body = new JSONObject ();
2002
+ body .put ("coordinates" , getParameter ("coordinatesShort" ));
2003
+ body .put ("user_speed_limits" , userSpeedLimits );
2004
+
2005
+ given ()
2006
+ .header ("Accept" , "application/json" )
2007
+ .header ("Content-Type" , "application/json" )
2008
+ .pathParam ("profile" , getParameter ("profile" ))
2009
+ .body (body .toString ())
2010
+ .when ()
2011
+ .post (getEndPointPath () + "/{profile}" )
2012
+ .then ()
2013
+ .assertThat ()
2014
+ .body ("any { it.key == 'routes' }" , is (false ))
2015
+ .body ("error.code" , is (2003 ))
2016
+ .statusCode (400 );
2017
+ }
2018
+
2019
+ // when given an unknown unit, an error should appear
2020
+ @ Test
2021
+ public void expect2003onUnknownUnit (){
2022
+ JSONObject userSpeedLimits = new JSONObject ();
2023
+ userSpeedLimits .put ("unit" , "unknownUnit" );
2024
+
2025
+ JSONObject body = new JSONObject ();
2026
+ body .put ("coordinates" , getParameter ("coordinatesShort" ));
2027
+ body .put ("user_speed_limits" , userSpeedLimits );
2028
+
2029
+ given ()
2030
+ .header ("Accept" , "application/json" )
2031
+ .header ("Content-Type" , "application/json" )
2032
+ .pathParam ("profile" , getParameter ("profile" ))
2033
+ .body (body .toString ())
2034
+ .when ()
2035
+ .post (getEndPointPath () + "/{profile}" )
2036
+ .then ()
2037
+ .assertThat ()
2038
+ .body ("any { it.key == 'routes' }" , is (false ))
2039
+ .body ("error.code" , is (2003 ))
2040
+ .statusCode (400 );
2041
+ }
1831
2042
}
0 commit comments