Class Contract
- java.lang.Object
-
- org.springframework.cloud.contract.spec.Contract
-
public class Contract extends Object
The definition of a Contract. Contains helper methods in Groovy left for backward compatibility reasons.- Since:
- 1.0.0
-
-
Constructor Summary
Constructors Constructor Description Contract()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidassertContract(Contract dsl)voiddescription(String description)Description text.booleanequals(Object o)StringgetDescription()booleangetIgnored()booleangetInProgress()InputgetInput()StringgetLabel()Map<String,Object>getMetadata()StringgetName()OutputMessagegetOutputMessage()IntegergetPriority()RequestgetRequest()ResponsegetResponse()inthashCode()voidignored()Whether the contract should be ignored or not.voidinProgress()Whether the contract is in progress or not.voidinput(groovy.lang.Closure consumer)The input part of the contract.voidinput(Consumer<Input> consumer)The input part of the contract.booleanisIgnored()booleanisInProgress()voidlabel(String label)Label used by the messaging contracts to trigger a message on the consumer side.static Contractmake(groovy.lang.Closure closure)Groovy point of entry to build a contract.static Contractmake(Consumer<Contract> consumer)Point of entry to build a contract.voidmetadata(Map<String,Object> map)Appends all entries to the existing metadata mapping.voidname(String name)Name of the generated test / stub.voidoutputMessage(groovy.lang.Closure consumer)The output part of the contract.voidoutputMessage(Consumer<OutputMessage> consumer)The output part of the contract.voidpriority(int priority)You can set the level of priority of this contract.voidrequest(groovy.lang.Closure consumer)The HTTP request part of the contract.voidrequest(Consumer<Request> consumer)The HTTP request part of the contract.voidresponse(groovy.lang.Closure consumer)The HTTP response part of the contract.voidresponse(Consumer<Response> consumer)The HTTP response part of the contract.voidsetDescription(String description)voidsetIgnored(boolean ignored)voidsetInProgress(boolean inProgress)voidsetInput(Input input)voidsetLabel(String label)voidsetMetadata(Map<String,Object> metadata)voidsetName(String name)voidsetOutputMessage(OutputMessage outputMessage)voidsetPriority(Integer priority)voidsetRequest(Request request)voidsetResponse(Response response)StringtoString()
-
-
-
Method Detail
-
priority
public void priority(int priority)
You can set the level of priority of this contract. If there are two contracts mapped for example to the same endpoint, then the one with greater priority should take precedence. A priority of 1 is highest and takes precedence over a priority of 2.- Parameters:
priority- the higher the value the lower the priority
-
name
public void name(String name)
Name of the generated test / stub. If not provided then the file name will be used. If you have multiple contracts in a single file and you don't provide this value then a prefix will be added to the file with the index number while iterating over the collection of contracts. Remember to have a unique name for every single contract. Otherwise you might generate tests that have two identical methods or you will override the stubs.- Parameters:
name- name of the contract
-
label
public void label(String label)
Label used by the messaging contracts to trigger a message on the consumer side.- Parameters:
label- - name of the label of a messaging contract to trigger
-
description
public void description(String description)
Description text. Might be used to describe the usage scenario.- Parameters:
description- - value of the description
-
assertContract
public static void assertContract(Contract dsl)
-
make
public static Contract make(Consumer<Contract> consumer)
Point of entry to build a contract.- Parameters:
consumer- function to manipulate the contract- Returns:
- manipulated contract
-
make
public static Contract make(@DelegatesTo(Contract.class) groovy.lang.Closure closure)
Groovy point of entry to build a contract. Left for backward compatibility reasons.- Parameters:
closure- function to manipulate the contract- Returns:
- manipulated contract
-
request
public void request(Consumer<Request> consumer)
The HTTP request part of the contract.- Parameters:
consumer- function to manipulate the request
-
response
public void response(Consumer<Response> consumer)
The HTTP response part of the contract.- Parameters:
consumer- function to manipulate the response
-
input
public void input(Consumer<Input> consumer)
The input part of the contract.- Parameters:
consumer- function to manipulate the input
-
outputMessage
public void outputMessage(Consumer<OutputMessage> consumer)
The output part of the contract.- Parameters:
consumer- function to manipulate the output message
-
request
public void request(@DelegatesTo(Request.class) groovy.lang.Closure consumer)
The HTTP request part of the contract.- Parameters:
consumer- function to manipulate the request
-
response
public void response(@DelegatesTo(Response.class) groovy.lang.Closure consumer)
The HTTP response part of the contract.- Parameters:
consumer- function to manipulate the response
-
input
public void input(@DelegatesTo(Input.class) groovy.lang.Closure consumer)
The input part of the contract.- Parameters:
consumer- function to manipulate the input
-
outputMessage
public void outputMessage(@DelegatesTo(OutputMessage.class) groovy.lang.Closure consumer)
The output part of the contract.- Parameters:
consumer- function to manipulate the output message
-
metadata
public void metadata(Map<String,Object> map)
Appends all entries to the existing metadata mapping.- Parameters:
map- metadata to set
-
ignored
public void ignored()
Whether the contract should be ignored or not.
-
inProgress
public void inProgress()
Whether the contract is in progress or not.
-
isInProgress
public boolean isInProgress()
-
getPriority
public Integer getPriority()
-
setPriority
public void setPriority(Integer priority)
-
getRequest
public Request getRequest()
-
setRequest
public void setRequest(Request request)
-
getResponse
public Response getResponse()
-
setResponse
public void setResponse(Response response)
-
getLabel
public String getLabel()
-
setLabel
public void setLabel(String label)
-
getDescription
public String getDescription()
-
setDescription
public void setDescription(String description)
-
getName
public String getName()
-
setName
public void setName(String name)
-
getInput
public Input getInput()
-
setInput
public void setInput(Input input)
-
getOutputMessage
public OutputMessage getOutputMessage()
-
setOutputMessage
public void setOutputMessage(OutputMessage outputMessage)
-
getIgnored
public boolean getIgnored()
-
isIgnored
public boolean isIgnored()
-
setIgnored
public void setIgnored(boolean ignored)
-
getInProgress
public boolean getInProgress()
-
setInProgress
public void setInProgress(boolean inProgress)
-
-