Last active
January 9, 2019 15:47
-
-
Save alexmoleiro/94dad4bfc5bc5fe794d2034b28ae8e24 to your computer and use it in GitHub Desktop.
Test Feign client with Pact and Spring
This file contains hidden or 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
@RunWith(SpringRunner.class) | |
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = {ClientConfiguration.class, | |
CochesnetPropertiesConfiguration.class}) | |
@TestPropertySource(properties = {"cochesnet.ConnectTimeout=1000", "cochesnet.ReadTimeout=1000", | |
"cochesnet.url=http://localhost:8080"}) | |
public class CochesPactTest { | |
@Autowired | |
private FeignCochesnetDraft feignCochesnetDraft; | |
@Rule | |
public PactProviderRuleMk2 mockProvider | |
= new PactProviderRuleMk2("cochesDraft", "localhost", 8080, this); | |
@Pact(consumer = "PTA_consumer") | |
public RequestResponsePact createPact(PactDslWithProvider builder) { | |
Map<String, String> headers = new HashMap<>(); | |
headers.put("Content-Type", "application/json"); | |
Map<String, String> headersRequest = new HashMap<>(); | |
headersRequest.put("Authorization", "anyToken"); | |
return builder | |
.given("test ") | |
.uponReceiving("GET DRAFT FROM COCHES") | |
.path("/drafts") | |
.headers(headersRequest) | |
.method("GET") | |
.willRespondWith() | |
.status(200) | |
.headers(headers) | |
.body("{\"draftId\": \"anything\", \"carMake\": \"1\"}") | |
.toPact(); | |
} | |
@Test | |
@PactVerification() | |
public void shouldGetDraft() { | |
DraftResponse value = feignCochesnetDraft.getDraft("anyToken").toBlocking().value(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment