use of net.viperfish.framework.file.TextIOStreamHandler in project vsDiaryWriter by shilongdai.
the class OperationTest method exportJournals.
private void exportJournals(List<Journal> src) {
try {
String exported = new JsonGenerator().toJson(src);
IOFile exportFile = new IOFile(new File("test.txt"), new TextIOStreamHandler());
exportFile.write(exported, StandardCharsets.UTF_16);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of net.viperfish.framework.file.TextIOStreamHandler in project vsDiaryWriter by shilongdai.
the class OperationTest method testExportOperation.
@Test
public void testExportOperation() throws FailToSyncEntryException {
cleanUp();
addEntries(20, "toExport");
List<Journal> all = db.getAll();
for (Journal i : all) {
i.setId(null);
}
try {
String expectedOutput = new JsonGenerator().toJson(all.toArray(new Journal[1]));
new ExportJournalOperation("test.txt").execute();
IOFile exportFile = new IOFile(new File("test.txt"), new TextIOStreamHandler());
String actualOutput = exportFile.read(StandardCharsets.UTF_16);
Assert.assertEquals(expectedOutput, actualOutput);
} catch (IOException e) {
throw new RuntimeException(e);
}
cleanUp();
}
use of net.viperfish.framework.file.TextIOStreamHandler in project vsDiaryWriter by shilongdai.
the class FileEntryDatabaseTest method testPersistence.
@Test
public void testPersistence() {
File dir = new File("test");
FileEntryDatabase database = new FileEntryDatabase(new IOFile(new File(dir, "testPersist"), new TextIOStreamHandler()));
for (int i = 0; i < 10; ++i) {
Journal j = new Journal();
j.setSubject("testPersist");
j.setContent("testPersist");
database.addEntry(j);
}
database.flush();
database = new FileEntryDatabase(new IOFile(new File(dir, "testPersist"), new TextIOStreamHandler()));
database.load();
int count = 0;
for (Journal i : database.getAll()) {
Assert.assertEquals("testPersist", i.getContent());
Assert.assertEquals("testPersist", i.getSubject());
count++;
}
Assert.assertEquals(10, count);
CommonFunctions.delete(new File("testPersist"));
}
Aggregations