From dbd62ba2f3ca918acaf152991f9c1d0875fb7ab4 Mon Sep 17 00:00:00 2001 From: Leonardo Menezes Date: Mon, 4 Apr 2016 13:45:09 +0200 Subject: [PATCH] test for ClearIndexCacheController --- .../ClearIndexCacheControllerSpec.scala | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/test/controllers/ClearIndexCacheControllerSpec.scala b/test/controllers/ClearIndexCacheControllerSpec.scala index e884726..0fbcb02 100644 --- a/test/controllers/ClearIndexCacheControllerSpec.scala +++ b/test/controllers/ClearIndexCacheControllerSpec.scala @@ -1,6 +1,6 @@ package controllers -import elastic.ElasticClient +import elastic.{ElasticClient, ElasticResponse} import exceptions.MissingRequiredParamException import models.CerebroRequest import org.specs2.Specification @@ -8,24 +8,40 @@ import org.specs2.mock.Mockito import play.api.libs.json.Json import play.api.test.FakeApplication +import scala.concurrent.duration.Duration +import scala.concurrent.{Await, Future} + object ClearIndexCacheControllerSpec extends Specification with Mockito { def is = s2""" - ClearIndexCacheController should ${step(play.api.Play.start(FakeApplication()))} - - clear cache for given indices $clusterName - should throw exception if indices is missing $missingIndices - ${step(play.api.Play.stop(FakeApplication()))} + ClearIndexCacheController should ${step(play.api.Play.start(FakeApplication()))} + invoke clearIndexCache $clearIndexCache + should throw exception if indices param is missing $missingIndices + ${step(play.api.Play.stop(FakeApplication()))} """ val controller = new ClearIndexCacheController - def clusterName = { + def clearIndexCache = { + val expectedResponse = Json.parse( + """ + |{ + | "_shards": { + | "total": 10, + | "successful": 5, + | "failed": 0 + | } + |} + """.stripMargin + ) val body = Json.obj("host" -> "somehost", "indices" -> "a,b,c") val client = mock[ElasticClient] - controller.processElasticRequest(CerebroRequest(body), client) + client.clearIndexCache("a,b,c", "somehost") returns Future.successful(ElasticResponse(200, expectedResponse)) + val response = Await.result(controller.processElasticRequest(CerebroRequest(body), client), Duration("1s")) there was one(client).clearIndexCache("a,b,c", "somehost") + response.body mustEqual expectedResponse + response.status mustEqual 200 } def missingIndices = { -- GitLab