Контракт Spring Cloud с Spring Cucumber

#java #spring #cucumber #spring-cloud-contract

#java #spring #cucumber #spring-cloud-contract

Вопрос:

Я хочу реализовать 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:Usersuser.m2repository)]
  

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

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

ps :

Когда я реализую свой stub runner в базовом тестовом классе, все в порядке. Вот так :

 @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
  

Комментарии:

1. Может быть, попробовать использовать правило JUnit для запуска заглушки?

2. @SpringBootTest отсутствует в вашем stepdef.

3. Спасибо, но даже при добавлении аннотации @SpringBootTest у меня всегда возникает одна и та же ошибка…

4. Я не понимаю, о чем вы говорите. Вы можете ознакомиться с документацией cloud.spring.io/spring-cloud-static/Greenwich . РЕЛИЗ / сингл / … и образцы github.com/spring-cloud-samples/spring-cloud-contract-samples /…

5. @benjamin что происходит, когда вы используете репозиторий maven по умолчанию? Или устанавливается maven.repo.local каким-либо другим способом, после чего статический инициализируется.