From c9a8c0e0e3190c27c802135d4b3818f2ae93c4ab Mon Sep 17 00:00:00 2001 From: GtanSndil Date: Tue, 10 Feb 2026 16:31:42 +0100 Subject: [PATCH 1/7] fix: sparql query when dateMiseAJourTrue --- .../getDatasetById/getDataSetByIDSummary.ftlh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/resources/queries/dataSets/getDatasetById/getDataSetByIDSummary.ftlh b/src/main/resources/queries/dataSets/getDatasetById/getDataSetByIDSummary.ftlh index 161eead31..d3e4b213e 100644 --- a/src/main/resources/queries/dataSets/getDatasetById/getDataSetByIDSummary.ftlh +++ b/src/main/resources/queries/dataSets/getDatasetById/getDataSetByIDSummary.ftlh @@ -2,9 +2,13 @@ select distinct ?id ?dateModification FROM where { - ?uri a dcat:Dataset ; - dcterms:identifier "${ID}" ; - dcterms:identifier ?id ; - OPTIONAL {?uri dcterms:modified ?dateModification . } + ?uri a dcat:Dataset ; + dcterms:identifier "${ID}" ; + dcterms:identifier ?id ; + OPTIONAL { + ?record a dcat:CatalogRecord ; + foaf:primaryTopic ?uri ; + dcterms:modified ?dateModification . + } -} group by ?id ?dateModification \ No newline at end of file +} \ No newline at end of file From 499155155709082f79c60492f83cf332cbbff6d5 Mon Sep 17 00:00:00 2001 From: GtanSndil Date: Tue, 10 Feb 2026 16:32:49 +0100 Subject: [PATCH 2/7] fix: management for dateMiseAJourfalse when disseminationStatus or wasGeneratedBy is null --- .../dataset/DataSetModelSwagger.java | 11 ++++++++ .../rmes/services/datasets/DataSetsImpl.java | 25 ++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/insee/rmes/modelSwagger/dataset/DataSetModelSwagger.java b/src/main/java/fr/insee/rmes/modelSwagger/dataset/DataSetModelSwagger.java index de5d909c8..e69119ef1 100644 --- a/src/main/java/fr/insee/rmes/modelSwagger/dataset/DataSetModelSwagger.java +++ b/src/main/java/fr/insee/rmes/modelSwagger/dataset/DataSetModelSwagger.java @@ -196,4 +196,15 @@ public DataSetModelSwagger(Id id, List title, Uri uri, Modified mod this.validationState = validationState; this.themeModelSwaggerS = themeModelSwaggerS; } + + public DataSetModelSwagger(Id id, List title, Uri uri, String validationState, CatalogRecordCreated catalogRecordCreated, CatalogRecordModified catalogRecordModified, CatalogRecordCreator catalogRecordCreator, CatalogRecordContributor catalogRecordContributor) { + this.id = id.toString(); + this.title = title; + this.uri = uri.toString(); + this.validationState = validationState; + this.catalogRecordContributor = catalogRecordContributor; + this.catalogRecordCreator = catalogRecordCreator; + this.catalogRecordCreated = catalogRecordCreated; + this.catalogRecordModified = catalogRecordModified; + } } diff --git a/src/main/java/fr/insee/rmes/services/datasets/DataSetsImpl.java b/src/main/java/fr/insee/rmes/services/datasets/DataSetsImpl.java index 2c987fe18..61185df0a 100644 --- a/src/main/java/fr/insee/rmes/services/datasets/DataSetsImpl.java +++ b/src/main/java/fr/insee/rmes/services/datasets/DataSetsImpl.java @@ -150,13 +150,22 @@ protected DataSetModelSwagger findDataSetModelSwagger(String id) throws RmesExce List title = constructLangContent(catalogue_result.getString("titleLg1"), catalogue_result.getString("titleLg2")); Id id1=new Id(catalogue_result.getString("id")); Uri uri = new Uri(catalogue_result.getString("uri")); - DisseminationStatus disseminationStatus = new DisseminationStatus(ontologies_result.getString("labeldisseminationStatusLg1")); + CatalogRecordCreated catalogRecordCreated = new CatalogRecordCreated(catalogue_result.getString("catalogRecordCreated")); CatalogRecordModified catalogRecordModified = new CatalogRecordModified(catalogue_result.getString("catalogRecordModified")); CatalogRecordCreator catalogRecordCreator = new CatalogRecordCreator(catalogue_result.getString("catalogRecordCreator")); CatalogRecordContributor catalogRecordContributor = new CatalogRecordContributor(catalogue_result.getString("catalogRecordContributor")); String validationState = catalogue_result.getString("statutValidation"); - DataSetModelSwagger response = new DataSetModelSwagger(id1, title, uri, validationState, disseminationStatus, catalogRecordCreated,catalogRecordModified,catalogRecordCreator,catalogRecordContributor); + + DisseminationStatus disseminationStatus = null; + DataSetModelSwagger response = null; + if (ontologies_result.has("labeldisseminationStatusLg1")){ + disseminationStatus = new DisseminationStatus(ontologies_result.getString("labeldisseminationStatusLg1")); + response = new DataSetModelSwagger(id1, title, uri, validationState, disseminationStatus, catalogRecordCreated, catalogRecordModified, catalogRecordCreator, catalogRecordContributor); + } else { + response = new DataSetModelSwagger(id1, title, uri, validationState, catalogRecordCreated, catalogRecordModified, catalogRecordCreator, catalogRecordContributor); + } + testPresenceVariablePuisAjout(response,catalogue_result,adms_result,codes_result,organisations_result,structures_result); return response; } else { @@ -522,10 +531,14 @@ private List getWasGeneratedBy(List operationStat) throws RmesE params.put("URI", s.replace(" ", "")); JSONObject wasGeneratedByQuery = repoGestion.getResponseAsObject(buildRequest(Constants.DATASETS_QUERIES_PATH+DATASET_BY_ID_PATH, "getDataSetByIdWasGeneratedBy.ftlh", params)); - List wasGeneratedByTitles = constructLangContent(wasGeneratedByQuery.getString("labelwasGeneratedByLg1"),wasGeneratedByQuery.getString("labelwasGeneratedByLg2")); - IdLabel wasGeneratedByIdLabel = new IdLabel(wasGeneratedByQuery.getString("wasGeneratedById"),wasGeneratedByTitles); - wasGeneratedByIdLabel.setType(wasGeneratedByQuery.getString("typeWasGeneratedBy")); - wasGeneratedBy.add(wasGeneratedByIdLabel); + List wasGeneratedByTitles = null; + IdLabel wasGeneratedByIdLabel = null; + if (wasGeneratedByQuery.has("wasGeneratedById")) { + wasGeneratedByTitles = constructLangContent(wasGeneratedByQuery.getString("labelwasGeneratedByLg1"), wasGeneratedByQuery.getString("labelwasGeneratedByLg2")); + wasGeneratedByIdLabel = new IdLabel(wasGeneratedByQuery.getString("wasGeneratedById"), wasGeneratedByTitles); + wasGeneratedByIdLabel.setType(wasGeneratedByQuery.getString("typeWasGeneratedBy")); + wasGeneratedBy.add(wasGeneratedByIdLabel); + } } return wasGeneratedBy; } From c2905ae3445175fd1e05f8786cd0852141dc5c24 Mon Sep 17 00:00:00 2001 From: GtanSndil Date: Fri, 13 Feb 2026 17:22:35 +0100 Subject: [PATCH 3/7] test --- .../services/datasets/DataSetsImplTest.java | 187 +++++++++++++++++- .../services/utils/DataSetsUtilsTest.java | 1 - 2 files changed, 186 insertions(+), 2 deletions(-) diff --git a/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java b/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java index d63230717..c8d5b96bb 100644 --- a/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java +++ b/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; import fr.insee.rmes.dto.datasets.PatchDatasetDTO; -import fr.insee.rmes.model.datasets.Theme; +import fr.insee.rmes.model.datasets.*; import fr.insee.rmes.modelSwagger.dataset.*; import fr.insee.rmes.persistence.RepositoryGestion; import fr.insee.rmes.services.utils.DataSetsUtilsTest; @@ -247,9 +247,194 @@ void testConstructLangContentList(){ String expected_2 = "[LangContent(lang=lg2, content=contentLg2)]"; assertThat(actual_1).isEqualTo(expected_1); assertThat(actual_2).isEqualTo(expected_2); + } + + // --- Tests for findDataSetModelSwagger --- + + private JSONObject buildMinimalCatalogueResult() { + JSONObject catalogue = new JSONObject(); + catalogue.put("id", "jd1000"); + catalogue.put("titleLg1", "Titre FR"); + catalogue.put("titleLg2", "Title EN"); + catalogue.put("uri", "http://bauhaus/catalogues/jeuDeDonnees/jd1000"); + catalogue.put("catalogRecordCreated", "2024-01-01T00:00:00"); + catalogue.put("catalogRecordModified", "2024-01-02T00:00:00"); + catalogue.put("catalogRecordCreator", "creator1"); + catalogue.put("catalogRecordContributor", "contributor1"); + catalogue.put("statutValidation", "Modified"); + return catalogue; + } + + private void mockSubQueries(JSONObject adms, JSONObject codes, JSONObject ontologies, JSONObject organisations, JSONObject structures) throws RmesException { + when(repoGestion.getResponseAsObject("getDataSetById_catalogueAdms.ftlh")).thenReturn(adms); + when(repoGestion.getResponseAsObject("getDataSetById_catalogueCodes.ftlh")).thenReturn(codes); + when(repoGestion.getResponseAsObject("getDataSetById_catalogueOntologies.ftlh")).thenReturn(ontologies); + when(repoGestion.getResponseAsObject("getDataSetById_catalogueOrganisations.ftlh")).thenReturn(organisations); + when(repoGestion.getResponseAsObject("getDataSetById_catalogueStructures.ftlh")).thenReturn(structures); + } + + @Test + void findDataSetModelSwagger_shouldReturnMinimalDataSet_withoutDisseminationStatus() throws RmesException, JsonProcessingException { + JSONObject catalogueResult = buildMinimalCatalogueResult(); + JSONObject emptyJson = new JSONObject(); + + when(repoGestion.getResponseAsObject("getDataSetById_catalogue.ftlh")).thenReturn(catalogueResult); + mockSubQueries(emptyJson, emptyJson, emptyJson, emptyJson, emptyJson); + + DataSetModelSwagger result = dataSetsImpl.findDataSetModelSwagger("jd1000"); + + assertThat(result.getId()).isEqualTo("jd1000"); + assertThat(result.getUri()).isEqualTo("http://bauhaus/catalogues/jeuDeDonnees/jd1000"); + assertThat(result.getValidationState()).isEqualTo("Modified"); + assertThat(result.getTitle()).isEqualTo(dataSetsImpl.constructLangContent("Titre FR", "Title EN")); + assertThat(result.getCatalogRecordCreated()).isEqualTo(new CatalogRecordCreated("2024-01-01T00:00:00")); + assertThat(result.getCatalogRecordModified()).isEqualTo(new CatalogRecordModified("2024-01-02T00:00:00")); + assertThat(result.getCatalogRecordCreator()).isEqualTo(new CatalogRecordCreator("creator1")); + assertThat(result.getCatalogRecordContributor()).isEqualTo(new CatalogRecordContributor("contributor1")); + assertThat(result.getDisseminationStatus()).isNull(); + assertThat(result.getKeyword()).isEmpty(); + } + + @Test + void findDataSetModelSwagger_shouldReturnDataSet_withDisseminationStatus() throws RmesException, JsonProcessingException { + JSONObject catalogueResult = buildMinimalCatalogueResult(); + JSONObject emptyJson = new JSONObject(); + JSONObject ontologiesResult = new JSONObject(); + ontologiesResult.put("labeldisseminationStatusLg1", "Public"); + + when(repoGestion.getResponseAsObject("getDataSetById_catalogue.ftlh")).thenReturn(catalogueResult); + mockSubQueries(emptyJson, emptyJson, ontologiesResult, emptyJson, emptyJson); + + DataSetModelSwagger result = dataSetsImpl.findDataSetModelSwagger("jd1000"); + + assertThat(result.getId()).isEqualTo("jd1000"); + assertThat(result.getDisseminationStatus()).isEqualTo("Public"); + assertThat(result.getTitle()).isEqualTo(dataSetsImpl.constructLangContent("Titre FR", "Title EN")); + } + + @Test + void findDataSetModelSwagger_shouldSetOptionalFields_whenPresentInCatalogue() throws RmesException, JsonProcessingException { + JSONObject catalogueResult = buildMinimalCatalogueResult(); + catalogueResult.put("dateModification", "2024-06-15T10:00:00"); + catalogueResult.put("subtitleLg1", "Sous-titre FR"); + catalogueResult.put("subtitleLg2", "Subtitle EN"); + catalogueResult.put("abstractLg1", "Resume FR"); + catalogueResult.put("abstractLg2", "Abstract EN"); + catalogueResult.put("version", "1.0"); + catalogueResult.put("dateEmission", "2024-01-15"); + + JSONObject emptyJson = new JSONObject(); + + when(repoGestion.getResponseAsObject("getDataSetById_catalogue.ftlh")).thenReturn(catalogueResult); + mockSubQueries(emptyJson, emptyJson, emptyJson, emptyJson, emptyJson); + + DataSetModelSwagger result = dataSetsImpl.findDataSetModelSwagger("jd1000"); + + assertThat(result.getModified()).isEqualTo("2024-06-15T10:00:00"); + assertThat(result.getSubtitle()).isEqualTo(dataSetsImpl.constructLangContent("Sous-titre FR", "Subtitle EN")); + assertThat(result.getAbstractDataset()).isEqualTo(dataSetsImpl.constructLangContent("Resume FR", "Abstract EN")); + assertThat(result.getVersion()).isEqualTo("1.0"); + assertThat(result.getIssued()).isEqualTo("2024-01-15"); + } + + @Test + void findDataSetModelSwagger_shouldSetIdentifier_whenPresentInAdms() throws RmesException, JsonProcessingException { + JSONObject catalogueResult = buildMinimalCatalogueResult(); + JSONObject admsResult = new JSONObject(); + admsResult.put("identifier", "INSEE-JD1000"); + JSONObject emptyJson = new JSONObject(); + + when(repoGestion.getResponseAsObject("getDataSetById_catalogue.ftlh")).thenReturn(catalogueResult); + mockSubQueries(admsResult, emptyJson, emptyJson, emptyJson, emptyJson); + + DataSetModelSwagger result = dataSetsImpl.findDataSetModelSwagger("jd1000"); + + assertThat(result.getIdentifier()).isEqualTo("INSEE-JD1000"); + } + @Test + void findDataSetModelSwagger_shouldSetPublisher_whenPresentInOrganisations() throws RmesException, JsonProcessingException { + JSONObject catalogueResult = buildMinimalCatalogueResult(); + JSONObject organisationsResult = new JSONObject(); + organisationsResult.put("idPublisher", "INSEE"); + organisationsResult.put("labelPublisherLg1", "Institut national de la statistique"); + organisationsResult.put("labelPublisherLg2", "National Institute of Statistics"); + JSONObject emptyJson = new JSONObject(); + + when(repoGestion.getResponseAsObject("getDataSetById_catalogue.ftlh")).thenReturn(catalogueResult); + mockSubQueries(emptyJson, emptyJson, emptyJson, organisationsResult, emptyJson); + + DataSetModelSwagger result = dataSetsImpl.findDataSetModelSwagger("jd1000"); + + assertThat(result.getPublisher()).isNotNull(); + assertThat(result.getPublisher().getId()).isEqualTo("INSEE"); + } + + @Test + void findDataSetModelSwagger_shouldSetTypeAndAccessRights_whenPresentInCodes() throws RmesException, JsonProcessingException { + JSONObject catalogueResult = buildMinimalCatalogueResult(); + JSONObject codesResult = new JSONObject(); + codesResult.put("labeltypeLg1", "Fichier detail"); + codesResult.put("labeltypeLg2", "Detail file"); + codesResult.put("labelaccessRightsLg1", "Acces libre"); + codesResult.put("labelaccessRightsLg2", "Open access"); + JSONObject emptyJson = new JSONObject(); + + when(repoGestion.getResponseAsObject("getDataSetById_catalogue.ftlh")).thenReturn(catalogueResult); + mockSubQueries(emptyJson, codesResult, emptyJson, emptyJson, emptyJson); + + DataSetModelSwagger result = dataSetsImpl.findDataSetModelSwagger("jd1000"); + + assertThat(result.getType()).isEqualTo(dataSetsImpl.constructLangContent("Fichier detail", "Detail file")); + assertThat(result.getAccessRights()).isEqualTo(dataSetsImpl.constructLangContent("Acces libre", "Open access")); + } + + @Test + void findDataSetModelSwagger_shouldSetTemporal_whenPresentInCatalogue() throws RmesException, JsonProcessingException { + JSONObject catalogueResult = buildMinimalCatalogueResult(); + catalogueResult.put("startPeriod", "2020-01-01"); + catalogueResult.put("endPeriod", "2023-12-31"); + JSONObject emptyJson = new JSONObject(); + + when(repoGestion.getResponseAsObject("getDataSetById_catalogue.ftlh")).thenReturn(catalogueResult); + mockSubQueries(emptyJson, emptyJson, emptyJson, emptyJson, emptyJson); + + DataSetModelSwagger result = dataSetsImpl.findDataSetModelSwagger("jd1000"); + assertThat(result.getTemporal()).isNotNull(); } + @Test + void findDataSetModelSwagger_shouldSetStructure_whenDsdPresentInStructures() throws RmesException, JsonProcessingException { + JSONObject catalogueResult = buildMinimalCatalogueResult(); + JSONObject structuresResult = new JSONObject(); + structuresResult.put("uri", "http://structures/dsd1"); + structuresResult.put("structureId", "dsd1"); + structuresResult.put("dsd", "DSD_CHAMP"); + structuresResult.put("DataStructureDefinition", "true"); + JSONObject emptyJson = new JSONObject(); + + when(repoGestion.getResponseAsObject("getDataSetById_catalogue.ftlh")).thenReturn(catalogueResult); + mockSubQueries(emptyJson, emptyJson, emptyJson, emptyJson, structuresResult); + + DataSetModelSwagger result = dataSetsImpl.findDataSetModelSwagger("jd1000"); + + assertThat(result.getStructure()).isNotNull(); + } + + @Test + void findDataSetModelSwagger_shouldSetStructureFromUri_whenNoDsd() throws RmesException, JsonProcessingException { + JSONObject catalogueResult = buildMinimalCatalogueResult(); + JSONObject structuresResult = new JSONObject(); + structuresResult.put("uri", "http://structures/struct1"); + JSONObject emptyJson = new JSONObject(); + + when(repoGestion.getResponseAsObject("getDataSetById_catalogue.ftlh")).thenReturn(catalogueResult); + mockSubQueries(emptyJson, emptyJson, emptyJson, emptyJson, structuresResult); + + DataSetModelSwagger result = dataSetsImpl.findDataSetModelSwagger("jd1000"); + + assertThat(result.getStructure()).isNotNull(); + } } \ No newline at end of file diff --git a/src/test/java/fr/insee/rmes/services/utils/DataSetsUtilsTest.java b/src/test/java/fr/insee/rmes/services/utils/DataSetsUtilsTest.java index 1c225b976..a0b691a12 100644 --- a/src/test/java/fr/insee/rmes/services/utils/DataSetsUtilsTest.java +++ b/src/test/java/fr/insee/rmes/services/utils/DataSetsUtilsTest.java @@ -6,7 +6,6 @@ public class DataSetsUtilsTest { public static final String EXPECTED_THEMELIST_GET_THEME_MODEL_SWAGGERS = "[ThemeModelSwagger(uri=uri0, labelDataSet=[LabelDataSet(lang=fr, content=labelThemeLg10), LabelDataSet(lang=en, content=labelThemeLg20)], themeTaxonomy=themeTaxonomy0), ThemeModelSwagger(uri=uri1, labelDataSet=[LabelDataSet(lang=fr, content=labelThemeLg11), LabelDataSet(lang=en, content=labelThemeLg21)], themeTaxonomy=themeTaxonomy1), ThemeModelSwagger(uri=uri2, labelDataSet=[LabelDataSet(lang=fr, content=labelThemeLg12), LabelDataSet(lang=en, content=labelThemeLg22)], themeTaxonomy=themeTaxonomy2), ThemeModelSwagger(uri=uri3, labelDataSet=[LabelDataSet(lang=fr, content=labelThemeLg13), LabelDataSet(lang=en, content=labelThemeLg23)], themeTaxonomy=themeTaxonomy3)]"; public static final String EXPECTED_LANGCONTENTLIST_SET_ID_LABEL = "IdLabel(id=id, label=[LangContent(lang=fr, content=content1), LangContent(lang=en, content=content2)], type=null)"; public static final String EXPECTED_LANGCONTENTLIST_SET_ID_LABEL_WITH_TYPE = "IdLabel(id=id, label=[LangContent(lang=fr, content=content1), LangContent(lang=en, content=content2)], type=type)"; - public static final String URI_TEST = "http://uri.test"; public static final String DATA_SET_LIST= """ [ { From 4ff6f7f3b3d0ce91bf7d52f7a42436610531378c Mon Sep 17 00:00:00 2001 From: GtanSndil Date: Mon, 16 Feb 2026 09:42:07 +0100 Subject: [PATCH 4/7] refactor: test --- .../services/datasets/DataSetsImplTest.java | 31 ++++++------------- .../services/utils/DataSetsUtilsTest.java | 2 ++ 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java b/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java index c8d5b96bb..86a8973e9 100644 --- a/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java +++ b/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java @@ -251,19 +251,6 @@ void testConstructLangContentList(){ // --- Tests for findDataSetModelSwagger --- - private JSONObject buildMinimalCatalogueResult() { - JSONObject catalogue = new JSONObject(); - catalogue.put("id", "jd1000"); - catalogue.put("titleLg1", "Titre FR"); - catalogue.put("titleLg2", "Title EN"); - catalogue.put("uri", "http://bauhaus/catalogues/jeuDeDonnees/jd1000"); - catalogue.put("catalogRecordCreated", "2024-01-01T00:00:00"); - catalogue.put("catalogRecordModified", "2024-01-02T00:00:00"); - catalogue.put("catalogRecordCreator", "creator1"); - catalogue.put("catalogRecordContributor", "contributor1"); - catalogue.put("statutValidation", "Modified"); - return catalogue; - } private void mockSubQueries(JSONObject adms, JSONObject codes, JSONObject ontologies, JSONObject organisations, JSONObject structures) throws RmesException { when(repoGestion.getResponseAsObject("getDataSetById_catalogueAdms.ftlh")).thenReturn(adms); @@ -275,7 +262,7 @@ private void mockSubQueries(JSONObject adms, JSONObject codes, JSONObject ontolo @Test void findDataSetModelSwagger_shouldReturnMinimalDataSet_withoutDisseminationStatus() throws RmesException, JsonProcessingException { - JSONObject catalogueResult = buildMinimalCatalogueResult(); + var catalogueResult = new JSONObject(DataSetsUtilsTest.CATALOGUE_RESULT_MINIMAL); JSONObject emptyJson = new JSONObject(); when(repoGestion.getResponseAsObject("getDataSetById_catalogue.ftlh")).thenReturn(catalogueResult); @@ -297,7 +284,7 @@ void findDataSetModelSwagger_shouldReturnMinimalDataSet_withoutDisseminationStat @Test void findDataSetModelSwagger_shouldReturnDataSet_withDisseminationStatus() throws RmesException, JsonProcessingException { - JSONObject catalogueResult = buildMinimalCatalogueResult(); + var catalogueResult = new JSONObject(DataSetsUtilsTest.CATALOGUE_RESULT_MINIMAL); JSONObject emptyJson = new JSONObject(); JSONObject ontologiesResult = new JSONObject(); ontologiesResult.put("labeldisseminationStatusLg1", "Public"); @@ -314,7 +301,7 @@ void findDataSetModelSwagger_shouldReturnDataSet_withDisseminationStatus() throw @Test void findDataSetModelSwagger_shouldSetOptionalFields_whenPresentInCatalogue() throws RmesException, JsonProcessingException { - JSONObject catalogueResult = buildMinimalCatalogueResult(); + var catalogueResult = new JSONObject(DataSetsUtilsTest.CATALOGUE_RESULT_MINIMAL); catalogueResult.put("dateModification", "2024-06-15T10:00:00"); catalogueResult.put("subtitleLg1", "Sous-titre FR"); catalogueResult.put("subtitleLg2", "Subtitle EN"); @@ -339,7 +326,7 @@ void findDataSetModelSwagger_shouldSetOptionalFields_whenPresentInCatalogue() th @Test void findDataSetModelSwagger_shouldSetIdentifier_whenPresentInAdms() throws RmesException, JsonProcessingException { - JSONObject catalogueResult = buildMinimalCatalogueResult(); + var catalogueResult = new JSONObject(DataSetsUtilsTest.CATALOGUE_RESULT_MINIMAL); JSONObject admsResult = new JSONObject(); admsResult.put("identifier", "INSEE-JD1000"); JSONObject emptyJson = new JSONObject(); @@ -354,7 +341,7 @@ void findDataSetModelSwagger_shouldSetIdentifier_whenPresentInAdms() throws Rmes @Test void findDataSetModelSwagger_shouldSetPublisher_whenPresentInOrganisations() throws RmesException, JsonProcessingException { - JSONObject catalogueResult = buildMinimalCatalogueResult(); + var catalogueResult = new JSONObject(DataSetsUtilsTest.CATALOGUE_RESULT_MINIMAL); JSONObject organisationsResult = new JSONObject(); organisationsResult.put("idPublisher", "INSEE"); organisationsResult.put("labelPublisherLg1", "Institut national de la statistique"); @@ -372,7 +359,7 @@ void findDataSetModelSwagger_shouldSetPublisher_whenPresentInOrganisations() thr @Test void findDataSetModelSwagger_shouldSetTypeAndAccessRights_whenPresentInCodes() throws RmesException, JsonProcessingException { - JSONObject catalogueResult = buildMinimalCatalogueResult(); + var catalogueResult = new JSONObject(DataSetsUtilsTest.CATALOGUE_RESULT_MINIMAL); JSONObject codesResult = new JSONObject(); codesResult.put("labeltypeLg1", "Fichier detail"); codesResult.put("labeltypeLg2", "Detail file"); @@ -391,7 +378,7 @@ void findDataSetModelSwagger_shouldSetTypeAndAccessRights_whenPresentInCodes() t @Test void findDataSetModelSwagger_shouldSetTemporal_whenPresentInCatalogue() throws RmesException, JsonProcessingException { - JSONObject catalogueResult = buildMinimalCatalogueResult(); + var catalogueResult = new JSONObject(DataSetsUtilsTest.CATALOGUE_RESULT_MINIMAL); catalogueResult.put("startPeriod", "2020-01-01"); catalogueResult.put("endPeriod", "2023-12-31"); JSONObject emptyJson = new JSONObject(); @@ -406,7 +393,7 @@ void findDataSetModelSwagger_shouldSetTemporal_whenPresentInCatalogue() throws R @Test void findDataSetModelSwagger_shouldSetStructure_whenDsdPresentInStructures() throws RmesException, JsonProcessingException { - JSONObject catalogueResult = buildMinimalCatalogueResult(); + var catalogueResult = new JSONObject(DataSetsUtilsTest.CATALOGUE_RESULT_MINIMAL); JSONObject structuresResult = new JSONObject(); structuresResult.put("uri", "http://structures/dsd1"); structuresResult.put("structureId", "dsd1"); @@ -424,7 +411,7 @@ void findDataSetModelSwagger_shouldSetStructure_whenDsdPresentInStructures() thr @Test void findDataSetModelSwagger_shouldSetStructureFromUri_whenNoDsd() throws RmesException, JsonProcessingException { - JSONObject catalogueResult = buildMinimalCatalogueResult(); + var catalogueResult = new JSONObject(DataSetsUtilsTest.CATALOGUE_RESULT_MINIMAL); JSONObject structuresResult = new JSONObject(); structuresResult.put("uri", "http://structures/struct1"); JSONObject emptyJson = new JSONObject(); diff --git a/src/test/java/fr/insee/rmes/services/utils/DataSetsUtilsTest.java b/src/test/java/fr/insee/rmes/services/utils/DataSetsUtilsTest.java index a0b691a12..46511cdfe 100644 --- a/src/test/java/fr/insee/rmes/services/utils/DataSetsUtilsTest.java +++ b/src/test/java/fr/insee/rmes/services/utils/DataSetsUtilsTest.java @@ -69,4 +69,6 @@ public class DataSetsUtilsTest { public static final String CATALOGUE_RESULT_RELATIONS = "{\"relations\":\"http://www.insee.fr,http://www.rdf.insee.fr\"}"; public static final String EXPECTED_RELATIONS = "[\"http://www.insee.fr\", \"http://www.rdf.insee.fr\"]"; + public static final String CATALOGUE_RESULT_MINIMAL = "{\"id\":\"jd1000\", \"titleLg1\":\"Titre FR\", \"titleLg2\":\"Title EN\", \"uri\":\"http://bauhaus/catalogues/jeuDeDonnees/jd1000\", \"catalogRecordCreated\":\"2024-01-01T00:00:00\", \"catalogRecordModified\":\"2024-01-02T00:00:00\", \"catalogRecordCreator\":\"creator1\", \"catalogRecordContributor\":\"contributor1\", \"statutValidation\":\"Modified\"}"; + } From f7d402e9be5b654e5eab2b43fc0fb02a6878f85a Mon Sep 17 00:00:00 2001 From: GtanSndil Date: Mon, 16 Feb 2026 10:00:21 +0100 Subject: [PATCH 5/7] test: when bollean true --- .../services/datasets/DataSetsImplTest.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java b/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java index 86a8973e9..930eb85ce 100644 --- a/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java +++ b/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java @@ -220,6 +220,22 @@ void getDataSetByIDDateMiseAJour_shouldReturn404IfInexistentId() throws RmesExce .hasMessageContaining("Non existent dataset identifier"); } + @Test + void getDataSetByIDSummary_shouldReturnIdUriAndModified_whenDataSetExists() throws RmesException, JsonProcessingException { + JSONObject mockJSON = new JSONObject(); + mockJSON.put("id", "jd1000"); + mockJSON.put("uri", "http://bauhaus/catalogues/jeuDeDonnees/jd1000"); + mockJSON.put("dateMiseAJour", "2024-06-15T10:00:00"); + when(repoGestion.getResponseAsObject(Mockito.anyString())).thenReturn(mockJSON); + + String result = dataSetsImpl.getDataSetByIDSummary("jd1000"); + + var resultNode = MAPPER.readTree(result); + assertThat(resultNode.get("id").asText()).isEqualTo("jd1000"); + assertThat(resultNode.get("uri").asText()).isEqualTo("http://bauhaus/catalogues/jeuDeDonnees/jd1000"); + assertThat(resultNode.get("modified").asText()).isEqualTo("2024-06-15T10:00:00"); + } + @Test void patchDataset_shouldReturn400() { @@ -249,7 +265,9 @@ void testConstructLangContentList(){ assertThat(actual_2).isEqualTo(expected_2); } - // --- Tests for findDataSetModelSwagger --- + // ///////////////////////////////////// + // Tests for findDataSetModelSwagger // + // ///////////////////////////////////// private void mockSubQueries(JSONObject adms, JSONObject codes, JSONObject ontologies, JSONObject organisations, JSONObject structures) throws RmesException { From ab320f3b95fcc0941d7b64e3403aef8a384511f9 Mon Sep 17 00:00:00 2001 From: GtanSndil Date: Mon, 16 Feb 2026 13:04:21 +0100 Subject: [PATCH 6/7] test: getStatisticalUnit --- .../services/datasets/DataSetsImplTest.java | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java b/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java index 930eb85ce..8351e5e3a 100644 --- a/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java +++ b/src/test/java/fr/insee/rmes/services/datasets/DataSetsImplTest.java @@ -25,6 +25,8 @@ import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.HttpStatus; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.*; import java.util.function.Supplier; import java.util.stream.Stream; @@ -48,7 +50,7 @@ class DataSetsImplTest { void getListDataSetsTest() throws RmesException, JsonProcessingException { JSONArray mockJSON = new JSONArray(DataSetsUtilsTest.DATA_SET_LIST); when(repoGestion.getResponseAsArray(Mockito.anyString())).thenReturn(mockJSON); - assertThat(MAPPER.readTree(dataSetsImpl.getListDataSets(""))).isEqualTo(MAPPER.readTree(DataSetsUtilsTest.EXPECTED_GET_DATA_SET_LIST.toString())); + assertThat(MAPPER.readTree(dataSetsImpl.getListDataSets(""))).isEqualTo(MAPPER.readTree(DataSetsUtilsTest.EXPECTED_GET_DATA_SET_LIST)); } @Test @@ -171,9 +173,6 @@ void getThemeModelSwaggerSTest() { } @ParameterizedTest(name = "{0}") - /*@CsvSource({ - "subtitleLg1, subtitleLg2" - })*/ @MethodSource(value = "argumentsProvider") void testPresenceVariablePuisAjoutTest_checkFieldIsAdded(String key1, String key2, Supplier> getListLangContent) throws RmesException, JsonProcessingException { var catalogue_result = new JSONObject(Map.of(key1, "l1", key2, "l2")); @@ -442,4 +441,42 @@ void findDataSetModelSwagger_shouldSetStructureFromUri_whenNoDsd() throws RmesEx assertThat(result.getStructure()).isNotNull(); } + @Test + void getStatisticalUnit_shouldReturnIdLabelsForEachUri() throws Exception { + JSONObject response1 = new JSONObject(); + response1.put("labelUriStatisticalLg1", "Ménages"); + response1.put("labelUriStatisticalLg2", "Households"); + + JSONObject response2 = new JSONObject(); + response2.put("labelUriStatisticalLg1", "Individus"); + response2.put("labelUriStatisticalLg2", "Individuals"); + + when(repoGestion.getResponseAsObject(Mockito.anyString())) + .thenReturn(response1) + .thenReturn(response2); + + Method method = DataSetsImpl.class.getDeclaredMethod("getStatisticalUnit", List.class, String.class); + method.setAccessible(true); + + @SuppressWarnings("unchecked") + List result = (List) method.invoke(dataSetsImpl, List.of("http://uri1", "http://uri2"), "jd1000"); + + assertThat(result).hasSize(2); + assertThat(result.get(0).getId()).isEqualTo("http://uri1"); + assertThat(result.get(0).getLabel()).isEqualTo(dataSetsImpl.constructLangContent("Ménages", "Households")); + assertThat(result.get(1).getId()).isEqualTo("http://uri2"); + assertThat(result.get(1).getLabel()).isEqualTo(dataSetsImpl.constructLangContent("Individus", "Individuals")); + } + + @Test + void getStatisticalUnit_shouldReturnEmptyList_whenNoUris() throws Exception { + Method method = DataSetsImpl.class.getDeclaredMethod("getStatisticalUnit", List.class, String.class); + method.setAccessible(true); + + @SuppressWarnings("unchecked") + List result = (List) method.invoke(dataSetsImpl, List.of(), "jd1000"); + + assertThat(result).isEmpty(); + } + } \ No newline at end of file From 5594dc39c9931342c11cfca4efa395e6490ec0b8 Mon Sep 17 00:00:00 2001 From: GtanSndil Date: Mon, 16 Feb 2026 14:11:05 +0100 Subject: [PATCH 7/7] tests: of new constructor of DataSetmodelSwagger --- .../dataset/DataSetModelSwaggerTest.java | 56 +++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/src/test/java/fr/insee/rmes/modelSwagger/dataset/DataSetModelSwaggerTest.java b/src/test/java/fr/insee/rmes/modelSwagger/dataset/DataSetModelSwaggerTest.java index 08bac2df1..e71d343a1 100644 --- a/src/test/java/fr/insee/rmes/modelSwagger/dataset/DataSetModelSwaggerTest.java +++ b/src/test/java/fr/insee/rmes/modelSwagger/dataset/DataSetModelSwaggerTest.java @@ -3,14 +3,13 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; -import fr.insee.rmes.model.datasets.CatalogRecordContributor; -import fr.insee.rmes.model.datasets.CatalogRecordCreated; -import fr.insee.rmes.model.datasets.CatalogRecordCreator; -import fr.insee.rmes.model.datasets.CatalogRecordModified; +import fr.insee.rmes.model.datasets.*; import org.json.JSONException; import org.json.JSONObject; import org.junit.jupiter.api.Test; +import java.util.List; + import static org.assertj.core.api.Assertions.assertThat; class DataSetModelSwaggerTest { @@ -34,4 +33,53 @@ void verify_jacksonAnnotation_test() throws JsonProcessingException, JSONExcepti "\"catalogRecordModified\":\"modified\""); } + @Test + void constructor_withIdTitleUriValidationStateAndCatalogFields_shouldSetAllFields() { + Id id = new Id("jd1000"); + Uri uri = new Uri("http://bauhaus/catalogues/jeuDeDonnees/jd1000"); + List title = List.of(new LangContent("fr", "Titre FR"), new LangContent("en", "Title EN")); + String validationState = "Published"; + CatalogRecordCreated created = new CatalogRecordCreated("2024-01-01T00:00:00"); + CatalogRecordModified modified = new CatalogRecordModified("2024-06-15T10:00:00"); + CatalogRecordCreator creator = new CatalogRecordCreator("creator1"); + CatalogRecordContributor contributor = new CatalogRecordContributor("contributor1"); + + DataSetModelSwagger result = new DataSetModelSwagger(id, title, uri, validationState, created, modified, creator, contributor); + + assertThat(result.getId()).isEqualTo("jd1000"); + assertThat(result.getUri()).isEqualTo("http://bauhaus/catalogues/jeuDeDonnees/jd1000"); + assertThat(result.getTitle()).isEqualTo(title); + assertThat(result.getValidationState()).isEqualTo("Published"); + assertThat(result.getCatalogRecordCreated()).isEqualTo(created); + assertThat(result.getCatalogRecordModified()).isEqualTo(modified); + assertThat(result.getCatalogRecordCreator()).isEqualTo(creator); + assertThat(result.getCatalogRecordContributor()).isEqualTo(contributor); + } + + @Test + void constructor_withIdTitleUriValidationStateAndCatalogFields_shouldSerializeToJson() throws JsonProcessingException, JSONException { + Id id = new Id("jd1000"); + Uri uri = new Uri("http://bauhaus/catalogues/jeuDeDonnees/jd1000"); + List title = List.of(new LangContent("fr", "Titre FR"), new LangContent("en", "Title EN")); + CatalogRecordCreated created = new CatalogRecordCreated("2024-01-01T00:00:00"); + CatalogRecordModified modified = new CatalogRecordModified("2024-06-15T10:00:00"); + CatalogRecordCreator creator = new CatalogRecordCreator("creator1"); + CatalogRecordContributor contributor = new CatalogRecordContributor("contributor1"); + + DataSetModelSwagger result = new DataSetModelSwagger(id, title, uri, "Published", created, modified, creator, contributor); + + ObjectMapper mapper = new JsonMapper(); + String json = mapper.writeValueAsString(result); + JSONObject jsonObject = new JSONObject(json); + + assertThat(jsonObject.getString("id")).isEqualTo("jd1000"); + assertThat(jsonObject.getString("uri")).isEqualTo("http://bauhaus/catalogues/jeuDeDonnees/jd1000"); + assertThat(jsonObject.getString("validationState")).isEqualTo("Published"); + assertThat(jsonObject.getString("catalogRecordCreated")).isEqualTo("2024-01-01T00:00:00"); + assertThat(jsonObject.getString("catalogRecordModified")).isEqualTo("2024-06-15T10:00:00"); + assertThat(jsonObject.getString("catalogRecordCreator")).isEqualTo("creator1"); + assertThat(jsonObject.getString("catalogRecordContributor")).isEqualTo("contributor1"); + assertThat(jsonObject.getJSONArray("title")).hasSize(2); + } + } \ No newline at end of file