@@ -88,9 +88,12 @@ class FeaturesControllerIntegrationTest {
8888 @ Value ("${tailormap-api.features.wfs_count_exact:false}" )
8989 private boolean exactWfsCounts ;
9090
91- @ Value ("${tailormap-api.pageSize }" )
91+ @ Value ("${tailormap-api.default-page-size }" )
9292 private int pageSize ;
9393
94+ @ Value ("${tailormap-api.max-page-size}" )
95+ private int maxPageSize ;
96+
9497 static Stream <Arguments > databaseArgumentsProvider () {
9598 return Stream .of (
9699 // docker host,table,url, feature count
@@ -433,6 +436,74 @@ void should_return_empty_featurecollection_for_out_of_range_page_from_wfs() thro
433436 assertEquals (0 , features .size (), "there should be 0 provinces in the list" );
434437 }
435438
439+ @ Test
440+ @ WithMockUser (
441+ username = "tm-admin" ,
442+ authorities = {"admin" })
443+ void should_use_default_page_size_when_not_specified () throws Exception {
444+ final String url = apiBasePath + begroeidterreindeelUrlPostgis ;
445+ MvcResult result = mockMvc .perform (get (url ).accept (MediaType .APPLICATION_JSON )
446+ .with (setServletPath (url ))
447+ .param ("page" , "1" ))
448+ .andExpect (status ().isOk ())
449+ .andExpect (content ().contentType (MediaType .APPLICATION_JSON ))
450+ .andExpect (jsonPath ("$.page" ).value (1 ))
451+ .andExpect (jsonPath ("$.pageSize" ).value (pageSize ))
452+ .andExpect (jsonPath ("$.features" ).isArray ())
453+ .andExpect (jsonPath ("$.features" ).isNotEmpty ())
454+ .andReturn ();
455+
456+ List <?> features = JsonPath .read (result .getResponse ().getContentAsString (), "$.features" );
457+ assertEquals (pageSize , features .size (), "number of returned features should equal the default page size" );
458+ }
459+
460+ @ Test
461+ @ WithMockUser (
462+ username = "tm-admin" ,
463+ authorities = {"admin" })
464+ void should_use_custom_page_size_when_specified () throws Exception {
465+ int requestedPageSize = pageSize - 1 ; // smaller than default, so the data set has enough rows
466+ final String url = apiBasePath + begroeidterreindeelUrlPostgis ;
467+ MvcResult result = mockMvc .perform (get (url ).accept (MediaType .APPLICATION_JSON )
468+ .with (setServletPath (url ))
469+ .param ("page" , "1" )
470+ .param ("pageSize" , String .valueOf (requestedPageSize )))
471+ .andExpect (status ().isOk ())
472+ .andExpect (content ().contentType (MediaType .APPLICATION_JSON ))
473+ .andExpect (jsonPath ("$.page" ).value (1 ))
474+ .andExpect (jsonPath ("$.pageSize" ).value (requestedPageSize ))
475+ .andExpect (jsonPath ("$.features" ).isArray ())
476+ .andExpect (jsonPath ("$.features" ).isNotEmpty ())
477+ .andReturn ();
478+
479+ List <?> features = JsonPath .read (result .getResponse ().getContentAsString (), "$.features" );
480+ assertEquals (
481+ requestedPageSize , features .size (), "number of returned features should equal the requested page size" );
482+ }
483+
484+ @ Test
485+ @ WithMockUser (
486+ username = "tm-admin" ,
487+ authorities = {"admin" })
488+ void should_cap_page_size_at_max_page_size () throws Exception {
489+ int oversizedPageSize = maxPageSize + 100 ; // well above the configured maxPageSize
490+ final String url = apiBasePath + begroeidterreindeelUrlPostgis ;
491+ MvcResult result = mockMvc .perform (get (url ).accept (MediaType .APPLICATION_JSON )
492+ .with (setServletPath (url ))
493+ .param ("page" , "1" )
494+ .param ("pageSize" , String .valueOf (oversizedPageSize )))
495+ .andExpect (status ().isOk ())
496+ .andExpect (content ().contentType (MediaType .APPLICATION_JSON ))
497+ .andExpect (jsonPath ("$.page" ).value (1 ))
498+ .andExpect (jsonPath ("$.pageSize" ).value (maxPageSize ))
499+ .andExpect (jsonPath ("$.features" ).isArray ())
500+ .andExpect (jsonPath ("$.features" ).isNotEmpty ())
501+ .andReturn ();
502+
503+ List <?> features = JsonPath .read (result .getResponse ().getContentAsString (), "$.features" );
504+ assertEquals (maxPageSize , features .size (), "number of returned features should be capped at maxPageSize" );
505+ }
506+
436507 @ Test
437508 @ WithMockUser (
438509 username = "tm-admin" ,
0 commit comments