@Test
public void testDirectoryLayerDirectoryValidation() throws Exception {

    KeySpace root = new KeySpace(
            new DirectoryLayerDirectory("school", "school")
                    .addSubdirectory(new DirectoryLayerDirectory("school_name")
                        .addSubdirectory(new DirectoryLayerDirectory("teachers", "teachers"))
                        .addSubdirectory(new DirectoryLayerDirectory("students", "students"))));
    final FDBDatabase database = FDBDatabaseFactory.instance().getDatabase();
    final Tuple teachersTuple;
    final Tuple studentsTuple;
    try (FDBRecordContext context = database.openContext()) {
        teachersTuple = root.path("school").add("school_name", "Football Tech").add("teachers").toTuple(context);
        studentsTuple = root.path("school").add("school_name", "Football Tech").add("students").toTuple(context);
        context.commit();
    }
    try (FDBRecordContext context = database.openContext()) {
        // Use the wrong directory layer value for the students and teachers
        assertThrows(RecordCoreArgumentException.class,
                () -> root.path("school")
                        .add("school_name", "Football Tech")
                        .add("teachers", studentsTuple.getLong(1)).toTuple(context));
        assertThrows(RecordCoreArgumentException.class,
                () -> root.path("school")
                        .add("school_name", "Football Tech")
                        .add("students", teachersTuple.getLong(1)).toTuple(context));
        // Use a value that does not exist in the directory layer as the school name.
        assertThrows(NoSuchElementException.class,
                () -> root.path("school")
                        .add("school_name", -746464638L)
                        .add("teachers").toTuple(context));
    }
}