Repository : load testé

This commit is contained in:
Maximilien LEDOUX 2022-03-08 12:12:04 +01:00
parent d979fbd1f3
commit 4291618774
4 changed files with 43 additions and 6 deletions

View File

@ -92,8 +92,8 @@ public class JsonAdapter implements Adapter {
return this.appData; return this.appData;
} catch (JsonParseException parseException) { } catch (JsonParseException parseException) {
System.out.println("[FFE] : Error while loading configuration file"); //TODO - changer en log System.out.println("[FFE] : Error while loading configuration file"); //TODO - changer en log
return null;
} }
return null;
} }
private void getUsers(JsonArray jsonUsers, List<User> users) { private void getUsers(JsonArray jsonUsers, List<User> users) {

View File

@ -10,8 +10,6 @@ import java.nio.file.StandardOpenOption;
public class Repository { public class Repository {
//static final String CONFIG_FILE_PATH = "../../resources/config.json";
static void save(String filePath, Adapter adapter) { static void save(String filePath, Adapter adapter) {
if (filePath != null) { if (filePath != null) {
String jsonAppData = adapter.toString(); String jsonAppData = adapter.toString();
@ -24,12 +22,12 @@ public class Repository {
} }
} }
AppData load(String filePath, Adapter adapter) { static AppData load(String filePath, Adapter adapter) {
String jsonString = readFile(filePath); String jsonString = readFile(filePath);
return adapter.fromString(jsonString); return adapter.fromString(jsonString);
} }
static private String readFile(String filePath) { private static String readFile(String filePath) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath).toAbsolutePath(), StandardCharsets.UTF_8)) { try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath).toAbsolutePath(), StandardCharsets.UTF_8)) {
while (reader.ready()) { while (reader.ready()) {

View File

@ -30,7 +30,7 @@ public class RepositoryTests {
@Test @Test
public void save() { public void save() {
//GIVEN an AppData instance, a JsonAdapter and a Repository //GIVEN an AppData instance and a Json Adapter
AppData appData = AppData.getInstance(); AppData appData = AppData.getInstance();
AppConfig appConfig = AppConfig.getInstance(); AppConfig appConfig = AppConfig.getInstance();
appConfig.setUnicastPort(32000); appConfig.setUnicastPort(32000);
@ -53,4 +53,19 @@ public class RepositoryTests {
//THEN //THEN
assertTrue(Files.exists(Paths.get("src/test/resources/test.json").toAbsolutePath())); assertTrue(Files.exists(Paths.get("src/test/resources/test.json").toAbsolutePath()));
} }
@Test
public void load() {
//GIVEN a test json file loadTest.json
JsonAdapter jsonAdapter = new JsonAdapter(null);
//WHEN repository calls load method
AppData appData = Repository.load("src/test/resources/loadTest.json", jsonAdapter);
//THEN
assertNotNull(appData.getAppConfig());
assertEquals("My network interface", appData.getAppConfig().getNetworkInterface());
assertEquals(32000, appData.getAppConfig().getUnicastPort());
assertEquals("224.25.0.1", appData.getAppConfig().getMulticastIp());
assertEquals(15502, appData.getAppConfig().getMulticastPort());
assertFalse(appData.getAppConfig().isTls());
}
} }

View File

@ -0,0 +1,24 @@
{
"unicast_port": 32000,
"multicast_ip": "224.25.0.1",
"multicast_port": 15502,
"network_interface": "My network interface",
"tls": false,
"users": [
{
"name": "User1",
"password": "Password",
"aes_key": "djdjjdj",
"files": [
{
"name": "File1",
"size": 15,
"iv": "8d8d8d8d",
"storage": [
"StorBackEnd1"
]
}
]
}
]
}