Modification de repository
This commit is contained in:
@@ -22,17 +22,15 @@ public class JsonAdapterTests {
|
||||
appConfig.setMulticastPort(15502);
|
||||
appConfig.setNetworkInterface("My network interface");
|
||||
appConfig.setTls(false);
|
||||
Map<String, File> files = new HashMap<>();
|
||||
Set<String> storage = new HashSet<>();
|
||||
storage.add("StorBackEnd1");
|
||||
File file1 = new File("File1", 15, "8d8d8d8d", storage);
|
||||
files.put(file1.getName(), file1);
|
||||
User user1 = new User("User1", "Password", "djdjjdj", files);
|
||||
appData.setAppConfig(appConfig);
|
||||
//appData.addUser(user1);
|
||||
JsonAdapter jsonAdapter = new JsonAdapter(appData);
|
||||
appData.addUser("User1", "Password","djdjjdj");
|
||||
appData.addFileFor(file1, "User1");
|
||||
JsonAdapter jsonAdapter = new JsonAdapter();
|
||||
//WHEN the adapter converts AppData to Json
|
||||
String jsonAppData = jsonAdapter.toString();
|
||||
String jsonAppData = jsonAdapter.toString(appData);
|
||||
//THEN
|
||||
assertTrue(jsonAppData.contains("32000"));
|
||||
assertTrue(jsonAppData.contains("224.25.0.1"));
|
||||
@@ -53,7 +51,7 @@ public class JsonAdapterTests {
|
||||
//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);
|
||||
JsonAdapter jsonAdapter = new JsonAdapter();
|
||||
AppData appData = jsonAdapter.fromString(json);
|
||||
//THEN
|
||||
assertNotNull(appData.getAppConfig());
|
||||
|
||||
@@ -40,11 +40,11 @@ public class RepositoryTests {
|
||||
File file1 = new File("File1", 15, "8d8d8d8d", storage);
|
||||
appData.setAppConfig(appConfig);
|
||||
appData.addUser("User1", "Password", "djdjjdj");
|
||||
JsonAdapter jsonAdapter = new JsonAdapter(appData);
|
||||
JsonAdapter jsonAdapter = new JsonAdapter();
|
||||
appData.addFileFor(file1, "User1");
|
||||
//WHEN Repository calls save method
|
||||
String filePath = "src/test/resources/test.json";
|
||||
Repository repository = new Repository(filePath, jsonAdapter);
|
||||
Repository repository = new Repository(filePath, appData, jsonAdapter);
|
||||
repository.save();
|
||||
//THEN
|
||||
assertTrue(Files.exists(Paths.get("src/test/resources/test.json").toAbsolutePath()));
|
||||
@@ -53,9 +53,9 @@ public class RepositoryTests {
|
||||
@Test
|
||||
public void load() {
|
||||
//GIVEN a test json file loadTest.json
|
||||
JsonAdapter jsonAdapter = new JsonAdapter(null);
|
||||
JsonAdapter jsonAdapter = new JsonAdapter();
|
||||
//WHEN repository calls load method
|
||||
Repository repository = new Repository("src/test/resources/loadTest.json", jsonAdapter);
|
||||
Repository repository = new Repository("src/test/resources/loadTest.json", AppData.getInstance(), jsonAdapter);
|
||||
AppData appData = repository.load();
|
||||
//THEN
|
||||
assertNotNull(appData.getAppConfig());
|
||||
|
||||
Reference in New Issue
Block a user