FSRegistryOperationsService extends CompositeService implements RegistryOperations { @Override public List<String> list(String path) throws PathNotFoundException, InvalidPathnameException, IOException { FileStatus[] statArray = fs.listStatus(makePath(path)); String basePath = fs.getFileStatus(makePath(path)).getPath().toString(); List<String> paths = new ArrayList<String>(); FileStatus stat; for (int i = 0; i < statArray.length; i++) { stat = statArray[i]; if (stat.isDirectory()) { String relativePath = relativize(basePath, stat.getPath().toString()); paths.add(relativePath); } } return paths; } FSRegistryOperationsService(); @VisibleForTesting FileSystem getFs(); @Override boolean mknode(String path, boolean createParents); @Override void bind(String path, ServiceRecord record, int flags); @Override ServiceRecord resolve(String path); @Override RegistryPathStatus stat(String path); @Override boolean exists(String path); @Override List<String> list(String path); @Override void delete(String path, boolean recursive); @Override boolean addWriteAccessor(String id, String pass); @Override void clearWriteAccessors();  }
@Test public void testList() throws IOException { System.out.println("pre-create test path with children and mocked records"); fs.mkdirs(new Path("test/registryTestNode")); fs.mkdirs(new Path("test/registryTestNode/child1")); fs.mkdirs(new Path("test/registryTestNode/child2")); fs.create(new Path("test/registryTestNode/_record")).close(); fs.create(new Path("test/registryTestNode/child1/_record")).close(); List<String> ls = null; ls = registry.list("test/registryTestNode"); Assert.assertNotNull(ls); Assert.assertEquals(2, ls.size()); System.out.println(ls); Assert.assertTrue(ls.contains("child1")); Assert.assertTrue(ls.contains("child2")); ls = null; ls = registry.list("test/registryTestNode/child1"); Assert.assertNotNull(ls); Assert.assertTrue(ls.isEmpty()); ls = null; ls = registry.list("test/registryTestNode/child2"); Assert.assertNotNull(ls); Assert.assertTrue(ls.isEmpty()); }