Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FRosner committed Jul 13, 2016
1 parent 88083c8 commit a6b9800
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ libraryDependencies += ws

libraryDependencies += specs2 % Test

libraryDependencies += "com.typesafe.akka" %% "akka-testkit" % "2.3.13"

resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"

routesGenerator := InjectedRoutesGenerator
Expand Down
66 changes: 66 additions & 0 deletions test/de/frosner/broccoli/controllers/InstanceControllerSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package de.frosner.broccoli.controllers

import akka.actor.ActorSystem
import de.frosner.broccoli.models.Template
import de.frosner.broccoli.services.{InstanceService, TemplateService}
import org.mockito.Mockito._
import org.specs2.concurrent.ExecutionEnv
import play.api.libs.json.{JsArray, JsObject, JsString}
import play.api.test.{FakeRequest, PlaySpecification}
import akka.testkit.{TestActorRef, TestKit, TestProbe}

import scala.util.Success

class InstanceControllerSpec extends TestKit(ActorSystem("TestProbesTestSystem")) with PlaySpecification {

"list instances" should {

"list all available instances" in { implicit ee: ExecutionEnv =>
val instanceService = TestProbe()
// val future = instanceService.ref ? "hello"
// instanceService.expectMsg(0 millis, "hello")
// instanceService.reply("world")
// assert(future.isCompleted && future.value == Some(Success("world")))
val controller = new InstanceController(instanceService.ref)
1 === 1
}

"list all available instances of the specified template" in { implicit ee: ExecutionEnv =>

}

}

"show template" should {

"return the template if it exists" in { implicit ee: ExecutionEnv =>
val templateService = mock(classOf[TemplateService])
val template = Template(
id = "id",
template = "template {{name}}",
description = "description"
)
when(templateService.template("id")).thenReturn(Some(template))
val controller = new TemplateController(templateService)

val result = controller.show("id").apply(FakeRequest())
status(result) must be equalTo 200
contentAsJson(result) must be equalTo JsObject(Map(
"id" -> JsString(template.id),
"parameters" -> JsArray(Seq(JsString("name"))),
"description" -> JsString(template.description)
))
}

"return 404 if the template does not exist" in {
val templateService = mock(classOf[TemplateService])
when(templateService.template("id")).thenReturn(None)
val controller = new TemplateController(templateService)

val result = controller.show("id").apply(FakeRequest())
status(result) must be equalTo 404
}

}

}

0 comments on commit a6b9800

Please sign in to comment.