Commit fc0de8bd authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

change route on tests to take application

parent 359eb7bb
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ object AnalysisControllerSpec extends MockedServices {
      """.stripMargin
    )
    client.getIndices(ElasticServer("somehost")) returns Future.successful(ElasticResponse(200, expectedResponse))
    val response = route(FakeRequest(POST, "/analysis/indices").withBody(Json.obj("host" -> "somehost"))).get
    val response = route(application, FakeRequest(POST, "/analysis/indices").withBody(Json.obj("host" -> "somehost"))).get
    ensure(response, 200, Json.arr("index1", "index2"))
  }

@@ -59,7 +59,7 @@ object AnalysisControllerSpec extends MockedServices {
      """.stripMargin
    )
    client.getIndexSettings("foo", ElasticServer("somehost")) returns Future.successful(ElasticResponse(200, expectedResponse))
    val response = route(FakeRequest(POST, "/analysis/analyzers").withBody(Json.obj("host" -> "somehost", "index" -> "foo"))).get
    val response = route(application, FakeRequest(POST, "/analysis/analyzers").withBody(Json.obj("host" -> "somehost", "index" -> "foo"))).get
    ensure(response, 200, Json.arr("foo_analyzer"))
  }

@@ -84,7 +84,7 @@ object AnalysisControllerSpec extends MockedServices {
      """.stripMargin
    )
    client.getIndexMapping("foo", ElasticServer("somehost")) returns Future.successful(ElasticResponse(200, expectedResponse))
    val response = route(FakeRequest(POST, "/analysis/fields").withBody(Json.obj("host" -> "somehost", "index" -> "foo"))).get
    val response = route(application, FakeRequest(POST, "/analysis/fields").withBody(Json.obj("host" -> "somehost", "index" -> "foo"))).get
    ensure(response, 200, Json.arr("name"))
  }

@@ -106,7 +106,7 @@ object AnalysisControllerSpec extends MockedServices {
    )
    client.analyzeTextByAnalyzer("foo", "bar", "qux", ElasticServer("somehost")) returns Future.successful(ElasticResponse(200, expectedResponse))
    val params = Json.obj("host" -> "somehost", "index" -> "foo", "analyzer" -> "bar", "text" -> "qux")
    val response = route(FakeRequest(POST, "/analysis/analyze/analyzer").withBody(params)).get
    val response = route(application, FakeRequest(POST, "/analysis/analyze/analyzer").withBody(params)).get
    val expected = Json.parse(
      """
        |[
@@ -140,7 +140,7 @@ object AnalysisControllerSpec extends MockedServices {
    )
    client.analyzeTextByField("foo", "bar", "qux", ElasticServer("somehost")) returns Future.successful(ElasticResponse(200, expectedResponse))
    val params = Json.obj("host" -> "somehost", "index" -> "foo", "field" -> "bar", "text" -> "qux")
    val response = route(FakeRequest(POST, "/analysis/analyze/field").withBody(params)).get
    val response = route(application, FakeRequest(POST, "/analysis/analyze/field").withBody(params)).get
    val expected = Json.parse(
      """
        |[
+2 −1
Original line number Diff line number Diff line
package controllers

import controllers.AnalysisControllerSpec.application
import elastic.ElasticResponse
import models.ElasticServer
import play.api.libs.json.Json
@@ -47,7 +48,7 @@ object ClusterChangesControllerSpec extends MockedServices {
    client.main(ElasticServer("somehost", None)) returns Future.successful(ElasticResponse(200, mainResponse))
    client.getNodes(ElasticServer("somehost", None)) returns Future.successful(ElasticResponse(200, nodesResponse))
    client.getIndices(ElasticServer("somehost", None)) returns Future.successful(ElasticResponse(200, indicesResponse))
    val response = route(FakeRequest(POST, "/cluster_changes").withBody(Json.obj("host" -> "somehost"))).get
    val response = route(application, FakeRequest(POST, "/cluster_changes").withBody(Json.obj("host" -> "somehost"))).get
    ensure(response, 200, expectedResponse)
  }
}
+3 −3
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ object ClusterSettingsControllerSpec extends MockedServices {
      """.stripMargin
    )
    client.getClusterSettings(ElasticServer("somehost", None)) returns Future.successful(ElasticResponse(200, expectedResponse))
    val response = route(FakeRequest(POST, "/cluster_settings").withBody(Json.obj("host" -> "somehost"))).get
    val response = route(application, FakeRequest(POST, "/cluster_settings").withBody(Json.obj("host" -> "somehost"))).get
    ensure(response, 200, expectedResponse)
  }

@@ -51,12 +51,12 @@ object ClusterSettingsControllerSpec extends MockedServices {
        |}
      """.stripMargin)
    client.saveClusterSettings(body, ElasticServer("somehost", None)) returns Future.successful(ElasticResponse(200, expectedResponse))
    val response = route(FakeRequest(POST, "/cluster_settings/save").withBody(Json.obj("host" -> "somehost", "settings" -> body))).get
    val response = route(application, FakeRequest(POST, "/cluster_settings/save").withBody(Json.obj("host" -> "somehost", "settings" -> body))).get
    ensure(response, 200, expectedResponse)
  }

  def requireSettings = {
    val response = route(FakeRequest(POST, "/cluster_settings/save").withBody(Json.obj("host" -> "somehost"))).get
    val response = route(application, FakeRequest(POST, "/cluster_settings/save").withBody(Json.obj("host" -> "somehost"))).get
    ensure(response, 400, Json.parse("{\"error\":\"Missing required parameter settings\"}"))
  }

+7 −7
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ class CommonsControllerSpec extends MockedServices {
      """.stripMargin
    )
    client.getIndices(ElasticServer("somehost", None)) returns Future.successful(ElasticResponse(200, expectedResponse))
    val response = route(FakeRequest(POST, "/commons/indices").withBody(Json.obj("host" -> "somehost"))).get
    val response = route(application, FakeRequest(POST, "/commons/indices").withBody(Json.obj("host" -> "somehost"))).get
    ensure(response, 200, Json.arr("index1", "index2"))
  }

