diff --git a/README.md b/README.md index fd63811..471c5eb 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,24 @@ -# ciip-gruppe8-password-manager +# ciip-grp8-password-manager +## Dependencies +- productive + - java 11 +- development + - java 11 + - maven + +## Build jar file artifact +- requires development dependencies + +`mvn package` + +## Run jar file artifact +- requires productive dependencies +- requires a built jar file to run + +`java -jar target/ciip-grp8-password-manager-1.0-SNAPSHOT.jar` + +## Contributors +- binsky - Timo Triebensky +- fdai6352 - Pascal Schubert +- fdai5728 - Claudia Metzler diff --git a/pom.xml b/pom.xml index d27a545..5e9fa46 100644 --- a/pom.xml +++ b/pom.xml @@ -4,8 +4,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.ciip-gruppe8-password-manager - ciip-gruppe8-password-manager + org.ciip-grp8-password-manager + ciip-grp8-password-manager 1.0-SNAPSHOT @@ -70,9 +70,26 @@ 5.7.0 - + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + org.junit.jupiter + junit-jupiter-engine + 5.7.0 + + + + + + true + PasswordManager + + + diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 0000000..bf2e353 --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,50 @@ +import java.io.*; +import java.util.Scanner; + +public class Storage implements StorageInterface { + @Override + public void export() { + + } + + @Override + public void load() { + + } + + public boolean writeFile(String path, String content) { + if (!path.isEmpty() && !content.isEmpty()) { + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(path, false)); + writer.append(content); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + + return true; + } + return false; + } + + public String readFile(String path) { + if (!path.isEmpty()) { + StringBuilder data = new StringBuilder(); + try { + File f = new File(path); + Scanner myReader = new Scanner(f); + while (myReader.hasNextLine()) { + data.append(myReader.nextLine()); + } + myReader.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return null; + } + + return data.toString(); + } + return null; + } +} diff --git a/src/main/java/StorageInterface.java b/src/main/java/StorageInterface.java new file mode 100644 index 0000000..796d12b --- /dev/null +++ b/src/main/java/StorageInterface.java @@ -0,0 +1,4 @@ +public interface StorageInterface { + public void export(); + public void load(); +} diff --git a/src/test/java/StorageTest.java b/src/test/java/StorageTest.java new file mode 100644 index 0000000..4f7c595 --- /dev/null +++ b/src/test/java/StorageTest.java @@ -0,0 +1,62 @@ +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.*; + +class StorageTest { + + static Storage storage; + static String testFilePath = "/tmp/test.txt"; + + @BeforeAll + static void init() { + storage = new Storage(); + + if (System.getProperty("os.name").toLowerCase().contains("win")) { + testFilePath = "C:\\test.txt"; + } + } + + @AfterAll + static void clear() { + File myObj = new File(testFilePath); + myObj.delete(); + } + + @Test + void constructor() { + assertInstanceOf(Storage.class, storage); + } + + @Test + void export() { + } + + @Test + void load() { + } + + @Test + void writeFile() { + String content = "test"; + assertTrue(storage.writeFile(testFilePath, content)); + + File f = new File(testFilePath); + assertTrue(f.isFile()); + } + + @Test + void readFile() { + String content = "test"; + + File f = new File(testFilePath); + if (!f.isFile()) { + assertTrue(storage.writeFile(testFilePath, content)); + } + + assertEquals(content, storage.readFile(testFilePath)); + } +} \ No newline at end of file