Skip to content

Commit

Permalink
fix configs test
Browse files Browse the repository at this point in the history
  • Loading branch information
hilpitome committed Jan 21, 2025
1 parent 73e9449 commit c4627bc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,19 @@ public class TranslateCommandTest {
@BeforeEach
public void setUp() throws IOException {



// Create temp application directory and add configs, fhir_content, questionnaire dirs and content
// Create temp application directory and add configs, fhir_content, questionnaire dirs and
// content
tempAppFolderPath = createTempDirectory("tempApp");
tempAppConfigsFolder = tempAppFolderPath.resolve("configs");
Files.createDirectory(tempAppConfigsFolder);
FctUtils.copyDirectoryContent(Paths.get("src/test/resources/clean_configs_folder"), tempAppConfigsFolder);
FctUtils.copyDirectoryContent(
Paths.get("src/test/resources/clean_configs_folder"), tempAppConfigsFolder);
fhirContentFolderPath = createSubDirectory(tempAppFolderPath, "fhir_content");
Path questionnairesFolderPath = createSubDirectory(fhirContentFolderPath, "questionnaires");
rawQuestionnairePath = Paths.get("src/test/resources/raw_questionnaire.json");
tempRawQuestionnaire = questionnairesFolderPath.resolve("temp_raw_questionnaire.json");
Files.createFile(tempRawQuestionnaire);


Path cleanTestConfigFile = tempAppConfigsFolder.resolve("profile_config.json");
Files.copy(tempAppConfigsFolder, cleanTestConfigFile, StandardCopyOption.REPLACE_EXISTING);
Files.copy(rawQuestionnairePath, tempRawQuestionnaire, StandardCopyOption.REPLACE_EXISTING);

translateCommand = new TranslateCommand();
}
Expand Down Expand Up @@ -72,11 +69,10 @@ public void testRunExtractWithInvalidInputPath() {
public void testRunExtract() throws IOException {
// Assuming you have a valid JSON file for testing

Path tempRawQuestionnaire = createTempFileWithContents(
"temp_raw_questionnaire", ".json", rawQuestionnairePath);
Path tempRawQuestionnaire =
createTempFileWithContents("temp_raw_questionnaire", ".json", rawQuestionnairePath);
Path tempDefaultPropertiesPath = createTempFile("temp_strings_default", ".properties");


translateCommand.mode = "extract";
translateCommand.resourceFile = tempRawQuestionnaire.toString();
translateCommand.translationFile = tempDefaultPropertiesPath.toString();
Expand All @@ -85,16 +81,16 @@ public void testRunExtract() throws IOException {
assertDoesNotThrow(() -> translateCommand.run());

compareProperties(
"src/test/resources/strings_default.properties",
tempDefaultPropertiesPath.toString());
"src/test/resources/strings_default.properties", tempDefaultPropertiesPath.toString());

deleteFile(tempRawQuestionnaire);
deleteFile(tempDefaultPropertiesPath);
}

@Test
public void testRunExtractFhirContentGivenFolderPathWithoutTranslationFileAndWithoutExtractionType() throws IOException {

public void
testRunExtractFhirContentGivenFolderPathWithoutTranslationFileAndWithoutExtractionType()
throws IOException {

Files.copy(rawQuestionnairePath, tempRawQuestionnaire, StandardCopyOption.REPLACE_EXISTING);

Expand All @@ -107,17 +103,15 @@ public void testRunExtractFhirContentGivenFolderPathWithoutTranslationFileAndWit
assertDoesNotThrow(() -> translateCommand.run());

compareProperties(
"src/test/resources/strings_default.properties",
tempDefaultPropertiesPath.toString());
"src/test/resources/strings_default.properties", tempDefaultPropertiesPath.toString());

deleteFile(tempRawQuestionnaire);
deleteFile(tempDefaultPropertiesPath);

}

@Test
public void testRunExtractFhirContentGivenFolderNameWithExtractionTypeWithoutTranslationFile() throws IOException {

public void testRunExtractFhirContentGivenFolderNameWithExtractionTypeWithoutTranslationFile()
throws IOException {

Files.copy(rawQuestionnairePath, tempRawQuestionnaire, StandardCopyOption.REPLACE_EXISTING);

Expand All @@ -130,34 +124,28 @@ public void testRunExtractFhirContentGivenFolderNameWithExtractionTypeWithoutTra

assertDoesNotThrow(() -> translateCommand.run());


compareProperties(
"src/test/resources/strings_default.properties",
tempDefaultPropertiesPath.toString());
"src/test/resources/strings_default.properties", tempDefaultPropertiesPath.toString());

deleteFile(tempRawQuestionnaire);
deleteFile(tempDefaultPropertiesPath);

}


@Test
public void testRunExtractConfigWithCleanConfigsFolderGivenFolderNameWithoutExtractionTypeAndWithoutTranslationFileRunsSuccessfully() throws IOException {

public void
testRunExtractConfigWithCleanConfigsFolderGivenFolderNameWithoutExtractionTypeAndWithoutTranslationFileRunsSuccessfully()
throws IOException {

TranslateCommand translateCommandSpy = Mockito.spy(translateCommand);
translateCommandSpy.mode = "extract";
translateCommandSpy.resourceFile = tempAppConfigsFolder.toString();

Path frPropertiesPathOriginal = Paths.get("src/test/resources/strings_fr.properties");
Path frPropertiesPathTest =
tempAppConfigsFolder.resolve(frPropertiesPathOriginal.getFileName());
Files.createFile(frPropertiesPathTest);
// Files.copy(frPropertiesPathOriginal, frPropertiesPathTest, StandardCopyOption.REPLACE_EXISTING);
translateCommandSpy.translationFile = frPropertiesPathTest.toString();
Path propertiesPathOriginal =
Paths.get("src/test/resources/clean_configs_folder/strings_configs.properties");
Path propertiesPathTest = createTempFile("strings_default", "properties");
translateCommandSpy.translationFile = propertiesPathTest.toString();
translateCommandSpy.run();
compareProperties(
frPropertiesPathTest.toString(), frPropertiesPathOriginal.toString());
compareProperties(propertiesPathOriginal.toString(), propertiesPathOriginal.toString());

Mockito.verify(translateCommandSpy, Mockito.atLeast(2))
.copyDirectoryContent(Mockito.any(), Mockito.any());
Expand All @@ -166,8 +154,9 @@ public void testRunExtractConfigWithCleanConfigsFolderGivenFolderNameWithoutExtr
}

@Test
public void testRunExtractConfigGivenFolderPathAndWithoutTranslationFileAndWithExtractionTypeRunsSuccessfully() throws IOException {

public void
testRunExtractConfigGivenFolderPathAndWithoutTranslationFileAndWithExtractionTypeRunsSuccessfully()
throws IOException {

TranslateCommand translateCommandSpy = Mockito.spy(translateCommand);
translateCommandSpy.mode = "extract";
Expand All @@ -176,14 +165,14 @@ public void testRunExtractConfigGivenFolderPathAndWithoutTranslationFileAndWithE

Path frPropertiesPathOriginal = Paths.get("src/test/resources/strings_fr.properties");
Path frPropertiesPathTest =
tempAppConfigsFolder.resolve(frPropertiesPathOriginal.getFileName());
tempAppConfigsFolder.resolve(frPropertiesPathOriginal.getFileName());
Files.copy(frPropertiesPathOriginal, frPropertiesPathTest, StandardCopyOption.REPLACE_EXISTING);
translateCommandSpy.translationFile = frPropertiesPathTest.toString();
translateCommandSpy.run();
Mockito.verify(translateCommandSpy, Mockito.atLeast(2))
.copyDirectoryContent(Mockito.any(), Mockito.any());
.copyDirectoryContent(Mockito.any(), Mockito.any());
Mockito.verify(translateCommandSpy, Mockito.atLeast(1))
.deleteDirectoryRecursively(Mockito.any());
.deleteDirectoryRecursively(Mockito.any());
}

@Test
Expand Down Expand Up @@ -233,7 +222,8 @@ private Path createTempDirectory(String name) throws IOException {
return Files.createTempDirectory(name);
}

private Path createTempDirectoryWithContents(String tempDirName, String sourceDir) throws IOException {
private Path createTempDirectoryWithContents(String tempDirName, String sourceDir)
throws IOException {
Path tempDir = createTempDirectory(tempDirName);
FctUtils.copyDirectoryContent(Paths.get(sourceDir), tempDir);
return tempDir;
Expand All @@ -249,7 +239,8 @@ private Path createTempFile(String prefix, String suffix) throws IOException {
return Files.createTempFile(prefix, suffix);
}

private Path createTempFileWithContents(String prefix, String suffix, Path sourceFile) throws IOException {
private Path createTempFileWithContents(String prefix, String suffix, Path sourceFile)
throws IOException {
Path tempFile = createTempFile(prefix, suffix);
Files.copy(sourceFile, tempFile, StandardCopyOption.REPLACE_EXISTING);
return tempFile;
Expand All @@ -275,8 +266,10 @@ private void compareProperties(String expectedPath, String actualPath) throws IO

private void compareJsonFiles(Path actualPath, Path expectedPath) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode actualJson = objectMapper.readTree(Files.newBufferedReader(actualPath, StandardCharsets.UTF_8));
JsonNode expectedJson = objectMapper.readTree(Files.newBufferedReader(expectedPath, StandardCharsets.UTF_8));
JsonNode actualJson =
objectMapper.readTree(Files.newBufferedReader(actualPath, StandardCharsets.UTF_8));
JsonNode expectedJson =
objectMapper.readTree(Files.newBufferedReader(expectedPath, StandardCharsets.UTF_8));
assertEquals(expectedJson, actualJson, "JSON files do not match.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
690595fc5623820f343974834fee514b=Edit Client Info
6 changes: 5 additions & 1 deletion efsity-cli/src/test/resources/strings_fr.properties
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
690595fc5623820f343974834fee514b=Edit Client Info
#Thu Nov 02 09:51:17 EAT 2023
b989b9027fad22ec89690367614e2da6=Raison de l?examen abdominal
f89de0a4cd9317a2987dfc2546e2da5e=Examen abdominal effectué
bafd7322c6e97d25b6299b5d6fe8920b=Non
93cba07454f06a4a960172bbd6e2a435=Oui

0 comments on commit c4627bc

Please sign in to comment.