将 Spring Cloud Contract 验证发布到 Pact broker [英] Publish Spring Cloud Contract verification to Pact broker

查看:38
本文介绍了将 Spring Cloud Contract 验证发布到 Pact broker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 Spring Cloud Contract Producer 验证发布给 Pact broker?

解决方案

您必须将 DSL 转换为 Pact 文件,然后推送这些文件.所以从技术上讲这是可能的.

更新:我们在文档中描述了如何做到这一点 - https://cloud.spring.io/spring-cloud-contract/reference/html/howto.html#how-to-generate-pact-from-scc

因为在 SO 中似乎检查文档"的答案不被接受,让我复制粘贴文档

<块引用>

  1. 如何从 Spring Cloud Contract Contract 生成 Pact、YAML 或 X 文件?

Spring Cloud Contract 带有一个 ToFileContractsTransformer 类,可让您将合同转储为给定 ContractConverter 的文件.它包含一个静态 void main 方法,可让您将转换器作为可执行文件执行.它需要以下参数:

argument 1 : FQN:ContractConverter 的完全限定名称(例如,PactContractConverter).需要.参数 2 : path: 应存储转储文件的路径.可选 — 默认为目标/转换合同.参数 3 : path: 应搜索合同的路径.可选 — 默认为 src/test/resources/contracts.

在执行转换器后,Spring Cloud 合约文件将被处理,并根据 ContractTransformer 提供的 FQN,将合约转换为所需的格式并转储到提供的文件夹中.

以下示例显示了如何为 Maven 和 Gradle 配置 Pact 集成:

行家

<groupId>org.codehaus.mojo</groupId><artifactId>exec-maven-plugin</artifactId><version>1.6.0</version><执行><执行><id>convert-dsl-to-pact</id><阶段>过程测试类</阶段><配置><classpathScope>test</classpathScope><mainClass>org.springframework.cloud.contract.verifier.util.ToFileContractsTransformer</mainClass><参数><参数>org.springframework.cloud.contract.verifier.spec.pact.PactContractConverter</参数><argument>${project.basedir}/target/pacts</argument><参数>${project.basedir}/src/test/resources/contracts</参数></参数></配置><目标><目标>java</目标></目标></执行></执行></插件>

毕业

task convertContracts(type: JavaExec) {main = "org.springframework.cloud.contract.verifier.util.ToFileContractsTransformer"类路径 = sourceSets.test.compileClasspathargs("org.springframework.cloud.contract.verifier.spec.pact.PactContractConverter","${project.rootDir}/build/pacts", "${project.rootDir}/src/test/resources/contracts")}test.dependsOn("convertContracts")

build/pactstarget/pacts 生成文件后,您可以使用 Pact Gradle/Maven 插件将这些文件上传到代理.

Is it possible to publish Spring Cloud Contract Producer verification to a Pact broker?

解决方案

You would have to convert the DSL to Pact files and then push those. So technically that is possible.

Update: We describe how to do this in the documentation - https://cloud.spring.io/spring-cloud-contract/reference/html/howto.html#how-to-generate-pact-from-scc

Since in SO it seems that an answer "Check the docs" is not an accepted one, let me just copy paste the documentation

  1. How Can I Generate Pact, YAML, or X files from Spring Cloud Contract Contracts?

Spring Cloud Contract comes with a ToFileContractsTransformer class that lets you dump contracts as files for the given ContractConverter. It contains a static void main method that lets you execute the transformer as an executable. It takes the following arguments:

argument 1 : FQN: Fully qualified name of the ContractConverter (for example, PactContractConverter). REQUIRED.

argument 2 : path: Path where the dumped files should be stored. OPTIONAL — defaults to target/converted-contracts.

argument 3 : path: Path were the contracts should be searched for. OPTIONAL — defaults to src/test/resources/contracts.

After executing the transformer, the Spring Cloud Contract files are processed and, depending on the provided FQN of the ContractTransformer, the contracts are transformed to the required format and dumped to the provided folder.

The following example shows how to configure Pact integration for both Maven and Gradle:

maven

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <executions>
        <execution>
            <id>convert-dsl-to-pact</id>
            <phase>process-test-classes</phase>
            <configuration>
                <classpathScope>test</classpathScope>
                <mainClass>
                    org.springframework.cloud.contract.verifier.util.ToFileContractsTransformer
                </mainClass>
                <arguments>
                    <argument>
                        org.springframework.cloud.contract.verifier.spec.pact.PactContractConverter
                    </argument>
                    <argument>${project.basedir}/target/pacts</argument>
                    <argument>
                        ${project.basedir}/src/test/resources/contracts
                    </argument>
                </arguments>
            </configuration>
            <goals>
                <goal>java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

gradle

task convertContracts(type: JavaExec) {
    main = "org.springframework.cloud.contract.verifier.util.ToFileContractsTransformer"
    classpath = sourceSets.test.compileClasspath
    args("org.springframework.cloud.contract.verifier.spec.pact.PactContractConverter",
            "${project.rootDir}/build/pacts", "${project.rootDir}/src/test/resources/contracts")
}

test.dependsOn("convertContracts")

After having the files generated at build/pacts or target/pacts you can use the Pact Gradle / Maven plugin to upload those files to the broker.

这篇关于将 Spring Cloud Contract 验证发布到 Pact broker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