首页 > 解决方案 > Spring Cloud Contract 与 Spring Cucumber

问题描述

我想用我的 Spring Cucumber 集成测试来实现 Spring Cloud Contract,我在我的类步骤定义中定义了我的存根运行器,如下所示:

@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

标签: javaspringcucumberspring-cloud-contract

解决方案


推荐阅读