-
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.
#8 first test list in template controller
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
test/de/frosner/broccoli/controllers/TemplateControllerSpec.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,39 @@ | ||
package de.frosner.broccoli.controllers | ||
|
||
import de.frosner.broccoli.models.Template | ||
import de.frosner.broccoli.services.TemplateService | ||
import org.specs2.mutable.Specification | ||
import play.api.test.{FakeRequest, PlaySpecification} | ||
import org.mockito.Mockito._ | ||
import play.api.libs.json.{JsArray, JsObject, JsString} | ||
import org.specs2.concurrent.ExecutionEnv | ||
import play.api.mvc.BodyParsers | ||
|
||
class TemplateControllerSpec extends PlaySpecification { | ||
|
||
"/templates" should { | ||
|
||
"list all available templates" in { implicit ee: ExecutionEnv => | ||
val templateService = mock(classOf[TemplateService]) | ||
val template = Template( | ||
id = "id", | ||
template = "template {{name}}", | ||
description = "description" | ||
) | ||
when(templateService.templates).thenReturn(Seq(template)) | ||
val controller = new TemplateController(templateService) | ||
|
||
val result = controller.list.apply(FakeRequest()) | ||
status(result) must be equalTo 200 | ||
contentAsJson(result) must be equalTo JsArray(Seq( | ||
JsObject(Map( | ||
"id" -> JsString(template.id), | ||
"parameters" -> JsArray(Seq(JsString("name"))), | ||
"description" -> JsString(template.description) | ||
)) | ||
)) | ||
} | ||
|
||
} | ||
|
||
} |