Skip to content

Commit

Permalink
Merge pull request #209 from ansforge/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
romainfd authored Dec 5, 2024
2 parents b3a053f + bb29e94 commit 11e8b5f
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 8 deletions.
7 changes: 1 addition & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
id 'maven-publish'
id 'com.github.hierynomus.license' version '0.16.1'
id 'jacoco'
id 'com.github.johnrengelman.shadow' version '7.1.2'
}

task generateXml(type:JavaExec) {
Expand All @@ -30,6 +29,7 @@ dependencies {
implementation 'javax.validation:validation-api:2.0.1.Final'
implementation 'jakarta.annotation:jakarta.annotation-api:1.3.5'
implementation 'com.networknt:json-schema-validator:1.0.87'
implementation 'org.json:json:20240303'
implementation 'org.projectlombok:lombok:1.18.22'
implementation 'org.junit.jupiter:junit-jupiter-params:5.8.2'
implementation 'com.google.guava:guava:32.1.3-jre'
Expand All @@ -41,11 +41,6 @@ dependencies {
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
}

// I let this in the code waiting for use case explanation
//shadowJar {
// archiveClassifier.set('')
//}

jacocoTestReport {
reports {
html.required = true
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/sample/examples/messagesList.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@
"environment": "Régulation médicale du médecin urgentiste - Ajout d'observations médicales"
},
{
"file": "RS-EDA-MAJ/RS-EDA-MAJ_FemmeEnceinte_DelphineVigneau.10.json",
"icon": "mdi-human-pregnant",
"file": "RS-EDA-MAJ/RS-EDA-MAJ_FuiteDeGaz_AliceGregoireNormand.10.json",
"icon": "mdi-molecule-co2",
"name": "Alice et Grégoire NORMAND.10",
"context": "Pas de test suivant: RS-SR - Alice et Grégoire NORMAND.11",
"environment": "Partage de la décision d'orientation du patient"
Expand Down
92 changes: 92 additions & 0 deletions src/test/java/com/hubsante/model/MessagesListTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright © 2023-2024 Agence du Numerique en Sante (ANS)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hubsante.model;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.fail;

public class MessagesListTest {

static ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

@Test
@DisplayName("Should be able to properly read messagesList.json and verify presence of all schemas mentioned in it")
public void testMessagesList() {
List<String> errors = new ArrayList<>();
// We get messagesList.json from resources/sample/examples folder
String path = "sample/examples/messagesList.json";
// We read the contents of messagesList.json
File file = new File(classLoader.getResource(path).getFile());
String messagesList = null;
JSONArray messagesListJsonArray = null;
try {
messagesList = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
} catch (IOException e) {
// If we can't read messagesList.json, we fail the test
fail("Error while reading messagesList.json: " + e.getMessage());
}
try {
messagesListJsonArray = new JSONArray(messagesList);
} catch (Exception e) {
// If there is an exception while reading messagesList.json, we fail the test
fail("Error while parsing messagesList.json: " + e.getMessage());
}
// We iterate over all the schemas mentioned in messagesList.json
// and verify that they are present in the resources/json-schema folder
System.out.println("Verifying presence of all schemas mentioned in messagesList.json");
for (int i = 0; i < messagesListJsonArray.length(); i++) {
JSONObject message = messagesListJsonArray.getJSONObject(i);
String schemaName = message.getString("schemaName");
String schemaPath = "json-schema/" + schemaName;
try {
new File(classLoader.getResource(schemaPath).getFile());
} catch (NullPointerException e) {
errors.add("Schema not found: "+ schemaPath);
}
}

// We iterate over test messages mentioned in messagesList.json
// and verify that they are present in the resources/sample/examples folder
System.out.println("Verifying presence of all test messages mentioned in messagesList.json");
for (int i = 0; i < messagesListJsonArray.length(); i++) {
JSONObject message = messagesListJsonArray.getJSONObject(i);
for (int j = 0; j < message.getJSONArray("examples").length(); j++) {
JSONObject example = message.getJSONArray("examples").getJSONObject(j);
String examplePath = "sample/examples/" + example.getString("file");
try {
new File(classLoader.getResource(examplePath).getFile());
} catch (NullPointerException e) {
errors.add("Message not found: " + examplePath);
}
}
}

if (!errors.isEmpty()) {
fail(String.join("\n", errors));
}
}
}

0 comments on commit 11e8b5f

Please sign in to comment.