Scala Specs2 throws error "Could not create an instance of Proxies" on Api call

222 views Asked by At

I am trying to write unit tests in Scala using specs2. I want to test a third-party api (Bluemix watson) that is written inside my send() function.

class BMProxy() extends BaseProxy()
{
    override def send(data:JsValue):JsValue =
    {
        val id = "--123---"
        val workspaceid = "---xyz---"
        val username = "---username---"
        val password = "---password---"
        val bluemixURL = s"https://gateway.watsonplatform.net/conversation/api/v1/workspaces/$id/message?version=2016-07-11"
       Logger.info(s"data: $data")

        val req = WS.url(bluemixURL).
          withAuth(username, password, WSAuthScheme.BASIC).
          withHeaders("Content-Type" -> "application/json").
          post(data.toString).
          map {
            response => {
              val rawbody = response.body
              val responsecode = response.status
              val responsetext = response.statusText
              Json.parse(rawbody)
              }
          }
         Await.result(req, 5 seconds)
    }   
}

and below is the unit test method of the above method:

class Proxies extends Specification {
"Chatscript proxy" should {
    "gives response" in {
      val data = Json.parse("""{"input":{"text":"Hey"},"context":{"conversation_id":"234234234" } }""")
      val response = new BMProxy().send(data)
      println("---", response)
      Json.stringify(response) must contain ("response")
    }
  }
}

but it throws error -

[error] Could not create an instance of Proxies
[error]   caused by java.lang.Exception: Could not instantiate class Proxies: null
[error]   
0

There are 0 answers