use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class OperationTest method testDeleteEntryOperation.
@Test
public void testDeleteEntryOperation() throws FailToSyncEntryException {
cleanUp();
Journal toAdd = new Journal();
toAdd.setContent("test");
toAdd.setDate(new Date());
toAdd.setSubject("test");
Journal result = db.addEntry(toAdd);
Long id = result.getId();
toAdd.setId(id);
result = db.getEntry(id);
Assert.assertEquals(true, result.equals(toAdd));
new DeleteEntryOperation(id).execute();
result = db.getEntry(id);
Assert.assertEquals(null, result);
Assert.assertEquals(false, indexer.contains(id));
cleanUp();
}
use of net.viperfish.journal.framework.Journal 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.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class OperationTest method testChangeConfig.
@Test
public void testChangeConfig() throws FailToSyncEntryException {
cleanUp();
Map<String, String> testConfig = new HashMap<>();
addEntries(10);
testConfig.put("viperfish.secure.encrytion.algorithm", "DES");
testConfig.put(ConfigMapping.DB_COMPONENT, "H2Database");
new ChangeConfigurationOperation(testConfig).execute();
Assert.assertEquals("DES", Configuration.getString("viperfish.secure.encrytion.algorithm"));
Assert.assertEquals("H2Database", Configuration.getString(ConfigMapping.DB_COMPONENT));
initComponents();
Assert.assertEquals(((JournalEncryptionWrapper) db).getDb().getClass(), ((JournalEncryptionWrapper) EntryDatabases.INSTANCE.getEntryDatabase("H2Database")).getDb().getClass());
for (Journal i : db.getAll()) {
Assert.assertEquals("test", i.getContent());
}
setupConfig();
initComponents();
cleanUp();
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class OperationTest method addEntries.
private List<Long> addEntries(int howMany, String allContent) throws FailToSyncEntryException {
List<Long> resultList = new LinkedList<>();
for (int i = 0; i < howMany; ++i) {
Journal j = new Journal();
j.setContent(allContent);
j.setSubject(allContent);
Journal result = db.addEntry(j);
resultList.add(result.getId());
}
return resultList;
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class OperationTest method testGetDateRange.
@Test
public void testGetDateRange() throws FailToSyncEntryException {
cleanUp();
Calendar cal = Calendar.getInstance();
cal.set(1990, 0, 1);
Date lowerBound = cal.getTime();
cal.set(1990, 1, 12);
Date upperBound = cal.getTime();
cal.set(1990, 0, 22);
Date inBound = cal.getTime();
Journal valid = new Journal();
valid.setDate(inBound);
valid.setSubject("valid entry");
valid.setContent("valid content");
db.addEntry(valid);
cal.set(1990, 2, 4);
Date outBound = cal.getTime();
Journal invalid = new Journal();
invalid.setDate(outBound);
invalid.setContent("out of bound");
invalid.setSubject("out of bound");
db.addEntry(invalid);
GetDateRangeOperation range = new GetDateRangeOperation(lowerBound, upperBound);
range.execute();
Set<JournalPointer> result = range.getResult();
Assert.assertEquals(true, result.contains(new JournalPointer(valid)));
Assert.assertEquals(false, result.contains(new JournalPointer(invalid)));
}
Aggregations