@Test
public void testVerifyParentDir() throws Exception {

  hdfs.mkdirs(new Path("/dir1/dir2"));
  hdfs.createNewFile(new Path("/dir1/file"));
  hdfs.createNewFile(new Path("/dir1/dir2/file"));
  INodesInPath iip = fsdir.resolvePath(null, "/", DirOp.READ);
  fsdir.verifyParentDir(iip);
  iip = fsdir.resolvePath(null, "/dir1", DirOp.READ);
  fsdir.verifyParentDir(iip);
  iip = fsdir.resolvePath(null, "/dir1/file", DirOp.READ);
  fsdir.verifyParentDir(iip);
  iip = fsdir.resolvePath(null, "/dir-nonexist/file", DirOp.READ);
  try {
    fsdir.verifyParentDir(iip);
    fail("expected FNF");
  } catch (FileNotFoundException fnf) {
    // expected.
  }
  iip = fsdir.resolvePath(null, "/dir1/dir2", DirOp.READ);
  fsdir.verifyParentDir(iip);
  iip = fsdir.resolvePath(null, "/dir1/dir2/file", DirOp.READ);
  fsdir.verifyParentDir(iip);
  iip = fsdir.resolvePath(null, "/dir1/dir-nonexist/file", DirOp.READ);
  try {
    fsdir.verifyParentDir(iip);
    fail("expected FNF");
  } catch (FileNotFoundException fnf) {
    // expected.
  }
  try {
    iip = fsdir.resolvePath(null, "/dir1/file/fail", DirOp.READ);
    fail("expected ACE");
  } catch (AccessControlException ace) {
    assertTrue(ace.getMessage().contains("is not a directory"));
  }
  try {
    iip = fsdir.resolvePath(null, "/dir1/file/fail", DirOp.WRITE);
    fail("expected ACE");
  } catch (AccessControlException ace) {
    assertTrue(ace.getMessage().contains("is not a directory"));
  }
  try {
    iip = fsdir.resolvePath(null, "/dir1/file/fail", DirOp.CREATE);
    fail("expected PNDE");
  } catch (ParentNotDirectoryException pnde) {
    assertTrue(pnde.getMessage().contains("is not a directory"));
  }
}