Skip to content

Commit

Permalink
Merge pull request #740 from InseeFr/fix/unit-test
Browse files Browse the repository at this point in the history
fix: solve issue with dataset unit test
  • Loading branch information
HugoBouttes authored Sep 4, 2024
2 parents 6e0b417 + 4d6075a commit 0139f3a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand All @@ -29,8 +29,14 @@ jobs:
with:
java-version: '21'
distribution: 'temurin'
- name: Build, Test and analyze
- name: Run unit tests
env:
run: mvn -B clean test
- name: Run TestContainer
env:
run: mvn -B clean test -Ptest-containers
- name: Run Sonar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B clean test -Ptest-containers verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
run: mvn -B clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,24 @@ public Dataset getDatasetByID(String id) throws RmesException {
private void addKeywordsToDataset(String id, JSONObject dataset) throws RmesException {
JSONArray keywords = this.repoGestion.getResponseAsArray(DatasetQueries.getKeywords(id, getDatasetsGraph()));



List<String> lg1 = new ArrayList<>();
List<String> lg2 = new ArrayList<>();

keywords.forEach((k) -> {
JSONObject keyword = (JSONObject) k;
if(keyword.getString("lang").equalsIgnoreCase(config.getLg1())){
lg1.add(keyword.getString("keyword"));
}
if(keyword.getString("lang").equalsIgnoreCase(config.getLg2())){
lg2.add(keyword.getString("keyword"));
}
});
if(keywords != null){
keywords.forEach((k) -> {
JSONObject keyword = (JSONObject) k;
if(keyword.getString("lang").equalsIgnoreCase(config.getLg1())){
lg1.add(keyword.getString("keyword"));
}
if(keyword.getString("lang").equalsIgnoreCase(config.getLg2())){
lg2.add(keyword.getString("keyword"));
}
});
}


JSONObject formattedKeywords = new JSONObject();
formattedKeywords.put("lg1", lg1);
formattedKeywords.put("lg2", lg2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void shouldReturnDataset() throws RmesException, JSONException, JsonProcessingEx
mockedFactory.when(() -> DatasetQueries.getDatasetStatisticalUnits(eq("1"), any())).thenReturn("query-statisticalUnits");
Dataset response = datasetService.getDatasetByID("1");
String responseJson = objectMapper.writeValueAsString(response);
Assertions.assertEquals("{\"creators\":[\"creator-1\"],\"statisticalUnit\":[\"statisticalUnit-1\"],\"spacialResolutions\":[\"spacialResolutions-1\"],\"id\":\"1\",\"themes\":[],\"catalogRecord\":{\"creator\":null,\"contributor\":null,\"created\":null,\"updated\":null}}", responseJson);
Assertions.assertEquals("{\"creators\":[\"creator-1\"],\"keywords\":{\"lg1\":[],\"lg2\":[]},\"statisticalUnit\":[\"statisticalUnit-1\"],\"spacialResolutions\":[\"spacialResolutions-1\"],\"id\":\"1\",\"themes\":[],\"catalogRecord\":{\"creator\":null,\"contributor\":null,\"created\":null,\"updated\":null}}", responseJson);
}
}

Expand Down

0 comments on commit 0139f3a

Please sign in to comment.