@@ -53,13 +53,13 @@ class CommonsControllerSpec extends MockedServices {
    )
    val body = Json.obj("host" -> "somehost", "index" -> "someIndex")
    client.getIndexMapping("someIndex", ElasticServer("somehost", None)) returns Future.successful(ElasticResponse(200, expectedResponse))
    val response = route(FakeRequest(POST, "/commons/get_index_mapping").withBody(body)).get
    val response = route(application, FakeRequest(POST, "/commons/get_index_mapping").withBody(body)).get
    ensure(response, 200, expectedResponse)
  }

  def missingIndexGetIndexMapping = {
    val body = Json.obj("host" -> "somehost")
    val response = route(FakeRequest(POST, "/commons/get_index_mapping").withBody(body)).get
    val response = route(application, FakeRequest(POST, "/commons/get_index_mapping").withBody(body)).get
    ensure(response, 400, Json.obj("error" -> "Missing required parameter index"))
  }

@@ -85,13 +85,13 @@ class CommonsControllerSpec extends MockedServices {
    )
    val body = Json.obj("host" -> "somehost", "index" -> "someIndex")
    client.getIndexSettings("someIndex", ElasticServer("somehost", None)) returns Future.successful(ElasticResponse(200, expectedResponse))
    val response = route(FakeRequest(POST, "/commons/get_index_settings").withBody(body)).get
    val response = route(application, FakeRequest(POST, "/commons/get_index_settings").withBody(body)).get
    ensure(response, 200, expectedResponse)
  }

  def missingIndexGetIndexSettings = {
    val body = Json.obj("host" -> "somehost")
    val response = route(FakeRequest(POST, "/commons/get_index_settings").withBody(body)).get
    val response = route(application, FakeRequest(POST, "/commons/get_index_settings").withBody(body)).get
    ensure(response, 400, Json.obj("error" -> "Missing required parameter index"))
  }

@@ -525,13 +525,13 @@ class CommonsControllerSpec extends MockedServices {
    )
    val body = Json.obj("host" -> "somehost", "node" -> "someNode")
    client.nodeStats("someNode", ElasticServer("somehost", None)) returns Future.successful(ElasticResponse(200, expectedResponse))
    val response = route(FakeRequest(POST, "/commons/get_node_stats").withBody(body)).get
    val response = route(application, FakeRequest(POST, "/commons/get_node_stats").withBody(body)).get
    ensure(response, 200, expectedResponse)
  }

  def missingNode = {
    val body = Json.obj("host" -> "somehost")
    val response = route(FakeRequest(POST, "/commons/get_node_stats").withBody(body)).get
    val response = route(application, FakeRequest(POST, "/commons/get_node_stats").withBody(body)).get
    ensure(response, 400, Json.obj("error" -> "Missing required parameter node"))
  }

+2 −2
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ object IndexSettingsControllerSpec extends MockedServices {
      """.stripMargin
    )
    client.getIndexSettingsFlat("foo", ElasticServer("somehost", None)) returns Future.successful(ElasticResponse(200, expectedResponse))
    val response = route(FakeRequest(POST, "/index_settings").withBody(Json.obj("host" -> "somehost", "index" -> "foo"))).get
    val response = route(application, FakeRequest(POST, "/index_settings").withBody(Json.obj("host" -> "somehost", "index" -> "foo"))).get
    ensure(response, 200, expectedResponse)
  }

@@ -58,7 +58,7 @@ object IndexSettingsControllerSpec extends MockedServices {
        |}
      """.stripMargin)
    client.updateIndexSettings("foo", body, ElasticServer("somehost", None)) returns Future.successful(ElasticResponse(200, expectedResponse))
    val response = route(FakeRequest(POST, "/index_settings/update").withBody(Json.obj("host" -> "somehost", "index" -> "foo", "settings" -> body))).get
    val response = route(application, FakeRequest(POST, "/index_settings/update").withBody(Json.obj("host" -> "somehost", "index" -> "foo", "settings" -> body))).get
    ensure(response, 200, expectedResponse)
  }

Loading