use of org.springframework.cloud.contract.verifier.converter.YamlContractConverter in project spring-cloud-contract by spring-cloud.
the class WireMockRequestStubStrategy method appendSpringCloudContractMatcher.
private void appendSpringCloudContractMatcher(ContractVerifierMetadata metadata, RequestPatternBuilder requestPatternBuilder) {
Parameters parameters = Parameters.one("tool", metadata.getTool() != null ? metadata.getTool() : "unknown");
YamlContractConverter converter = new YamlContractConverter();
List<YamlContract> contracts = converter.convertTo(Collections.singleton(contract));
Map<String, byte[]> store = converter.store(contracts);
parameters.put("contract", new String(store.entrySet().iterator().next().getValue()));
requestPatternBuilder.andMatching(SpringCloudContractRequestMatcher.NAME, parameters);
}
use of org.springframework.cloud.contract.verifier.converter.YamlContractConverter in project spring-cloud-contract by spring-cloud.
the class ContractVerifierUtil method contract.
/**
* Helper method to convert a file to bytes.
* @param testClass - test class relative to which the file is stored
* @param relativePath - relative path to the file
* @return bytes of the file
* @since 3.0.0
*/
public static YamlContract contract(Object testClass, String relativePath) {
String path = fromRelativePath(relativePath);
byte[] bytes = fileToBytes(testClass, path);
List<YamlContract> read = new YamlContractConverter().read(bytes);
return read.isEmpty() ? null : read.get(0);
}
use of org.springframework.cloud.contract.verifier.converter.YamlContractConverter in project spring-cloud-contract by spring-cloud.
the class AdditionalResourcesGenerationTests method should_convert_yaml_to_contract.
// @formatter:on
@Test
void should_convert_yaml_to_contract() throws IOException {
File ymlFile = new File("target/contract.yml");
Files.write(ymlFile.toPath(), CONTRACT.getBytes());
Collection<Contract> contracts = new YamlContractConverter().convertFrom(ymlFile);
BDDAssertions.then(contracts).isNotEmpty();
}
Aggregations