-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
test/de/frosner/broccoli/controllers/InstanceControllerSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} | ||
|
||
} |