dimanche 26 juin 2016

unable to test a case of receive function in Akka

package test


import javax.inject._
import org.specs2.mutable._
import play.api.test.Helpers._
import play.api.test._
import play.api.libs.json._
import play.api.cache._
import akka.stream._
import akka.actor._
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.actor.ActorRef
import akka.actor.Props
import akka.pattern.ask
import models.MyWebSocketActor
import models.ChatActor
import models.ValidatorClass
import scala.collection.mutable.Map 
import org.specs2.mock._
import play.api.mvc._
import akka.testkit.{TestActorRef, _}
import scala.concurrent.duration._

class MyWebSocketActorTest extends Specification with Mockito {

 implicit val system = ActorSystem("MockActorSystem")
  val mockMap : Map[ActorRef , String] = Map()
  val mockCache = mock[CacheApi]

  "MyWebSocketActor receive function" should {

"handle ClientSentMessage  " in {
      val probeActor1 = TestProbe()
      val probeActor2 = TestProbe()

      val testActorRef = TestActorRef[MyWebSocketActor](Props(new MyWebSocketActor(probeActor1.ref, probeActor2.ref, mockCache , mockMap)),"actor7")

      val testActor = testActorRef.underlyingActor

      val testMsg7 = Json.parse("""{"username":"testClient","message":"From MyWebSocketTest class","conn_status":2,"pub_key":"eyJhbGciOiJIbWFjU0hBMjU2IiwidHlwIjoiSldUIn0.eyJ1c2VybmFtZSI6InRlc3RDbGllbnQifQ.77-9Pjbvv73vv73vv717TFYy77-9WO-_ve-_ve-_vQXvv71X77-9HO-_ve-_vSnvv716D3nvv73vv73IhA","target":"all"}""")

      val expectedMsg7 = testMsg7

       testActor.receive(ClientSentMessage(testMsg7)) 

        val receivedMsg7 = probeActor1.receiveOne(500 millis)

       receivedMsg7 must equalTo (expectedMsg7)

 }
}
}

I have a MyWebSocketActor class which has a receive function in which there is a case defined as final case class ClientSentMessage(msg:JsValue) .But when i am testing the above case using code as shown above, it gives error:- not found ClientSentMessage.I know i am doing something wrong here, just can't figure out what? I am working in Scala 2.11.7, Akka 2.4.7,and Play 2.5.3

Aucun commentaire:

Enregistrer un commentaire