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()); + } }