22
33import java .util .Map ;
44
5+ /**
6+ * Config object for ContractCase
7+ */
58public class ContractCaseConfig {
69
7-
810 /**
911 * The name of the provider for this contract.
1012 */
11- public String providerName ;
13+ public final String providerName ;
1214
1315 /**
1416 * The name of the consumer for this contract.
1517 */
16- public String consumerName ;
18+ public final String consumerName ;
1719
1820
1921 /**
2022 * How much should we log during the test?
2123 *
2224 * @see LogLevel
2325 */
24- public LogLevel logLevel ;
26+ public final LogLevel logLevel ;
2527
2628 /**
2729 * The directory where the contract will be written. If you provide this, ContractCase will
2830 * generate the filename for you (unless `contractFilename` is specified, in which case this
2931 * setting is ignored)
3032 */
31- public String contractDir ;
33+ public final String contractDir ;
3234
3335 /**
3436 * The filename where the contract will be written. If you provide this, `contractDir` is ignored
3537 */
36- public String contractFilename ;
38+ public final String contractFilename ;
3739
3840 /**
3941 * Whether results should be printed on standard out during the test run
4042 */
41- public Boolean printResults ;
43+ public final Boolean printResults ;
4244
4345
4446 /**
@@ -50,49 +52,172 @@ public class ContractCaseConfig {
5052 * <p>
5153 * Default: `true` in contract definition, `false` in contract verification
5254 */
53- public Boolean throwOnFail ;
55+ public final Boolean throwOnFail ;
5456
5557 /**
5658 * Whether to publish contracts or verification results to the broker
5759 *
5860 * @see PublishType
5961 */
60- public PublishType publish ;
62+ public final PublishType publish ;
6163
6264 /**
6365 * The base URL for the contract broker
6466 */
65- public String brokerBaseUrl ;
67+ public final String brokerBaseUrl ;
6668
6769 /**
6870 * The access token to use for the contract broker. Must have CI scope.
6971 * <p>
7072 * If this is specified along with brokerBasicAuth, the basic auth is ignored.
7173 */
72- public String brokerCiAccessToken ;
74+ public final String brokerCiAccessToken ;
7375
7476 /**
7577 * The basic authentication username and password to access the contract broker.
7678 * <p>
7779 * If this is specified along with brokerCiAccessToken, basic auth credentials are ignored.
7880 */
79- public BrokerBasicAuthCredentials brokerBasicAuth ;
81+ public final BrokerBasicAuthCredentials brokerBasicAuth ;
8082
8183 /**
8284 * The base URL for your real server, if you are testing an http server.
8385 *
8486 * @deprecated This will be moved to a config property that allows configuration for arbitrary
8587 * mocks
8688 */
87- public String baseUrlUnderTest ;
89+ @ Deprecated
90+ public final String baseUrlUnderTest ;
8891
8992
90- public TriggerGroups triggers ;
93+ public final TriggerGroups triggers ;
9194
9295 /**
9396 * State setup and teardown handlers for any states this test requires (see (<a
9497 * href="https://case.contract-testing.io/docs/reference/state-handlers/">writing state
9598 * handlers</a>)) for more details
9699 */
97- public Map <String , StateHandler > stateHandlers ;
100+ public final Map <String , StateHandler > stateHandlers ;
101+
102+ public ContractCaseConfig (String providerName , String consumerName , LogLevel logLevel ,
103+ String contractDir , String contractFilename , Boolean printResults , Boolean throwOnFail ,
104+ PublishType publish , String brokerBaseUrl , String brokerCiAccessToken ,
105+ BrokerBasicAuthCredentials brokerBasicAuth , String baseUrlUnderTest , TriggerGroups triggers ,
106+ Map <String , StateHandler > stateHandlers ) {
107+ this .providerName = providerName ;
108+ this .consumerName = consumerName ;
109+ this .logLevel = logLevel ;
110+ this .contractDir = contractDir ;
111+ this .contractFilename = contractFilename ;
112+ this .printResults = printResults ;
113+ this .throwOnFail = throwOnFail ;
114+ this .publish = publish ;
115+ this .brokerBaseUrl = brokerBaseUrl ;
116+ this .brokerCiAccessToken = brokerCiAccessToken ;
117+ this .brokerBasicAuth = brokerBasicAuth ;
118+ this .baseUrlUnderTest = baseUrlUnderTest ;
119+ this .triggers = triggers ;
120+ this .stateHandlers = stateHandlers ;
121+ }
122+
123+ public static final class ContractCaseConfigBuilder {
124+
125+ private String providerName ;
126+ private String consumerName ;
127+ private LogLevel logLevel ;
128+ private String contractDir ;
129+ private String contractFilename ;
130+ private Boolean printResults ;
131+ private Boolean throwOnFail ;
132+ private PublishType publish ;
133+ private String brokerBaseUrl ;
134+ private String brokerCiAccessToken ;
135+ private BrokerBasicAuthCredentials brokerBasicAuth ;
136+ private String baseUrlUnderTest ;
137+ private TriggerGroups triggers ;
138+ private Map <String , StateHandler > stateHandlers ;
139+
140+ private ContractCaseConfigBuilder () {
141+ }
142+
143+ public static ContractCaseConfigBuilder aContractCaseConfig () {
144+ return new ContractCaseConfigBuilder ();
145+ }
146+
147+ public ContractCaseConfigBuilder providerName (String providerName ) {
148+ this .providerName = providerName ;
149+ return this ;
150+ }
151+
152+ public ContractCaseConfigBuilder consumerName (String consumerName ) {
153+ this .consumerName = consumerName ;
154+ return this ;
155+ }
156+
157+ public ContractCaseConfigBuilder logLevel (LogLevel logLevel ) {
158+ this .logLevel = logLevel ;
159+ return this ;
160+ }
161+
162+ public ContractCaseConfigBuilder contractDir (String contractDir ) {
163+ this .contractDir = contractDir ;
164+ return this ;
165+ }
166+
167+ public ContractCaseConfigBuilder contractFilename (String contractFilename ) {
168+ this .contractFilename = contractFilename ;
169+ return this ;
170+ }
171+
172+ public ContractCaseConfigBuilder printResults (Boolean printResults ) {
173+ this .printResults = printResults ;
174+ return this ;
175+ }
176+
177+ public ContractCaseConfigBuilder throwOnFail (Boolean throwOnFail ) {
178+ this .throwOnFail = throwOnFail ;
179+ return this ;
180+ }
181+
182+ public ContractCaseConfigBuilder publish (PublishType publish ) {
183+ this .publish = publish ;
184+ return this ;
185+ }
186+
187+ public ContractCaseConfigBuilder brokerBaseUrl (String brokerBaseUrl ) {
188+ this .brokerBaseUrl = brokerBaseUrl ;
189+ return this ;
190+ }
191+
192+ public ContractCaseConfigBuilder brokerCiAccessToken (String brokerCiAccessToken ) {
193+ this .brokerCiAccessToken = brokerCiAccessToken ;
194+ return this ;
195+ }
196+
197+ public ContractCaseConfigBuilder brokerBasicAuth (BrokerBasicAuthCredentials brokerBasicAuth ) {
198+ this .brokerBasicAuth = brokerBasicAuth ;
199+ return this ;
200+ }
201+
202+ public ContractCaseConfigBuilder baseUrlUnderTest (String baseUrlUnderTest ) {
203+ this .baseUrlUnderTest = baseUrlUnderTest ;
204+ return this ;
205+ }
206+
207+ public ContractCaseConfigBuilder triggers (TriggerGroups triggers ) {
208+ this .triggers = triggers ;
209+ return this ;
210+ }
211+
212+ public ContractCaseConfigBuilder stateHandlers (Map <String , StateHandler > stateHandlers ) {
213+ this .stateHandlers = stateHandlers ;
214+ return this ;
215+ }
216+
217+ public ContractCaseConfig build () {
218+ return new ContractCaseConfig (providerName , consumerName , logLevel , contractDir ,
219+ contractFilename , printResults , throwOnFail , publish , brokerBaseUrl , brokerCiAccessToken ,
220+ brokerBasicAuth , baseUrlUnderTest , triggers , stateHandlers );
221+ }
222+ }
98223}
0 commit comments