W3Cschool
恭喜您成為首批注冊用戶
獲得88經驗值獎勵
WireMock允許您注冊自定義擴展。默認情況下,Spring Cloud Contract注冊該轉換器,使您可以引用響應中的請求。如果要提供自己的擴展,則可以注冊org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions
接口的實現。由于我們使用spring.factories擴展方法,因此可以在META-INF/spring.factories
文件中創(chuàng)建一個類似于以下內容的條目:
org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions=\ org.springframework.cloud.contract.stubrunner.provider.wiremock.TestWireMockExtensions org.springframework.cloud.contract.spec.ContractConverter=\ org.springframework.cloud.contract.stubrunner.TestCustomYamlContractConverter
以下是自定義擴展的示例:
TestWireMockExtensions.groovy。
/* * Copyright 2013-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.cloud.contract.verifier.dsl.wiremock import com.github.tomakehurst.wiremock.extension.Extension /** * Extension that registers the default transformer and the custom one */ class TestWireMockExtensions implements WireMockExtensions { @Override List<Extension> extensions() { return [ new DefaultResponseTransformer(), new CustomExtension() ] } } class CustomExtension implements Extension { @Override String getName() { return "foo-transformer" } }
如果要將轉換僅應用于明確需要它的映射,請記住重寫applyGlobally()
方法并將其設置為false
。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: