diff --git a/app/controllers/GetIndexMapping.scala b/app/controllers/GetIndexMappingController.scala similarity index 67% rename from app/controllers/GetIndexMapping.scala rename to app/controllers/GetIndexMappingController.scala index 6f951960b012fab4a34b69928150607ce687c9df..ca77cb0a09dc9cf40b48aff8ee761a0a5aa15a19 100644 --- a/app/controllers/GetIndexMapping.scala +++ b/app/controllers/GetIndexMappingController.scala @@ -1,6 +1,6 @@ package controllers -class GetIndexMapping extends ElasticActionController { +class GetIndexMappingController extends ElasticActionController { def processElasticRequest = (request, client) => client.getIndexMapping(request.get("index"), request.host) diff --git a/conf/routes b/conf/routes index b340f04ad767ffd3c85e807187019baedb30ff8b..99543de7a2711d0045534736202278c94895b015 100644 --- a/conf/routes +++ b/conf/routes @@ -16,7 +16,7 @@ POST /apis/clear_indices_cache @controllers.ClearIndexCacheControl POST /apis/refresh_indices @controllers.RefreshIndexController.execute POST /apis/delete_indices @controllers.DeleteIndexController.execute POST /apis/get_index_settings @controllers.GetIndexSettings.execute -POST /apis/get_index_mapping @controllers.GetIndexMapping.execute +POST /apis/get_index_mapping @controllers.GetIndexMappingController.execute POST /apis/update_cluster_settings @controllers.PutClusterSettings.execute POST /apis/get_node_stats @controllers.NodeStatsController.execute POST /apis/disable_shard_allocation @controllers.DisableShardAllocationController.execute diff --git a/test/controllers/GetIndexMappingControllerSpec.scala b/test/controllers/GetIndexMappingControllerSpec.scala new file mode 100644 index 0000000000000000000000000000000000000000..11a6ec98ab83affdf33123701b19ed0bc1b46060 --- /dev/null +++ b/test/controllers/GetIndexMappingControllerSpec.scala @@ -0,0 +1,51 @@ +package controllers + +import elastic.{ElasticResponse, ElasticClient} +import exceptions.MissingRequiredParamException +import models.CerebroRequest +import org.specs2.Specification +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 GetIndexMappingControllerSpec extends Specification with Mockito { + + def is = + s2""" + GetIndexMappingController should ${step(play.api.Play.start(FakeApplication()))} + invoke getIndexMapping $getIndexMapping + should throw exception if index param is missing $missingIndex + ${step(play.api.Play.stop(FakeApplication()))} + """ + + val controller = new GetIndexMappingController + + def getIndexMapping = { + val expectedResponse = Json.parse( + """ + |{ + | "someIndex": { + | "mappings": {} + | } + |} + """.stripMargin + ) + val body = Json.obj("host" -> "somehost", "index" -> "someIndex") + val client = mock[ElasticClient] + client.getIndexMapping("someIndex", "somehost") returns Future.successful(ElasticResponse(200, expectedResponse)) + val response = Await.result(controller.processElasticRequest(CerebroRequest(body), client), Duration("1s")) + there was one(client).getIndexMapping("someIndex", "somehost") + response.body mustEqual expectedResponse + response.status mustEqual 200 + } + + def missingIndex = { + val body = Json.obj("host" -> "somehost") + val client = mock[ElasticClient] + controller.processElasticRequest(CerebroRequest(body), client) must throwA[MissingRequiredParamException] + } + +}