<commit_before><commit_msg>added unit test for trailing slash in url parameter #356<commit_after>package de.maibornwolff.codecharta.importer.sonar

import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock.*
import com.github.tomakehurst.wiremock.junit.WireMockRule
import de.maibornwolff.codecharta.importer.sonar.SonarImporterMain.Companion.main
import de.maibornwolff.codecharta.importer.sonar.dataaccess.SonarMetricsAPIDatasource

import org.junit.Rule
import org.junit.Test

class SonarImporterMainTest {
    companion object {
        private const val PORT = 8089

        private fun METRIC_LIST_URL_PATH(page: Int): String {
            return "/api/metrics/search?f=hidden,decimalScale&p=$page&ps=${SonarMetricsAPIDatasource.PAGE_SIZE}"
        }

    }

    @JvmField
    @Rule
    var wireMockRule = WireMockRule(PORT)

    @Test
    @Throws(Exception::class)
    fun `should call correct url with trailing backslash in URL parameter`() {
        WireMock.stubFor(
                WireMock.get(WireMock.urlEqualTo(METRIC_LIST_URL_PATH(1)))
                        .willReturn(WireMock.aResponse()
                                .withStatus(200)
                                .withHeader("Content-Type", "application/json")
                                .withBody("{\"metrics\": [],\"total\": 0, \"p\": 0, \"ps\": 0}")))


        main(arrayOf("http://localhost:8089/",  "someproject"))

        verify ( 1, getRequestedFor(urlEqualTo("/api/metrics/search?f=hidden,decimalScale&p=1&ps=500")) )
    }

    @Test
    @Throws(Exception::class)
    fun `should call correct url without trailing backslash in URL parameter`() {
        WireMock.stubFor(
                WireMock.get(WireMock.urlEqualTo(METRIC_LIST_URL_PATH(1)))
                        .willReturn(WireMock.aResponse()
                                .withStatus(200)
                                .withHeader("Content-Type", "application/json")
                                .withBody("{\"metrics\": [],\"total\": 0, \"p\": 0, \"ps\": 0}")))


        main(arrayOf("http://localhost:8089",  "someproject"))

        verify ( 1, getRequestedFor(urlEqualTo("/api/metrics/search?f=hidden,decimalScale&p=1&ps=500")) )
    }
}
{'fraction_non_alphanumeric': 0.12898936170212766, 'fraction_numerical': 0.017287234042553192, 'mean_word_length': 2.54874213836478, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '3409196', 'n_tokens_mistral': 731, 'n_tokens_neox': 672, 'n_words': 108}