From a37e14eb7dc82d0d8d38f547ad42eb6be83f6c9e Mon Sep 17 00:00:00 2001 From: Hugo <103732523+HugoBouttes@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:10:14 +0200 Subject: [PATCH 1/4] 117 add kubernetes ci (#134) * feat : change Dockerfile and add build.yaml * feat : add Date Class * fix : change String date in Date date * fix : change test to fit Date * fix : change test to fit Date (bis) * fix : change method GetWithCodeAndDate with Date instead of String --- .github/workflows/build.yaml | 5 + Dockerfile | 1 + .../rmes/api/classifications/CodesAPI.java | 13 +- .../api/geo/territoire/AireAttractionApi.java | 34 ++++-- .../api/geo/territoire/ArrondissementApi.java | 105 ++++++++++------ .../ArrondissementMunicipalApi.java | 95 ++++++++++----- .../geo/territoire/BassinDeVie2022Api.java | 19 +-- .../rmes/api/geo/territoire/CantonAPI.java | 104 ++++++++++------ .../api/geo/territoire/CantonOuVilleApi.java | 86 ++++++++----- .../CirconscriptionTerritorialeApi.java | 23 ++-- .../territoire/CollectivitesDOutreMerAPI.java | 35 ++++-- .../rmes/api/geo/territoire/CommuneApi.java | 114 ++++++++++++------ .../geo/territoire/CommuneAssocieeApi.java | 34 ++++-- .../geo/territoire/CommuneDelegueeApi.java | 34 ++++-- .../api/geo/territoire/DepartementApi.java | 101 ++++++++++------ .../rmes/api/geo/territoire/DistrictApi.java | 23 ++-- .../geo/territoire/IntercommunaliteAPI.java | 41 ++++--- .../rmes/api/geo/territoire/IrisApi.java | 50 +++++--- .../rmes/api/geo/territoire/RegionApi.java | 92 +++++++++----- .../api/geo/territoire/UniteUrbaineApi.java | 34 ++++-- .../api/geo/territoire/ZoneEmploiApi.java | 34 ++++-- .../fr/insee/rmes/modeles/utils/Date.java | 24 ++++ .../api/classifications/CodesAPITest.java | 13 +- .../ArrondissementApiIntegrationTest.java | 5 +- ...ndissementMunicipalApiIntegrationTest.java | 5 +- .../CantonApiIntegrationTest.java | 3 +- .../CommuneApiIntegrationTest.java | 5 +- .../ConstantForIntegration.java | 3 +- .../DepartementApiIntegrationTest.java | 5 +- .../geo/territoire/AireAttractionAPITest.java | 15 +-- .../geo/territoire/ArrondissementApiTest.java | 41 ++++--- .../ArrondissementMunicipalApiTest.java | 42 +++---- .../api/geo/territoire/CantonAPITest.java | 49 ++++---- .../geo/territoire/CantonOuVilleApiTest.java | 59 +++++---- .../CirconscriptionTerritorialeApiTest.java | 9 +- .../CollectivitesDOutreMerApiTest.java | 9 +- .../api/geo/territoire/CommuneApiTest.java | 49 ++++---- .../territoire/CommuneAssocieeApiTest.java | 15 +-- .../territoire/CommuneDelegueeApiTest.java | 15 +-- .../geo/territoire/DepartementApiTest.java | 45 +++---- .../api/geo/territoire/DistrictApiTest.java | 9 +- .../rmes/api/geo/territoire/IrisApiTest.java | 25 ++-- .../api/geo/territoire/RegionApiTest.java | 41 ++++--- .../geo/territoire/UniteUrbaineAPITest.java | 15 +-- .../api/geo/territoire/ZoneEmploiAPITest.java | 15 +-- 45 files changed, 978 insertions(+), 615 deletions(-) create mode 100644 src/main/java/fr/insee/rmes/modeles/utils/Date.java diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ee27d586..513ac8e3 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -17,6 +17,7 @@ jobs: - name: Get version id: version + run: echo "version=$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT - name: Print version @@ -47,6 +48,7 @@ jobs: with: ref: ${{ steps.extract_branch.outputs.branch }} + - name: Set up JDK 21 uses: actions/setup-java@v4 with: @@ -56,6 +58,7 @@ jobs: - name: Build API run: mvn package -Dchangelist=-SNAPSHOT --no-transfer-progress + - name: Upload API war uses: actions/upload-artifact@v4 with: @@ -70,6 +73,7 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Download uploaded war uses: actions/download-artifact@v4 with: @@ -82,4 +86,5 @@ jobs: name: inseefr/metadata-api username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + tags: "latest, ${{ needs.check-version.outputs.release-version }}" diff --git a/Dockerfile b/Dockerfile index 02cab860..52601b03 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ + # Utiliser une image de base qui inclut Tomcat 10 et Java 17. FROM tomcat:10-jdk17-temurin diff --git a/src/main/java/fr/insee/rmes/api/classifications/CodesAPI.java b/src/main/java/fr/insee/rmes/api/classifications/CodesAPI.java index 06d3cf2f..90b6c69e 100644 --- a/src/main/java/fr/insee/rmes/api/classifications/CodesAPI.java +++ b/src/main/java/fr/insee/rmes/api/classifications/CodesAPI.java @@ -12,6 +12,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.joda.time.DateTime; import fr.insee.rmes.api.AbstractMetadataApi; @@ -110,7 +111,7 @@ public Response getCategorieJuridiqueNiveauIII( public Response getCategoriesJuridiques( @Parameter(required = true, description = "Code de la catégorie juridique", example="5307") @QueryParam("code") String code, @Parameter( - description = "Date à laquelle la catégorie juridique est valide (Format : 'AAAA-MM-JJ' ; '*' pour obtenir tout l'historique ; paramètre absent pour la date du jour)", example="2020-05-11") @QueryParam("date") String date, + description = "Date à laquelle la catégorie juridique est valide (Format : 'AAAA-MM-JJ' ; '*' pour obtenir tout l'historique ; paramètre absent pour la date du jour)", example="2020-05-11") @QueryParam("date") Date date, @Parameter(hidden = true) @HeaderParam("Accept") String header) { String csvResult = ""; @@ -121,10 +122,10 @@ else if (date.equals("*")) { csvResult = sparqlUtils.executeSparqlQuery(CJQueries.getCJ(code)); } else { - if ( ! DateUtils.isValidDate(date)) { + if ( ! DateUtils.isValidDate(date.getString())) { return Response.status(Status.BAD_REQUEST).entity("").build(); } - DateTime dt = DateUtils.getDateTimeFromDateString(date); + DateTime dt = DateUtils.getDateTimeFromDateString(date.getString()); csvResult = sparqlUtils.executeSparqlQuery(CJQueries.getCJByCodeAndDate(code, dt)); } @@ -295,7 +296,7 @@ public Response getGroupeNA1973( public Response getActivities( @Parameter(required = true, description = "Code de l'activité", example="25.2") @QueryParam("code") String code, @Parameter( - description = "Date à laquelle l'activité est valide (Format : 'AAAA-MM-JJ' ; '*' pour obtenir tout l'historique ; paramètre absent pour la date du jour)") @QueryParam("date") String date, + description = "Date à laquelle l'activité est valide (Format : 'AAAA-MM-JJ' ; '*' pour obtenir tout l'historique ; paramètre absent pour la date du jour)") @QueryParam("date") Date date, @Parameter(hidden = true) @HeaderParam("Accept") String header) { String csvResult = ""; @@ -307,10 +308,10 @@ else if (date.equals("*")) { csvResult = sparqlUtils.executeSparqlQuery(ActivitesQueries.getActivites(code)); } else { - if ( ! DateUtils.isValidDate(date)) { + if ( ! DateUtils.isValidDate(date.getString())) { return Response.status(Status.BAD_REQUEST).entity("").build(); } - DateTime dt = DateUtils.getDateTimeFromDateString(date); + DateTime dt = DateUtils.getDateTimeFromDateString(date.getString()); csvResult = sparqlUtils.executeSparqlQuery(ActivitesQueries.getActiviteByCodeAndDate(code, dt)); } diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/AireAttractionApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/AireAttractionApi.java index c01ab2a4..05550336 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/AireAttractionApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/AireAttractionApi.java @@ -16,6 +16,7 @@ import fr.insee.rmes.modeles.geo.territoire.Territoire; import fr.insee.rmes.modeles.geo.territoires.AiresDAttractionDesVilles2020; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -66,9 +67,12 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -76,7 +80,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getAireAttractionByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getAireAttractionByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new AireDAttractionDesVilles2020(code)); } @@ -107,14 +111,17 @@ public Response getDescendants( description = "Filtre pour renvoyer les territoires inclus dans l'aire d'attraction active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, example="ArrondissementMunicipal")) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -125,7 +132,7 @@ public Response getDescendants( GeoQueries .getDescendantsAireAttraction( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -153,16 +160,19 @@ public Response getListe( description = "Filtre pour renvoyer les aire d'attractions actives à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListAiresAttraction(this.formatValidParameterDateIfIsNull(date))), + .executeSparqlQuery(GeoQueries.getListAiresAttraction(this.formatValidParameterDateIfIsNull(dateString))), header, AiresDAttractionDesVilles2020.class, AireDAttractionDesVilles2020.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/ArrondissementApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/ArrondissementApi.java index 9fe5847e..f99da30b 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/ArrondissementApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/ArrondissementApi.java @@ -17,6 +17,7 @@ import fr.insee.rmes.modeles.geo.territoires.Arrondissements; import fr.insee.rmes.modeles.geo.territoires.Projections; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Hidden; @@ -70,9 +71,12 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -81,7 +85,7 @@ public Response getByCode( sparqlUtils .executeSparqlQuery( GeoQueries - .getArrondissementByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + .getArrondissementByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new Arrondissement(code)); } @@ -112,14 +116,17 @@ public Response getAscendants( description = "Filtre pour renvoyer les territoires contenant l'arrondissement actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -130,7 +137,7 @@ public Response getAscendants( GeoQueries .getAscendantsArrondissement( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -163,14 +170,17 @@ public Response getDescendants( description = "Filtre pour renvoyer les territoires inclus dans l'arrondissement actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING), example="CommuneDeleguee") @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -181,7 +191,7 @@ public Response getDescendants( GeoQueries .getDescendantsArrondissement( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -208,9 +218,12 @@ public Response getListe( description = "Filtre pour renvoyer les arrondissements actifs à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -219,7 +232,7 @@ public Response getListe( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getListArrondissements(this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getListArrondissements(this.formatValidParameterDateIfIsNull(dateString))), header, Arrondissements.class, Arrondissement.class); @@ -251,9 +264,12 @@ public Response getSuivant( description = LITTERAL_DATE_ORIGINE_PROJ_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -261,7 +277,7 @@ public Response getSuivant( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getNextArrondissement(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getNextArrondissement(code, this.formatValidParameterDateIfIsNull(dateString))), header, Arrondissements.class, Arrondissement.class); @@ -293,9 +309,12 @@ public Response getPrecedent( description = LITTERAL_DATE_ORIGINE_PROJ_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -303,7 +322,7 @@ public Response getPrecedent( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getPreviousArrondissement(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getPreviousArrondissement(code, this.formatValidParameterDateIfIsNull(dateString))), header, Arrondissements.class, Arrondissement.class); @@ -335,14 +354,21 @@ public Response getProjection( description = LITTERAL_DATE_ORIGINE_PROJ_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_DATE_PROJECTION_DESCRIPTION, required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE), example="1994-07-30") @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { + String dateString = null; + String dateProjectionString = null; + if (date !=null) { + dateString = date.getString(); + } + if (dateProjection != null){ + dateProjectionString = dateProjection.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjectionString)) { return this.generateBadRequestResponse(); } else { @@ -353,8 +379,8 @@ public Response getProjection( GeoQueries .getProjectionArrondissement( code, - this.formatValidParameterDateIfIsNull(date), - dateProjection)), + this.formatValidParameterDateIfIsNull(dateString), + dateProjectionString)), header, Arrondissements.class, Arrondissement.class); @@ -381,14 +407,21 @@ public Response getAllProjections( description = "Filtre pour préciser les arrondissements de départ. Par défaut, c’est la date courante qui est utilisée.", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = "Date vers laquelle sont projetées les arrondissements. Paramètre obligatoire (erreur 400 si absent)", required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { + String dateString = null; + String dateProjectionString = null; + if (date !=null) { + dateString = date.getString(); + } + if (dateProjection != null){ + dateProjectionString = dateProjection.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjectionString)) { return this.generateBadRequestResponse(); } else { @@ -398,8 +431,8 @@ public Response getAllProjections( .executeSparqlQuery( GeoQueries .getAllProjectionArrondissement( - this.formatValidParameterDateIfIsNull(date), - dateProjection)), + this.formatValidParameterDateIfIsNull(dateString), + dateProjectionString)), header); } } diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/ArrondissementMunicipalApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/ArrondissementMunicipalApi.java index ef95b55a..fff5c8ca 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/ArrondissementMunicipalApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/ArrondissementMunicipalApi.java @@ -17,6 +17,7 @@ import fr.insee.rmes.modeles.geo.territoires.ArrondissementsMunicipaux; import fr.insee.rmes.modeles.geo.territoires.Projections; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Hidden; @@ -69,9 +70,12 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString =null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -82,7 +86,7 @@ public Response getByCode( GeoQueries .getArrondissementmunicipalByCodeAndDate( code, - this.formatValidParameterDateIfIsNull(date))), + this.formatValidParameterDateIfIsNull(dateString))), header, new ArrondissementMunicipal(code)); } @@ -113,14 +117,17 @@ public Response getAscendants( description = "Filtre pour renvoyer les territoires contenant l'arrondissement municipal actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString =null; + if (date != null){ + dateString = date.getString(); + } + if (!this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -131,7 +138,7 @@ public Response getAscendants( GeoQueries .getAscendantsArrondissementMunicipal( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -158,18 +165,20 @@ public Response getListe( description = LITTERAL_PARAMETER_DATE_DESCRIPTION + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString =null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { - return this .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getListArrondissementsMunicipaux(this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getListArrondissementsMunicipaux(this.formatValidParameterDateIfIsNull(dateString))), header, ArrondissementsMunicipaux.class, ArrondissementMunicipal.class); @@ -203,9 +212,12 @@ public Response getSuivant( required = false, example=LITTERAL_DATE_EXAMPLE, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString =null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -214,7 +226,7 @@ public Response getSuivant( sparqlUtils .executeSparqlQuery( GeoQueries - .getNextArrondissementMunicipal(code, this.formatValidParameterDateIfIsNull(date))), + .getNextArrondissementMunicipal(code, this.formatValidParameterDateIfIsNull(dateString))), header, ArrondissementsMunicipaux.class, ArrondissementMunicipal.class); @@ -247,9 +259,12 @@ public Response getPrecedent( description = LITTERAL_DATE_ORIGINE_PROJ_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString =null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -258,7 +273,7 @@ public Response getPrecedent( sparqlUtils .executeSparqlQuery( GeoQueries - .getPreviousArrondissementMunicipal(code, this.formatValidParameterDateIfIsNull(date))), + .getPreviousArrondissementMunicipal(code, this.formatValidParameterDateIfIsNull(dateString))), header, ArrondissementsMunicipaux.class, ArrondissementMunicipal.class); @@ -290,14 +305,21 @@ public Response getProjection( description = LITTERAL_DATE_ORIGINE_PROJ_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_DATE_PROJECTION_DESCRIPTION, required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_PROJETE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { + String dateString = null; + String dateprojectionString = null; + if (date != null){ + dateString = date.getString(); + } + if (dateProjection != null){ + dateprojectionString = dateProjection.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) || ! this.verifyParameterDateIsRightWithoutHistory(dateprojectionString) || dateprojectionString == null) { return this.generateBadRequestResponse(); } else { @@ -308,8 +330,8 @@ public Response getProjection( GeoQueries .getProjectionArrondissementMunicipal( code, - this.formatValidParameterDateIfIsNull(date), - dateProjection)), + this.formatValidParameterDateIfIsNull(dateString), + dateprojectionString)), header, ArrondissementsMunicipaux.class, ArrondissementMunicipal.class); @@ -336,14 +358,21 @@ public Response getAllProjections( description = "Filtre pour préciser les arrondissements municipaux de départ. Par défaut, c’est la date courante qui est utilisée.", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = "Date vers laquelle sont projetées les arrondissements municipaux. Paramètre obligatoire (erreur 400 si absent)", required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { + String dateString = null; + String dateprojectionString = null; + if (date != null){ + dateString = date.getString(); + } + if (dateProjection != null){ + dateprojectionString = dateProjection.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) || ! this.verifyParameterDateIsRightWithoutHistory(dateprojectionString)) { return this.generateBadRequestResponse(); } else { @@ -353,8 +382,8 @@ public Response getAllProjections( .executeSparqlQuery( GeoQueries .getAllProjectionArrondissementMunicipal( - this.formatValidParameterDateIfIsNull(date), - dateProjection)), + this.formatValidParameterDateIfIsNull(dateString), + dateprojectionString)), header); } } diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/BassinDeVie2022Api.java b/src/main/java/fr/insee/rmes/api/geo/territoire/BassinDeVie2022Api.java index 2abfd8d9..0334718d 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/BassinDeVie2022Api.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/BassinDeVie2022Api.java @@ -16,6 +16,7 @@ import fr.insee.rmes.modeles.geo.territoire.Territoire; import fr.insee.rmes.modeles.geo.territoires.BassinsDeVie2022; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -67,9 +68,9 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { + value = Constants.PARAMETER_DATE) Date date) { - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(date.getString())) { return this.generateBadRequestResponse(); } else { @@ -77,7 +78,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getBassinDeVie2022ByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getBassinDeVie2022ByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date.getString()))), header, new BassinDeVie2022(code)); } @@ -102,7 +103,7 @@ public Response getListe( description = "Filtre pour renvoyer les bassins de vie à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_NAME_DESCRIPTION, required = false, @@ -110,14 +111,14 @@ public Response getListe( value = Constants.PARAMETER_FILTRE) String filtreNom) { - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + if ( ! this.verifyParameterDateIsRightWithHistory(date.getString())) { return this.generateBadRequestResponse(); } else { return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListBassinsDeVie(this.formatValidParameterDateIfIsNull(date), this.formatValidParameterFiltreIfIsNull(filtreNom))), + .executeSparqlQuery(GeoQueries.getListBassinsDeVie(this.formatValidParameterDateIfIsNull(date.getString()), this.formatValidParameterFiltreIfIsNull(filtreNom))), header, BassinsDeVie2022.class, BassinDeVie2022.class); @@ -149,14 +150,14 @@ public Response getDescendants( description = "Filtre pour renvoyer les territoires inclus dans le bassin de vie actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, example="Commune")) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date.getString())) { return this.generateBadRequestResponse(); } else { @@ -167,7 +168,7 @@ public Response getDescendants( GeoQueries .getDescendantsBassinDeVie( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(date.getString()), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/CantonAPI.java b/src/main/java/fr/insee/rmes/api/geo/territoire/CantonAPI.java index 6952c584..1cc73c43 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/CantonAPI.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/CantonAPI.java @@ -8,6 +8,7 @@ import fr.insee.rmes.modeles.geo.territoires.Cantons; import fr.insee.rmes.modeles.geo.territoires.Communes; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -25,7 +26,7 @@ @Tag(name = ConstGeoApi.TAG_NAME, description = ConstGeoApi.TAG_DESCRIPTION) public class CantonAPI extends AbstractGeoApi { - private static final String CODE_PATTERN = "/{code:}"; + private static final String CODE_PATTERN = "/{code:[0-9]{4}}"; private static final String LITTERAL_PARAMETER_TYPE_DESCRIPTION = "Filtre sur le type de territoire renvoyé."; private static final String LITTERAL_PARAMETER_NAME_DESCRIPTION = "Filtre sur le nom des communes renvoyées" ; @@ -66,17 +67,19 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if (!code.matches(ConstGeoApi.PATTERN_CANTON)) { - String errorMessage = ConstGeoApi.ERREUR_PATTERN; - return Response.status(Response.Status.BAD_REQUEST) - .entity(errorMessage) - .type(MediaType.TEXT_PLAIN) - .build(); - } - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if (!code.matches(ConstGeoApi.PATTERN_CANTON)) { + String errorMessage = ConstGeoApi.ERREUR_PATTERN; + return Response.status(Response.Status.BAD_REQUEST) + .entity(errorMessage) + .type(MediaType.TEXT_PLAIN) + .build(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -84,7 +87,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getCantonByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getCantonByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new Canton(code)); } @@ -113,20 +116,23 @@ public Response getListe( description = "Filtre pour renvoyer les cantons actifs à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { - Response Response = this + return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListCantons(this.formatValidParameterDateIfIsNull(date))), + .executeSparqlQuery(GeoQueries.getListCantons(this.formatValidParameterDateIfIsNull(dateString))), header, Cantons.class, Canton.class); - return Response; } } @@ -155,7 +161,11 @@ public Response getSuivant( description = "Filtre pour préciser le canton de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } if (!code.matches(ConstGeoApi.PATTERN_CANTON)) { String errorMessage = ConstGeoApi.ERREUR_PATTERN; return Response.status(Response.Status.BAD_REQUEST) @@ -163,7 +173,7 @@ public Response getSuivant( .type(MediaType.TEXT_PLAIN) .build(); } - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -171,7 +181,7 @@ public Response getSuivant( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getNextCanton(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getNextCanton(code, this.formatValidParameterDateIfIsNull(dateString))), header, Cantons.class, Canton.class); @@ -204,8 +214,11 @@ public Response getPrecedent( description = "Filtre pour préciser le canton de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } if (!code.matches(ConstGeoApi.PATTERN_CANTON)) { String errorMessage = ConstGeoApi.ERREUR_PATTERN; return Response.status(Response.Status.BAD_REQUEST) @@ -213,7 +226,7 @@ public Response getPrecedent( .type(MediaType.TEXT_PLAIN) .build(); } - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) ) { return this.generateBadRequestResponse(); } else { @@ -221,7 +234,7 @@ public Response getPrecedent( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getPreviousCanton(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getPreviousCanton(code, this.formatValidParameterDateIfIsNull(dateString))), header, Cantons.class, Canton.class); @@ -253,13 +266,20 @@ public Response getProjection( description = "Filtre pour préciser le canton de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = "Date vers laquelle est projetée le canton. Paramètre obligatoire (Format : 'AAAA-MM-JJ', erreur 400 si absent)", required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { - + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + String dateProjectionString = null; + if (dateProjection != null){ + dateProjectionString = dateProjection.getString(); + } if (!code.matches(ConstGeoApi.PATTERN_CANTON)) { String errorMessage = ConstGeoApi.ERREUR_PATTERN; return Response.status(Response.Status.BAD_REQUEST) @@ -267,7 +287,7 @@ public Response getProjection( .type(MediaType.TEXT_PLAIN) .build(); } - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjectionString) ) { return this.generateBadRequestResponse(); } else { @@ -278,8 +298,8 @@ public Response getProjection( GeoQueries .getProjectionCanton( code, - this.formatValidParameterDateIfIsNull(date), - dateProjection)), + this.formatValidParameterDateIfIsNull(dateString), + dateProjectionString)), header, Cantons.class, Canton.class); @@ -310,7 +330,11 @@ public Response getCommunes( @Parameter( description = "La requête renvoie les communes actives à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date){ + value = Constants.PARAMETER_DATE) Date date){ + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } if (!code.matches(ConstGeoApi.PATTERN_CANTON)) { String errorMessage = ConstGeoApi.ERREUR_PATTERN; @@ -319,7 +343,7 @@ public Response getCommunes( @Parameter( .type(MediaType.TEXT_PLAIN) .build(); } - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -330,7 +354,7 @@ public Response getCommunes( @Parameter( GeoQueries .getCommunesCanton( code, - this.formatValidParameterDateIfIsNull(date))), + this.formatValidParameterDateIfIsNull(dateString))), header, Communes.class, Commune.class); @@ -365,14 +389,17 @@ public Response getAscendants( description = "Filtre pour renvoyer les territoires contenant le canton actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -383,7 +410,7 @@ public Response getAscendants( GeoQueries .getAscendantsCanton( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -392,5 +419,4 @@ public Response getAscendants( } - } diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/CantonOuVilleApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/CantonOuVilleApi.java index 9c48ff31..b111455c 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/CantonOuVilleApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/CantonOuVilleApi.java @@ -6,6 +6,7 @@ import fr.insee.rmes.modeles.geo.territoire.Territoire; import fr.insee.rmes.modeles.geo.territoires.CantonsEtVilles; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.CSVUtils; import fr.insee.rmes.utils.Constants; @@ -71,8 +72,11 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } if (!code.matches(ConstGeoApi.PATTERN_CANTON_OU_VILLE)) { String errorMessage = ConstGeoApi.ERREUR_PATTERN; return Response.status(Response.Status.BAD_REQUEST) @@ -80,7 +84,7 @@ public Response getByCode( .type(MediaType.TEXT_PLAIN) .build(); } - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -88,7 +92,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getCantonOuVilleByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getCantonOuVilleByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new CantonOuVille(code)); } @@ -113,9 +117,12 @@ public Response getListe( description = "Filtre pour renvoyer les cantons-ou-villes actifs à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -123,7 +130,7 @@ public Response getListe( return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListCantonsOuVilles(this.formatValidParameterDateIfIsNull(date))), + .executeSparqlQuery(GeoQueries.getListCantonsOuVilles(this.formatValidParameterDateIfIsNull(dateString))), header, CantonsEtVilles.class, CantonOuVille.class); @@ -155,7 +162,7 @@ public Response getDescendants( description = "Filtre pour renvoyer les territoires inclus dans le canton-ou-ville actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, @@ -166,7 +173,10 @@ public Response getDescendants( required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_FILTRE) String filtreNom) { - + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } if (!code.matches(ConstGeoApi.PATTERN_CANTON_OU_VILLE)) { String errorMessage = ConstGeoApi.ERREUR_PATTERN; return Response.status(Response.Status.BAD_REQUEST) @@ -174,7 +184,7 @@ public Response getDescendants( .type(MediaType.TEXT_PLAIN) .build(); } - if (!this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + if (!this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { return this @@ -184,7 +194,7 @@ public Response getDescendants( GeoQueries .getDescendantsCantonOuVille( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire), this.formatValidParameterFiltreIfIsNull(filtreNom))), header, Territoires.class, @@ -218,13 +228,16 @@ public Response getAscendants( description = "Filtre pour renvoyer les territoires contenant le canton-ou-ville actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } if (!code.matches(ConstGeoApi.PATTERN_CANTON_OU_VILLE)) { String errorMessage = ConstGeoApi.ERREUR_PATTERN; return Response.status(Response.Status.BAD_REQUEST) @@ -232,7 +245,7 @@ public Response getAscendants( .type(MediaType.TEXT_PLAIN) .build(); } - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -243,7 +256,7 @@ public Response getAscendants( GeoQueries .getAscendantsCantonOuVille( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -276,8 +289,11 @@ public Response getPrecedent( description = "Filtre pour préciser le canton-ou-ville de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } if (!code.matches(ConstGeoApi.PATTERN_CANTON_OU_VILLE)) { String errorMessage = ConstGeoApi.ERREUR_PATTERN; return Response.status(Response.Status.BAD_REQUEST) @@ -285,7 +301,7 @@ public Response getPrecedent( .type(MediaType.TEXT_PLAIN) .build(); } - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -293,7 +309,7 @@ public Response getPrecedent( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getPreviousCantonOuVille(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getPreviousCantonOuVille(code, this.formatValidParameterDateIfIsNull(dateString))), header, CantonsEtVilles.class, CantonOuVille.class); @@ -325,8 +341,11 @@ public Response getSuivant( description = "Filtre pour préciser le canton-ou-ville de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } if (!code.matches(ConstGeoApi.PATTERN_CANTON_OU_VILLE)) { String errorMessage = ConstGeoApi.ERREUR_PATTERN; return Response.status(Response.Status.BAD_REQUEST) @@ -334,7 +353,7 @@ public Response getSuivant( .type(MediaType.TEXT_PLAIN) .build(); } - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -342,7 +361,7 @@ public Response getSuivant( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getNextCantonOuVille(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getNextCantonOuVille(code, this.formatValidParameterDateIfIsNull(dateString))), header, CantonsEtVilles.class, CantonOuVille.class); @@ -374,13 +393,20 @@ public Response getProjection( description = "Filtre pour préciser le canton-ou-ville de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = "Date vers laquelle est projetée le canton-ou-ville. Paramètre obligatoire (Format : 'AAAA-MM-JJ', erreur 400 si absent)", required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { - + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { + String dateString = null; + String dateProjectionString = null; + if (date !=null) { + dateString = date.getString(); + } + if (dateProjection != null){ + dateProjectionString = dateProjection.getString(); + } if (!code.matches(ConstGeoApi.PATTERN_CANTON_OU_VILLE)) { String errorMessage = ConstGeoApi.ERREUR_PATTERN; return Response.status(Response.Status.BAD_REQUEST) @@ -388,7 +414,7 @@ public Response getProjection( .type(MediaType.TEXT_PLAIN) .build(); } - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjectionString)) { return this.generateBadRequestResponse(); } else { @@ -399,8 +425,8 @@ public Response getProjection( GeoQueries .getProjectionCantonOuVille( code, - this.formatValidParameterDateIfIsNull(date), - dateProjection)), + this.formatValidParameterDateIfIsNull(dateString), + dateProjectionString)), header, CantonsEtVilles.class, CantonOuVille.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/CirconscriptionTerritorialeApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/CirconscriptionTerritorialeApi.java index 73b4036b..7f07f7e5 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/CirconscriptionTerritorialeApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/CirconscriptionTerritorialeApi.java @@ -15,6 +15,7 @@ import fr.insee.rmes.modeles.geo.territoire.CirconscriptionTerritoriale; import fr.insee.rmes.modeles.geo.territoire.Territoire; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -66,9 +67,12 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -76,7 +80,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getCirconscriptionTerritorialeByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getCirconscriptionTerritorialeByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new CirconscriptionTerritoriale(code)); } @@ -107,14 +111,17 @@ public Response getAscendants( description = "Filtre pour renvoyer les territoires contenant la circonscription territoriale actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -125,7 +132,7 @@ public Response getAscendants( GeoQueries .getAscendantsCirconscriptionTerritoriale( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerAPI.java b/src/main/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerAPI.java index f7c294a6..dbf8b1c3 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerAPI.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerAPI.java @@ -17,6 +17,7 @@ import fr.insee.rmes.modeles.geo.territoire.Territoire; import fr.insee.rmes.modeles.geo.territoires.CollectivitesDOutreMer; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -65,17 +66,19 @@ public Response getListe( description = "Filtre pour renvoyer les collectivités d'outre-mer actives à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) - + value = Constants.PARAMETER_DATE) Date date) { - - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { return this .generateResponseListOfTerritoire( - sparqlUtils.executeSparqlQuery(GeoQueries.getListCollectivitesDOutreMer(this.formatValidParameterDateIfIsNull(date))), + sparqlUtils.executeSparqlQuery(GeoQueries.getListCollectivitesDOutreMer(this.formatValidParameterDateIfIsNull(dateString))), header, CollectivitesDOutreMer.class, CollectiviteDOutreMer.class ); @@ -108,9 +111,12 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -118,7 +124,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getCollectiviteDOutreMerByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getCollectiviteDOutreMerByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new CollectiviteDOutreMer(code)); } @@ -150,7 +156,7 @@ public Response getDescendants( description ="Filtre pour renvoyer les territoires inclus dans la collectivité d'outre-mer active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION+ "(Commune ou District)", required = false, @@ -161,14 +167,17 @@ public Response getDescendants( required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_FILTRE) String filtreNom) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { return this.generateResponseListOfTerritoire( sparqlUtils.executeSparqlQuery(GeoQueries.getDescendantsCollectiviteDOutreMer(code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire), this.formatValidParameterFiltreIfIsNull(filtreNom))), header, Territoires.class, Territoire.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java index 7d9f9c62..3c09383d 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java @@ -19,6 +19,7 @@ import fr.insee.rmes.modeles.geo.territoires.Communes; import fr.insee.rmes.modeles.geo.territoires.Projections; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Hidden; @@ -72,9 +73,12 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -82,7 +86,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getCommuneByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getCommuneByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new Commune(code)); } @@ -113,14 +117,17 @@ public Response getAscendants( description = "Filtre pour renvoyer les territoires contenant la commune active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -131,7 +138,7 @@ public Response getAscendants( GeoQueries .getAscendantsCommune( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -164,14 +171,17 @@ public Response getDescendants( description = "Filtre pour renvoyer les territoires inclus dans la commune active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, example="ArrondissementMunicipal")) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -182,7 +192,7 @@ public Response getDescendants( GeoQueries .getDescendantsCommune( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -209,7 +219,7 @@ public Response getListe( description = "Filtre pour renvoyer les communes actives à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_NAME_DESCRIPTION, required = false, @@ -222,15 +232,18 @@ public Response getListe( value = Constants.PARAMETER_STRING) Boolean com ) { - - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListCommunes(this.formatValidParameterDateIfIsNull(date), this.formatValidParameterFiltreIfIsNull(filtreNom),this.formatValidParameterBooleanIfIsNull(com))), + .executeSparqlQuery(GeoQueries.getListCommunes(this.formatValidParameterDateIfIsNull(dateString), this.formatValidParameterFiltreIfIsNull(filtreNom),this.formatValidParameterBooleanIfIsNull(com))), header, Communes.class, Commune.class); @@ -262,9 +275,12 @@ public Response getSuivant( description = "Filtre pour préciser la commune de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -272,7 +288,7 @@ public Response getSuivant( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getNextCommune(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getNextCommune(code, this.formatValidParameterDateIfIsNull(dateString))), header, Communes.class, Commune.class); @@ -304,9 +320,12 @@ public Response getPrecedent( description = "Filtre pour préciser la commune de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -314,7 +333,7 @@ public Response getPrecedent( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getPreviousCommune(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getPreviousCommune(code, this.formatValidParameterDateIfIsNull(dateString))), header, Communes.class, Commune.class); @@ -346,14 +365,21 @@ public Response getProjection( description = "Filtre pour préciser la commune de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = "Date vers laquelle est projetée la commune. Paramètre obligatoire (Format : 'AAAA-MM-JJ', erreur 400 si absent)", required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { + String dateString = null; + String dateProjectionString = null; + if (date !=null) { + dateString = date.getString(); + } + if (dateProjection !=null) { + dateProjectionString = dateProjection.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjectionString) || dateProjectionString== null) { return this.generateBadRequestResponse(); } else { @@ -364,8 +390,8 @@ public Response getProjection( GeoQueries .getProjectionCommune( code, - this.formatValidParameterDateIfIsNull(date), - dateProjection)), + this.formatValidParameterDateIfIsNull(dateString), + dateProjectionString)), header, Communes.class, Commune.class); @@ -392,14 +418,21 @@ public Response getAllProjections( description = "Filtre pour préciser les communes de départ. Par défaut, c’est la date courante qui est utilisée.", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = "Date vers laquelle sont projetées les communes. Paramètre obligatoire (erreur 400 si absent)", required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { + String dateString = null; + String dateProjectionString = null; + if (date !=null) { + dateString = date.getString(); + } + if (dateProjection !=null) { + dateProjectionString = dateProjection.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjectionString)) { return this.generateBadRequestResponse(); } else { @@ -408,7 +441,7 @@ public Response getAllProjections( sparqlUtils .executeSparqlQuery( GeoQueries - .getAllProjectionCommune(this.formatValidParameterDateIfIsNull(date), dateProjection)), + .getAllProjectionCommune(this.formatValidParameterDateIfIsNull(dateString), dateProjectionString)), header); } } @@ -438,9 +471,12 @@ public Response getCantonForCommune( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date !=null) { + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -451,7 +487,7 @@ public Response getCantonForCommune( GeoQueries.getCantonCommunes( code, - this.formatValidParameterDateIfIsNull(date))), + this.formatValidParameterDateIfIsNull(dateString))), header, Cantons.class, Canton.class); } diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneAssocieeApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneAssocieeApi.java index cacc391b..a9bd30cb 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneAssocieeApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneAssocieeApi.java @@ -17,6 +17,7 @@ import fr.insee.rmes.modeles.geo.territoire.Territoire; import fr.insee.rmes.modeles.geo.territoires.CommunesAssociees; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -68,9 +69,12 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -79,7 +83,7 @@ public Response getByCode( sparqlUtils .executeSparqlQuery( GeoQueries - .getCommuneAssocieeByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + .getCommuneAssocieeByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new CommuneAssociee(code)); } @@ -110,14 +114,17 @@ public Response getAscendants( description = "Filtre pour renvoyer les territoires contenant la commune associée active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -128,7 +135,7 @@ public Response getAscendants( GeoQueries .getAscendantsCommuneAssociee( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -155,9 +162,12 @@ public Response getListe( description = "Filtre pour renvoyer les communes associées actives à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -166,7 +176,7 @@ public Response getListe( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getListCommunesAssociees(this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getListCommunesAssociees(this.formatValidParameterDateIfIsNull(dateString))), header, CommunesAssociees.class, CommuneAssociee.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneDelegueeApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneDelegueeApi.java index 29a0e02a..8a9e94fc 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneDelegueeApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneDelegueeApi.java @@ -17,6 +17,7 @@ import fr.insee.rmes.modeles.geo.territoire.Territoire; import fr.insee.rmes.modeles.geo.territoires.CommunesDeleguees; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -66,9 +67,12 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -77,7 +81,7 @@ public Response getByCode( sparqlUtils .executeSparqlQuery( GeoQueries - .getCommuneDelegueeByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + .getCommuneDelegueeByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new CommuneDeleguee(code)); } @@ -108,14 +112,17 @@ public Response getAscendants( description = "Filtre pour renvoyer les territoires contenant la commune déléguée active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -126,7 +133,7 @@ public Response getAscendants( GeoQueries .getAscendantsCommuneDeleguee( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -153,9 +160,12 @@ public Response getListe( description = "Filtre pour renvoyer les communes déléguées actives à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -164,7 +174,7 @@ public Response getListe( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getListCommunesDeleguees(this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getListCommunesDeleguees(this.formatValidParameterDateIfIsNull(dateString))), header, CommunesDeleguees.class, CommuneDeleguee.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/DepartementApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/DepartementApi.java index c9e31403..3b551baf 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/DepartementApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/DepartementApi.java @@ -17,6 +17,7 @@ import fr.insee.rmes.modeles.geo.territoires.Departements; import fr.insee.rmes.modeles.geo.territoires.Projections; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Hidden; @@ -65,9 +66,12 @@ public Response getByCode( description = "Filtre pour renvoyer la département actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -75,7 +79,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getDepartementByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getDepartementByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new Departement(code)); } @@ -106,14 +110,17 @@ public Response getAscendants( description = "Filtre pour renvoyer les territoires contenant le département actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -124,7 +131,7 @@ public Response getAscendants( GeoQueries .getAscendantsDepartement( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -157,7 +164,7 @@ public Response getDescendants( description = "Filtre pour renvoyer les territoires inclus dans le département actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, @@ -168,8 +175,11 @@ public Response getDescendants( required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_FILTRE) String filtreNom) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -180,7 +190,7 @@ public Response getDescendants( GeoQueries .getDescendantsDepartement( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire),this.formatValidParameterFiltreIfIsNull(filtreNom))), header, Territoires.class, @@ -207,16 +217,19 @@ public Response getListe( description = "Filtre pour renvoyer le département actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { return this .generateResponseListOfTerritoire( - sparqlUtils.executeSparqlQuery(GeoQueries.getListDepartements(this.formatValidParameterDateIfIsNull(date))), + sparqlUtils.executeSparqlQuery(GeoQueries.getListDepartements(this.formatValidParameterDateIfIsNull(dateString))), header, Departements.class, Departement.class); @@ -248,9 +261,12 @@ public Response getSuivant( description = "Filtre pour préciser le departement de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -258,7 +274,7 @@ public Response getSuivant( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getNextDepartement(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getNextDepartement(code, this.formatValidParameterDateIfIsNull(dateString))), header, Departements.class, Departement.class); @@ -290,9 +306,12 @@ public Response getPrecedent( description = "Filtre pour préciser le departement de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -300,7 +319,7 @@ public Response getPrecedent( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getPreviousDepartement(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getPreviousDepartement(code, this.formatValidParameterDateIfIsNull(dateString))), header, Departements.class, Departement.class); @@ -332,14 +351,17 @@ public Response getProjection( description = "Filtre pour préciser le departement de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = "Date vers laquelle est projetée le departement. Paramètre obligatoire (Format : 'AAAA-MM-JJ', erreur 400 si absent)", required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection.getString())) { return this.generateBadRequestResponse(); } else { @@ -350,8 +372,8 @@ public Response getProjection( GeoQueries .getProjectionDepartement( code, - this.formatValidParameterDateIfIsNull(date), - dateProjection)), + this.formatValidParameterDateIfIsNull(dateString), + dateProjection.getString())), header, Departements.class, Departement.class); @@ -378,14 +400,21 @@ public Response getAllProjections( description = "Filtre pour préciser les departements de départ. Par défaut, c’est la date courante qui est utilisée.", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = "Date vers laquelle sont projetées les departements. Paramètre obligatoire (erreur 400 si absent)", required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { + String dateString = null; + String dateProjectionString = null; + if (date != null){ + dateString = date.getString(); + } + if (dateProjection != null){ + dateProjectionString = dateProjection.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjectionString)) { return this.generateBadRequestResponse(); } else { @@ -395,8 +424,8 @@ public Response getAllProjections( .executeSparqlQuery( GeoQueries .getAllProjectionDepartement( - this.formatValidParameterDateIfIsNull(date), - dateProjection)), + this.formatValidParameterDateIfIsNull(dateString), + dateProjectionString)), header); } } diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/DistrictApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/DistrictApi.java index 2dc582ce..7caaa74f 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/DistrictApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/DistrictApi.java @@ -15,6 +15,7 @@ import fr.insee.rmes.modeles.geo.territoire.District; import fr.insee.rmes.modeles.geo.territoire.Territoire; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -67,9 +68,12 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -77,7 +81,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getDistrictByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getDistrictByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new District(code)); } @@ -108,14 +112,17 @@ public Response getAscendants( description = "Filtre pour renvoyer les territoires contenant le district actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -126,7 +133,7 @@ public Response getAscendants( GeoQueries .getAscendantsDistrict( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/IntercommunaliteAPI.java b/src/main/java/fr/insee/rmes/api/geo/territoire/IntercommunaliteAPI.java index d556578b..f19caa4c 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/IntercommunaliteAPI.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/IntercommunaliteAPI.java @@ -16,6 +16,7 @@ import fr.insee.rmes.modeles.geo.territoire.Territoire; import fr.insee.rmes.modeles.geo.territoires.Intercommunalites; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -68,9 +69,9 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { + value = Constants.PARAMETER_DATE) Date date) { - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(date.getString())) { return this.generateBadRequestResponse(); } else { @@ -78,7 +79,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getIntercommunaliteByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getIntercommunaliteByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date.getString()))), header, new Intercommunalite(code)); } @@ -104,7 +105,7 @@ public Response getListe( description = "Filtre pour renvoyer les intercommunalités à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_NAME_DESCRIPTION, required = false, @@ -112,14 +113,14 @@ public Response getListe( value = Constants.PARAMETER_FILTRE) String filtreNom) { - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + if ( ! this.verifyParameterDateIsRightWithHistory(date.getString())) { return this.generateBadRequestResponse(); } else { return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListIntercommunalites(this.formatValidParameterDateIfIsNull(date), this.formatValidParameterFiltreIfIsNull(filtreNom))), + .executeSparqlQuery(GeoQueries.getListIntercommunalites(this.formatValidParameterDateIfIsNull(date.getString()), this.formatValidParameterFiltreIfIsNull(filtreNom))), header, Intercommunalites.class, Intercommunalite.class); @@ -151,9 +152,9 @@ public Response getAscendants( description = "Filtre pour renvoyer les informations concernant les intercommunalités qui précèdent l’intercommunalité à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { + value = Constants.PARAMETER_DATE) Date date) { - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(date.getString())) { return this.generateBadRequestResponse(); } else { @@ -164,7 +165,7 @@ public Response getAscendants( GeoQueries .getPreviousIntercommunalite( code, - this.formatValidParameterDateIfIsNull(date) + this.formatValidParameterDateIfIsNull(date.getString()) )), header, Intercommunalites.class, @@ -197,14 +198,14 @@ public Response getDescendants( description = "Filtre pour renvoyer les territoires inclus dans l'intercommunalité active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, example="Commune")) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date.getString())) { return this.generateBadRequestResponse(); } else { @@ -215,7 +216,7 @@ public Response getDescendants( GeoQueries .getDescendantsIntercommunalite( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(date.getString()), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -248,9 +249,9 @@ public Response getSuivant( description = "Filtre pour préciser l'intercommunalité de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { + value = Constants.PARAMETER_DATE) Date date) { - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(date.getString())) { return this.generateBadRequestResponse(); } else { @@ -258,7 +259,7 @@ public Response getSuivant( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getNextIntercommunalite(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getNextIntercommunalite(code, this.formatValidParameterDateIfIsNull(date.getString()))), header, Intercommunalites.class, Intercommunalite.class); @@ -291,14 +292,14 @@ public Response getProjection( description = "Filtre pour préciser l'intercommunalité de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = "Date vers laquelle est projetée l'intercommunalité. Paramètre obligatoire (Format : 'AAAA-MM-JJ', erreur 400 si absent)", required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example="2013-01-01")) @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + if ( ! this.verifyParameterDateIsRightWithoutHistory(date.getString()) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection.getString())) { return this.generateBadRequestResponse(); } else { @@ -309,8 +310,8 @@ public Response getProjection( GeoQueries .getProjectionIntercommunalite( code, - this.formatValidParameterDateIfIsNull(date), - dateProjection)), + this.formatValidParameterDateIfIsNull(date.getString()), + dateProjection.getString())), header, Intercommunalites.class, Intercommunalite.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/IrisApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/IrisApi.java index 3b44666b..65d9bf3a 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/IrisApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/IrisApi.java @@ -7,6 +7,7 @@ import fr.insee.rmes.modeles.geo.territoire.PseudoIris; import fr.insee.rmes.modeles.geo.territoire.Territoire; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.*; import io.swagger.v3.oas.annotations.Operation; @@ -71,20 +72,23 @@ public Response getByCode( @Parameter( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } var codeIris = CodeIris.of(code); if (codeIris.isInvalid()) { return generateBadRequestResponse(ConstGeoApi.ERREUR_PATTERN); } - if (!this.verifyParameterDateIsRightWithoutHistory(date)) { + if (!this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } return getResponseForIrisOrPseudoIris(codeIris, header, date); } - private Response getResponseForIrisOrPseudoIris(CodeIris codeIris, String header, String date) { + private Response getResponseForIrisOrPseudoIris(CodeIris codeIris, String header, Date date) { if (irisUtils.hasIrisDescendant(codeIris.codeCommune())) { return getResponseForIris(codeIris, header, date); } else { @@ -93,11 +97,15 @@ private Response getResponseForIrisOrPseudoIris(CodeIris codeIris, String header } - private Response getResponseForPseudoIris(CodeIris codeIris, String header, String date) { + private Response getResponseForPseudoIris(CodeIris codeIris, String header, Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } if (codeIris.isPseudoIrisCode()) { return this.generateResponseATerritoireByCode( sparqlUtils.executeSparqlQuery( - GeoQueries.getIrisByCodeAndDate(codeIris.code(), this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getIrisByCodeAndDate(codeIris.code(), this.formatValidParameterDateIfIsNull(dateString))), header, new PseudoIris(codeIris.code())); } else { @@ -105,14 +113,18 @@ private Response getResponseForPseudoIris(CodeIris codeIris, String header, Stri } } - private Response getResponseForIris(CodeIris codeIris, String header, String date) { + private Response getResponseForIris(CodeIris codeIris, String header, Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } if (codeIris.isPseudoIrisCode()) { return Response.status(Response.Status.NOT_FOUND).entity("").build(); } else { Territoire territoire = new Iris(codeIris.code()); return this.generateResponseATerritoireByCode( sparqlUtils.executeSparqlQuery( - GeoQueries.getIrisByCodeAndDate(codeIris.code(), this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getIrisByCodeAndDate(codeIris.code(), this.formatValidParameterDateIfIsNull(dateString))), header, territoire); } @@ -137,21 +149,24 @@ public Response getListe( @Parameter( description = "Filtre pour renvoyer les Iris ou faux-Iris à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter(description = "les Iris (et pseudo-iris) des collectivités d'outre-mer", required = true, schema = @Schema(type = Constants.TYPE_BOOLEAN, allowableValues = {"true", "false"}, example = "false", defaultValue = "false")) @QueryParam( value = Constants.PARAMETER_STRING) Boolean com ) { - - if (!this.verifyParameterDateIsRightWithHistory(date)) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if (!this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListIris(this.formatValidParameterDateIfIsNull(date), this.formatValidParameterBooleanIfIsNull(com))), + .executeSparqlQuery(GeoQueries.getListIris(this.formatValidParameterDateIfIsNull(dateString), this.formatValidParameterBooleanIfIsNull(com))), header, Territoires.class, Territoire.class); @@ -183,13 +198,16 @@ public Response getAscendants( @Parameter( description = "Filtre pour renvoyer les territoires contenant l'iris actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if (!this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if (!this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { return this @@ -199,7 +217,7 @@ public Response getAscendants( GeoQueries .getAscendantsIris( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/RegionApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/RegionApi.java index 00e2af6d..5bab041c 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/RegionApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/RegionApi.java @@ -17,6 +17,7 @@ import fr.insee.rmes.modeles.geo.territoires.Projections; import fr.insee.rmes.modeles.geo.territoires.Regions; import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Hidden; @@ -68,9 +69,12 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -78,7 +82,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getRegionByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getRegionByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new Region(code)); } @@ -109,7 +113,7 @@ public Response getDescendants( description = "Filtre pour renvoyer les territoires inclus dans la région active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, @@ -120,8 +124,11 @@ public Response getDescendants( required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( value = Constants.PARAMETER_FILTRE) String filtreNom) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -132,7 +139,7 @@ public Response getDescendants( GeoQueries .getDescendantsRegion( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire),this.formatValidParameterFiltreIfIsNull(filtreNom))), header, Territoires.class, @@ -159,9 +166,12 @@ public Response getListe( description = "Filtre pour renvoyer les régions actives à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -169,7 +179,7 @@ public Response getListe( return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListRegions(this.formatValidParameterDateIfIsNull(date))), + .executeSparqlQuery(GeoQueries.getListRegions(this.formatValidParameterDateIfIsNull(dateString))), header, Regions.class, Region.class); @@ -201,9 +211,12 @@ public Response getSuivant( description = "Filtre pour préciser la region de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -211,7 +224,7 @@ public Response getSuivant( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getNextRegion(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getNextRegion(code, this.formatValidParameterDateIfIsNull(dateString))), header, Regions.class, Region.class); @@ -243,9 +256,12 @@ public Response getPrecedent( description = "Filtre pour préciser la region de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -253,7 +269,7 @@ public Response getPrecedent( .generateResponseListOfTerritoire( sparqlUtils .executeSparqlQuery( - GeoQueries.getPreviousRegion(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getPreviousRegion(code, this.formatValidParameterDateIfIsNull(dateString))), header, Regions.class, Region.class); @@ -285,14 +301,21 @@ public Response getProjection( description = "Filtre pour préciser la region de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = "Date vers laquelle est projetée la region. Paramètre obligatoire (Format : 'AAAA-MM-JJ', erreur 400 si absent)", required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { + String dateString = null; + String dateProjectionString = null; + if (date != null){ + dateString = date.getString(); + } + if (dateProjection != null){ + dateProjectionString = dateProjection.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjectionString) ) { return this.generateBadRequestResponse(); } else { @@ -303,8 +326,8 @@ public Response getProjection( GeoQueries .getProjectionRegion( code, - this.formatValidParameterDateIfIsNull(date), - dateProjection)), + this.formatValidParameterDateIfIsNull(dateString), + dateProjectionString)), header, Regions.class, Region.class); @@ -331,14 +354,21 @@ public Response getAllProjections( description = "Filtre pour préciser les régions de départ. Par défaut, c’est la date courante qui est utilisée.", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = "Date vers laquelle sont projetées les régions. Paramètre obligatoire (erreur 400 si absent)", required = true, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE_PROJECTION) String dateProjection) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjection)) { + value = Constants.PARAMETER_DATE_PROJECTION) Date dateProjection) { + String dateString = null; + String dateProjectionString = null; + if (date != null){ + dateString = date.getString(); + } + if (dateProjection != null){ + dateProjectionString = dateProjection.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString) || ! this.verifyParameterDateIsRightWithoutHistory(dateProjectionString)) { return this.generateBadRequestResponse(); } else { @@ -347,7 +377,7 @@ public Response getAllProjections( sparqlUtils .executeSparqlQuery( GeoQueries - .getAllProjectionRegion(this.formatValidParameterDateIfIsNull(date), dateProjection)), + .getAllProjectionRegion(this.formatValidParameterDateIfIsNull(dateString), dateProjectionString)), header); } } diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/UniteUrbaineApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/UniteUrbaineApi.java index 58083ff1..42e919c3 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/UniteUrbaineApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/UniteUrbaineApi.java @@ -16,6 +16,7 @@ import fr.insee.rmes.modeles.geo.territoire.UniteUrbaine2020; import fr.insee.rmes.modeles.geo.territoires.Territoires; import fr.insee.rmes.modeles.geo.territoires.UnitesUrbaines2020; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -68,9 +69,12 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -78,7 +82,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getUniteUrbaineByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getUniteUrbaineByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new UniteUrbaine2020(code)); } @@ -109,14 +113,17 @@ public Response getDescendants( description = "Filtre pour renvoyer les territoires inclus dans l'unité urbaine active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, example="ArrondissementMunicipal")) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -127,7 +134,7 @@ public Response getDescendants( GeoQueries .getDescendantsUniteUrbaine( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -154,16 +161,19 @@ public Response getListe( description = "Filtre pour renvoyer les unités urbaines actives à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListUnitesUrbaines(this.formatValidParameterDateIfIsNull(date))), + .executeSparqlQuery(GeoQueries.getListUnitesUrbaines(this.formatValidParameterDateIfIsNull(dateString))), header, UnitesUrbaines2020.class, UniteUrbaine2020.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/ZoneEmploiApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/ZoneEmploiApi.java index 53b421f0..ccd3fc86 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/ZoneEmploiApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/ZoneEmploiApi.java @@ -16,6 +16,7 @@ import fr.insee.rmes.modeles.geo.territoire.ZoneDEmploi2020; import fr.insee.rmes.modeles.geo.territoires.Territoires; import fr.insee.rmes.modeles.geo.territoires.ZonesDEmploi2020; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -66,9 +67,12 @@ public Response getByCode( description = LITTERAL_PARAMETER_DATE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) { return this.generateBadRequestResponse(); } else { @@ -76,7 +80,7 @@ public Response getByCode( .generateResponseATerritoireByCode( sparqlUtils .executeSparqlQuery( - GeoQueries.getZoneEmploiByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + GeoQueries.getZoneEmploiByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))), header, new ZoneDEmploi2020(code)); } @@ -107,14 +111,17 @@ public Response getDescendants( description = "Filtre pour renvoyer les territoires inclus dans la zone d'emploi active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date, + value = Constants.PARAMETER_DATE) Date date, @Parameter( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, example="ArrondissementMunicipal")) @QueryParam( value = Constants.PARAMETER_TYPE) String typeTerritoire) { - - if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, dateString)) { return this.generateBadRequestResponse(); } else { @@ -125,7 +132,7 @@ public Response getDescendants( GeoQueries .getDescendantsZoneEmploi( code, - this.formatValidParameterDateIfIsNull(date), + this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), header, Territoires.class, @@ -152,16 +159,19 @@ public Response getListe( description = "Filtre pour renvoyer les zones d'emploi actives à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY, required = false, schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam( - value = Constants.PARAMETER_DATE) String date) { - - if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + value = Constants.PARAMETER_DATE) Date date) { + String dateString = null; + if (date != null){ + dateString = date.getString(); + } + if ( ! this.verifyParameterDateIsRightWithHistory(dateString)) { return this.generateBadRequestResponse(); } else { return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListZonesEmploi(this.formatValidParameterDateIfIsNull(date))), + .executeSparqlQuery(GeoQueries.getListZonesEmploi(this.formatValidParameterDateIfIsNull(dateString))), header, ZonesDEmploi2020.class, ZoneDEmploi2020.class); diff --git a/src/main/java/fr/insee/rmes/modeles/utils/Date.java b/src/main/java/fr/insee/rmes/modeles/utils/Date.java new file mode 100644 index 00000000..3247cebf --- /dev/null +++ b/src/main/java/fr/insee/rmes/modeles/utils/Date.java @@ -0,0 +1,24 @@ +package fr.insee.rmes.modeles.utils; + +public class Date { + + private String date; + + public Date(String date) { + if (date == null){ + this.date = null; + } + else{ + this.date = date; + } + } + + public String getString() { + if (date != null && !date.isEmpty()) { + return date; + } + else{ + return null; //without this it might cause some trouble to test with new Date(null) + } + } +} diff --git a/src/test/java/fr/insee/rmes/api/classifications/CodesAPITest.java b/src/test/java/fr/insee/rmes/api/classifications/CodesAPITest.java index c4dd8be5..63e8ca5e 100644 --- a/src/test/java/fr/insee/rmes/api/classifications/CodesAPITest.java +++ b/src/test/java/fr/insee/rmes/api/classifications/CodesAPITest.java @@ -8,6 +8,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -107,10 +108,10 @@ void givenGetCategoriesJuridiques_whenCorrectRequest_thenResponseIsOk() { codesAPI.getCategoriesJuridiques("", null, MediaType.APPLICATION_JSON); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); - codesAPI.getCategoriesJuridiques("", "*", MediaType.APPLICATION_JSON); + codesAPI.getCategoriesJuridiques("", new Date("*"), MediaType.APPLICATION_JSON); verify(mockResponseUtils, times(2)).produceResponse(Mockito.any(), Mockito.any()); - codesAPI.getCategoriesJuridiques("", "2010-10-10", MediaType.APPLICATION_JSON); + codesAPI.getCategoriesJuridiques("", new Date("2010-10-10"), MediaType.APPLICATION_JSON); verify(mockResponseUtils, times(3)).produceResponse(Mockito.any(), Mockito.any()); codesAPI.getCategoriesJuridiques("", null, MediaType.APPLICATION_XML); @@ -138,7 +139,7 @@ void givenGetCategoriesJuridiques_whenCorrectRequest_andCJNotFound_thenResponseI @Test void givenGetCategoriesJuridiques_whenBadRequest_thenResponseIsBadRequest() { // Call method - Response response = codesAPI.getCategoriesJuridiques("", "1234", MediaType.APPLICATION_JSON); + Response response = codesAPI.getCategoriesJuridiques("", new Date("1234"), MediaType.APPLICATION_JSON); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -294,10 +295,10 @@ void givenGetActivities_whenCorrectRequest_thenResponseIsOk() { codesAPI.getActivities("", null, MediaType.APPLICATION_JSON); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); - codesAPI.getActivities("", "*", MediaType.APPLICATION_JSON); + codesAPI.getActivities("", new Date("*"), MediaType.APPLICATION_JSON); verify(mockResponseUtils, times(2)).produceResponse(Mockito.any(), Mockito.any()); - codesAPI.getActivities("", "2010-10-10", MediaType.APPLICATION_JSON); + codesAPI.getActivities("", new Date("2010-10-10"), MediaType.APPLICATION_JSON); verify(mockResponseUtils, times(3)).produceResponse(Mockito.any(), Mockito.any()); codesAPI.getActivities("", null, MediaType.APPLICATION_XML); @@ -321,7 +322,7 @@ void givenGetActivities_whenCorrectRequest_andNotFound_thenResponseIsNotFound() @Test void givenGetActivities_whenBadRequest_thenResponseIsBadRequest() { // Call method - Response response = codesAPI.getActivities("", "1234", MediaType.APPLICATION_JSON); + Response response = codesAPI.getActivities("", new Date("1234"), MediaType.APPLICATION_JSON); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/ArrondissementApiIntegrationTest.java b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/ArrondissementApiIntegrationTest.java index dd5d2d7b..f81c3627 100644 --- a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/ArrondissementApiIntegrationTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/ArrondissementApiIntegrationTest.java @@ -8,6 +8,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -127,7 +128,7 @@ public void givengetPrecedentsArrondissements_whenCorrectRequest_With_XML_Header public void givengetSuivantsArrondissements_whenCorrectRequest_With_JSON_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.ARRONDISSEMENT_MOCK_SERVER_RETURN_PRECEDENTS); - Response response = geoApi.getSuivant(CODE_SUIVANT, MediaType.APPLICATION_JSON, "1943-01-01"); + Response response = geoApi.getSuivant(CODE_SUIVANT, MediaType.APPLICATION_JSON, new Date("1943-01-01")); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEquals(ConstantForIntegration.ARRONDISSEMENT_EXPECTED_RESPONSE_SUIVANTS_JSON, response.getEntity()); } @@ -136,7 +137,7 @@ public void givengetSuivantsArrondissements_whenCorrectRequest_With_JSON_Header_ public void givengetSuivantsArrondissements_whenCorrectRequest_With_XML_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.ARRONDISSEMENT_MOCK_SERVER_RETURN_PRECEDENTS); - Response response = geoApi.getSuivant(CODE_SUIVANT, MediaType.APPLICATION_XML, "1943-01-01"); + Response response = geoApi.getSuivant(CODE_SUIVANT, MediaType.APPLICATION_XML, new Date("1943-01-01")); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEquals(ConstantForIntegration.ARRONDISSEMENT_EXPECTED_RESPONSE_SUIVANTS_XML, response.getEntity()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/ArrondissementMunicipalApiIntegrationTest.java b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/ArrondissementMunicipalApiIntegrationTest.java index 60b397af..93f4828b 100644 --- a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/ArrondissementMunicipalApiIntegrationTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/ArrondissementMunicipalApiIntegrationTest.java @@ -1,6 +1,7 @@ package fr.insee.rmes.api.geo.pseudointegrationtest; import fr.insee.rmes.api.geo.territoire.ArrondissementMunicipalApi; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.utils.SparqlUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -108,7 +109,7 @@ public void givengetPrecedentsArrondissementMunicipals_whenCorrectRequest_With_J public void givengetPrecedentsArrondissementMunicipals_whenCorrectRequest_With_XML_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.ARRONDISSEMENT_MUNICIPAL_MOCK_SERVER_RETURN_PRECEDENTS); - Response response = geoApi.getPrecedent(CODE_SUIV_OU_PREC, MediaType.APPLICATION_XML, "1943-01-01"); + Response response = geoApi.getPrecedent(CODE_SUIV_OU_PREC, MediaType.APPLICATION_XML, new Date("1943-01-01")); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEquals( ConstantForIntegration.ARRONDISSEMENT_MUNICIPAL_EXPECTED_RESPONSE_PRECEDENTS_XML, @@ -120,7 +121,7 @@ public void givengetPrecedentsArrondissementMunicipals_whenCorrectRequest_With_X public void givengetSuivantsArrondissementMunicipals_whenCorrectRequest_With_JSON_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.ARRONDISSEMENT_MUNICIPAL_MOCK_SERVER_RETURN_PRECEDENTS); - Response response = geoApi.getSuivant(CODE_SUIV_OU_PREC, MediaType.APPLICATION_JSON, "1943-01-01"); + Response response = geoApi.getSuivant(CODE_SUIV_OU_PREC, MediaType.APPLICATION_JSON,new Date("1943-01-01")); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEquals( ConstantForIntegration.ARRONDISSEMENT_MUNICIPAL_EXPECTED_RESPONSE_SUIVANTS_JSON, diff --git a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/CantonApiIntegrationTest.java b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/CantonApiIntegrationTest.java index 2475c0f8..0f561763 100644 --- a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/CantonApiIntegrationTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/CantonApiIntegrationTest.java @@ -1,6 +1,7 @@ package fr.insee.rmes.api.geo.pseudointegrationtest; import fr.insee.rmes.api.geo.territoire.CantonAPI; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.utils.SparqlUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -53,7 +54,7 @@ void givengetCanton_whenCorrectRequest_With_JSON_Header_thenResponseIsOk() { @ParameterizedTest(name = "{0} - {2} : {4}") @MethodSource("argumentProvider") - void test_getCommunes(String titre, String sparqlResult, String media, String date, Status status, String expected) { + void test_getCommunes(String titre, String sparqlResult, String media, Date date, Status status, String expected) { lenient().when(mockSparqlUtils.executeSparqlQuery(anyString())).thenReturn(sparqlResult); Response response = geoApi.getCommunes(CODE, media, date); Assertions.assertEquals(status.getStatusCode(), response.getStatus()); diff --git a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/CommuneApiIntegrationTest.java b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/CommuneApiIntegrationTest.java index cf7b4e87..5fd68048 100644 --- a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/CommuneApiIntegrationTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/CommuneApiIntegrationTest.java @@ -1,6 +1,7 @@ package fr.insee.rmes.api.geo.pseudointegrationtest; import fr.insee.rmes.api.geo.territoire.CommuneApi; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.utils.SparqlUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -126,7 +127,7 @@ void givengetPrecedentsCommunes_whenCorrectRequest_With_XML_Header_thenResponseI void givengetSuivantsCommunes_whenCorrectRequest_With_JSON_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.COMMUNE_MOCK_SERVER_RETURN_SUIVANTS); - Response response = geoApi.getSuivant(CODE_SUIVANT, MediaType.APPLICATION_JSON, "1973-01-01"); + Response response = geoApi.getSuivant(CODE_SUIVANT, MediaType.APPLICATION_JSON, new Date("1973-01-01")); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEqualsJson(ConstantForIntegration.COMMUNE_EXPECTED_RESPONSE_SUIVANTS_JSON, response.getEntity()); } @@ -135,7 +136,7 @@ void givengetSuivantsCommunes_whenCorrectRequest_With_JSON_Header_thenResponseIs void givengetSuivantsCommunes_whenCorrectRequest_With_XML_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.COMMUNE_MOCK_SERVER_RETURN_PRECEDENTS); - Response response = geoApi.getSuivant(CODE_SUIVANT, MediaType.APPLICATION_XML, "1973-01-01"); + Response response = geoApi.getSuivant(CODE_SUIVANT, MediaType.APPLICATION_XML, new Date("1973-01-01")); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEqualsXml(ConstantForIntegration.COMMUNE_EXPECTED_RESPONSE_PRECEDENTS_XML, response.getEntity()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/ConstantForIntegration.java b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/ConstantForIntegration.java index d4e193f6..d425b57e 100644 --- a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/ConstantForIntegration.java +++ b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/ConstantForIntegration.java @@ -1,6 +1,7 @@ package fr.insee.rmes.api.geo.pseudointegrationtest; import com.fasterxml.jackson.databind.ObjectMapper; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.opentest4j.AssertionFailedError; import org.xml.sax.SAXException; @@ -846,7 +847,7 @@ private interface ReaderThrowing { } public interface GetWithCodeAndDate { - Response get(String code, String mediaType, String date); + Response get(String code, String mediaType, Date date); } diff --git a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/DepartementApiIntegrationTest.java b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/DepartementApiIntegrationTest.java index 72baa111..0fbf5c30 100644 --- a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/DepartementApiIntegrationTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/DepartementApiIntegrationTest.java @@ -8,6 +8,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -126,7 +127,7 @@ public void givengetPrecedentsDepartements_whenCorrectRequest_With_XML_Header_th public void givengetSuivantsDepartements_whenCorrectRequest_With_JSON_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.DEPARTEMENT_MOCK_SERVER_RETURN_SUIVANTS); - Response response = geoApi.getSuivant(CODE_PREC_OR_SUIV, MediaType.APPLICATION_JSON, "1943-01-01"); + Response response = geoApi.getSuivant(CODE_PREC_OR_SUIV, MediaType.APPLICATION_JSON, new Date("1973-01-01")); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEquals(ConstantForIntegration.DEPARTEMENT_EXPECTED_RESPONSE_SUIVANTS_JSON, response.getEntity()); } @@ -135,7 +136,7 @@ public void givengetSuivantsDepartements_whenCorrectRequest_With_JSON_Header_the public void givengetSuivantsDepartements_whenCorrectRequest_With_XML_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.DEPARTEMENT_MOCK_SERVER_RETURN_SUIVANTS); - Response response = geoApi.getSuivant(CODE_PREC_OR_SUIV, MediaType.APPLICATION_XML, "1943-01-01"); + Response response = geoApi.getSuivant(CODE_PREC_OR_SUIV, MediaType.APPLICATION_XML, new Date("1973-01-01")); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEquals(ConstantForIntegration.DEPARTEMENT_EXPECTED_RESPONSE_SUIVANTS_XML, response.getEntity()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/AireAttractionAPITest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/AireAttractionAPITest.java index c26e409c..8d60f0cb 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/AireAttractionAPITest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/AireAttractionAPITest.java @@ -3,6 +3,7 @@ import fr.insee.rmes.api.AbstractApiTest; import fr.insee.rmes.modeles.geo.EnumTypeGeographie; import fr.insee.rmes.modeles.geo.territoire.AireDAttractionDesVilles2020; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -79,7 +80,7 @@ void givenGetAireAttraction_WhenCorrectRequest_thenParameterDateIsRight() { this.mockUtilsMethodsThenReturnOnePojo(aireDAttractionDesVilles2020, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("1973-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -87,7 +88,7 @@ void givenGetAireAttraction_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetAireAttraction_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -144,7 +145,7 @@ void givenGetAireAttractionDescendants_WhenCorrectRequest_thenParameterDateIsRig list.add(new AireDAttractionDesVilles2020()); // Call method header content = xml - geoApi.getDescendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("1973-01-01"), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -152,7 +153,7 @@ void givenGetAireAttractionDescendants_WhenCorrectRequest_thenParameterDateIsRig void givenGetAireAttractionDescendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -241,7 +242,7 @@ void givenGetListeAireAttraction_WhenCorrectRequest_thenResponseIsNotFound() { @ParameterizedTest @ValueSource(strings = {"2000-01-01", "*"}) - @NullSource //default = current day + @NullSource void givenGetListeAireAttraction_WhenCorrectRequest_thenParameterDateIsRight(String date) { // Mock methods @@ -249,7 +250,7 @@ void givenGetListeAireAttraction_WhenCorrectRequest_thenParameterDateIsRight(Str list.add(new AireDAttractionDesVilles2020()); // Call method header content = xml - geoApi.getListe(MediaType.APPLICATION_XML, date); + geoApi.getListe(MediaType.APPLICATION_XML, new Date(date)); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -257,7 +258,7 @@ void givenGetListeAireAttraction_WhenCorrectRequest_thenParameterDateIsRight(Str void givenGetListeAireAttraction_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getListe(MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getListe(MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/ArrondissementApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/ArrondissementApiTest.java index 13f3b31d..eb3721af 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/ArrondissementApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/ArrondissementApiTest.java @@ -8,6 +8,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -77,7 +78,7 @@ void givenGetArrondissement_WhenCorrectRequest_thenParameterDateIsRight() { this.mockUtilsMethodsThenReturnOnePojo(arrondissement, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("1973-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -85,7 +86,7 @@ void givenGetArrondissement_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetArrondissement_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -138,7 +139,7 @@ void givenGetArrondissementAscendants_WhenCorrectRequest_thenParameterDateIsRigh list.add(new Arrondissement()); // Call method header content = xml - geoApi.getAscendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("1973-01-01"), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -146,7 +147,7 @@ void givenGetArrondissementAscendants_WhenCorrectRequest_thenParameterDateIsRigh void givenGetArrondissementAscendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getAscendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -230,7 +231,7 @@ void givenGetListeArrondissement_WhenCorrectRequest_thenResponseIsNotFound() { @ParameterizedTest @ValueSource(strings = {"2000-01-01", "*"}) - @NullSource //default = current day + @NullSource void givenGetListeArrondissement_WhenCorrectRequest_thenParameterDateIsRight(String date) { // Mock methods @@ -238,7 +239,7 @@ void givenGetListeArrondissement_WhenCorrectRequest_thenParameterDateIsRight(Str list.add(new Arrondissement()); // Call method header content = xml - geoApi.getListe(MediaType.APPLICATION_XML, date); + geoApi.getListe(MediaType.APPLICATION_XML, new Date(date)); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -246,7 +247,7 @@ void givenGetListeArrondissement_WhenCorrectRequest_thenParameterDateIsRight(Str void givenGetListeArrondissement_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getListe(MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getListe(MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -299,7 +300,7 @@ void givenGetArrondissementDescendants_WhenCorrectRequest_thenParameterDateIsRig list.add(new Arrondissement()); // Call method header content = xml - geoApi.getDescendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("1973-01-01"), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -307,7 +308,7 @@ void givenGetArrondissementDescendants_WhenCorrectRequest_thenParameterDateIsRig void givenGetArrondissementDescendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -397,7 +398,7 @@ void givenGetArrondissementSuivant_WhenCorrectRequest_thenParameterDateIsRight() list.add(new Arrondissement()); // Call method header content = xml - geoApi.getSuivant("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getSuivant("something", MediaType.APPLICATION_XML, new Date("1973-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -405,7 +406,7 @@ void givenGetArrondissementSuivant_WhenCorrectRequest_thenParameterDateIsRight() void givenGetArrondissementSuivant_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getSuivant("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getSuivant("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -458,7 +459,7 @@ void givenGetArrondissementPrecedent_WhenCorrectRequest_thenParameterDateIsRight list.add(new Arrondissement()); // Call method header content = xml - geoApi.getPrecedent("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getPrecedent("something", MediaType.APPLICATION_XML, new Date("1973-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -466,7 +467,7 @@ void givenGetArrondissementPrecedent_WhenCorrectRequest_thenParameterDateIsRight void givenGetArrondissementPrecedent_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getPrecedent("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getPrecedent("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -478,7 +479,7 @@ void givenGetArrondissementProjetes_whenCorrectRequest_andHeaderContentIsJson_th list.add(new Arrondissement()); // Call method - geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, new Date("1973-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -490,7 +491,7 @@ void givenGetArrondissementProjetes_whenCorrectRequest_andHeaderContentIsXml_the list.add(new Arrondissement()); // Call method - geoApi.getProjection("something", MediaType.APPLICATION_XML, null, "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, null, new Date("1973-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -501,11 +502,11 @@ void givenGetArrondissementProjetes_WhenCorrectRequest_thenResponseIsNotFound() this.mockUtilsMethodsThenReturnListOfPojo(Boolean.FALSE); // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, "2019-01-01"); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, new Date("1973-01-01")); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); // Call method header content = json - response = geoApi.getProjection("something", MediaType.APPLICATION_XML, null, "2019-01-01"); + response = geoApi.getProjection("something", MediaType.APPLICATION_XML, null, new Date("1973-01-01")); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); @@ -519,7 +520,7 @@ void givenGetArrondissementProjetes_WhenCorrectRequest_thenParameterDateIsRight( list.add(new Arrondissement()); // Call method header content = xml - geoApi.getProjection("something", MediaType.APPLICATION_XML, "2000-01-01", "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -529,7 +530,7 @@ void givenGetArrondissementProjetes_WhenCorrectRequest_thenParameterDateIsRight( void givenGetArrondissementProjetes_WhenCorrectRequest_thenParameterDateIsBad(String date) { // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, "nimportequoi", date); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), new Date(date)); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -540,7 +541,7 @@ void givenGetArrondissementProjetes_WhenCorrectRequest_thenParameterDateProjeteI list.add(new Arrondissement()); // Call method header content = xml - geoApi.getProjection("something", MediaType.APPLICATION_XML, "2000-01-01", "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/ArrondissementMunicipalApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/ArrondissementMunicipalApiTest.java index 15ffdf1a..c466144c 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/ArrondissementMunicipalApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/ArrondissementMunicipalApiTest.java @@ -8,6 +8,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -79,7 +80,7 @@ void givenGetArrondissement_WhenCorrectRequest_thenParameterDateIsRight() { this.mockUtilsMethodsThenReturnOnePojo(arrondissement, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("1973-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -87,7 +88,7 @@ void givenGetArrondissement_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetArrondissement_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -130,7 +131,7 @@ void givenGetArrondissementMunicipalAscendants_WhenCorrectRequest_thenParameterD list.add(new ArrondissementMunicipal()); // Call method header content = xml - geoApi.getAscendants("something", MediaType.APPLICATION_XML, date , null); + geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date(date) , null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -138,7 +139,7 @@ void givenGetArrondissementMunicipalAscendants_WhenCorrectRequest_thenParameterD @ValueSource(strings = {"*", "nimportequoi"}) void givenGetArrondissementMunicipalAscendants_WhenCorrectRequest_thenParameterDateIsBad(String date) { // Call method header content = xml - Response response = geoApi.getAscendants("something", MediaType.APPLICATION_XML, date, null); + Response response = geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date(date), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -154,7 +155,7 @@ void givenGetArrondissementMunicipalAscendants_WhenCorrectRequest_thenParameterT .getAscendants( "something", MediaType.APPLICATION_XML, - null, + null, EnumTypeGeographie.ARRONDISSEMENT.getTypeObjetGeo()); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -210,7 +211,7 @@ void givenGetListeArrondissementMunicipal_WhenCorrectRequest_thenResponseIsNotFo @ParameterizedTest @ValueSource(strings = {"2000-01-01", "*"}) - @NullSource //default = current day + @NullSource void givenGetListeArrondissementMunicipal_WhenCorrectRequest_thenParameterDateIsRight(String date) { // Mock methods @@ -218,7 +219,7 @@ void givenGetListeArrondissementMunicipal_WhenCorrectRequest_thenParameterDateIs list.add(new ArrondissementMunicipal()); // Call method header content = xml - geoApi.getListe(MediaType.APPLICATION_XML, date); + geoApi.getListe(MediaType.APPLICATION_XML, new Date(date)); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -227,7 +228,7 @@ void givenGetListeArrondissementMunicipal_WhenCorrectRequest_thenParameterDateIs void givenGetListeArrondissementMunicipal_WhenCorrectRequest_thenParameterDateIsBad(String date) { // Call method header content = xml - Response response = geoApi.getListe(MediaType.APPLICATION_XML, date); + Response response = geoApi.getListe(MediaType.APPLICATION_XML, new Date(date)); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -280,7 +281,7 @@ void givenGetArrondissementMunicipalSuivant_WhenCorrectRequest_thenParameterDate list.add(new ArrondissementMunicipal()); // Call method header content = xml - geoApi.getSuivant("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getSuivant("something", MediaType.APPLICATION_XML, new Date("1973-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -288,7 +289,7 @@ void givenGetArrondissementMunicipalSuivant_WhenCorrectRequest_thenParameterDate void givenGetArrondissementMunicipalSuivant_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getSuivant("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getSuivant("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -341,7 +342,7 @@ void givenGetArrondissementMunicipalPrecedent_WhenCorrectRequest_thenParameterDa list.add(new ArrondissementMunicipal()); // Call method header content = xml - geoApi.getPrecedent("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getPrecedent("something", MediaType.APPLICATION_XML, new Date("1973-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -349,7 +350,7 @@ void givenGetArrondissementMunicipalPrecedent_WhenCorrectRequest_thenParameterDa void givenGetArrondissementMunicipalPrecedent_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getPrecedent("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getPrecedent("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -361,13 +362,12 @@ void givenGetArrondissementMunicipalProjetes_whenCorrectRequest_andHeaderContent list.add(new ArrondissementMunicipal()); // Call method - geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, new Date("1973-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @ParameterizedTest @ValueSource(strings = {"2000-01-01"}) - @NullSource void givenGetArrondissementMunicipalProjetes_whenCorrectRequest_andHeaderContentIsXml_thenResponseIsOk(String date) { // Mock methods @@ -375,7 +375,7 @@ void givenGetArrondissementMunicipalProjetes_whenCorrectRequest_andHeaderContent list.add(new ArrondissementMunicipal()); // Call method - geoApi.getProjection("something", MediaType.APPLICATION_XML, date, "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("1973-01-01"), new Date(date)); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -386,11 +386,11 @@ void givenGetArrondissementMunicipalProjetes_WhenCorrectRequest_thenResponseIsNo this.mockUtilsMethodsThenReturnListOfPojo(Boolean.FALSE); // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, "2019-01-01"); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, new Date("1973-01-01")); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); // Call method header content = json - response = geoApi.getProjection("something", MediaType.APPLICATION_XML, null, "2019-01-01"); + response = geoApi.getProjection("something", MediaType.APPLICATION_XML, null, new Date("1973-01-01")); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); @@ -401,7 +401,7 @@ void givenGetArrondissementMunicipalProjetes_WhenCorrectRequest_thenResponseIsNo void givenGetArrondissementMunicipalProjetes_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, "nimportequoi", "2019-01-01"); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), new Date("2019-01-01")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -412,7 +412,7 @@ void givenGetArrondissementMunicipalProjetes_WhenCorrectRequest_thenParameterDat list.add(new ArrondissementMunicipal()); // Call method header content = xml - geoApi.getProjection("something", MediaType.APPLICATION_XML, "2000-01-01", "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), new Date("2010-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -421,7 +421,7 @@ void givenGetArrondissementMunicipalProjetes_WhenCorrectRequest_thenParameterDat // Call method header content = xml Response response = - geoApi.getProjection("something", MediaType.APPLICATION_XML, "2000-05-05", "nimportequoi"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("1973-01-01"), new Date("blabla")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -429,7 +429,7 @@ void givenGetArrondissementMunicipalProjetes_WhenCorrectRequest_thenParameterDat void givenGetArrondissementMunicipalProjetes_WhenCorrectRequest_thenParameterDateProjeteIsNull() { // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("2010-01-01"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/CantonAPITest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/CantonAPITest.java index c62b664d..52af86d4 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/CantonAPITest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/CantonAPITest.java @@ -3,6 +3,7 @@ import fr.insee.rmes.api.AbstractApiTest; import fr.insee.rmes.api.geo.pseudointegrationtest.ConstantForIntegration.GetWithCodeAndDate; import fr.insee.rmes.modeles.geo.territoire.Canton; +import fr.insee.rmes.modeles.utils.Date; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -38,12 +39,11 @@ class CantonAPITest extends AbstractApiTest { private final String codeCantonCorrect="1234"; - public Stream getWithCodeAndDatefactory() { + public Stream getWithCodeAndDateFactory() { Stream gets = Stream.of(geoApiSansMock::getByCode, geoApiSansMock::getSuivant, geoApiSansMock::getCommunes, geoApiSansMock::getPrecedent ); var intermediare= merge(gets, List.of(APPLICATION_XML, APPLICATION_JSON), Pair::of ); - return merge(intermediare, Arrays.asList(null, "mauvaiseDate", "1982-07-19"), (pair, d)->Arguments.of(pair.getLeft(), pair.getRight(), d)); + return merge(intermediare, Arrays.asList(null, new Date("mauvaiseDate"), new Date("1982-07-19")), (pair, d)->Arguments.of(pair.getLeft(), pair.getRight(), d)); } - @ParameterizedTest @ValueSource(strings = {APPLICATION_XML, MediaType.APPLICATION_JSON}) void givenGetCanton_whenCorrectRequestt_thenResponseIsOk(String mediaType) { @@ -58,12 +58,12 @@ void givenGetCanton_whenCorrectRequestt_thenResponseIsOk(String mediaType) { } @ParameterizedTest - @MethodSource("getWithCodeAndDatefactory") - void givenAllGetsWithCodeAndDate_whenIncorrectCode_thenResponseIsKo(GetWithCodeAndDate getWithCodeAndDate, String mediaType, String date) { + @MethodSource("getWithCodeAndDateFactory") + void givenAllGetsWithCodeAndDate_whenIncorrectCode_thenResponseIsKo(GetWithCodeAndDate getWithCodeAndDate, String mediaType, Date date) { // Call method String codeCantonIncorrect = "something"; - var response=getWithCodeAndDate.get(codeCantonIncorrect, mediaType, date); + var response=getWithCodeAndDate.get(codeCantonIncorrect, mediaType,date); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); } @@ -76,7 +76,7 @@ void givenGetCanton_WhenCorrectRequest_thenParameterDateIsRight() { this.mockUtilsMethodsThenReturnOnePojo(canton, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode(codeCantonCorrect, APPLICATION_XML, "2000-01-01"); + geoApi.getByCode(codeCantonCorrect, APPLICATION_XML, new Date("2010-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -84,7 +84,7 @@ void givenGetCanton_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetCanton_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode(codeCantonCorrect, APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode(codeCantonCorrect, APPLICATION_XML, new Date("nimportequoi")); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -124,7 +124,6 @@ void givenGetListeCanton_WhenCorrectRequest_thenResponseIsNotFound() { @ParameterizedTest @ValueSource(strings = {"2000-01-01", "*"}) @NullSource - //default = current day void givenGetListeCanton_WhenCorrectRequest_thenParameterDateIsRight(String date) { // Mock methods @@ -132,7 +131,7 @@ void givenGetListeCanton_WhenCorrectRequest_thenParameterDateIsRight(String date list.add(new Canton()); // Call method header content = xml - geoApi.getListe(APPLICATION_XML, date); + geoApi.getListe(APPLICATION_XML, new Date(date)); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -140,7 +139,7 @@ void givenGetListeCanton_WhenCorrectRequest_thenParameterDateIsRight(String date void givenGetListeCanton_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getListe(APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getListe(APPLICATION_XML, new Date("nimportequoi")); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -196,7 +195,7 @@ void givenGetcantonSuivant_whenCorrectRequestWithDate_thenResponseIsOk() { list.add(new Canton()); // Call method header content = xml - geoApi.getSuivant(codeCantonCorrect, APPLICATION_XML, "2000-01-01"); + geoApi.getSuivant(codeCantonCorrect, APPLICATION_XML, new Date("2010-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -204,7 +203,7 @@ void givenGetcantonSuivant_whenCorrectRequestWithDate_thenResponseIsOk() { void givenGetCantonSuivant_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getSuivant(codeCantonCorrect, APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getSuivant(codeCantonCorrect, APPLICATION_XML, new Date("nimportequoi")); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -249,7 +248,7 @@ void givenGetCantonPrecedent_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Canton()); // Call method header content = xml - geoApi.getPrecedent(codeCantonCorrect, APPLICATION_XML, "2000-01-01"); + geoApi.getPrecedent(codeCantonCorrect, APPLICATION_XML, new Date("2010-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -257,7 +256,7 @@ void givenGetCantonPrecedent_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetCantonPrecedent_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getPrecedent(codeCantonCorrect, APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getPrecedent(codeCantonCorrect, APPLICATION_XML, new Date("nimportequoi")); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -270,7 +269,7 @@ void givenGetCantonProjetes_whenCorrectRequest_thenResponseIsOk(String mediaType list.add(new Canton()); // Call method - geoApi.getProjection(codeCantonCorrect, mediaType, null, "2019-01-01"); + geoApi.getProjection(codeCantonCorrect, mediaType, null, new Date("2010-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -283,11 +282,11 @@ void givenGetCantonProjetes_WhenCorrectRequest_thenResponseIsNotFound() { list.clear(); // Call method header content = xml - Response response = geoApi.getProjection(codeCantonCorrect, MediaType.APPLICATION_JSON, null, "2019-01-01"); + Response response = geoApi.getProjection(codeCantonCorrect, MediaType.APPLICATION_JSON, null, new Date("2010-01-01")); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); // Call method header content = json - response = geoApi.getProjection(codeCantonCorrect, APPLICATION_XML, null, "2019-01-01"); + response = geoApi.getProjection(codeCantonCorrect, APPLICATION_XML, null, new Date("2010-01-01")); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); @@ -300,7 +299,7 @@ void givenGetCantonProjetes_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Canton()); // Call method header content = xml - geoApi.getProjection(codeCantonCorrect, APPLICATION_XML, "2000-01-01", "2019-01-01"); + geoApi.getProjection(codeCantonCorrect, APPLICATION_XML, new Date("2010-01-01"), new Date("2018-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -314,7 +313,7 @@ void givenGetCantonProjetes_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetCantonProjetes_WhenCorrectRequest_thenParameterDateIsBad(String date, String dateProjection) { // Call method header content = xml - Response response = geoApi.getProjection(codeCantonCorrect, APPLICATION_XML, date, dateProjection); + Response response = geoApi.getProjection(codeCantonCorrect, APPLICATION_XML, new Date(date), new Date(dateProjection)); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -326,7 +325,7 @@ void givenGetCantonProjetes_WhenCorrectRequest_thenParameterDateProjeteIsRight() list.add(new Canton()); // Call method header content = xml - geoApi.getProjection(codeCantonCorrect, APPLICATION_XML, "2000-01-01", "2019-01-01"); + geoApi.getProjection(codeCantonCorrect, APPLICATION_XML, new Date("2010-01-01"), new Date("2020-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -345,7 +344,7 @@ void givenGetCantonAscendants_whenCorrectRequest_thenResponseIsOk(String mediaTy list.add(new Canton()); // Call method - geoApi.getAscendants(codeCantonCorrect, mediaType, date, typeTerritoire); + geoApi.getAscendants(codeCantonCorrect, mediaType, new Date(date), typeTerritoire); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -376,7 +375,7 @@ void givenGetCantonAscendants_WhenCorrectRequest_thenResponseIsNotFound() { void givenGetCantonAscendants_WhenCorrectRequest_WithBadParameter(String mediaType, String date, String typeTerritoire) { // Call method header content = xml - Response response = geoApi.getAscendants(codeCantonCorrect,mediaType, date, typeTerritoire); + Response response = geoApi.getAscendants(codeCantonCorrect,mediaType, new Date(date), typeTerritoire); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -394,14 +393,14 @@ void givenGetCommunes_WhenCorrectRequest(String mediaType, String date) { list.add(new Canton()); // Call method header content = xml - geoApi.getCommunes(codeCantonCorrect, mediaType, date); + geoApi.getCommunes(codeCantonCorrect, mediaType, new Date(date)); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @Test void givenGetCommunes_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getCommunes(codeCantonCorrect, APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getCommunes(codeCantonCorrect, APPLICATION_XML, new Date("nimportequoi")); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/CantonOuVilleApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/CantonOuVilleApiTest.java index f503628b..d874f05d 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/CantonOuVilleApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/CantonOuVilleApiTest.java @@ -3,6 +3,7 @@ import fr.insee.rmes.api.AbstractApiTest; import fr.insee.rmes.api.geo.pseudointegrationtest.ConstantForIntegration.GetWithCodeAndDate; import fr.insee.rmes.modeles.geo.territoire.CantonOuVille; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.utils.CSVUtils; import fr.insee.rmes.utils.ResponseUtils; import fr.insee.rmes.utils.SparqlUtils; @@ -43,12 +44,18 @@ private CantonOuVilleApiTest() { geoApi = new CantonOuVilleApi(mockSparqlUtils, mockCSVUtils, mockResponseUtils); } - public Stream getWithCodeAndDatefactory() { Stream gets = Stream.of(geoApi::getByCode, geoApi::getSuivant, geoApi::getPrecedent); var intermediare = merge(gets, List.of(APPLICATION_XML, APPLICATION_JSON), Pair::of); - return merge(intermediare, Arrays.asList(null, "1982-07-19"), (pair, d) -> Arguments.of(pair.getLeft(), pair.getRight(), d)); + return merge(intermediare, Arrays.asList(null, new Date("1982-07-19"), new Date("nimportequoi")), (pair, d) -> Arguments.of(pair.getLeft(), pair.getRight(), d)); } + + public Stream getWithCodeAndDatefactoryWithOnlyGoodDate() { + Stream gets = Stream.of(geoApi::getByCode, geoApi::getSuivant, geoApi::getPrecedent); + var intermediare = merge(gets, List.of(APPLICATION_XML, APPLICATION_JSON), Pair::of); + return merge(intermediare, Arrays.asList(null, new Date("1982-07-19")), (pair, d) -> Arguments.of(pair.getLeft(), pair.getRight(), d)); + } + @BeforeEach void resetSomeMocks(){ Mockito.reset(super.mockResponseUtils); @@ -58,7 +65,7 @@ void resetSomeMocks(){ @ParameterizedTest @MethodSource("getWithCodeAndDatefactory") - void givenAllGetsWithCodeAndDate_whenIncorrectCode_thenResponseIsKo(GetWithCodeAndDate getWithCodeAndDate, String mediaType, String date) { + void givenAllGetsWithCodeAndDate_whenIncorrectCode_thenResponseIsKo(GetWithCodeAndDate getWithCodeAndDate, String mediaType, Date date) { // Call method String codeCantonIncorrect = "something"; // pour précédent ? list.add(new CantonOuVille()); @@ -68,8 +75,8 @@ void givenAllGetsWithCodeAndDate_whenIncorrectCode_thenResponseIsKo(GetWithCodeA } @ParameterizedTest - @MethodSource("getWithCodeAndDatefactory") - void givenAllGetsWithCodeAndDate_whenCorrectRequest_thenResponseIsOk(GetWithCodeAndDate getWithCodeAndDate, String mediaType, String date) { + @MethodSource("getWithCodeAndDatefactoryWithOnlyGoodDate") + void givenAllGetsWithCodeAndDate_whenCorrectRequest_thenResponseIsOk(GetWithCodeAndDate getWithCodeAndDate, String mediaType, Date date) { // Mock methods cantonOuVille.setUri("something"); @@ -77,15 +84,15 @@ void givenAllGetsWithCodeAndDate_whenCorrectRequest_thenResponseIsOk(GetWithCode // pour précédent ? list.add(new CantonOuVille()); this.mockUtilsMethodsThenReturnOnePojo(cantonOuVille, Boolean.TRUE); - getWithCodeAndDate.get(codeCantonOuVilleCorrect, mediaType, date); - + var response = getWithCodeAndDate.get(codeCantonOuVilleCorrect, mediaType, date); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @ParameterizedTest - @MethodSource("getWithCodeAndDatefactory") - void givenAllGetsWithCodeAndDate_WhenCorrectRequest_thenResponseIsNotFound(GetWithCodeAndDate getWithCodeAndDate, String mediaType, String date) { + @MethodSource("getWithCodeAndDatefactoryWithOnlyGoodDate") + void givenAllGetsWithCodeAndDate_WhenCorrectRequest_thenResponseIsNotFound(GetWithCodeAndDate getWithCodeAndDate, String mediaType, Date date) { // Mock methods this.mockUtilsMethodsThenReturnOnePojo(cantonOuVille, Boolean.FALSE); @@ -95,15 +102,19 @@ void givenAllGetsWithCodeAndDate_WhenCorrectRequest_thenResponseIsNotFound(GetWi assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); } + + public Stream getWithCodeAndDatefactoryBadDate() { Stream gets = Stream.of(geoApi::getByCode, geoApi::getSuivant, geoApi::getPrecedent); var intermediare = merge(gets, List.of(APPLICATION_XML, APPLICATION_JSON), Pair::of); return merge(intermediare, List.of("mauvaiseDate"), (pair, d) -> Arguments.of(pair.getLeft(), pair.getRight(), d)); } + + @ParameterizedTest @MethodSource("getWithCodeAndDatefactoryBadDate") - void givenAllGetsWithCodeAndDate_WhenCorrectRequest_thenParameterDateIsBad(GetWithCodeAndDate getWithCodeAndDate, String mediaType, String date) { + void givenAllGetsWithCodeAndDate_WhenCorrectRequest_thenParameterDateIsBad(GetWithCodeAndDate getWithCodeAndDate, String mediaType, Date date) { // Call method header content = xml Response response = getWithCodeAndDate.get(codeCantonOuVilleCorrect, mediaType, date); @@ -164,14 +175,14 @@ void givenAnyCall_WhenHeaderIsNotAcceptable(String titre, Supplier geo public Stream callsWithBadParameters() { return Stream.of( - Arguments.of("getListeWithBadDate", (Supplier) () -> geoApi.getListe(APPLICATION_XML, "nimportequoi")), - Arguments.of("getDescendantsWithBadDate", (Supplier) () -> geoApi.getDescendants(codeCantonOuVilleCorrect, APPLICATION_XML, "nimportequoi", null, null)), + Arguments.of("getListeWithBadDate", (Supplier) () -> geoApi.getListe(APPLICATION_XML, new Date("nimportequoi"))), + Arguments.of("getDescendantsWithBadDate", (Supplier) () -> geoApi.getDescendants(codeCantonOuVilleCorrect, APPLICATION_XML, new Date("nimportequoi"), null, null)), Arguments.of("getDescendantsWithBadTerritory", (Supplier) () -> geoApi.getDescendants(codeCantonOuVilleCorrect, APPLICATION_XML, null, "unTypeQuelconque", null)), - Arguments.of("getAscendantsWithBadDate", (Supplier) () -> geoApi.getAscendants(codeCantonOuVilleCorrect, APPLICATION_XML, "nimportequoi", null)), + Arguments.of("getAscendantsWithBadDate", (Supplier) () -> geoApi.getAscendants(codeCantonOuVilleCorrect, APPLICATION_XML, new Date("nimportequoi"), null)), Arguments.of("getAscendantsWithBadTerritory", (Supplier) () -> geoApi.getAscendants(codeCantonOuVilleCorrect, APPLICATION_XML, null, "unTypeQuelconque")), - Arguments.of("getProjectionWithBadDate", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, APPLICATION_XML, "nimportequoi", "2019-01-01")), - Arguments.of("getProjectionWithTwoBadDates", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, APPLICATION_XML, "nimportequoi", "nimportequoi")), - Arguments.of("getDescendantsWithBadDateAndNull", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, APPLICATION_XML, "nimportequoi", null)) + Arguments.of("getProjectionWithBadDate", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, APPLICATION_XML, new Date("2010-01-01"), new Date("nimportequoi"))), + Arguments.of("getProjectionWithTwoBadDates", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, APPLICATION_XML, new Date("nimportequoi"), new Date("nimportequoi"))), + Arguments.of("getDescendantsWithBadDateAndNull", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, APPLICATION_XML, new Date("nimportequoi"), null)) ); } @@ -180,26 +191,26 @@ public Stream callsWithBadHeaders() { Arguments.of("getListeWithBadHeader", (Supplier) () -> geoApi.getListe(TEXT_PLAIN, null)), Arguments.of("getDescendantsWithBadHeader", (Supplier) () -> geoApi.getDescendants(codeCantonOuVilleCorrect, TEXT_PLAIN, null, null, null)), Arguments.of("getAscendantsWithBadHeader", (Supplier) () -> geoApi.getAscendants(codeCantonOuVilleCorrect, TEXT_PLAIN, null, null)), - Arguments.of("getProjectionWithBadHeader", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, TEXT_PLAIN, null, "2019-01-01")) + Arguments.of("getProjectionWithBadHeader", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, TEXT_PLAIN, null, new Date("2010-01-01"))) ); } public Stream callsWithCorrectRequest() { return Stream.of( - Arguments.of("getProjection_JSON_null_date_projection", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, APPLICATION_JSON, null, "2019-01-01")), - Arguments.of("getProjection_XML_null_date_projection", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, APPLICATION_XML, null, "2019-01-01")), - Arguments.of("getProjection_XML_noDateNull", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, APPLICATION_XML, "2000-01-01", "2019-01-01")), + Arguments.of("getProjection_JSON_null_date_projection", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, APPLICATION_JSON, null, new Date("2010-01-01"))), + Arguments.of("getProjection_XML_null_date_projection", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, APPLICATION_XML, null, new Date("2010-01-01"))), + Arguments.of("getProjection_XML_noDateNull", (Supplier) () -> geoApi.getProjection(codeCantonOuVilleCorrect, APPLICATION_XML, new Date("2010-01-01"), new Date("2010-01-01"))), Arguments.of("getListe_JSON_noDate", (Supplier) () -> geoApi.getListe(APPLICATION_JSON, null)), Arguments.of("getListe_XML_noDate", (Supplier) () -> geoApi.getListe(APPLICATION_XML, null)), - Arguments.of("getListe_XML_date", (Supplier) () -> geoApi.getListe(APPLICATION_XML, "2000-01-01")), - Arguments.of("getListe_dateStar", (Supplier) () -> geoApi.getListe(APPLICATION_JSON, "*")), + Arguments.of("getListe_XML_date", (Supplier) () -> geoApi.getListe(APPLICATION_XML, new Date("2010-01-01"))), + Arguments.of("getListe_dateStar", (Supplier) () -> geoApi.getListe(APPLICATION_JSON, new Date("*"))), Arguments.of("getDescendants_JSON", (Supplier) () -> geoApi.getDescendants(codeCantonOuVilleCorrect, APPLICATION_JSON, null, null, null)), Arguments.of("getDescendants_XML", (Supplier) () -> geoApi.getDescendants(codeCantonOuVilleCorrect, APPLICATION_XML, null, null, null)), - Arguments.of("getDescendants_XML_date", (Supplier) () -> geoApi.getDescendants(codeCantonOuVilleCorrect, APPLICATION_XML, "2000-01-01", null, null)), + Arguments.of("getDescendants_XML_date", (Supplier) () -> geoApi.getDescendants(codeCantonOuVilleCorrect, APPLICATION_XML, new Date("2010-01-01"), null, null)), Arguments.of("getDescendants_XML_Territory", (Supplier) () -> geoApi.getDescendants(codeCantonOuVilleCorrect, APPLICATION_XML, null, "CantonOuVille", null)), Arguments.of("getAscendants_JSON", (Supplier) () -> geoApi.getAscendants(codeCantonOuVilleCorrect, APPLICATION_JSON, null, null)), Arguments.of("getAscendants_XML", (Supplier) () -> geoApi.getAscendants(codeCantonOuVilleCorrect, APPLICATION_XML, null, null)), - Arguments.of("getAscendants_XML_date", (Supplier) () -> geoApi.getAscendants(codeCantonOuVilleCorrect, APPLICATION_XML, "2000-01-01", null)), + Arguments.of("getAscendants_XML_date", (Supplier) () -> geoApi.getAscendants(codeCantonOuVilleCorrect, APPLICATION_XML, new Date("2010-01-01"), null)), Arguments.of("getAscendants_XML_territory", (Supplier) () -> geoApi.getAscendants(codeCantonOuVilleCorrect, APPLICATION_XML, null, "CantonOuVille")) ); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/CirconscriptionTerritorialeApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/CirconscriptionTerritorialeApiTest.java index e3221901..57aed5c1 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/CirconscriptionTerritorialeApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/CirconscriptionTerritorialeApiTest.java @@ -8,6 +8,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -80,7 +81,7 @@ void givenGetCirconscriptionTerritoriale_WhenCorrectRequest_thenParameterDateIsR this.mockUtilsMethodsThenReturnOnePojo(circonscriptionTerritoriale, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("2000-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -88,7 +89,7 @@ void givenGetCirconscriptionTerritoriale_WhenCorrectRequest_thenParameterDateIsR void givenGetCirconscriptionTerritoriale_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -141,7 +142,7 @@ void givenGetCirconscriptionTerritorialeAscendants_WhenCorrectRequest_thenParame list.add(new CirconscriptionTerritoriale()); // Call method header content = xml - geoApi.getAscendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -149,7 +150,7 @@ void givenGetCirconscriptionTerritorialeAscendants_WhenCorrectRequest_thenParame void givenGetCirconscriptionTerritorialeAscendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getAscendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerApiTest.java index 4ff8c503..b300475f 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerApiTest.java @@ -8,6 +8,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -82,7 +83,7 @@ void givenGetCollectiviteDOutreMer_WhenCorrectRequest_thenParameterDateIsRight() this.mockUtilsMethodsThenReturnOnePojo(collectiviteDOutreMer, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("2000-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -90,7 +91,7 @@ void givenGetCollectiviteDOutreMer_WhenCorrectRequest_thenParameterDateIsRight() void givenGetCollectiviteDOutreMer_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -144,7 +145,7 @@ void givenGetCollectiviteDOutreMerDescendants_WhenCorrectRequest_thenParameterDa list.add(new CollectiviteDOutreMer()); // Call method header content = xml - geoApi.getDescendants("something", MediaType.APPLICATION_XML, "2000-01-01", null, null);/*modifier suite a changement du nombre de variables */ + geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), null, null);/*modifier suite a changement du nombre de variables */ verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -152,7 +153,7 @@ void givenGetCollectiviteDOutreMerDescendants_WhenCorrectRequest_thenParameterDa void givenGetCollectiviteDOutreMerDescendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, "nimportequoi", null, null);/*modifier suite a changement du nombre de variables */ + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null, null);/*modifier suite a changement du nombre de variables */ Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneApiTest.java index 006bd7fd..562c1cf9 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneApiTest.java @@ -10,6 +10,7 @@ import jakarta.ws.rs.core.Response.Status; import fr.insee.rmes.modeles.geo.territoire.Canton; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -81,7 +82,7 @@ void givenGetCommune_WhenCorrectRequest_thenParameterDateIsRight() { this.mockUtilsMethodsThenReturnOnePojo(commune, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("2010-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -89,7 +90,7 @@ void givenGetCommune_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetCommune_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -142,7 +143,7 @@ void givenGetCommuneAscendants_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Commune()); // Call method header content = xml - geoApi.getAscendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("2010-01-01"), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -150,7 +151,7 @@ void givenGetCommuneAscendants_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetCommuneAscendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getAscendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -240,7 +241,7 @@ void givenGetCommuneDescendants_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Commune()); // Call method header content = xml - geoApi.getDescendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("2010-01-01"), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -248,7 +249,7 @@ void givenGetCommuneDescendants_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetCommuneDescendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -332,7 +333,7 @@ void givenGetListeCommune_WhenCorrectRequest_thenResponseIsNotFound() { @ParameterizedTest @ValueSource(strings = {"2000-01-01", "*"}) - @NullSource //default = current day + @NullSource void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsRight(String date) { // Mock methods @@ -340,7 +341,7 @@ void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsRight(String dat list.add(new Commune()); // Call method header content = xml - geoApi.getListe(MediaType.APPLICATION_XML, date, date, Boolean.TRUE);/*modifier suite a changement du nombre de variables */ + geoApi.getListe(MediaType.APPLICATION_XML, new Date(date), date, Boolean.TRUE);/*modifier suite a changement du nombre de variables */ verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -348,7 +349,7 @@ void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsRight(String dat void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getListe(MediaType.APPLICATION_XML, "nimportequoi", null, null);/*modifier suite a changement du nombre de variables */ + Response response = geoApi.getListe(MediaType.APPLICATION_XML, new Date("nimportequoi"), null, null);/*modifier suite a changement du nombre de variables */ Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -401,7 +402,7 @@ void givenGetCommunePrecedents_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Commune()); // Call method header content = xml - geoApi.getPrecedent("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getPrecedent("something", MediaType.APPLICATION_XML, new Date("2010-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -409,7 +410,7 @@ void givenGetCommunePrecedents_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetCommunePrecedents_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getPrecedent("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getPrecedent("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -474,7 +475,7 @@ void givenGetCommuneSuivants_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Commune()); // Call method header content = xml - geoApi.getSuivant("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getSuivant("something", MediaType.APPLICATION_XML, new Date("2010-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -482,7 +483,7 @@ void givenGetCommuneSuivants_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetCommuneSuivants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getSuivant("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getSuivant("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -506,7 +507,7 @@ void givenGetCommuneProjetes_whenCorrectRequest_andHeaderContentIsJson_thenRespo list.add(new Commune()); // Call method - geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -518,7 +519,7 @@ void givenGetCommuneProjetes_whenCorrectRequest_andHeaderContentIsXml_thenRespon list.add(new Commune()); // Call method - geoApi.getProjection("something", MediaType.APPLICATION_XML, null, "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, null, new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -529,11 +530,11 @@ void givenGetCommuneProjetes_WhenCorrectRequest_thenResponseIsNotFound() { this.mockUtilsMethodsThenReturnListOfPojo(Boolean.FALSE); // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, "2019-01-01"); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, new Date("2019-01-01")); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); // Call method header content = json - response = geoApi.getProjection("something", MediaType.APPLICATION_XML, null, "2019-01-01"); + response = geoApi.getProjection("something", MediaType.APPLICATION_XML, null, new Date("2019-01-01")); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); @@ -547,7 +548,7 @@ void givenGetCommuneProjetes_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Commune()); // Call method header content = xml - geoApi.getProjection("something", MediaType.APPLICATION_XML, "2000-01-01", "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("2009-01-01"), new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -555,7 +556,7 @@ void givenGetCommuneProjetes_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetCommuneProjetes_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, "nimportequoi", "2019-01-01"); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -567,7 +568,7 @@ void givenGetCommuneProjetes_WhenCorrectRequest_thenParameterDateProjeteIsRight( list.add(new Commune()); // Call method header content = xml - geoApi.getProjection("something", MediaType.APPLICATION_XML, "2000-01-01", "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("2010-01-01"), new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -576,7 +577,7 @@ void givenGetCommuneProjetes_WhenCorrectRequest_thenParameterDateProjeteIsBad() // Call method header content = xml Response response = - geoApi.getProjection("something", MediaType.APPLICATION_XML, "nimportequoi", "nimportequoi"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("blabla"), new Date("blabla")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -584,7 +585,7 @@ void givenGetCommuneProjetes_WhenCorrectRequest_thenParameterDateProjeteIsBad() void givenGetCommuneProjetes_WhenCorrectRequest_thenParameterDateProjeteIsNull() { // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("2019-01-01"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -637,7 +638,7 @@ void givenGetListeCantonsCommunes_WhenCorrectRequest_thenParameterDateIsRight() list.add(new Canton()); // Call method header content = xml - geoApi.getCantonForCommune("something", MediaType.APPLICATION_XML, "2000-01-01");/*modifier suite a changement du nombre de variables */ + geoApi.getCantonForCommune("something", MediaType.APPLICATION_XML, new Date("2019-01-01"));/*modifier suite a changement du nombre de variables */ verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -646,7 +647,7 @@ void givenGetListeCantonsCommunes_WhenCorrectRequest_thenParameterDateIsRight() void givenGetListeCantonsCommunes_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getCantonForCommune("something", MediaType.APPLICATION_XML, "nimportequoi");/*modifier suite a changement du nombre de variables */ + Response response = geoApi.getCantonForCommune("something", MediaType.APPLICATION_XML, new Date("blabla"));/*modifier suite a changement du nombre de variables */ Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneAssocieeApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneAssocieeApiTest.java index 10e34510..86170291 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneAssocieeApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneAssocieeApiTest.java @@ -8,6 +8,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -79,7 +80,7 @@ void givenGetCommune_WhenCorrectRequest_thenParameterDateIsRight() { this.mockUtilsMethodsThenReturnOnePojo(commune, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("2000-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -87,7 +88,7 @@ void givenGetCommune_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetCommune_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -139,7 +140,7 @@ void givenGetCommuneAscendants_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Commune()); // Call method header content = xml - geoApi.getAscendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -148,7 +149,7 @@ void givenGetCommuneAscendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml Response response = - geoApi.getAscendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -233,7 +234,7 @@ void givenGetListeCommune_WhenCorrectRequest_thenResponseIsNotFound() { @ParameterizedTest @ValueSource(strings = {"2000-01-01", "*"}) - @NullSource //default = current day + @NullSource void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsRight(String date) { // Mock methods @@ -241,7 +242,7 @@ void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsRight(String dat list.add(new Commune()); // Call method header content = xml - geoApi.getListe(MediaType.APPLICATION_XML, date); + geoApi.getListe(MediaType.APPLICATION_XML, new Date(date)); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -249,7 +250,7 @@ void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsRight(String dat void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getListe(MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getListe(MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneDelegueeApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneDelegueeApiTest.java index e86c4ca7..e18d9ea3 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneDelegueeApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneDelegueeApiTest.java @@ -8,6 +8,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -79,7 +80,7 @@ void givenGetCommune_WhenCorrectRequest_thenParameterDateIsRight() { this.mockUtilsMethodsThenReturnOnePojo(commune, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("2000-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -87,7 +88,7 @@ void givenGetCommune_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetCommune_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -140,7 +141,7 @@ void givenGetCommuneAscendants_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Commune()); // Call method header content = xml - geoApi.getAscendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -149,7 +150,7 @@ void givenGetCommuneAscendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml Response response = - geoApi.getAscendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -234,7 +235,7 @@ void givenGetListeCommune_WhenCorrectRequest_thenResponseIsNotFound() { @ParameterizedTest @ValueSource(strings = {"2000-01-01", "*"}) - @NullSource //default = current day + @NullSource void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsRight(String date) { // Mock methods @@ -242,7 +243,7 @@ void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsRight(String dat list.add(new Commune()); // Call method header content = xml - geoApi.getListe(MediaType.APPLICATION_XML, date); + geoApi.getListe(MediaType.APPLICATION_XML, new Date(date)); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -250,7 +251,7 @@ void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsRight(String dat void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getListe(MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getListe(MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/DepartementApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/DepartementApiTest.java index 5d5253f9..7e0ffe94 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/DepartementApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/DepartementApiTest.java @@ -8,6 +8,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -79,7 +80,7 @@ void givenGetDepartement_WhenCorrectRequest_thenParameterDateIsRight() { this.mockUtilsMethodsThenReturnOnePojo(departement, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -87,7 +88,7 @@ void givenGetDepartement_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetDepartement_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -134,7 +135,7 @@ void givenGetListeDepartement_WhenCorrectRequest_thenResponseIsNotFound() { @ParameterizedTest @ValueSource(strings = {"2000-01-01", "*"}) - @NullSource //default = current day + @NullSource void givenGetListeDepartement_WhenCorrectRequest_thenParameterDateIsRight(String date) { // Mock methods @@ -142,7 +143,7 @@ void givenGetListeDepartement_WhenCorrectRequest_thenParameterDateIsRight(String list.add(new Departement()); // Call method header content = xml - geoApi.getListe(MediaType.APPLICATION_XML, date); + geoApi.getListe(MediaType.APPLICATION_XML, new Date(date)); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -150,7 +151,7 @@ void givenGetListeDepartement_WhenCorrectRequest_thenParameterDateIsRight(String void givenGetListeDepartement_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getListe(MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getListe(MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -203,7 +204,7 @@ void givenGetDepartementAscendants_WhenCorrectRequest_thenParameterDateIsRight() list.add(new Departement()); // Call method header content = xml - geoApi.getAscendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("2019-01-01"), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -211,7 +212,7 @@ void givenGetDepartementAscendants_WhenCorrectRequest_thenParameterDateIsRight() void givenGetDepartementAscendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getAscendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -297,7 +298,7 @@ void givenGetDepartementDescendants_WhenCorrectRequest_thenParameterDateIsRight( list.add(new Departement()); // Call method header content = xml - geoApi.getDescendants("something", MediaType.APPLICATION_XML, "2000-01-01", null, null);/*modifier suite a changement du nombre de variables */ + geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), null, null);/*modifier suite a changement du nombre de variables */ verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -305,7 +306,7 @@ void givenGetDepartementDescendants_WhenCorrectRequest_thenParameterDateIsRight( void givenGetDepartementDescendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, "nimportequoi", null, null);/*modifier suite a changement du nombre de variables */ + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null, null);/*modifier suite a changement du nombre de variables */ Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -391,7 +392,7 @@ void givenGetDepartementSuivant_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Departement()); // Call method header content = xml - geoApi.getSuivant("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getSuivant("something", MediaType.APPLICATION_XML, new Date("2000-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -399,7 +400,7 @@ void givenGetDepartementSuivant_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetDepartementSuivant_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getSuivant("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getSuivant("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -452,7 +453,7 @@ void givenGetDepartementPrecedent_WhenCorrectRequest_thenParameterDateIsRight() list.add(new Departement()); // Call method header content = xml - geoApi.getPrecedent("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getPrecedent("something", MediaType.APPLICATION_XML, new Date("2000-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -460,7 +461,7 @@ void givenGetDepartementPrecedent_WhenCorrectRequest_thenParameterDateIsRight() void givenGetDepartementPrecedent_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getPrecedent("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getPrecedent("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -472,7 +473,7 @@ void givenGetDepartementProjetes_whenCorrectRequest_andHeaderContentIsJson_thenR list.add(new Departement()); // Call method - geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -484,7 +485,7 @@ void givenGetDepartementProjetes_whenCorrectRequest_andHeaderContentIsXml_thenRe list.add(new Departement()); // Call method - geoApi.getProjection("something", MediaType.APPLICATION_XML, null, "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, null, new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -495,11 +496,11 @@ void givenGetDepartementProjetes_WhenCorrectRequest_thenResponseIsNotFound() { this.mockUtilsMethodsThenReturnListOfPojo(Boolean.FALSE); // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, "2019-01-01"); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, new Date("2019-01-01")); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); // Call method header content = json - response = geoApi.getProjection("something", MediaType.APPLICATION_XML, null, "2019-01-01"); + response = geoApi.getProjection("something", MediaType.APPLICATION_XML, null, new Date("2019-01-01")); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); @@ -513,7 +514,7 @@ void givenGetDepartementProjetes_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Departement()); // Call method header content = xml - geoApi.getProjection("something", MediaType.APPLICATION_XML, "2000-01-01", "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -521,7 +522,7 @@ void givenGetDepartementProjetes_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetDepartementProjetes_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, "nimportequoi", "2019-01-01"); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), new Date("2019-01-01")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -533,7 +534,7 @@ void givenGetDepartementProjetes_WhenCorrectRequest_thenParameterDateProjeteIsRi list.add(new Departement()); // Call method header content = xml - geoApi.getProjection("something", MediaType.APPLICATION_XML, "2000-01-01", "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -542,7 +543,7 @@ void givenGetDepartementProjetes_WhenCorrectRequest_thenParameterDateProjeteIsBa // Call method header content = xml Response response = - geoApi.getProjection("something", MediaType.APPLICATION_XML, "nimportequoi", "nimportequoi"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -550,7 +551,7 @@ void givenGetDepartementProjetes_WhenCorrectRequest_thenParameterDateProjeteIsBa void givenGetDepartementProjetes_WhenCorrectRequest_thenParameterDateProjeteIsNull() { // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), new Date(null)); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/DistrictApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/DistrictApiTest.java index 928f2781..e52f8b03 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/DistrictApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/DistrictApiTest.java @@ -9,6 +9,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -81,7 +82,7 @@ void givenGetDistrict_WhenCorrectRequest_thenParameterDateIsRight() { this.mockUtilsMethodsThenReturnOnePojo(district, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("2000-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -89,7 +90,7 @@ void givenGetDistrict_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetDistrict_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -142,7 +143,7 @@ void givenGetDistrictAscendants_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new District()); // Call method header content = xml - geoApi.getAscendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -150,7 +151,7 @@ void givenGetDistrictAscendants_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetDistrictAscendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getAscendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getAscendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/IrisApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/IrisApiTest.java index c6417cb4..94e575b3 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/IrisApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/IrisApiTest.java @@ -5,6 +5,7 @@ import fr.insee.rmes.modeles.geo.territoire.Canton; import fr.insee.rmes.modeles.geo.territoire.CodeIris; import fr.insee.rmes.modeles.geo.territoire.Iris; +import fr.insee.rmes.modeles.utils.Date; import fr.insee.rmes.utils.CSVUtils; import fr.insee.rmes.utils.IrisUtils; import fr.insee.rmes.utils.ResponseUtils; @@ -87,10 +88,11 @@ class IrisApiTest extends AbstractApiTest { private final String codeIrisCorrect="010040101"; + public Stream getWithCodeAndDatefactory() { Stream gets = Stream.of(geoApiSansMock::getByCode); var intermediaire= merge(gets, List.of(APPLICATION_XML, APPLICATION_JSON), Pair::of ); - return merge(intermediaire, Arrays.asList(null, "mauvaiseDate", "1982-07-19"), (pair, d)->Arguments.of(pair.getLeft(), pair.getRight(), d)); + return merge(intermediaire, Arrays.asList(null, new Date("mauvaiseDate"), new Date("1982-07-19")), (pair, d)->Arguments.of(pair.getLeft(), pair.getRight(), d)); } @BeforeEach @@ -102,7 +104,7 @@ void resetSomeMocks(){ @ParameterizedTest @MethodSource("getWithCodeAndDatefactory") - void givenAllGetsIrisWithCodeAndDate_whenIncorrectCode_thenResponseIsKo(ConstantForIntegration.GetWithCodeAndDate getWithCodeAndDate, String mediaType, String date) { + void givenAllGetsIrisWithCodeAndDate_whenIncorrectCode_thenResponseIsKo(ConstantForIntegration.GetWithCodeAndDate getWithCodeAndDate, String mediaType, Date date) { // Call method String codeIrisIncorrect = "something"; @@ -116,7 +118,7 @@ void givenAllGetsIrisWithCodeAndDate_whenIncorrectCode_thenResponseIsKo(Constant void givenGetIris_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode(codeIrisCorrect, APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode(codeIrisCorrect, APPLICATION_XML, new Date("nimportequoi")); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -213,7 +215,6 @@ void givenGetListeIris_WhenCorrectRequest_thenResponseIsNotFound() { @ParameterizedTest @ValueSource(strings = {"2000-01-01", "*"}) @NullSource - //default = current day void givenGetListeIris_WhenCorrectRequest_thenParameterDateIsRight(String date) { // Mock methods @@ -221,7 +222,7 @@ void givenGetListeIris_WhenCorrectRequest_thenParameterDateIsRight(String date) list.add(new Iris()); // Call method header content = xml - geoApi.getListe(APPLICATION_XML, date,true); + geoApi.getListe(APPLICATION_XML, new Date(date),true); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -229,7 +230,7 @@ void givenGetListeIris_WhenCorrectRequest_thenParameterDateIsRight(String date) void givenGetListeIris_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getListe(APPLICATION_XML, "nimportequoi",true); + Response response = geoApi.getListe(APPLICATION_XML, new Date("nimportequoi"),true); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -259,7 +260,7 @@ void givenGetIrisAscendants_whenCorrectRequest_thenResponseIsOk(String mediaType list.add(new Canton()); // Call method - geoApi.getAscendants(codeIrisCorrect, mediaType, date, typeTerritoire); + geoApi.getAscendants(codeIrisCorrect, mediaType, new Date(date), typeTerritoire); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -290,13 +291,13 @@ void givenGetIrisAscendants_WhenCorrectRequest_thenResponseIsNotFound() { void givenGetIrisAscendants_WhenCorrectRequest_WithBadParameter(String mediaType, String date, String typeTerritoire) { // Call method header content = xml - Response response = geoApi.getAscendants(codeIrisCorrect,mediaType, date, typeTerritoire); + Response response = geoApi.getAscendants(codeIrisCorrect,mediaType, new Date(date), typeTerritoire); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } public Stream callsWithBadParameters() { return Stream.of( - Arguments.of("getListeWithBadDate", (Supplier) () -> geoApi.getListe(APPLICATION_XML, "nimportequoi",null)), - Arguments.of("getAscendantsWithBadDate", (Supplier) () -> geoApi.getAscendants(codeIrisCorrect, APPLICATION_XML, "nimportequoi", null)), + Arguments.of("getListeWithBadDate", (Supplier) () -> geoApi.getListe(APPLICATION_XML, new Date("nimportequoi"),null)), + Arguments.of("getAscendantsWithBadDate", (Supplier) () -> geoApi.getAscendants(codeIrisCorrect, APPLICATION_XML, new Date("nimportequoi"), null)), Arguments.of("getAscendantsWithBadTerritory", (Supplier) () -> geoApi.getAscendants(codeIrisCorrect, APPLICATION_XML, null, "unTypeQuelconque")) ); } @@ -312,8 +313,8 @@ public Stream callsWithCorrectRequest() { return Stream.of( Arguments.of("getListe_JSON_noDate", (Supplier) () -> geoApi.getListe(APPLICATION_JSON, null,true)), Arguments.of("getListe_XML_noDate", (Supplier) () -> geoApi.getListe(APPLICATION_XML, null,true)), - Arguments.of("getListe_XML_date", (Supplier) () -> geoApi.getListe(APPLICATION_XML, "2000-01-01",true)), - Arguments.of("getListe_dateStar", (Supplier) () -> geoApi.getListe(APPLICATION_JSON, "*",true)) + Arguments.of("getListe_XML_date", (Supplier) () -> geoApi.getListe(APPLICATION_XML, new Date("2000-01-01"),true)), + Arguments.of("getListe_dateStar", (Supplier) () -> geoApi.getListe(APPLICATION_JSON, new Date("*"),true)) ); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/RegionApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/RegionApiTest.java index 1d18d063..09fc1db7 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/RegionApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/RegionApiTest.java @@ -9,6 +9,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -80,7 +81,7 @@ void givenGetRegion_WhenCorrectRequest_thenParameterDateIsRight() { this.mockUtilsMethodsThenReturnOnePojo(region, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("2000-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -88,7 +89,7 @@ void givenGetRegion_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetRegion_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -135,7 +136,7 @@ void givenGetListeRegion_WhenCorrectRequest_thenResponseIsNotFound() { @ParameterizedTest @ValueSource(strings = {"2000-01-01", "*"}) - @NullSource //default = current day + @NullSource void givenGetListeRegion_WhenCorrectRequest_thenParameterDateIsRight(String date) { // Mock methods @@ -143,7 +144,7 @@ void givenGetListeRegion_WhenCorrectRequest_thenParameterDateIsRight(String date list.add(new Region()); // Call method header content = xml - geoApi.getListe(MediaType.APPLICATION_XML, date); + geoApi.getListe(MediaType.APPLICATION_XML, new Date(date)); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -151,7 +152,7 @@ void givenGetListeRegion_WhenCorrectRequest_thenParameterDateIsRight(String date void givenGetListeRegion_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getListe(MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getListe(MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -216,7 +217,7 @@ void givenGetRegionDescendants_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Region()); // Call method header content = xml - geoApi.getDescendants("something", MediaType.APPLICATION_XML, "2000-01-01", null, null); + geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), null, null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -224,7 +225,7 @@ void givenGetRegionDescendants_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetRegionDescendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, "nimportequoi", null, null); + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null, null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -314,7 +315,7 @@ void givenGetRegionSuivant_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Region()); // Call method header content = xml - geoApi.getSuivant("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getSuivant("something", MediaType.APPLICATION_XML, new Date("2000-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -322,7 +323,7 @@ void givenGetRegionSuivant_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetRegionSuivant_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getSuivant("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getSuivant("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -375,7 +376,7 @@ void givenGetRegionPrecedent_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Region()); // Call method header content = xml - geoApi.getPrecedent("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getPrecedent("something", MediaType.APPLICATION_XML, new Date("2000-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -383,7 +384,7 @@ void givenGetRegionPrecedent_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetRegionPrecedent_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getPrecedent("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getPrecedent("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -395,7 +396,7 @@ void givenGetRegionProjetes_whenCorrectRequest_andHeaderContentIsJson_thenRespon list.add(new Region()); // Call method - geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -407,7 +408,7 @@ void givenGetRegionProjetes_whenCorrectRequest_andHeaderContentIsXml_thenRespons list.add(new Region()); // Call method - geoApi.getProjection("something", MediaType.APPLICATION_XML, null, "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, null, new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -418,11 +419,11 @@ void givenGetRegionProjetes_WhenCorrectRequest_thenResponseIsNotFound() { this.mockUtilsMethodsThenReturnListOfPojo(Boolean.FALSE); // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, "2019-01-01"); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_JSON, null, new Date("2019-01-01")); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); // Call method header content = json - response = geoApi.getProjection("something", MediaType.APPLICATION_XML, null, "2019-01-01"); + response = geoApi.getProjection("something", MediaType.APPLICATION_XML, null, new Date("2019-01-01")); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); @@ -436,7 +437,7 @@ void givenGetRegionProjetes_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Region()); // Call method header content = xml - geoApi.getProjection("something", MediaType.APPLICATION_XML, "2000-01-01", "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -444,7 +445,7 @@ void givenGetRegionProjetes_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetRegionProjetes_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, "nimportequoi", "2019-01-01"); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), new Date("2019-01-01")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -456,7 +457,7 @@ void givenGetRegionProjetes_WhenCorrectRequest_thenParameterDateProjeteIsRight() list.add(new Region()); // Call method header content = xml - geoApi.getProjection("something", MediaType.APPLICATION_XML, "2000-01-01", "2019-01-01"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), new Date("2019-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -465,7 +466,7 @@ void givenGetRegionProjetes_WhenCorrectRequest_thenParameterDateProjeteIsBad() { // Call method header content = xml Response response = - geoApi.getProjection("something", MediaType.APPLICATION_XML, "nimportequoi", "nimportequoi"); + geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -473,7 +474,7 @@ void givenGetRegionProjetes_WhenCorrectRequest_thenParameterDateProjeteIsBad() { void givenGetRegionProjetes_WhenCorrectRequest_thenParameterDateProjeteIsNull() { // Call method header content = xml - Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getProjection("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/UniteUrbaineAPITest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/UniteUrbaineAPITest.java index d75f3ec6..01b5b27e 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/UniteUrbaineAPITest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/UniteUrbaineAPITest.java @@ -8,6 +8,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -82,7 +83,7 @@ void givenGetUniteUrbaine_WhenCorrectRequest_thenParameterDateIsRight() { this.mockUtilsMethodsThenReturnOnePojo(uniteUrbaine2020, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("2000-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -90,7 +91,7 @@ void givenGetUniteUrbaine_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetUniteUrbaine_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -147,7 +148,7 @@ void givenGetUniteUrbaineDescendants_WhenCorrectRequest_thenParameterDateIsRight list.add(new UniteUrbaine2020()); // Call method header content = xml - geoApi.getDescendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -155,7 +156,7 @@ void givenGetUniteUrbaineDescendants_WhenCorrectRequest_thenParameterDateIsRight void givenGetUniteUrbaineDescendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -244,7 +245,7 @@ void givenGetListeUniteUrbaine_WhenCorrectRequest_thenResponseIsNotFound() { @ParameterizedTest @ValueSource(strings = {"2000-01-01", "*"}) - @NullSource //default = current day + @NullSource void givenGetListeUniteUrbaine_WhenCorrectRequest_thenParameterDateIsRight(String date) { // Mock methods @@ -252,7 +253,7 @@ void givenGetListeUniteUrbaine_WhenCorrectRequest_thenParameterDateIsRight(Strin list.add(new UniteUrbaine2020()); // Call method header content = xml - geoApi.getListe(MediaType.APPLICATION_XML, date); + geoApi.getListe(MediaType.APPLICATION_XML, new Date(date)); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -260,7 +261,7 @@ void givenGetListeUniteUrbaine_WhenCorrectRequest_thenParameterDateIsRight(Strin void givenGetListeUniteUrbaine_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getListe(MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getListe(MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/ZoneEmploiAPITest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/ZoneEmploiAPITest.java index 8daa35a2..22b44c9f 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/ZoneEmploiAPITest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/ZoneEmploiAPITest.java @@ -8,6 +8,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; +import fr.insee.rmes.modeles.utils.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -82,7 +83,7 @@ void givenGetZoneEmploi_WhenCorrectRequest_thenParameterDateIsRight() { this.mockUtilsMethodsThenReturnOnePojo(zoneDEmploi2020, Boolean.TRUE); // Call method header content = xml - geoApi.getByCode("something", MediaType.APPLICATION_XML, "2000-01-01"); + geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("2000-01-01")); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -90,7 +91,7 @@ void givenGetZoneEmploi_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetZoneEmploi_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -147,7 +148,7 @@ void givenGetZoneEmploiDescendants_WhenCorrectRequest_thenParameterDateIsRight() list.add(new ZoneDEmploi2020()); // Call method header content = xml - geoApi.getDescendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("2000-01-01"), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -155,7 +156,7 @@ void givenGetZoneEmploiDescendants_WhenCorrectRequest_thenParameterDateIsRight() void givenGetZoneEmploiDescendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, new Date("nimportequoi"), null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -245,7 +246,7 @@ void givenGetListeZoneEmploi_WhenCorrectRequest_thenResponseIsNotFound() { @ParameterizedTest @ValueSource(strings = {"2000-01-01", "*"}) - @NullSource //default = current day + @NullSource void givenGetListeZoneEmploi_WhenCorrectRequest_thenParameterDateIsRight(String date) { // Mock methods @@ -253,7 +254,7 @@ void givenGetListeZoneEmploi_WhenCorrectRequest_thenParameterDateIsRight(String list.add(new ZoneDEmploi2020()); // Call method header content = xml - geoApi.getListe(MediaType.APPLICATION_XML, date); + geoApi.getListe(MediaType.APPLICATION_XML, new Date(date)); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -261,7 +262,7 @@ void givenGetListeZoneEmploi_WhenCorrectRequest_thenParameterDateIsRight(String void givenGetListeZoneEmploi_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getListe(MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getListe(MediaType.APPLICATION_XML, new Date("nimportequoi")); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } From 1df88e803dc4bc5d3001b8ba4efe8ccc8ffdea6b Mon Sep 17 00:00:00 2001 From: Hugo Bouttes Date: Wed, 2 Oct 2024 10:54:52 +0200 Subject: [PATCH 2/4] fix : type filtreNom & header --- .../java/fr/insee/rmes/api/DescribeApi.java | 6 +++-- .../java/fr/insee/rmes/api/geo/PaysApi.java | 5 ++-- .../geo/territoire/BassinDeVie2022Api.java | 5 ++-- .../api/geo/territoire/CantonOuVilleApi.java | 5 ++-- .../territoire/CollectivitesDOutreMerAPI.java | 5 ++-- .../rmes/api/geo/territoire/CommuneApi.java | 5 ++-- .../api/geo/territoire/DepartementApi.java | 5 ++-- .../geo/territoire/IntercommunaliteAPI.java | 5 ++-- .../rmes/api/geo/territoire/RegionApi.java | 5 ++-- .../insee/rmes/modeles/utils/FiltreNom.java | 23 +++++++++++++++++++ .../fr/insee/rmes/modeles/utils/Header.java | 21 +++++++++++++++++ .../fr/insee/rmes/api/geo/PaysApiTest.java | 13 +++++++---- 12 files changed, 81 insertions(+), 22 deletions(-) create mode 100644 src/main/java/fr/insee/rmes/modeles/utils/FiltreNom.java create mode 100644 src/main/java/fr/insee/rmes/modeles/utils/Header.java diff --git a/src/main/java/fr/insee/rmes/api/DescribeApi.java b/src/main/java/fr/insee/rmes/api/DescribeApi.java index 031bdada..3b42bd29 100644 --- a/src/main/java/fr/insee/rmes/api/DescribeApi.java +++ b/src/main/java/fr/insee/rmes/api/DescribeApi.java @@ -12,6 +12,8 @@ import org.apache.commons.lang3.StringUtils; +import fr.insee.rmes.modeles.utils.Header; + import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; @@ -25,7 +27,7 @@ public class DescribeApi extends AbstractMetadataApi { @Operation(operationId = "describeUri", summary = "Service pour déréférencer une uri") public Response describeUri( @Parameter(required = true, description = "Iri à déréférencer", schema = @Schema(type = "string")) @QueryParam("uri") String uri, - @Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header) { + @Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) Header header) { if (StringUtils.isEmpty(uri)){ return Response.serverError().build(); } @@ -33,7 +35,7 @@ public Response describeUri( if (Boolean.FALSE.equals(result)) { return Response.status(Status.NOT_FOUND).entity("").build(); } - else return Response.ok(sparqlUtils.executeSparqlQuery("DESCRIBE <"+uri+"> ", header)).build(); + else return Response.ok(sparqlUtils.executeSparqlQuery("DESCRIBE <"+uri+"> ", header.getString())).build(); } diff --git a/src/main/java/fr/insee/rmes/api/geo/PaysApi.java b/src/main/java/fr/insee/rmes/api/geo/PaysApi.java index 5199f053..7eadeaf8 100644 --- a/src/main/java/fr/insee/rmes/api/geo/PaysApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/PaysApi.java @@ -11,6 +11,7 @@ import jakarta.ws.rs.core.Response.Status; import fr.insee.rmes.modeles.geo.Country; +import fr.insee.rmes.modeles.utils.Header; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -48,7 +49,7 @@ public Response getByCode( schema = @Schema( pattern = ConstGeoApi.PATTERN_PAYS, type = Constants.TYPE_STRING, example="99217")) @PathParam(Constants.CODE) String code, - @Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header) { + @Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) Header header) { Country country = new Country(code); String csvResult = sparqlUtils.executeSparqlQuery(GeoQueries.getCountry(code)); @@ -58,7 +59,7 @@ public Response getByCode( return Response.status(Status.NOT_FOUND).entity("").build(); } else { - return Response.ok(responseUtils.produceResponse(country, this.getFirstValidHeader(header))).build(); + return Response.ok(responseUtils.produceResponse(country, this.getFirstValidHeader(header.getString()))).build(); } } } diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/BassinDeVie2022Api.java b/src/main/java/fr/insee/rmes/api/geo/territoire/BassinDeVie2022Api.java index 0334718d..e2daf9ed 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/BassinDeVie2022Api.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/BassinDeVie2022Api.java @@ -17,6 +17,7 @@ import fr.insee.rmes.modeles.geo.territoires.BassinsDeVie2022; import fr.insee.rmes.modeles.geo.territoires.Territoires; import fr.insee.rmes.modeles.utils.Date; +import fr.insee.rmes.modeles.utils.FiltreNom; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -108,7 +109,7 @@ public Response getListe( description = LITTERAL_PARAMETER_NAME_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, example="Ambérieu-en-Bugey")) @QueryParam( - value = Constants.PARAMETER_FILTRE) String filtreNom) + value = Constants.PARAMETER_FILTRE) FiltreNom filtreNom) { if ( ! this.verifyParameterDateIsRightWithHistory(date.getString())) { @@ -118,7 +119,7 @@ public Response getListe( return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListBassinsDeVie(this.formatValidParameterDateIfIsNull(date.getString()), this.formatValidParameterFiltreIfIsNull(filtreNom))), + .executeSparqlQuery(GeoQueries.getListBassinsDeVie(this.formatValidParameterDateIfIsNull(date.getString()), this.formatValidParameterFiltreIfIsNull(filtreNom.getString()))), header, BassinsDeVie2022.class, BassinDeVie2022.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/CantonOuVilleApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/CantonOuVilleApi.java index b111455c..f2652be6 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/CantonOuVilleApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/CantonOuVilleApi.java @@ -7,6 +7,7 @@ import fr.insee.rmes.modeles.geo.territoires.CantonsEtVilles; import fr.insee.rmes.modeles.geo.territoires.Territoires; import fr.insee.rmes.modeles.utils.Date; +import fr.insee.rmes.modeles.utils.FiltreNom; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.CSVUtils; import fr.insee.rmes.utils.Constants; @@ -172,7 +173,7 @@ public Response getDescendants( description = LITTERAL_PARAMETER_NAME_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( - value = Constants.PARAMETER_FILTRE) String filtreNom) { + value = Constants.PARAMETER_FILTRE) FiltreNom filtreNom) { String dateString = null; if (date !=null) { dateString = date.getString(); @@ -195,7 +196,7 @@ public Response getDescendants( .getDescendantsCantonOuVille( code, this.formatValidParameterDateIfIsNull(dateString), - this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire), this.formatValidParameterFiltreIfIsNull(filtreNom))), + this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire), this.formatValidParameterFiltreIfIsNull(filtreNom.getString()))), header, Territoires.class, Territoire.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerAPI.java b/src/main/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerAPI.java index dbf8b1c3..940a4238 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerAPI.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerAPI.java @@ -18,6 +18,7 @@ import fr.insee.rmes.modeles.geo.territoires.CollectivitesDOutreMer; import fr.insee.rmes.modeles.geo.territoires.Territoires; import fr.insee.rmes.modeles.utils.Date; +import fr.insee.rmes.modeles.utils.FiltreNom; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -166,7 +167,7 @@ public Response getDescendants( description = "Filtre sur le nom du ou des territoires renvoyés", required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( - value = Constants.PARAMETER_FILTRE) String filtreNom) { + value = Constants.PARAMETER_FILTRE) FiltreNom filtreNom) { String dateString = null; if (date != null){ dateString = date.getString(); @@ -179,7 +180,7 @@ public Response getDescendants( sparqlUtils.executeSparqlQuery(GeoQueries.getDescendantsCollectiviteDOutreMer(code, this.formatValidParameterDateIfIsNull(dateString), this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire), - this.formatValidParameterFiltreIfIsNull(filtreNom))), + this.formatValidParameterFiltreIfIsNull(filtreNom.getString()))), header, Territoires.class, Territoire.class); } } diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java index 3c09383d..dfd30b53 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java @@ -20,6 +20,7 @@ import fr.insee.rmes.modeles.geo.territoires.Projections; import fr.insee.rmes.modeles.geo.territoires.Territoires; import fr.insee.rmes.modeles.utils.Date; +import fr.insee.rmes.modeles.utils.FiltreNom; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Hidden; @@ -224,7 +225,7 @@ public Response getListe( description = LITTERAL_PARAMETER_NAME_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, example="Bonnay")) @QueryParam( - value = Constants.PARAMETER_FILTRE) String filtreNom, + value = Constants.PARAMETER_FILTRE) FiltreNom filtreNom, @Parameter(description = LITTERAL_PARAMETER_COM_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_BOOLEAN, allowableValues = {"true","false"},example="false", defaultValue = "false")) @@ -243,7 +244,7 @@ public Response getListe( return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListCommunes(this.formatValidParameterDateIfIsNull(dateString), this.formatValidParameterFiltreIfIsNull(filtreNom),this.formatValidParameterBooleanIfIsNull(com))), + .executeSparqlQuery(GeoQueries.getListCommunes(this.formatValidParameterDateIfIsNull(dateString), this.formatValidParameterFiltreIfIsNull(filtreNom.getString()),this.formatValidParameterBooleanIfIsNull(com))), header, Communes.class, Commune.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/DepartementApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/DepartementApi.java index 3b551baf..f4fdaf5e 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/DepartementApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/DepartementApi.java @@ -18,6 +18,7 @@ import fr.insee.rmes.modeles.geo.territoires.Projections; import fr.insee.rmes.modeles.geo.territoires.Territoires; import fr.insee.rmes.modeles.utils.Date; +import fr.insee.rmes.modeles.utils.FiltreNom; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Hidden; @@ -174,7 +175,7 @@ public Response getDescendants( description = LITTERAL_PARAMETER_NAME_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( - value = Constants.PARAMETER_FILTRE) String filtreNom) { + value = Constants.PARAMETER_FILTRE) FiltreNom filtreNom) { String dateString = null; if (date != null){ dateString = date.getString(); @@ -191,7 +192,7 @@ public Response getDescendants( .getDescendantsDepartement( code, this.formatValidParameterDateIfIsNull(dateString), - this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire),this.formatValidParameterFiltreIfIsNull(filtreNom))), + this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire),this.formatValidParameterFiltreIfIsNull(filtreNom.getString()))), header, Territoires.class, Territoire.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/IntercommunaliteAPI.java b/src/main/java/fr/insee/rmes/api/geo/territoire/IntercommunaliteAPI.java index f19caa4c..66c93e9d 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/IntercommunaliteAPI.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/IntercommunaliteAPI.java @@ -17,6 +17,7 @@ import fr.insee.rmes.modeles.geo.territoires.Intercommunalites; import fr.insee.rmes.modeles.geo.territoires.Territoires; import fr.insee.rmes.modeles.utils.Date; +import fr.insee.rmes.modeles.utils.FiltreNom; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Operation; @@ -110,7 +111,7 @@ public Response getListe( description = LITTERAL_PARAMETER_NAME_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING, example="Plaine de l\'Ain")) @QueryParam( - value = Constants.PARAMETER_FILTRE) String filtreNom) + value = Constants.PARAMETER_FILTRE) FiltreNom filtreNom) { if ( ! this.verifyParameterDateIsRightWithHistory(date.getString())) { @@ -120,7 +121,7 @@ public Response getListe( return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListIntercommunalites(this.formatValidParameterDateIfIsNull(date.getString()), this.formatValidParameterFiltreIfIsNull(filtreNom))), + .executeSparqlQuery(GeoQueries.getListIntercommunalites(this.formatValidParameterDateIfIsNull(date.getString()), this.formatValidParameterFiltreIfIsNull(filtreNom.getString()))), header, Intercommunalites.class, Intercommunalite.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/RegionApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/RegionApi.java index 5bab041c..55258448 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/RegionApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/RegionApi.java @@ -18,6 +18,7 @@ import fr.insee.rmes.modeles.geo.territoires.Regions; import fr.insee.rmes.modeles.geo.territoires.Territoires; import fr.insee.rmes.modeles.utils.Date; +import fr.insee.rmes.modeles.utils.FiltreNom; import fr.insee.rmes.queries.geo.GeoQueries; import fr.insee.rmes.utils.Constants; import io.swagger.v3.oas.annotations.Hidden; @@ -123,7 +124,7 @@ public Response getDescendants( description = LITTERAL_PARAMETER_NAME_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( - value = Constants.PARAMETER_FILTRE) String filtreNom) { + value = Constants.PARAMETER_FILTRE) FiltreNom filtreNom) { String dateString = null; if (date != null){ dateString = date.getString(); @@ -140,7 +141,7 @@ public Response getDescendants( .getDescendantsRegion( code, this.formatValidParameterDateIfIsNull(dateString), - this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire),this.formatValidParameterFiltreIfIsNull(filtreNom))), + this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire),this.formatValidParameterFiltreIfIsNull(filtreNom.getString()))), header, Territoires.class, Territoire.class); diff --git a/src/main/java/fr/insee/rmes/modeles/utils/FiltreNom.java b/src/main/java/fr/insee/rmes/modeles/utils/FiltreNom.java new file mode 100644 index 00000000..4ca76f0c --- /dev/null +++ b/src/main/java/fr/insee/rmes/modeles/utils/FiltreNom.java @@ -0,0 +1,23 @@ +package fr.insee.rmes.modeles.utils; + +public class FiltreNom { + private String filtreNom; + + public FiltreNom(String filtreNom) { + if (filtreNom == null){ + this.filtreNom = null; + } + else{ + this.filtreNom = filtreNom; + } + } + + public String getString() { + if (filtreNom != null && !filtreNom.isEmpty()) { + return filtreNom; + } + else{ + return null; //without this it might cause some trouble to test with new FiltreNom(null) + } + } +} diff --git a/src/main/java/fr/insee/rmes/modeles/utils/Header.java b/src/main/java/fr/insee/rmes/modeles/utils/Header.java new file mode 100644 index 00000000..4f6686bd --- /dev/null +++ b/src/main/java/fr/insee/rmes/modeles/utils/Header.java @@ -0,0 +1,21 @@ +public class Header { + private String header; + + public Header(String header) { + if (header == null){ + this.header = null; + } + else{ + this.header = header; + } + } + + public String getString() { + if (header != null && !header.isEmpty()) { + return header; + } + else{ + return null; //without this it might cause some trouble to test with new Header(null) + } + } +} diff --git a/src/test/java/fr/insee/rmes/api/geo/PaysApiTest.java b/src/test/java/fr/insee/rmes/api/geo/PaysApiTest.java index d6e6e565..e3a821ab 100644 --- a/src/test/java/fr/insee/rmes/api/geo/PaysApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/PaysApiTest.java @@ -17,6 +17,7 @@ import fr.insee.rmes.api.AbstractApiTest; import fr.insee.rmes.modeles.geo.Country; +import fr.insee.rmes.modeles.utils.Header; @ExtendWith(MockitoExtension.class) class PaysApiTest extends AbstractApiTest { @@ -26,6 +27,10 @@ class PaysApiTest extends AbstractApiTest { private Country country = new Country(); + private Header headerJSON = new Header(MediaType.APPLICATION_JSON); + private Header headerXML = new Header( MediaType.APPLICATION_XML); + + @Test void givenGetCountry_whenCorrectRequest_andHeaderContentIsJson_thenResponseIsOk() { @@ -34,7 +39,7 @@ void givenGetCountry_whenCorrectRequest_andHeaderContentIsJson_thenResponseIsOk( this.mockUtilsMethodsThenReturnOnePojo(country, Boolean.TRUE); // Call method - geoApi.getByCode("something", MediaType.APPLICATION_JSON); + geoApi.getByCode("something",headerJSON); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -46,7 +51,7 @@ void givenGetCountry_whenCorrectRequest_andHeaderContentIsXml_thenResponseIsOk() this.mockUtilsMethodsThenReturnOnePojo(country, Boolean.TRUE); // Mock methods - geoApi.getByCode("something", MediaType.APPLICATION_XML); + geoApi.getByCode("something",headerXML); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -57,11 +62,11 @@ void givenGetCountry_WhenCorrectRequest_thenResponseIsNotFound() { this.mockUtilsMethodsThenReturnOnePojo(country, Boolean.FALSE); // Call method header content = xml - Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML); + Response response = geoApi.getByCode("something", headerXML); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); // Call method header content = json - response = geoApi.getByCode("something", MediaType.APPLICATION_JSON); + response = geoApi.getByCode("something", headerJSON); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); From c89306f77f176d3269f5c89ed31dc5ea97eb4df7 Mon Sep 17 00:00:00 2001 From: Hugo <103732523+HugoBouttes@users.noreply.github.com> Date: Wed, 2 Oct 2024 10:58:45 +0200 Subject: [PATCH 3/4] fix late commits (#136) * upgrade dependencies(pom) * Update pom.xml version --------- Co-authored-by: Guylene Tandeau Co-authored-by: G TanSndil <72496065+GtanSndil@users.noreply.github.com> --- pom.xml | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 44f41924..2e424e05 100644 --- a/pom.xml +++ b/pom.xml @@ -6,20 +6,20 @@ metadata-api war Implementation of the RMéS metadata API - 3.8.3 + 3.8.4 17 ${java.version} ${java.version} 4.0.0-M1 - 2.17.0 - 6.0.0 + 2.17.2 + 6.1.0 2.18.0 - 2.2.21 - 5.10.0 - 4.0.0 - 2.3.31 - 2.8.3 + 2.2.22 + 5.10.3 + 5.12.0 + 2.3.32 + 2.10.0 UTF-8 UTF-8 @@ -134,13 +134,13 @@ com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-json-provider - 2.16.1 + 2.17.2 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-xml-provider - 2.16.1 + 2.17.2 jakarta.servlet @@ -150,30 +150,30 @@ jakarta.xml.bind jakarta.xml.bind-api - 4.0.0 + 4.0.2 org.eclipse.persistence org.eclipse.persistence.moxy - 3.0.2 + 4.0.4 runtime jakarta.validation jakarta.validation-api - 3.0.1 + 3.1.0 jakarta.activation jakarta.activation-api - 2.0.1 + 2.1.3 runtime org.glassfish.jaxb jaxb-runtime - 4.0.2 + 4.0.5 @@ -195,7 +195,7 @@ joda-time joda-time - 2.12.5 + 2.12.7 @@ -209,7 +209,7 @@ org.apache.commons commons-text - 1.10.0 + 1.11.0 @@ -287,4 +287,11 @@ + + + maven_central + Maven Central + https://repo.maven.apache.org/maven2/ + + From 3653cb96842da9ab4b9c92f6a7baf999ca79cf61 Mon Sep 17 00:00:00 2001 From: Hugo Bouttes Date: Fri, 4 Oct 2024 08:32:12 +0200 Subject: [PATCH 4/4] feat : try different way of header --- src/main/java/fr/insee/rmes/api/geo/PaysApi.java | 5 +++-- .../java/fr/insee/rmes/api/geo/PaysApiTest.java | 13 ++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main/java/fr/insee/rmes/api/geo/PaysApi.java b/src/main/java/fr/insee/rmes/api/geo/PaysApi.java index 7eadeaf8..8dd3ea40 100644 --- a/src/main/java/fr/insee/rmes/api/geo/PaysApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/PaysApi.java @@ -49,8 +49,9 @@ public Response getByCode( schema = @Schema( pattern = ConstGeoApi.PATTERN_PAYS, type = Constants.TYPE_STRING, example="99217")) @PathParam(Constants.CODE) String code, - @Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) Header header) { + @Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header) { + Header header2 = new Header(header); Country country = new Country(code); String csvResult = sparqlUtils.executeSparqlQuery(GeoQueries.getCountry(code)); country = (Country) csvUtils.populatePOJO(csvResult, country); @@ -59,7 +60,7 @@ public Response getByCode( return Response.status(Status.NOT_FOUND).entity("").build(); } else { - return Response.ok(responseUtils.produceResponse(country, this.getFirstValidHeader(header.getString()))).build(); + return Response.ok(responseUtils.produceResponse(country, this.getFirstValidHeader(header2.getString()))).build(); } } } diff --git a/src/test/java/fr/insee/rmes/api/geo/PaysApiTest.java b/src/test/java/fr/insee/rmes/api/geo/PaysApiTest.java index e3a821ab..3987d68c 100644 --- a/src/test/java/fr/insee/rmes/api/geo/PaysApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/PaysApiTest.java @@ -17,7 +17,6 @@ import fr.insee.rmes.api.AbstractApiTest; import fr.insee.rmes.modeles.geo.Country; -import fr.insee.rmes.modeles.utils.Header; @ExtendWith(MockitoExtension.class) class PaysApiTest extends AbstractApiTest { @@ -27,10 +26,6 @@ class PaysApiTest extends AbstractApiTest { private Country country = new Country(); - private Header headerJSON = new Header(MediaType.APPLICATION_JSON); - private Header headerXML = new Header( MediaType.APPLICATION_XML); - - @Test void givenGetCountry_whenCorrectRequest_andHeaderContentIsJson_thenResponseIsOk() { @@ -39,7 +34,7 @@ void givenGetCountry_whenCorrectRequest_andHeaderContentIsJson_thenResponseIsOk( this.mockUtilsMethodsThenReturnOnePojo(country, Boolean.TRUE); // Call method - geoApi.getByCode("something",headerJSON); + geoApi.getByCode("something",MediaType.APPLICATION_JSON); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -51,7 +46,7 @@ void givenGetCountry_whenCorrectRequest_andHeaderContentIsXml_thenResponseIsOk() this.mockUtilsMethodsThenReturnOnePojo(country, Boolean.TRUE); // Mock methods - geoApi.getByCode("something",headerXML); + geoApi.getByCode("something",MediaType.APPLICATION_XML); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -62,11 +57,11 @@ void givenGetCountry_WhenCorrectRequest_thenResponseIsNotFound() { this.mockUtilsMethodsThenReturnOnePojo(country, Boolean.FALSE); // Call method header content = xml - Response response = geoApi.getByCode("something", headerXML); + Response response = geoApi.getByCode("something", MediaType.APPLICATION_XML); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); // Call method header content = json - response = geoApi.getByCode("something", headerJSON); + response = geoApi.getByCode("something", MediaType.APPLICATION_JSON); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any());