@@ -432,4 +432,49 @@ void throwExceptionWhenHitsRequestFails() {
432432 uuid , layer , start , end , multiPolygon , fields , format )
433433 );
434434 }
435+
436+ @ Test
437+ void returnsNullWhenParserThrowsException () {
438+ String uuid = "lyr-123" ;
439+ String layer = "imos:aatams_sattag_dm_profile_map1" ;
440+ String start = "2024-01-01" ;
441+ String end = "2024-12-31" ;
442+ Object multiPolygon = new Object (); // or real geometry
443+ List <String > fields = List .of ("name" , "area" );
444+ String format = "application/json" ;
445+
446+ // 1. A syntax error XML, should not see this but just incase
447+ String hitsXml = """
448+ <?xml version="1.0" encoding="UTF-8"?>
449+ <ows:ExceptionReport23433 xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/ows https://geoserver-123.aodn.org.au/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd">
450+ <ows:Exception exceptionCode="InvalidParameterValue" locator="typeName">
451+ <ows:ExceptionText>Feature type imos:aatams_sattag_dm_profile_map1 unknown</ows:ExceptionText>
452+ </ows:Exception>
453+ </ows:ExceptionReport>
454+ """ ;
455+ ResponseEntity <String > hitsResponse = new ResponseEntity <>(hitsXml , HttpStatus .OK );
456+ doReturn (hitsResponse )
457+ .when (restTemplate ).exchange (
458+ argThat ((String url ) -> url != null && url .contains ("resultType=hits" )),
459+ eq (HttpMethod .GET ),
460+ any (HttpEntity .class ),
461+ eq (String .class ));
462+
463+ doReturn (Optional .of ("http://dummy.com/wfs" ))
464+ .when (wfsServer ).getFeatureServerUrl (eq (uuid ), anyString ());
465+
466+ WfsFields fs = WfsFields .builder ()
467+ .fields (List .of (
468+ WfsField .builder ().type ("dateTime" ).name ("time" ).build ()
469+ ))
470+ .build ();
471+
472+ doReturn (fs )
473+ .when (wfsServer ).getDownloadableFields (eq (uuid ), any (WfsServer .WfsFeatureRequest .class ));
474+
475+ BigInteger size = downloadWfsDataService .estimateDownloadSize (
476+ uuid , layer , start , end , multiPolygon , fields , format );
477+
478+ assertNull (size , "Size should be null" );
479+ }
435480}
0 commit comments