Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Issue/8 #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}

}

}