// Path: hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/util/SwiftTestUtils.java
// public static void assertListStatusFinds(FileSystem fs,
//                                          Path dir,
//                                          Path subdir) throws IOException {
//   FileStatus[] stats = fs.listStatus(dir);
//   boolean found = false;
//   StringBuilder builder = new StringBuilder();
//   for (FileStatus stat : stats) {
//     builder.append(stat.toString()).append('\n');
//     if (stat.getPath().equals(subdir)) {
//       found = true;
//     }
//   }
//   assertTrue("Path " + subdir
//                     + " not found in directory " + dir + ":" + builder,
//                     found);
// }
// 
// Path: hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/util/SwiftTestUtils.java
// public static void cleanup(String action,
//                            FileSystem fileSystem,
//                            String cleanupPath) {
//   noteAction(action);
//   try {
//     if (fileSystem != null) {
//       fileSystem.delete(new Path(cleanupPath).makeQualified(fileSystem),
//                         true);
//     }
//   } catch (Exception e) {
//     LOG.error("Error deleting in "+ action + " - "  + cleanupPath + ": " + e, e);
//   }
// }
// 
// Path: hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/util/SwiftTestUtils.java
// public static String dumpStats(String pathname, FileStatus[] stats) {
//   return pathname + SwiftUtils.fileStatsToString(stats,"\n");
// }
// 
// Path: hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/util/SwiftTestUtils.java
// public static void touch(FileSystem fs,
//                          Path path) throws IOException {
//   fs.delete(path, true);
//   writeTextFile(fs, path, null, false);
// }


import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.junit.Test;
import java.io.IOException;
import static org.apache.hadoop.fs.swift.util.SwiftTestUtils.assertListStatusFinds;
import static org.apache.hadoop.fs.swift.util.SwiftTestUtils.cleanup;
import static org.apache.hadoop.fs.swift.util.SwiftTestUtils.dumpStats;
import static org.apache.hadoop.fs.swift.util.SwiftTestUtils.touch;
  }

  @Test(timeout = SWIFT_TEST_TIMEOUT)
  public void testListStatusEmptyDirectory() throws Exception {
    createTestSubdirs();
    FileStatus[] paths;
    paths = fs.listStatus(path("/test/hadoop/a"));
    assertEquals(dumpStats("/test/hadoop/a", paths), 0,
                 paths.length);
  }

  @Test(timeout = SWIFT_TEST_TIMEOUT)
  public void testListStatusFile() throws Exception {
    describe("Create a single file under /test;" +
             " assert that listStatus(/test) finds it");
    Path file = path("/test/filename");
    createFile(file);
    FileStatus[] pathStats = fs.listStatus(file);
    assertEquals(dumpStats("/test/", pathStats),
                 1,
                 pathStats.length);
    //and assert that the len of that ls'd path is the same as the original
    FileStatus lsStat = pathStats[0];
    assertEquals("Wrong file len in listing of " + lsStat,
      data.length, lsStat.getLen());
  }

  @Test(timeout = SWIFT_TEST_TIMEOUT)
  public void testListEmptyRoot() throws Throwable {
    describe("Empty the root dir and verify that an LS / returns {}");
// Path: hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/util/SwiftTestUtils.java
// public static void assertListStatusFinds(FileSystem fs,
//                                          Path dir,
//                                          Path subdir) throws IOException {
//   FileStatus[] stats = fs.listStatus(dir);
//   boolean found = false;
//   StringBuilder builder = new StringBuilder();
//   for (FileStatus stat : stats) {
//     builder.append(stat.toString()).append('\n');
//     if (stat.getPath().equals(subdir)) {
//       found = true;
//     }
//   }
//   assertTrue("Path " + subdir
//                     + " not found in directory " + dir + ":" + builder,
//                     found);
// }
// 
// Path: hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/util/SwiftTestUtils.java
// public static void cleanup(String action,
//                            FileSystem fileSystem,
//                            String cleanupPath) {
//   noteAction(action);
//   try {
//     if (fileSystem != null) {
//       fileSystem.delete(new Path(cleanupPath).makeQualified(fileSystem),
//                         true);
//     }
//   } catch (Exception e) {
//     LOG.error("Error deleting in "+ action + " - "  + cleanupPath + ": " + e, e);
//   }
// }
// 
// Path: hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/util/SwiftTestUtils.java
// public static String dumpStats(String pathname, FileStatus[] stats) {
//   return pathname + SwiftUtils.fileStatsToString(stats,"\n");
// }
// 
// Path: hadoop-swiftfs/src/main/java/org/apache/hadoop/fs/swift/util/SwiftTestUtils.java
// public static void touch(FileSystem fs,
//                          Path path) throws IOException {
//   fs.delete(path, true);
//   writeTextFile(fs, path, null, false);
// }


// Path: hadoop-swiftfs/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemLsOperations.java
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.junit.Test;
import java.io.IOException;
import static org.apache.hadoop.fs.swift.util.SwiftTestUtils.assertListStatusFinds;
import static org.apache.hadoop.fs.swift.util.SwiftTestUtils.cleanup;
import static org.apache.hadoop.fs.swift.util.SwiftTestUtils.dumpStats;
import static org.apache.hadoop.fs.swift.util.SwiftTestUtils.touch;

  }

  @Test(timeout = SWIFT_TEST_TIMEOUT)
  public void testListStatusEmptyDirectory() throws Exception {
    createTestSubdirs();
    FileStatus[] paths;
    paths = fs.listStatus(path("/test/hadoop/a"));
    assertEquals(dumpStats("/test/hadoop/a", paths), 0,
                 paths.length);
  }

  @Test(timeout = SWIFT_TEST_TIMEOUT)
  public void testListStatusFile() throws Exception {
    describe("Create a single file under /test;" +
             " assert that listStatus(/test) finds it");
    Path file = path("/test/filename");
    createFile(file);
    FileStatus[] pathStats = fs.listStatus(file);
    assertEquals(dumpStats("/test/", pathStats),
                 1,
                 pathStats.length);
    //and assert that the len of that ls'd path is the same as the original
    FileStatus lsStat = pathStats[0];
    assertEquals("Wrong file len in listing of " + lsStat,
      data.length, lsStat.getLen());
  }

  @Test(timeout = SWIFT_TEST_TIMEOUT)
  public void testListEmptyRoot() throws Throwable {
    describe("Empty the root dir and verify that an LS / returns {}");
    cleanup("testListEmptyRoot", fs, "/test");