Search in sources :

Example 1 with YamlContractConverter

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);
}
Also used : QueryParameters(org.springframework.cloud.contract.spec.internal.QueryParameters) Parameters(com.github.tomakehurst.wiremock.extension.Parameters) YamlContract(org.springframework.cloud.contract.verifier.converter.YamlContract) YamlContractConverter(org.springframework.cloud.contract.verifier.converter.YamlContractConverter) GString(groovy.lang.GString)

Example 2 with YamlContractConverter

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);
}
Also used : YamlContract(org.springframework.cloud.contract.verifier.converter.YamlContract) YamlContractConverter(org.springframework.cloud.contract.verifier.converter.YamlContractConverter)

Example 3 with YamlContractConverter

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();
}
Also used : YamlContractConverter(org.springframework.cloud.contract.verifier.converter.YamlContractConverter) File(java.io.File) Contract(org.springframework.cloud.contract.spec.Contract) Test(org.junit.jupiter.api.Test)

Aggregations

YamlContractConverter (org.springframework.cloud.contract.verifier.converter.YamlContractConverter)3 YamlContract (org.springframework.cloud.contract.verifier.converter.YamlContract)2 Parameters (com.github.tomakehurst.wiremock.extension.Parameters)1 GString (groovy.lang.GString)1 File (java.io.File)1 Test (org.junit.jupiter.api.Test)1 Contract (org.springframework.cloud.contract.spec.Contract)1 QueryParameters (org.springframework.cloud.contract.spec.internal.QueryParameters)1