./gradlew generateWireMockClientStubs
+./gradlew generateClientStubs
From 5b28fd71cbcad2330fcb9923cc335ccfc87ae612 Mon Sep 17 00:00:00 2001
From: buildmaster
+
+
+
package com.example.fraud;
-import com.example.fraud.FraudDetectionController;
-import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc;
-
import org.junit.Before;
+import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc;
+
public class FraudBase {
@Before
public void setup() {
- RestAssuredMockMvc.standaloneSetup(new FraudDetectionController());
+ RestAssuredMockMvc.standaloneSetup(new FraudDetectionController(),
+ new FraudStatsController(stubbedStatsProvider()));
+ }
+
+ private StatsProvider stubbedStatsProvider() {
+ return fraudType -> {
+ switch (fraudType) {
+ case DRUNKS:
+ return 100;
+ case ALL:
+ return 200;
+ }
+ return 0;
+ };
}
public void assertThatRejectionReasonIsNull(Object rejectionReason) {
@@ -2527,7 +2550,7 @@ one to one to the contents of the repo.
com.example.ComBase whereas the rest of tests
./gradlew generateWireMockClientStubs
+./gradlew generateClientStubs
/*
- * Copyright 2013-2016 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
- *
- * http://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.stubrunner;
+package org.springframework.cloud.contract.stubrunner;
import java.net.URL;
import java.util.Collection;
@@ -5099,23 +5106,7 @@ the Stub Runner Boot.
/*
- * Copyright 2013-2016 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
- *
- * http://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.stubrunner;
+package org.springframework.cloud.contract.stubrunner;
import java.util.Collection;
import java.util.Map;
@@ -5478,22 +5469,6 @@ Remember to annotate your test class with @AutoConfigureMessageVerifier
<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Copyright 2013-2016 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
- ~
- ~ http://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.
- -->
-
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
@@ -6000,6 +5975,18 @@ You can also provide an import to the Contract class import o
a tiny subset of it (namely literals, method calls and closures). What’s more the DSL is designed to be programmer-readable without any knowledge of the DSL itself -
it’s statically typed.
+
+
+
+
+Tip
+
+
+Spring Cloud Contract supports defining multiple contracts in a single file!
+
+
+
+
The Contract is present in the spring-cloud-contract-spec module of the Spring Cloud Contract Verifier repository.
@@ -6083,18 +6070,6 @@ Spring Cloud Contract Verifier doesn’t support XML properly. Please use JS
Warning
-Spring Cloud Contract Verifier supports equality check on text response. Regular expressions are not yet available.
-
-
-
-
|
- Warning
- |
-
The support for the verification of size of JSON arrays is experimental. If you want to turn it on please provide
the value of a system property spring.cloud.contract.verifier.assert.size equal to true. By default this feature is set to
false. You can also provide the assertJsonSize property in the plugin configuration.
@@ -6140,6 +6115,28 @@ then:
+
+Name+
+
+You can provide a name of your contract. Let’s assume that you’ve provided a name
+
+
Ignoring contractsIf you want to ignore a contract you can either set a value of ignored contracts in the plugin configuration @@ -6501,7 +6498,7 @@ String uuid(){
-
- Extending the DSL+Customization+
+
+Extending the DSLIt is possible to provide your own functions to the DSL. The key requirement for this feature was to maintain the static compatibility. Below you will be able to see an example @@ -6891,8 +7006,8 @@ of: The full example can be found here.
-
Common JAR+
+
Common JARBelow you can find three classes that we will reuse in the DSLs.
-
+Adding the dependency to project+
+
-Adding the dependency to projectIn order for the plugins and IDE to be able to reference the common JAR classes you need to pass the dependency to your project.
-
-Test dependency in project’s dependencies+
+
Test dependency in project’s dependenciesFirst add the common jar dependency as a test dependency. That way since your contracts files are available at test resources path, automatically the @@ -7087,8 +7202,8 @@ common jar classes will be visible in your Groovy files.
-
Test dependency in plugin’s dependencies+
+
Test dependency in plugin’s dependenciesNow you have to add the dependency for the plugin to reuse at runtime.
-
Referencing classes in DSLs+
+
Referencing classes in DSLsNow you can reference your classes in your DSL. Example:
+
Pluggable architecture+
+
+There are cases where you have your contracts defined in other formats +like YAML, RAML or PACT. On the other hand you’d like to profit from +the test and stubs generation. It’s really easy to add your own implementation +of either of those. Also you can customize the way tests are generated (for example you can generate +tests for other languages) and you can do the same for stubs generation (you can generate +stubs for other stub http server implementations). +
+
+Custom contract converter+
+
+Let’s assume that your contract is written in a YAML file like this: +
+
+
+
+
+
+
+Thanks to the interface +
+
+
+
+
+
+
+you can register your own implementation of a contract structure converter. +Your implementation needs to state the condition on which it should start the +conversion. Also you have to define how to perform that conversion in both ways. +
+
+
+
+Example of a
+
+
+
+
+
+
+and the YAML implementation +
+
+
+
+
+
+
+Custom test generator+
+
+If you want to generate tests for different languages than Java or you’re +not happy with the way we’re building Java tests for you then you can register +your own implementation to do that. +
+
+Thanks to the interface +
+
+
+
+
+
+
+you can register your own implementation that generates a test. Again, it’s enough to provide
+a proper
+
+
+
+
+
+
+Custom stub generator+
+
+If you want to generate stubs for other stub server than WireMock it’s enough to + plug in your own implementation of this interface: +
+
+
+
+
+
+
+you can register your own implementation that generate Stubs. Again, it’s enough to provide
+a proper
+
+
+
+
+
+
+The default implementation is the WireMock stub generation. +
+
+Custom Stub Runner+
+
+If you decide to have a custom stub generation you also need a custom way of running +stubs with your different stub provider. +
+
+Let us assume that you’re using Moco to build your stubs. +You wrote a proper stub generator and your stubs got placed in a JAR file. +
+
+In order for Stub Runner to know how to run your stubs you have to define a custom + HTTP Stub server implementation. It can look like this: +
+
+
+
+
+
+
+and just register it in your
+
+
+
+
+
+
+that way you’ll be able to run stubs using Moco. +
+
+
Links |