<commit_before>package cc.vileda.kalfor

import com.github.kittinunf.fuel.httpGet
import org.junit.Test
import java.nio.charset.Charset
import kotlin.test.assertTrue

internal class KalforIT {
    @Test
    fun kalfor_should_map_requests_with_http_fetcher() {
        val mockServerPort = mockServer2()
        val mockKalforPort = mockKalforService()

        val expected = "test-1"

        val request = ("http://localhost:$mockKalforPort/combine?c=" +
                "http://localhost:$mockServerPort/res-text").httpGet()
        val result = request.response().third.get()
                .toString(Charset.defaultCharset())

        assertTrue(expected == result)
    }<commit_msg>add integration test<commit_after>package cc.vileda.kalfor

import com.github.kittinunf.fuel.httpGet
import com.github.kittinunf.fuel.httpPost
import com.github.salomonbrys.kotson.fromJson
import com.github.salomonbrys.kotson.jsonObject
import com.google.gson.Gson
import org.junit.Test
import java.nio.charset.Charset
import kotlin.test.assertTrue

internal class KalforIT {
    @Test
    fun kalfor_should_map_get_requests() {
        val mockServerPort = mockServer2()
        val mockKalforPort = mockKalforService()

        val expected = "test-1"

        val request = ("http://localhost:$mockKalforPort/combine?c=" +
                "http://localhost:$mockServerPort/res-text").httpGet()
        val result = request.response().third.get()
                .toString(Charset.defaultCharset())

        assertTrue(expected == result)
    }

    @Test
    fun kalfor_should_post_get_requests() {
        val mockServerPort = mockServer2()
        val mockKalforPort = mockKalforService()

        val expected = listOf(
                responseMock1(),
                response404Mock()
        )
        val body = Gson().toJson(listOf(
                KalforRequest(
                        proxyBaseUrl = "http://localhost:$mockServerPort",
                        proxyRequests = listOf(
                                KalforProxyRequest("res1", "/"),
                                KalforProxyRequest("res2", "/404")
                        )
                )
        ))
        val request = ("http://localhost:$mockKalforPort/combine?c=" +
                "http://localhost:$mockServerPort/res-text").httpPost()
        request.request.body(body, Charset.defaultCharset())
        val result = Gson().fromJson<List<KalforResponse>>(request.response().third.get()
                .toString(Charset.defaultCharset()))

        assertTrue(expected == result)
    }

    val responseMock = jsonObject("foo" to "bar").toString()

    private fun response404Mock(): KalforResponse {
        return KalforResponse("res2", 404,
                listOf(KalforProxyHeader("Connection", "keep-alive"),
                        KalforProxyHeader("Content-Length", "78"),
                        KalforProxyHeader("Content-Type", "text/html; charset=UTF-8")
                ),
                "<H1>404 Not Found</H1><P>Cannot find resource with the requested URI: /404</P>")
    }

    private fun responseMock1(): KalforResponse {
        return KalforResponse("res1", 200,
                listOf(KalforProxyHeader("Connection", "keep-alive"),
                        KalforProxyHeader("Content-Length", "13"),
                        KalforProxyHeader("Content-Type", "application/json")
                ),
                responseMock)
    }
{'fraction_non_alphanumeric': 0.11502620850320326, 'fraction_numerical': 0.011357018054746652, 'mean_word_length': 2.2436260623229463, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '7552801', 'n_tokens_mistral': 1006, 'n_tokens_neox': 933, 'n_words': 160}