Class StubRunnerExtension
java.lang.Object
org.springframework.cloud.contract.stubrunner.junit.StubRunnerExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback,org.junit.jupiter.api.extension.AfterEachCallback,org.junit.jupiter.api.extension.BeforeAllCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension,StubFinder,StubTrigger
- Direct Known Subclasses:
StubRunnerExtension.PortStubRunnerExtension
public class StubRunnerExtension
extends Object
implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, StubFinder
JUnit 5 extension that allows to download and run stubs.
- Since:
- 2.1.0
- Author:
- Olga Maciaszek-Sharma
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHelper class with additional port, related methods once you pick a stub to download. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) voidafterEach(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) downloadLatestStub(String groupId, String artifactId, String classifier) downloadStub(String ivyNotation) downloadStub(String groupId, String artifactId) downloadStub(String groupId, String artifactId, String version) downloadStub(String groupId, String artifactId, String version, String classifier) downloadStubs(String... ivyNotations) downloadStubs(List<String> ivyNotations) failOnNoStubs(boolean failOnNoStubs) findStubUrl(String ivyNotation) For the given Ivy notation[groupId]:artifactId:[version]:[classifier]tries to find the matching URL of the running stub.findStubUrl(String groupId, String artifactId) For the given groupId and artifactId tries to find the matching URL of the running stub.Map<StubConfiguration,Collection<org.springframework.cloud.contract.spec.Contract>> labels()Feature related to messaging.maxPort(int maxPort) messageVerifierReceiver(org.springframework.cloud.contract.verifier.messaging.MessageVerifierReceiver messageVerifier) messageVerifierSender(org.springframework.cloud.contract.verifier.messaging.MessageVerifierSender messageVerifier) minPort(int minPort) options(StubRunnerOptions stubRunnerOptions) stubsMode(StubRunnerProperties.StubsMode stubsMode) booleantrigger()Triggers all possible events.booleanTriggers an event by a given label.booleanTriggers an event by a given label for a givengroupid:artifactidnotation.withConsumerName(String consumerName) withDeleteStubsAfterTest(boolean deleteStubsAfterTest) withGenerateStubs(boolean generateStubs) withHttpServerStubConfigurer(Class<? extends HttpServerStubConfigurer> httpServerStubConfigurer) withMappingsOutputFolder(String mappingsOutputFolder) withProperties(Map<String, String> properties) withStubPerConsumer(boolean stubPerConsumer)
-
Constructor Details
-
StubRunnerExtension
public StubRunnerExtension()
-
-
Method Details
-
afterAll
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) - Specified by:
afterAllin interfaceorg.junit.jupiter.api.extension.AfterAllCallback
-
afterEach
- Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback- Throws:
Exception
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) - Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
-
beforeEach
- Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback- Throws:
Exception
-
findStubUrl
Description copied from interface:StubFinderFor the given groupId and artifactId tries to find the matching URL of the running stub.- Specified by:
findStubUrlin interfaceStubFinder- Parameters:
groupId- - might be null. In that case a search only via artifactId takes placeartifactId- - artifact id of the stub- Returns:
- URL of a running stub or throws exception if not found
- Throws:
StubNotFoundException- in case of not finding a stub
-
findStubUrl
Description copied from interface:StubFinderFor the given Ivy notation[groupId]:artifactId:[version]:[classifier]tries to find the matching URL of the running stub. You can also pass onlyartifactId.- Specified by:
findStubUrlin interfaceStubFinder- Parameters:
ivyNotation- - Ivy representation of the Maven artifact- Returns:
- URL of a running stub or throws exception if not found
- Throws:
StubNotFoundException- in case of not finding a stub
-
findAllRunningStubs
- Specified by:
findAllRunningStubsin interfaceStubFinder- Returns:
- all running stubs
-
getContracts
public Map<StubConfiguration,Collection<org.springframework.cloud.contract.spec.Contract>> getContracts()- Specified by:
getContractsin interfaceStubFinder- Returns:
- the list of Contracts
-
trigger
Description copied from interface:StubTriggerTriggers an event by a given label for a givengroupid:artifactidnotation. You can use onlyartifactIdtoo. Feature related to messaging.- Specified by:
triggerin interfaceStubTrigger- Parameters:
ivyNotation- ivy notation of a stublabelName- name of the label to trigger- Returns:
- true - if managed to run a trigger
-
trigger
Description copied from interface:StubTriggerTriggers an event by a given label. Feature related to messaging.- Specified by:
triggerin interfaceStubTrigger- Parameters:
labelName- name of the label to trigger- Returns:
- true - if managed to run a trigger
-
trigger
public boolean trigger()Description copied from interface:StubTriggerTriggers all possible events. Feature related to messaging.- Specified by:
triggerin interfaceStubTrigger- Returns:
- true - if managed to run a trigger
-
labels
Description copied from interface:StubTriggerFeature related to messaging.- Specified by:
labelsin interfaceStubTrigger- Returns:
- a mapping of ivy notation of a dependency to all the labels it has.
-
messageVerifierSender
public StubRunnerExtension messageVerifierSender(org.springframework.cloud.contract.verifier.messaging.MessageVerifierSender messageVerifier) -
messageVerifierReceiver
public StubRunnerExtension messageVerifierReceiver(org.springframework.cloud.contract.verifier.messaging.MessageVerifierReceiver messageVerifier) -
options
-
minPort
-
maxPort
-
repoRoot
-
stubsMode
-
downloadStub
public StubRunnerExtension.PortStubRunnerExtension downloadStub(String groupId, String artifactId, String version, String classifier) -
downloadLatestStub
public StubRunnerExtension.PortStubRunnerExtension downloadLatestStub(String groupId, String artifactId, String classifier) -
downloadStub
public StubRunnerExtension.PortStubRunnerExtension downloadStub(String groupId, String artifactId, String version) -
downloadStub
-
downloadStub
-
downloadStubs
-
downloadStubs
-
withStubPerConsumer
-
withConsumerName
-
withMappingsOutputFolder
-
withDeleteStubsAfterTest
-
withGenerateStubs
-
failOnNoStubs
-
withProperties
-
withHttpServerStubConfigurer
public StubRunnerExtension withHttpServerStubConfigurer(Class<? extends HttpServerStubConfigurer> httpServerStubConfigurer)
-