-
-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(JUnit 4): Allow provider state generator to fall back to the pro…
…vider state parameters
- Loading branch information
1 parent
7550a6d
commit e586656
Showing
5 changed files
with
158 additions
and
1 deletion.
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
47 changes: 47 additions & 0 deletions
47
...it/src/test/java/au/com/dius/pact/provider/junit/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,47 @@ | ||
package au.com.dius.pact.provider.junit; | ||
|
||
import au.com.dius.pact.provider.junit.target.HttpTarget; | ||
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 au.com.dius.pact.provider.junitsupport.target.Target; | ||
import au.com.dius.pact.provider.junitsupport.target.TestTarget; | ||
import com.github.restdriver.clientdriver.ClientDriverRule; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.runner.RunWith; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import static com.github.restdriver.clientdriver.RestClientDriver.giveResponse; | ||
import static com.github.restdriver.clientdriver.RestClientDriver.onRequestTo; | ||
|
||
@Provider("ProviderStateParametersInjected") | ||
@PactFolder("pacts") | ||
@RunWith(PactRunner.class) | ||
public class ProviderStateParametersInjectedTest { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ProviderStateParametersInjectedTest.class); | ||
|
||
@ClassRule | ||
public static final ClientDriverRule embeddedService = new ClientDriverRule(9241); | ||
|
||
@TestTarget | ||
public final Target target = new HttpTarget(9241); | ||
|
||
@Before | ||
public void before() { | ||
embeddedService.addExpectation( | ||
onRequestTo("/api/hello/John"), | ||
giveResponse("{\"name\": \"John\"}", "application/json") | ||
); | ||
} | ||
|
||
@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/junit/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