From ac04f86e72c02e4a1b5acba36f4d561d8893dffd Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 8 Mar 2022 11:17:26 +0100 Subject: [PATCH] =?UTF-8?q?Json=20adapter=20:=20Json=20vers=20AppData=20->?= =?UTF-8?q?=20test=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/storage/JsonAdapter.java | 2 +- .../lightcontainer/storage/JsonAdapterTest.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/storage/JsonAdapter.java b/app/src/main/java/lightcontainer/storage/JsonAdapter.java index 649bd35..076b079 100644 --- a/app/src/main/java/lightcontainer/storage/JsonAdapter.java +++ b/app/src/main/java/lightcontainer/storage/JsonAdapter.java @@ -99,7 +99,7 @@ public class JsonAdapter implements Adapter { private void getUsers(JsonArray jsonUsers, List users) { for (JsonElement element : jsonUsers) { JsonObject jsonUser = element.getAsJsonObject(); - String name = jsonUser.get("username").getAsString(); + String name = jsonUser.get("name").getAsString(); String password = jsonUser.get("password").getAsString(); String aeskey = jsonUser.get("aes_key").getAsString(); Map userFiles = new HashMap<>(); diff --git a/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java b/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java index 34348c0..2bde872 100644 --- a/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java +++ b/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java @@ -33,7 +33,6 @@ public class JsonAdapterTest { JsonAdapter jsonAdapter = new JsonAdapter(appData); //WHEN the adapter converts AppData to Json String jsonAppData = jsonAdapter.toString(); - System.out.println(jsonAppData); //THEN assertTrue(jsonAppData.contains("32000")); assertTrue(jsonAppData.contains("224.25.0.1")); @@ -48,4 +47,20 @@ public class JsonAdapterTest { assertTrue(jsonAppData.contains("8d8d8d8d")); assertTrue(jsonAppData.contains("StorBackEnd1")); } + + @Test + public void convertJsonToAppData() { + //GIVEN a Json string + String json = "{\"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\"]}]}]}"; + //WHEN the adapter converts Json to Appdata + JsonAdapter jsonAdapter = new JsonAdapter(null); + AppData appData = jsonAdapter.fromString(json); + //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()); + } }