<commit_before>package uk.ac.wellcome.platform.api

import com.fasterxml.jackson.databind.ObjectMapper
import com.twitter.finagle.http.{Response, Status}
import com.twitter.finatra.http.EmbeddedHttpServer
import com.twitter.inject.server.FeatureTestMixin
import org.scalatest.FunSpec
import uk.ac.wellcome.models._
import uk.ac.wellcome.test.utils.IndexedElasticSearchLocal
import uk.ac.wellcome.utils.JsonUtil.mapper

class ApiSwaggerTest extends FunSpec with FeatureTestMixin {

  implicit val jsonMapper = IdentifiedWork
  override val server =
    new EmbeddedHttpServer(
      new Server,
      flags = Map(
        "api.host" -> "test.host",
        "api.scheme" -> "http",
        "api.version" -> "v99",
        "api.name" -> "test"
      )
    )

  it("should return a valid JSON response") {
    val response: Response = server.httpGet(
      path = "/test/v99/swagger.json",
      andExpect = Status.Ok
    )

    val mapper = new ObjectMapper()

    noException should be thrownBy { mapper.readTree(response.contentString) }

    val tree = mapper.readTree(response.contentString)

    tree.at("/host").toString should be("\"test.host\"")
    tree.at("/schemes").toString should be("[\"http\"]")
    tree.at("/info/version").toString should be("\"v99\"")
    tree.at("/basePath").toString should be("\"/test/v99\"")
  }
}
<commit_msg>Refactor the Swagger tests for less repetition<commit_after>package uk.ac.wellcome.platform.api

import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
import com.twitter.finagle.http.{Response, Status}
import com.twitter.finatra.http.EmbeddedHttpServer
import com.twitter.inject.server.FeatureTestMixin
import org.scalatest.FunSpec
import uk.ac.wellcome.models._
import uk.ac.wellcome.test.utils.IndexedElasticSearchLocal
import uk.ac.wellcome.utils.JsonUtil.mapper

class ApiSwaggerTest extends FunSpec with FeatureTestMixin {

  implicit val jsonMapper = IdentifiedWork
  override val server =
    new EmbeddedHttpServer(
      new Server,
      flags = Map(
        "api.host" -> "test.host",
        "api.scheme" -> "http",
        "api.version" -> "v99",
        "api.name" -> "test"
      )
    )

  it("should return a valid JSON response") {
    val tree = readTree("/test/v99/swagger.json")

    tree.at("/host").toString should be("\"test.host\"")
    tree.at("/schemes").toString should be("[\"http\"]")
    tree.at("/info/version").toString should be("\"v99\"")
    tree.at("/basePath").toString should be("\"/test/v99\"")
  }

  def readTree(path: String): JsonNode = {
    val response: Response = server.httpGet(
      path = path,
      andExpect = Status.Ok
    )

    val mapper = new ObjectMapper()

    noException should be thrownBy { mapper.readTree(response.contentString) }

    mapper.readTree(response.contentString)
  }
}

{'fraction_non_alphanumeric': 0.1362339514978602, 'fraction_numerical': 0.005706134094151213, 'mean_word_length': 3.403453689167975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3956644', 'n_tokens_mistral': 905, 'n_tokens_neox': 876, 'n_words': 180}