-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow provider state generator to fall back to the provider sta…
…te parameters
- Loading branch information
1 parent
ea7037f
commit 7550a6d
Showing
7 changed files
with
250 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...5/src/test/java/au/com/dius/pact/provider/junit5/ProviderStateParametersInjectedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package au.com.dius.pact.provider.junit5; | ||
|
||
import au.com.dius.pact.provider.junitsupport.Provider; | ||
import au.com.dius.pact.provider.junitsupport.State; | ||
import au.com.dius.pact.provider.junitsupport.loader.PactFolder; | ||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import ru.lanwen.wiremock.ext.WiremockResolver; | ||
import ru.lanwen.wiremock.ext.WiremockUriResolver; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
|
||
@Provider("ProviderStateParametersInjected") | ||
@PactFolder("pacts") | ||
@ExtendWith({ | ||
WiremockResolver.class, | ||
WiremockUriResolver.class | ||
}) | ||
public class ProviderStateParametersInjectedTest { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ProviderStateParametersInjectedTest.class); | ||
|
||
@TestTemplate | ||
@ExtendWith(PactVerificationInvocationContextProvider.class) | ||
void testTemplate(PactVerificationContext context) { | ||
context.verifyInteraction(); | ||
} | ||
|
||
@BeforeEach | ||
void before(PactVerificationContext context, | ||
@WiremockResolver.Wiremock WireMockServer server, | ||
@WiremockUriResolver.WiremockUri String uri) throws MalformedURLException { | ||
context.setTarget(HttpTestTarget.fromUrl(new URL(uri))); | ||
|
||
server.stubFor( | ||
get(urlPathEqualTo("/api/hello/John")) | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("content-type", "application/json") | ||
.withBody("{\"name\": \"John\"}") | ||
) | ||
); | ||
} | ||
|
||
@State("User exists") | ||
public Map<String, Object> defaultState(Map<String, Object> params) { | ||
LOGGER.debug("Provider state params = " + params); | ||
return Collections.emptyMap(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
provider/junit5/src/test/resources/pacts/provider-state-parameter-injected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"consumer": { | ||
"name": "SomeConsumer" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "Hello John", | ||
"providerStates": [ | ||
{ | ||
"name": "User exists", | ||
"params": { | ||
"name": "John" | ||
} | ||
} | ||
], | ||
"request": { | ||
"generators": { | ||
"path": { | ||
"dataType": "STRING", | ||
"expression": "/api/hello/${name}", | ||
"type": "ProviderState" | ||
} | ||
}, | ||
"method": "GET", | ||
"path": "/api/hello/James" | ||
}, | ||
"response": { | ||
"body": { | ||
"name": "John" | ||
}, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"status": 200 | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"pact-jvm": { | ||
"version": "4.6.7" | ||
}, | ||
"pactSpecification": { | ||
"version": "3.0.0" | ||
} | ||
}, | ||
"provider": { | ||
"name": "ProviderStateParametersInjected" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters