@Test public void shouldStoreDocumentWithUnusedKeyAndWithNonNullMetadata() { Document doc = Schematic.newDocument("k1", "value1", "k2", 2); Document metadata = Schematic.newDocument("mimeType", "text/plain"); String key = "can be anything"; SchematicEntry prior = db.put(key, doc, metadata); assert prior == null : "Should not have found a prior entry"; // Read back from the database ... SchematicEntry entry = db.get(key); assert entry != null : "Should have found the entry"; // Verify the content ... Document read = entry.getContentAsDocument(); assert read != null; assert "value1".equals(read.getString("k1")); assert 2 == read.getInteger("k2"); assert entry.getContentAsBinary() == null : "Should not have a Binary value for the entry's content"; assert read.containsAll(doc); assert read.equals(doc); // Verify the metadata ... Document readMetadata = entry.getMetadata(); assert readMetadata != null; assert readMetadata.getString("mimeType").equals(metadata.getString("mimeType")); assert readMetadata.containsAll(metadata); // metadata contains more than what we specified ... assert !readMetadata.equals(metadata) : "Expected:\n" + metadata + "\nFound: \n" + readMetadata; }
@Test public void shouldStoreDocumentWithUnusedKeyAndWithNullMetadata() { Document doc = Schematic.newDocument("k1", "value1", "k2", 2); String key = "can be anything"; SchematicEntry prior = db.put(key, doc, null); assert prior == null : "Should not have found a prior entry"; SchematicEntry entry = db.get(key); assert entry != null : "Should have found the entry"; // Verify the content ... Document read = entry.getContentAsDocument(); assert read != null; assert "value1".equals(read.getString("k1")); assert 2 == read.getInteger("k2"); assert entry.getContentAsBinary() == null : "Should not have a Binary value for the entry's content"; assert read.containsAll(doc); assert read.equals(doc); // Verify the metadata ... Document readMetadata = entry.getMetadata(); assert readMetadata != null; assert readMetadata.getString("id").equals(key); }