diff --git a/app/src/main/java/lightcontainer/storage/JsonAdapter.java b/app/src/main/java/lightcontainer/storage/JsonAdapter.java index 076b079..831b0f1 100644 --- a/app/src/main/java/lightcontainer/storage/JsonAdapter.java +++ b/app/src/main/java/lightcontainer/storage/JsonAdapter.java @@ -92,8 +92,8 @@ public class JsonAdapter implements Adapter { return this.appData; } catch (JsonParseException parseException) { System.out.println("[FFE] : Error while loading configuration file"); //TODO - changer en log + return null; } - return null; } private void getUsers(JsonArray jsonUsers, List users) { diff --git a/app/src/main/java/lightcontainer/storage/Repository.java b/app/src/main/java/lightcontainer/storage/Repository.java index d6f12bc..3ea0ac6 100644 --- a/app/src/main/java/lightcontainer/storage/Repository.java +++ b/app/src/main/java/lightcontainer/storage/Repository.java @@ -10,8 +10,6 @@ import java.nio.file.StandardOpenOption; public class Repository { - //static final String CONFIG_FILE_PATH = "../../resources/config.json"; - static void save(String filePath, Adapter adapter) { if (filePath != null) { 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); return adapter.fromString(jsonString); } - static private String readFile(String filePath) { + private static String readFile(String filePath) { StringBuilder builder = new StringBuilder(); try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath).toAbsolutePath(), StandardCharsets.UTF_8)) { while (reader.ready()) { diff --git a/app/src/test/java/lightcontainer/storage/RepositoryTests.java b/app/src/test/java/lightcontainer/storage/RepositoryTests.java index 0fa557a..ed90a68 100644 --- a/app/src/test/java/lightcontainer/storage/RepositoryTests.java +++ b/app/src/test/java/lightcontainer/storage/RepositoryTests.java @@ -30,7 +30,7 @@ public class RepositoryTests { @Test public void save() { - //GIVEN an AppData instance, a JsonAdapter and a Repository + //GIVEN an AppData instance and a Json Adapter AppData appData = AppData.getInstance(); AppConfig appConfig = AppConfig.getInstance(); appConfig.setUnicastPort(32000); @@ -53,4 +53,19 @@ public class RepositoryTests { //THEN 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()); + } } diff --git a/app/src/test/resources/loadTest.json b/app/src/test/resources/loadTest.json new file mode 100644 index 0000000..f06f3af --- /dev/null +++ b/app/src/test/resources/loadTest.json @@ -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" + ] + } + ] + } + ] +} \ No newline at end of file