我已创建以下合同:
@Test
public void shouldGetTransactionsWhenRequestIsInvokedWithoutParameters() {
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/Json;charset=UTF-8");
DslPart body = newJsonBody((root) -> root.eachArrayLike("content", el ->
{
el.integerType() //ID
.object(booking ->
booking.numberType("id")
.stringType("vertical", "CAR_HIRE")
.stringType("trip_reference")
.booleanType("financial_change")
.numberType("version")
.stringType("business_model")
.date("pick_up_date_time", DATETIME_FORMAT)
.date("drop_off_time", DATETIME_FORMAT)
.stringType("pick_up_country")
.stringType("pick_up_location")
.stringType("drop_off_country")
.stringType("drop_off_country")
.stringType("drop_off_location")
.stringType("net_booking_attached")
.object("audit", audit ->
audit.date("created_date_time", DATETIME_FORMAT)
.date("updated_date_time", DATETIME_FORMAT))
)
.object(customer ->
customer.numberType("id", 1)
.stringType("country_of_residence")
.stringType("country_of_origin")
.stringType("postal_code")
.object("audit", audit ->
audit.date("created_date_time", DATETIME_FORMAT)
.date("updated_date_time", DATETIME_FORMAT))
)
.object(vendor ->
vendor.numberType("id", 1)
.stringType("name")
.booleanType("self billing", "true")
.stringType("contract_type", "PRINCIPLE")
.object("audit", audit ->
audit.date("created_date_time", DATETIME_FORMAT)
.date("updated_date_time", DATETIME_FORMAT))
)
.object(value_type ->
value_type.numberType("id")
.stringType("product")
.stringType("type")
.object("audit", audit ->
audit.date("created_date_time", DATETIME_FORMAT)
.date("updated_date_time", DATETIME_FORMAT))
)
.stringType("currency_code")
.date(DATETIME_FORMAT)
.numberType(280.05)
.numberType(180.05)
.stringType("sap_status")
.stringType("blackline_status")
.object(audit -> audit.date("created_date_time", DATETIME_FORMAT)
.date("updated_date_time", DATETIME_FORMAT));
})).build();
RequestResponsePact requestResponsePact = ConsumerPactBuilder
.consumer("TransactionConsumer")
.hasPactWith("bookinggo-Fin_API")
.given("")
.uponReceiving("Transactions")
.path("/transactions")
.method("GET")
.willRespondWith()
.headers(headers)
.status(200)
.body(body)
.toPact();
MockProviderConfig config = MockProviderConfig.httpConfig(MockProviderConfig.LOCALHOST, RandomUtils.nextInt(), PactSpecVersion.V2);
runConsumerTest(requestResponsePact, config, (mockServer, pactTestExecutionContext) ->
WebClient.create(mockServer.getUrl())
.method(HttpMethod.GET).uri("/transactions")
.exchange()
.flatMap(res -> res.bodyToMono(String.class))
.block());
}
但是,runConsumerTest
方法不会返回任何内容,因为mockServer
不会映射/ transactions端点。
我一直在遵循本教程https://github.com/Mikuu/Pact-JVM-Example/blob/master/example-consumer-miku/src/test/java/ariman/pact/consumer/PactJunitDSLTest.java提供的示例。
我在这里想念什么?