Skip to content
Snippets Groups Projects
Commit 7e2838cd authored by Robert Goldmann's avatar Robert Goldmann
Browse files

implemented test for database export

parent 977cfd1a
No related branches found
No related tags found
2 merge requests!142merge v1_3_0 into master,!116merge test into v1_3_0
{ "categories": [ { "ID": 1, "name": "NONE", "color": { "red": 1.0, "green": 1.0, "blue": 1.0, "opacity": 1.0 } }, { "ID": 2, "name": "Übertrag", "color": { "red": 1.0, "green": 1.0, "blue": 0.0, "opacity": 1.0 } }, { "ID": 3, "name": "123 Tü+?est Category", "color": { "red": 0.9411765, "green": 0.972549, "blue": 1.0, "opacity": 1.0 } } ], "normalPayments": [ { "ID": 1, "amount": 23, "date": "2017-06-02", "categoryID": 0, "name": "Test Normal", "description": "Lorem Ipsum" } ], "repeatingPayments": [ { "repeatInterval": 7, "repeatEndDate": "2017-06-30", "repeatMonthDay": 0, "ID": 3, "amount": -10012, "date": "2017-06-01", "categoryID": 1, "name": "Test Repeating", "description": "Lorem Ipsum" } ]}
\ No newline at end of file
{"categories":[{"ID":2,"name":"Übertrag","color":{"red":1.0,"green":1.0,"blue":0.0,"opacity":1.0}},{"ID":3,"name":"123 Tü+?est Category","color":{"red":0.9411765,"green":0.972549,"blue":1.0,"opacity":1.0}},{"ID":4,"name":"123 Tü+?est Category","color":{"red":0.9411765,"green":0.972549,"blue":1.0,"opacity":1.0}}],"normalPayments":[],"repeatingPayments":[]}
\ No newline at end of file
{"categories":[{"ID":1,"name":"NONE","color":{"red":1.0,"green":1.0,"blue":1.0,"opacity":1.0}},{"ID":2,"name":"Übertrag","color":{"red":1.0,"green":1.0,"blue":0.0,"opacity":1.0}},{"ID":3,"name":"123 Tü+?est Category","color":{"red":0.9411765,"green":0.972549,"blue":1.0,"opacity":1.0}}],"normalPayments":[{"ID":1,"amount":23,"date":"2017-06-02","categoryID":0,"name":"Test Normal","description":"Lorem Ipsum"}],"repeatingPayments":[{"repeatInterval":7,"repeatEndDate":"2017-06-30","repeatMonthDay":0,"ID":1,"amount":-10012,"date":"2017-06-01","categoryID":1,"name":"Test Repeating","description":"Lorem Ipsum"}]}
\ No newline at end of file
package de.deadlocker8.budgetmaster.tests.server.database;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.BeforeClass;
import org.junit.Test;
import com.google.gson.Gson;
import de.deadlocker8.budgetmasterserver.logic.DatabaseExporter;
import de.deadlocker8.budgetmasterserver.logic.Settings;
import de.deadlocker8.budgetmasterserver.logic.Utils;
public class DatabaseExportTest
{
private static Settings settings;
@BeforeClass
public static void init()
{
try
{
//init
settings = Utils.loadSettings();
}
catch(IOException | URISyntaxException e)
{
fail(e.getMessage());
}
}
@Test
public void testExport()
{
try
{
File file = Paths.get("tests/de/deadlocker8/budgetmaster/tests/resources/export.json").toFile();
DatabaseExporter exporter = new DatabaseExporter(settings);
Gson gson = new Gson();
String databaseJSON = gson.toJson(exporter.exportDatabase());
de.deadlocker8.budgetmaster.logic.Utils.saveDatabaseJSON(file, databaseJSON);
String expectedJSON = new String(Files.readAllBytes(Paths.get("tests/de/deadlocker8/budgetmaster/tests/resources/import.json")));
String exportedJSON = new String(Files.readAllBytes(Paths.get("tests/de/deadlocker8/budgetmaster/tests/resources/export.json")));
assertEquals(expectedJSON, exportedJSON);
}
catch(Exception e)
{
e.printStackTrace();
fail(e.getMessage());
}
}
}
\ No newline at end of file
......@@ -49,7 +49,7 @@ public class DatabaseImportTest
{
try
{
File file = Paths.get("tests/de/deadlocker8/budgetmaster/tests/resources/export.json").toFile();
File file = Paths.get("tests/de/deadlocker8/budgetmaster/tests/resources/import.json").toFile();
Database database = de.deadlocker8.budgetmaster.logic.Utils.loadDatabaseJSON(file);
DatabaseImporter importer = new DatabaseImporter(databaseHandler);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment