package eu.pepot.eu.spark.inputsplitter.common.file

import eu.pepot.eu.spark.inputsplitter.helper.TestConstants._
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.FileSystem
import org.specs2.mutable._

class FilesListerSpec extends Specification {

  implicit val fs = FileSystem.getLocal(new Configuration())

  "FileLister" should {

    "list all regular files (1)" in {
      val inputDir = resourcesBaseDir("scenario-000/input")

      val inputs = FileLister.listFiles(inputDir)

      inputs.files.map(_.path.getName).toSet mustEqual
        Set(
          "big.txt",
          "small1.txt",
          "small2.txt"
        )
    }

    "list all regular files (2)" in {
      val inputDir = resourcesBaseDir("hidden")

      val inputs = FileLister.listFiles(inputDir)

      inputs.files.map(_.path.getName).toSet mustEqual
        Set(
          "_SUCCESS",
          "part-r-00000"
        )
    }

  }

}


package eu.pepot.eu.spark.inputsplitter.common.file

import java.io.FileNotFoundException

import eu.pepot.eu.spark.inputsplitter.helper.TestConstants._
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.FileSystem
import org.specs2.mutable._

class FilesListerSpec extends Specification {

  implicit val fs = FileSystem.getLocal(new Configuration())

  "FileLister" should {

    "list all regular files (1)" in {
      val inputDir = resourcesBaseDir("scenario-000/input")

      val inputs = FileLister.listFiles(inputDir)

      inputs.files.map(_.path.getName).toSet mustEqual
        Set(
          "big.txt",
          "small1.txt",
          "small2.txt"
        )
    }

    "list all regular files (2)" in {
      val inputDir = resourcesBaseDir("hidden")

      val inputs = FileLister.listFiles(inputDir)

      inputs.files.map(_.path.getName).toSet mustEqual
        Set(
          "_SUCCESS",
          "part-r-00000"
        )
    }

    "throw exception if bad path" in {
      val inputDir = resourcesBaseDir("scenario-000/input-inexistent")
      FileLister.listFiles(inputDir) must throwAn[FileNotFoundException]
    }

  }

}


Test for invalid paths passed to FilesLister
Test for invalid paths passed to FilesLister
