}
@Test
public void shouldStoreDocumentAndFetchAndModifyAndRefetch() throws Exception {
// Store the document ...
Document doc = Schematic.newDocument("k1", "value1", "k2", 2);
String key = "can be anything";
SchematicEntry prior = db.put(key, doc);
assertThat("Should not have found a prior entry", prior, is(nullValue()));
// Read back from the database ...
SchematicEntry entry = db.get(key);
assertThat("Should have found the entry", entry, is(notNullValue()));
// Verify the content ...
Document read = entry.getContent();
assertThat(read, is(notNullValue()));
assertThat(read.getString("k1"), is("value1"));
assertThat(read.getInteger("k2"), is(2));
assertThat(read.containsAll(doc), is(true));
assertThat(read.equals(doc), is(true));
// Modify using an editor ...
try {
tm.begin();
db.lock(key);
EditableDocument editable = db.editContent(key, true);
editable.setBoolean("k3", true);
editable.setNumber("k4", 3.5d);
} finally {
tm.commit();
}
// Now re-read ...
SchematicEntry entry2 = db.get(key);
Document read2 = entry2.getContent();
assertThat(read2, is(notNullValue()));
assertThat(read2.getString("k1"), is("value1"));
assertThat(read2.getInteger("k2"), is(2));
assertThat(read2.getBoolean("k3"), is(true));
assertThat(read2.getDouble("k4") > 3.4d, is(true));
}