@Test
    public void testInheritance() {
        // Create types that inherit each other.. And test that it works..
        DocumentType parentType = new DocumentType("parent");
        parentType.addField(new Field("parentbodyint", DataType.INT));
        parentType.addField(new Field("parentheaderint", DataType.INT));
        parentType.addField(new Field("overwritten", DataType.INT));
        DocumentType childType = new DocumentType("child");
        childType.addField(new Field("childbodyint", DataType.INT));
        childType.addField(new Field("childheaderint", DataType.INT));
        childType.addField(new Field("overwritten", DataType.INT));
        childType.inherit(parentType);

        DocumentTypeManager manager = new DocumentTypeManager();
        manager.register(childType);

        Document child = new Document(childType, new DocumentId("id:ns:child::what:test"));
        child.setFieldValue(childType.getField("parentbodyint"), new IntegerFieldValue(4));
        child.setFieldValue("parentheaderint", 6);
        child.setFieldValue("overwritten", 7);
        child.setFieldValue("childbodyint", 14);

        GrowableByteBuffer buffer = new GrowableByteBuffer(1024, 2f);
        child.serialize(buffer);
        buffer.flip();
        Document childCopy = manager.createDocument(buffer);

        // Test various ways of retrieving values
        assertEquals(new IntegerFieldValue(4), childCopy.getFieldValue(childType.getField("parentbodyint")));
        assertEquals(new IntegerFieldValue(6), childCopy.getFieldValue("parentheaderint"));
        assertEquals(new IntegerFieldValue(7), childCopy.getFieldValue("overwritten"));

        assertEquals(child, childCopy);
    }
Test for Document and all its features, including (de)serialization.

@author Thomas Gundersen
@author bratseth
document/src/test/java/com/yahoo/document/DocumentTestCase.java