<commit_before>package org.seekay.contract.configuration
import com.fasterxml.jackson.databind.ObjectMapper
import org.seekay.contract.model.domain.Contract
import spock.lang.Specification

import static org.seekay.contract.model.domain.Method.GET
import static org.seekay.contract.model.util.ListTools.first

class LocalConfigurationSourceSpec extends Specification {

    def "contracts in a local directory should be loadable" () {
        given:
            ConfigurationSource source = new LocalConfigurationSource("src/test/resources/contracts/simpleLoadTest")
        when:
            List<Contract> contracts = source.load()
        then:
            contracts.size() == 1
    }

    def "contracts should be loaded correctly" () {
        given:
            ConfigurationSource source = new LocalConfigurationSource("src/test/resources/contracts/simpleLoadTest")
        when:
            List<Contract> contracts = source.load()
            Contract contract = first(contracts)
        then:
            contract.request.method == GET
            contract.request.path == "/entity/1"
            contract.request.headers["key"] == "value"
            contract.response.status == 200
            contract.response.body == "hello world"
    }

    def "multiple contracts can be loaded from a single directory" () {
        given:
            ConfigurationSource source = new LocalConfigurationSource("src/test/resources/contracts/multipleGetContracts")
        when:
            List<Contract> contracts = source.load()
        then:
            contracts.size() == 2
            contracts.collect { contract ->
                assert contract.response.body == "hello world"
                assert contract.response.status == 200
            }
    }

    def "multiple contracts can be loaded from arbitrary folder depths" () {
        given:
            ConfigurationSource source = new LocalConfigurationSource("src/test/resources/contracts/crazyFolderLayout")
        when:
            List<Contract> contracts = source.load()
        then:
            contracts.size() == 2
            contracts.collect { contract ->
                assert contract.response.body == "hello world"
                assert contract.response.status == 200
            }
    }

    def "when an exception is thrown loading a contract, it should be logged" () {
        given:
            ConfigurationSource source = new LocalConfigurationSource("src/test/resources/contracts/crazyFolderLayout")
            ObjectMapper objectMapper = Mock(ObjectMapper)
            source.objectMapper = objectMapper
        when:
            source.load()
        then:
            objectMapper.readValue(_, HashMap.class) >> {throw new IOException()}
			thrown(IllegalStateException)
    }

	def "tags should be generated correctly based on directory structure" () {
		given:
			ConfigurationSource source = new LocalConfigurationSource("src/test/resources/")
		when:
			List<Contract> contracts = source.load()
			Contract contract = first(contracts)
			Set tags = contract.info['tags']
		then:
			tags.size() == 2
			tags.contains('contracts')
			tags.contains('simpleloadtest')
	}
}
<commit_msg>Fixing badly merged unit test<commit_after>package org.seekay.contract.configuration
import com.fasterxml.jackson.databind.ObjectMapper
import org.seekay.contract.model.domain.Contract
import spock.lang.Specification

import static org.seekay.contract.model.domain.Method.GET
import static org.seekay.contract.model.util.ListTools.first

class LocalConfigurationSourceSpec extends Specification {

    def "contracts in a local directory should be loadable" () {
        given:
            ConfigurationSource source = new LocalConfigurationSource("src/test/resources/contracts/simpleLoadTest")
        when:
            List<Contract> contracts = source.load()
        then:
            contracts.size() == 1
    }

    def "contracts should be loaded correctly" () {
        given:
            ConfigurationSource source = new LocalConfigurationSource("src/test/resources/contracts/simpleLoadTest")
        when:
            List<Contract> contracts = source.load()
            Contract contract = first(contracts)
        then:
            contract.request.method == GET
            contract.request.path == "/entity/1"
            contract.request.headers["key"] == "value"
            contract.response.status == 200
            contract.response.body == "hello world"
    }

    def "multiple contracts can be loaded from a single directory" () {
        given:
            ConfigurationSource source = new LocalConfigurationSource("src/test/resources/contracts/multipleGetContracts")
        when:
            List<Contract> contracts = source.load()
        then:
            contracts.size() == 2
            contracts.collect { contract ->
                assert contract.response.body == "hello world"
                assert contract.response.status == 200
            }
    }

    def "multiple contracts can be loaded from arbitrary folder depths" () {
        given:
            ConfigurationSource source = new LocalConfigurationSource("src/test/resources/contracts/crazyFolderLayout")
        when:
            List<Contract> contracts = source.load()
        then:
            contracts.size() == 2
            contracts.collect { contract ->
                assert contract.response.body == "hello world"
                assert contract.response.status == 200
            }
    }

    def "when an exception is thrown loading a contract, it should be logged" () {
        given:
            ConfigurationSource source = new LocalConfigurationSource("src/test/resources/contracts/crazyFolderLayout")
            ObjectMapper objectMapper = Mock(ObjectMapper)
            source.objectMapper = objectMapper
        when:
            source.load()
        then:
            objectMapper.readValue(_, HashMap.class) >> {throw new IOException()}
			thrown(IllegalStateException)
    }

	def "tags should be generated correctly based on directory structure" () {
		given:
			ConfigurationSource source = new LocalConfigurationSource("src/test/resources/")
		when:
			List<Contract> contracts = source.load()
			contracts = contracts.sort()
			Contract contract = first(contracts)
			Set tags = contract.info['tags']
		then:
			tags.size() == 2
			tags.contains('contracts')
			tags.contains('simpleloadtest')
	}
}

{'fraction_non_alphanumeric': 0.0924422236102436, 'fraction_numerical': 0.004372267332916927, 'mean_word_length': 2.4809782608695654, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '3529329', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1534, 'n_words': 392}