<commit_before>package com.ofg.infrastructure.discovery

import com.ofg.infrastructure.discovery.config.PropertySourceConfiguration
import com.ofg.stub.config.StubRunnerConfiguration
import org.springframework.context.annotation.AnnotationConfigApplicationContext
import spock.lang.Specification

import static com.jayway.restassured.RestAssured.get
import static com.ofg.config.BasicProfiles.TEST
import static org.hamcrest.Matchers.equalTo

class ConsumerDrivenContractSpec extends Specification {

    public static final String GENERIC_FOOBAR = 'foobar'
    public static final String CONTEXT_SPECIFIC_FOOBAR = 'foobar Poland'
    private AnnotationConfigApplicationContext applicationContext

    static {
        //System.setProperty("ivy.message.logger.level", '4')
    }

    def setup() {
        applicationContext = new AnnotationConfigApplicationContext()
        applicationContext.environment.setActiveProfiles(TEST)
        applicationContext.register(PropertySourceConfiguration, StubRunnerConfiguration, ServiceResolverConfiguration)
        applicationContext.refresh()
    }

    def 'should register a collaborator in a TestingZookeeper'()  {
        given:
            ServiceResolver serviceResolver = applicationContext.getBean(ServiceResolver)
        expect:
            serviceResolver.getUrl('foo-bar').isPresent()
    }

    def 'should set up a stubbed http endpoint'()  {
        given:
            ServiceResolver serviceResolver = applicationContext.getBean(ServiceResolver)
        and:
            String fooBarUrl = serviceResolver.getUrl('foo-bar').get()
        expect:
            get("$fooBarUrl/foobar").then().assertThat().body(equalTo(GENERIC_FOOBAR));
            get("$fooBarUrl/pl/foobar").then().assertThat().body(equalTo(CONTEXT_SPECIFIC_FOOBAR));
    }

    def cleanup() {
        applicationContext.close()
    }
}<commit_msg>Initialising Spring context only once<commit_after>package com.ofg.infrastructure.discovery

import com.ofg.infrastructure.discovery.config.PropertySourceConfiguration
import com.ofg.stub.config.StubRunnerConfiguration
import org.springframework.context.annotation.AnnotationConfigApplicationContext
import spock.lang.Specification

import static com.jayway.restassured.RestAssured.get
import static com.ofg.config.BasicProfiles.TEST
import static org.hamcrest.Matchers.equalTo

class ConsumerDrivenContractSpec extends Specification {

    public static final String GENERIC_FOOBAR = 'foobar'
    public static final String CONTEXT_SPECIFIC_FOOBAR = 'foobar Poland'

    private static AnnotationConfigApplicationContext applicationContext

    static {
        //System.setProperty("ivy.message.logger.level", '4')
    }

    def setupSpec() {
        applicationContext = new AnnotationConfigApplicationContext()
        applicationContext.environment.setActiveProfiles(TEST)
        applicationContext.register(PropertySourceConfiguration, StubRunnerConfiguration, ServiceResolverConfiguration)
        applicationContext.refresh()
    }

    def 'should register a collaborator in a TestingZookeeper'()  {
        given:
            ServiceResolver serviceResolver = applicationContext.getBean(ServiceResolver)
        expect:
            serviceResolver.getUrl('foo-bar').isPresent()
    }

    def 'should set up a stubbed http endpoint'()  {
        given:
            ServiceResolver serviceResolver = applicationContext.getBean(ServiceResolver)
        and:
            String fooBarUrl = serviceResolver.getUrl('foo-bar').get()
        expect:
            get("$fooBarUrl/foobar").then().assertThat().body(equalTo(GENERIC_FOOBAR));
            get("$fooBarUrl/pl/foobar").then().assertThat().body(equalTo(CONTEXT_SPECIFIC_FOOBAR));
    }

    def cleanupSpec() {
        applicationContext.close()
    }
}
{'fraction_non_alphanumeric': 0.08544303797468354, 'fraction_numerical': 0.0005274261603375527, 'mean_word_length': 3.8815958815958815, 'pattern_counts': {'":': 0, '<': 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': '6653428', 'n_tokens_mistral': 1004, 'n_tokens_neox': 969, 'n_words': 181}