Class PactBuilder
-
- All Implemented Interfaces:
-
au.com.dius.pact.consumer.dsl.DslBuilder
public class PactBuilder implements DslBuilder
Pact builder DSL that supports V4 formatted Pact files
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classPactBuilder.Companion
-
Field Summary
Fields Modifier and Type Field Description private Stringconsumerprivate Stringproviderprivate PactSpecVersionpactVersionpublic final static PactBuilder.CompanionCompanion
-
Constructor Summary
Constructors Constructor Description PactBuilder(String consumer, String provider, PactSpecVersion pactVersion)
-
Method Summary
Modifier and Type Method Description final StringgetConsumer()final UnitsetConsumer(String consumer)final StringgetProvider()final UnitsetProvider(String provider)final PactSpecVersiongetPactVersion()final UnitsetPactVersion(PactSpecVersion pactVersion)final PactDslWithProviderusingLegacyDsl()Use the old HTTP Pact DSL final MessagePactBuilderusingLegacyMessageDsl()Use the old Message Pact DSL final SynchronousMessagePactBuilderusingSynchronousMessageDsl()Use the Synchronous Message DSL final UnitpactSpecVersion(PactSpecVersion version)Sets the Pact specification version final PactBuilderusingPlugin(String name, String version)Enable a plugin final PactBuilderusingPlugin(String name)Enable a plugin final PactBuildergiven(String state, Map<String, Object> params)Describe the state the provider needs to be in for the pact test to be verified. final PactBuildergiven(String state)Describe the state the provider needs to be in for the pact test to be verified. final PactBuildergiven(String state, String firstKey, Object firstValue, Object paramsKeyValuePair)Describe the state the provider needs to be in for the pact test to be verified. final PactBuildergiven(String state, Pair<String, Object> params)Describe the state the provider needs to be in for the pact test to be verified. final PactBuilderexpectsToReceive(String description, String interactionType, String key)Adds an interaction with the given description and type. final PactBuilderexpectsToReceive(String description, String interactionType)Adds an interaction with the given description and type. final PactBuilderwith(Map<String, Object> values)Values to configure the interaction. final PactBuilderwith(PluginInteractionBuilder builder)Configure the interaction using a builder supplied by the plugin author. UnitaddPluginConfiguration(ContentMatcher matcher, Map<String, JsonValue> pactConfiguration)final PactBuilderaddMetadataValue(String key, String value)Adds additional values to the metadata section of the Pact file final PactBuilderaddMetadataValue(String key, JsonValue value)Adds additional values to the metadata section of the Pact file final V4PacttoPact()Terminates this builder and returns the created Pact object final PactBuildercomment(String comment)Adds a text comment to the Pact interaction final PactBuilderexpectsToReceiveHttpInteraction(String description, Function1<HttpInteractionBuilder, HttpInteractionBuilder> builderFn)Creates a new HTTP interaction with the given description, and passes a builder to the builder function to construct it. final PactBuilderexpectsToReceiveMessageInteraction(String description, Function1<MessageInteractionBuilder, MessageInteractionBuilder> builderFn)Creates a new asynchronous message interaction with the given description, and passes a builder to the builder function to construct it. final PactBuilderexpectsToReceiveSynchronousMessageInteraction(String description, Function1<SynchronousMessageInteractionBuilder, SynchronousMessageInteractionBuilder> builderFn)Creates a new synchronous message interaction with the given description, and passes a builder to the builder function to construct it. final static StringtextFile(String filePath)Loads the file given by the file path and returns the contents. final static StringfilePath(String filePath)Convenience function to resolve a file path against the current working directory. -
-
Method Detail
-
getConsumer
final String getConsumer()
-
setConsumer
final Unit setConsumer(String consumer)
-
getProvider
final String getProvider()
-
setProvider
final Unit setProvider(String provider)
-
getPactVersion
final PactSpecVersion getPactVersion()
-
setPactVersion
final Unit setPactVersion(PactSpecVersion pactVersion)
-
usingLegacyDsl
final PactDslWithProvider usingLegacyDsl()
Use the old HTTP Pact DSL
-
usingLegacyMessageDsl
final MessagePactBuilder usingLegacyMessageDsl()
Use the old Message Pact DSL
-
usingSynchronousMessageDsl
final SynchronousMessagePactBuilder usingSynchronousMessageDsl()
Use the Synchronous Message DSL
-
pactSpecVersion
final Unit pactSpecVersion(PactSpecVersion version)
Sets the Pact specification version
-
usingPlugin
@JvmOverloads() final PactBuilder usingPlugin(String name, String version)
Enable a plugin
-
usingPlugin
@JvmOverloads() final PactBuilder usingPlugin(String name)
Enable a plugin
-
given
@JvmOverloads() final PactBuilder given(String state, Map<String, Object> params)
Describe the state the provider needs to be in for the pact test to be verified. Any parameters for the provider state can be provided in the second parameter.
-
given
@JvmOverloads() final PactBuilder given(String state)
Describe the state the provider needs to be in for the pact test to be verified. Any parameters for the provider state can be provided in the second parameter.
-
given
final PactBuilder given(String state, String firstKey, Object firstValue, Object paramsKeyValuePair)
Describe the state the provider needs to be in for the pact test to be verified.
- Parameters:
firstKey- Key of first parameter elementfirstValue- Value of first parameter elementparamsKeyValuePair- Additional parameters in key-value pairs
-
given
final PactBuilder given(String state, Pair<String, Object> params)
Describe the state the provider needs to be in for the pact test to be verified.
- Parameters:
params- Additional parameters in key-value pairs
-
expectsToReceive
@JvmOverloads() final PactBuilder expectsToReceive(String description, String interactionType, String key)
Adds an interaction with the given description and type. If interactionType is not specified (is the empty string) will default to an HTTP interaction
- Parameters:
description- The interaction description.interactionType- The key of the interaction type as found in the catalogue manager.key- (Optional) unique key to assign to the interaction
-
expectsToReceive
@JvmOverloads() final PactBuilder expectsToReceive(String description, String interactionType)
Adds an interaction with the given description and type. If interactionType is not specified (is the empty string) will default to an HTTP interaction
- Parameters:
description- The interaction description.interactionType- The key of the interaction type as found in the catalogue manager.
-
with
final PactBuilder with(Map<String, Object> values)
Values to configure the interaction. In the case of an interaction configured by a plugin, you need to follow the plugin documentation of what values must be specified here.
-
with
final PactBuilder with(PluginInteractionBuilder builder)
Configure the interaction using a builder supplied by the plugin author.
-
addPluginConfiguration
Unit addPluginConfiguration(ContentMatcher matcher, Map<String, JsonValue> pactConfiguration)
-
addMetadataValue
final PactBuilder addMetadataValue(String key, String value)
Adds additional values to the metadata section of the Pact file
-
addMetadataValue
final PactBuilder addMetadataValue(String key, JsonValue value)
Adds additional values to the metadata section of the Pact file
-
toPact
final V4Pact toPact()
Terminates this builder and returns the created Pact object
-
comment
final PactBuilder comment(String comment)
Adds a text comment to the Pact interaction
-
expectsToReceiveHttpInteraction
final PactBuilder expectsToReceiveHttpInteraction(String description, Function1<HttpInteractionBuilder, HttpInteractionBuilder> builderFn)
Creates a new HTTP interaction with the given description, and passes a builder to the builder function to construct it.
-
expectsToReceiveMessageInteraction
final PactBuilder expectsToReceiveMessageInteraction(String description, Function1<MessageInteractionBuilder, MessageInteractionBuilder> builderFn)
Creates a new asynchronous message interaction with the given description, and passes a builder to the builder function to construct it.
-
expectsToReceiveSynchronousMessageInteraction
final PactBuilder expectsToReceiveSynchronousMessageInteraction(String description, Function1<SynchronousMessageInteractionBuilder, SynchronousMessageInteractionBuilder> builderFn)
Creates a new synchronous message interaction with the given description, and passes a builder to the builder function to construct it.
-
textFile
final static String textFile(String filePath)
Loads the file given by the file path and returns the contents. Relative paths will be resolved against the current working directory.
-
-
-
-