Весенний Облачный Контракт с Весенним Огурцом - PullRequest
2 голосов
/ 14 марта 2019

Я хочу внедрить Spring Cloud Contract с моими интеграционными тестами Spring Cucumber. Я определил своего бегуна-заглушки в своем определении шага класса следующим образом:

@AutoConfigureStubRunner(
        ids = "fr.service:project-name:+:stubs:9090",
        stubsMode = StubRunnerProperties.StubsMode.LOCAL)
    public class CertificationStepdefs extends CertificationSpringBootTest {

    static {
        System.setProperty("maven.repo.local", "C:\\_Developpement\\Maven\\repository");
    }

    ...

Но когда после компиляции проекта яесть эта ошибка:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    2019-03-14T17:08:29,869 ERROR org.springframework.boot.SpringApplication - Application run failed
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'compositeDiscoveryClient' defined in class path resource [org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClientAutoConfiguration.class]: Unsatisfied dependency expressed through method 'compositeDiscoveryClient' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleDiscoveryClient' defined in class path resource [org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClientAutoConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchStubRunner' defined in class path resource [org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.contract.stubrunner.BatchStubRunner]: Factory method 'batchStubRunner' threw exception; nested exception is java.lang.IllegalArgumentException: For groupId [fr.service] artifactId [project-name] and classifier [stubs] the version was not resolved! The following exceptions took place [org.eclipse.aether.transfer.MetadataNotFoundException: Could not find metadata fr.service.domain:project-name/maven-metadata.xml in local (C:\Users\user\.m2\repository)]

Я хотел бы иметь решение для запуска моей заглушки на порт 9090 для моих тестов Cumcumber.

У вас есть какие-нибудь идеи?

ps:

Когда я внедряю свою заглушку в базовый тестовый класс, это нормально.Например:

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureStubRunner(
        ids = "fr.service:project-name:+:stubs:9090",
        stubsMode = StubRunnerProperties.StubsMode.LOCAL)
public class ContractTest {

    static {
        System.setProperty("maven.repo.local", "C:\\_Developpement\\Maven\\repository");
    }

    @Value("${constante-raic.scheme:}")
    private String scheme;

    @Value("${constante-raic.path-identite:}")
    private String pathIdentite;

    @Test
    public void testContract() {

        ReponseRaic reponseRaic;
        RestTemplate restTemplate = new RestTemplate();
        String nir = "111111111111";
        final UriComponents uriComponents = UriComponentsBuilder.newInstance()
                .scheme(scheme)
                .host("localhost:9090")
                .path(pathIdentite + nir)
                .build();

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
        HttpEntity entity = new HttpEntity(headers);
        reponseRaic = restTemplate.exchange(uriComponents.toUriString(), HttpMethod.GET, entity, ReponseRaic.class).getBody();

        Assert.assertEquals("RAIC946E7E1C-9526-4E59-9EFE-D1889CCCCE13", reponseRaic.getIdRaic());

    }

}

Контракт (.yml):

request:
  method: GET
  url: /identities/111111111111
  headers:
    Content-Type: application/json
response:
  status: 200
  body:
    id_raic: "RAIC946E7E1C-9526-4E59-9EFE-D1889CCCCE13"
  headers:
    Content-Type: application/json;charset=UTF-8
...