// 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;
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.hadoop.fs.swift;




/**
 * Test the FileSystem#listStatus() operations
 */
public class TestSwiftFileSystemLsOperations extends SwiftFileSystemBaseTest {

  private Path[] testDirs;

    /**
   * Setup creates dirs under test/hadoop
   *
   * @throws Exception
   */
  @Override
  public void setUp() throws Exception {
    super.setUp();
    //delete the test directory
    Path test = path("/test");
    fs.delete(test, true);
    mkdirs(test);
  }

  /**
   * Create subdirectories and files under test/ for those tests
   * that want them. Doing so adds overhead to setup and teardown,
   * so should only be done for those tests that need them.
   * @throws IOException on an IO problem
   */
  private void createTestSubdirs() throws IOException {
    testDirs = new Path[]{
              path("/test/hadoop/a"),
              path("/test/hadoop/b"),
              path("/test/hadoop/c/1"),
      };

    assertPathDoesNotExist("test directory setup", testDirs[0]);
    for (Path path : testDirs) {
      mkdirs(path);
    }
  }

  @Test(timeout = SWIFT_TEST_TIMEOUT)
  public void testListLevelTest() throws Exception {
    createTestSubdirs();
    FileStatus[] paths = fs.listStatus(path("/test"));
// 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;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.hadoop.fs.swift;




/**
 * Test the FileSystem#listStatus() operations
 */
public class TestSwiftFileSystemLsOperations extends SwiftFileSystemBaseTest {

  private Path[] testDirs;

    /**
   * Setup creates dirs under test/hadoop
   *
   * @throws Exception
   */
  @Override
  public void setUp() throws Exception {
    super.setUp();
    //delete the test directory
    Path test = path("/test");
    fs.delete(test, true);
    mkdirs(test);
  }

  /**
   * Create subdirectories and files under test/ for those tests
   * that want them. Doing so adds overhead to setup and teardown,
   * so should only be done for those tests that need them.
   * @throws IOException on an IO problem
   */
  private void createTestSubdirs() throws IOException {
    testDirs = new Path[]{
              path("/test/hadoop/a"),
              path("/test/hadoop/b"),
              path("/test/hadoop/c/1"),
      };

    assertPathDoesNotExist("test directory setup", testDirs[0]);
    for (Path path : testDirs) {
      mkdirs(path);
    }
  }

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