<commit_before>package com.socrata.tileserver
package util

import java.io.InputStream
import javax.servlet.http.HttpServletResponse

import org.mockito.Mockito.{verify, when}
import org.scalatest.mock.MockitoSugar
import org.scalatest.prop.PropertyChecks
import org.scalatest.{FunSuite, MustMatchers}

import com.socrata.http.client.Response
import com.socrata.http.common.util.Acknowledgeable

class UtilPackageTest
    extends FunSuite
    with MustMatchers
    with PropertyChecks
    with MockitoSugar {
  test("InvalidJson returns appropriate error message") {
    val outputStream = new util.ByteArrayServletOutputStream
    val resp = outputStream.responseFor

    InvalidJson(resp)

    verify(resp).setStatus(500)
    verify(resp).setContentType("application/json")

    outputStream.getLowStr must include ("invalid")
    outputStream.getLowStr must include  ("json")
  }

  test("Extensions return error on encoder failure") {
    val clientResp = mock[Response]
    val noneEncoder: Encoder = _ => None

    Extensions.values filter (_ != Json) foreach { ext: Extension =>
      val outputStream = new util.ByteArrayServletOutputStream
      val resp = outputStream.responseFor

      ext(noneEncoder, clientResp)(resp)

      verify(resp).setStatus(500)
      verify(resp).setContentType("application/json")

      outputStream.getLowStr must include ("invalid")
      outputStream.getLowStr must include  ("json")
    }
  }

  test("DefaultResponse includes CORS header") {
    val resp = mock[HttpServletResponse]

    DefaultResponse(resp)

    verify(resp).setStatus(200)
    verify(resp).setHeader("Access-Control-Allow-Origin", "*")
  }

  test("Extensions include CORS header on success") {
    val inputStream: InputStream with Acknowledgeable =
      new InputStream with Acknowledgeable {
        override def acknowledge() = {}
        override def read() = -1
      }

    val clientResp = mock[Response]
    when(clientResp.inputStream()).thenReturn(inputStream)

    val emptyEncoder: Encoder = _ => Some(Array.empty)

    Extensions.values foreach { ext: Extension =>
      val outputStream = new util.ByteArrayServletOutputStream
      val resp = outputStream.responseFor

      ext(emptyEncoder, clientResp)(resp)

      verify(resp).setStatus(200)
      verify(resp).setHeader("Access-Control-Allow-Origin", "*")
    }
  }

  test("Pbf sends bytes from encoder") {
    val clientResp = mock[Response]

    forAll { bytes: Array[Byte] =>
      val outputStream = new util.ByteArrayServletOutputStream
      val resp = outputStream.responseFor
      val encoder: Encoder = r => Some(bytes)

      Pbf(encoder, clientResp)(resp)

      verify(resp).setStatus(200)
      verify(resp).setHeader("Access-Control-Allow-Origin", "*")

      outputStream.getBytes must equal (bytes)
    }
  }

  test("B64Pbf sends base 64 encoded bytes from encoder") {}
  test("Txt") {}
  test("Json") {}
}
<commit_msg>Mark tests pending<commit_after>package com.socrata.tileserver
package util

import java.io.InputStream
import javax.servlet.http.HttpServletResponse

import org.mockito.Mockito.{verify, when}
import org.scalatest.mock.MockitoSugar
import org.scalatest.prop.PropertyChecks
import org.scalatest.{FunSuite, MustMatchers}

import com.socrata.http.client.Response
import com.socrata.http.common.util.Acknowledgeable

class UtilPackageTest
    extends FunSuite
    with MustMatchers
    with PropertyChecks
    with MockitoSugar {
  test("InvalidJson returns appropriate error message") {
    val outputStream = new util.ByteArrayServletOutputStream
    val resp = outputStream.responseFor

    InvalidJson(resp)

    verify(resp).setStatus(500)
    verify(resp).setContentType("application/json")

    outputStream.getLowStr must include ("invalid")
    outputStream.getLowStr must include  ("json")
  }

  test("Extensions return error on encoder failure") {
    val clientResp = mock[Response]
    val noneEncoder: Encoder = _ => None

    Extensions.values filter (_ != Json) foreach { ext: Extension =>
      val outputStream = new util.ByteArrayServletOutputStream
      val resp = outputStream.responseFor

      ext(noneEncoder, clientResp)(resp)

      verify(resp).setStatus(500)
      verify(resp).setContentType("application/json")

      outputStream.getLowStr must include ("invalid")
      outputStream.getLowStr must include  ("json")
    }
  }

  test("DefaultResponse includes CORS header") {
    val resp = mock[HttpServletResponse]

    DefaultResponse(resp)

    verify(resp).setStatus(200)
    verify(resp).setHeader("Access-Control-Allow-Origin", "*")
  }

  test("Extensions include CORS header on success") {
    val inputStream: InputStream with Acknowledgeable =
      new InputStream with Acknowledgeable {
        override def acknowledge() = {}
        override def read() = -1
      }

    val clientResp = mock[Response]
    when(clientResp.inputStream()).thenReturn(inputStream)

    val emptyEncoder: Encoder = _ => Some(Array.empty)

    Extensions.values foreach { ext: Extension =>
      val outputStream = new util.ByteArrayServletOutputStream
      val resp = outputStream.responseFor

      ext(emptyEncoder, clientResp)(resp)

      verify(resp).setStatus(200)
      verify(resp).setHeader("Access-Control-Allow-Origin", "*")
    }
  }

  test("Pbf sends bytes from encoder") {
    val clientResp = mock[Response]

    forAll { bytes: Array[Byte] =>
      val outputStream = new util.ByteArrayServletOutputStream
      val resp = outputStream.responseFor
      val encoder: Encoder = r => Some(bytes)

      Pbf(encoder, clientResp)(resp)

      verify(resp).setStatus(200)
      verify(resp).setHeader("Access-Control-Allow-Origin", "*")

      outputStream.getBytes must equal (bytes)
    }
  }

  test("B64Pbf sends base 64 encoded bytes from encoder")(pending)
  test("Txt")(pending)
  test("Json")(pending)
}

{'fraction_non_alphanumeric': 0.10209290454313426, 'fraction_numerical': 0.00680619363620895, 'mean_word_length': 3.740322580645161, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5628545', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1638, 'n_words': 380}