我想通过我的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