Specs2 & AudioSystem API

12 views
Skip to first unread message

Robert O'Regan

unread,
Jul 30, 2015, 5:55:59 AM7/30/15
to specs2-users
Hi,

I'm writing some Specs2 tests to test my Spray routes, one of which accepts file uploads and I am encountering some strange behaviour.

If I run the following code in a simple App class it works fine and outputs the audio samples sample rate...

      val stream:AudioInputStream = AudioSystem.getAudioInputStream(new File("uploads/A1.wav"))

      val audioFormat:AudioFormat = stream.getFormat();

      val samplingRate = audioFormat.getSampleRate()

      println("Sampling Rate: "+samplingRate)


However if I add the same code to a Specs2 test I get the following error...

      javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file


Test looks like...


      "Valid POST Requests with Unsupported Sampling Rates should return failure" in {

      // read in file contents

      val file = new File("uploads/A1.wav")

      //val bis = new BufferedInputStream(new java.io.FileInputStream(file))

      //val bArray = Stream.continually(bis.read).takeWhile(-1 !=).map(_.toByte).toArray

      

      val payload = MultipartFormData(Seq(

          BodyPart(new File("uploads/test.wav"), "file", MediaTypes.`application/octet-stream`),

          BodyPart("a", "category")))

      

      // attach to request

      //val httpEntity = HttpEntity(MediaTypes.`application/octet-stream`, bArray).asInstanceOf[HttpEntity.NonEmpty]

      //val mfd = MultipartFormData(Seq(BodyPart(FormFile("file", httpEntity), "file"), 

      //    BodyPart("a", "category")))

          

      // send mock request

      Post("/v1/sounds/analyse", payload) ~> 

        addHeader(Authorization(BasicHttpCredentials("bob", "123")))  ~> 

        sealRoute(phonemeRoutes) ~> check {

        response.status should be equalTo BadRequest

        responseAs[String] === "[Result: 0.43]"

      }

    }


This occurs when I run the test using "sbt test".

Could it be an encoding issue? Is the problem actually an sbt issue?


Anyone got any idea why this fails when running the tests? 


Thanks!

Reply all
Reply to author
Forward
0 new messages