Json adapter : Json vers AppData -> testé

This commit is contained in:
Maximilien LEDOUX 2022-03-08 11:17:26 +01:00
parent 558e4427fd
commit ac04f86e72
2 changed files with 17 additions and 2 deletions

View File

@ -99,7 +99,7 @@ public class JsonAdapter implements Adapter {
private void getUsers(JsonArray jsonUsers, List<User> 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<String, File> userFiles = new HashMap<>();

View File

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