Last active
May 5, 2019 14:31
-
-
Save AlicanAkkus/20a6d24297d54002756178b9dfc653a1 to your computer and use it in GitHub Desktop.
Spring Cloud Contract
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
package com.caysever.producer; | |
import com.caysever.producer.ProducerBaseContractTest; | |
import com.jayway.jsonpath.DocumentContext; | |
import com.jayway.jsonpath.JsonPath; | |
import io.restassured.response.Response; | |
import io.restassured.specification.RequestSpecification; | |
import org.junit.Test; | |
import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson; | |
import static io.restassured.RestAssured.*; | |
import static org.springframework.cloud.contract.verifier.assertion.SpringCloudContractAssertions.assertThat; | |
public class ContractVerifierTest extends ProducerBaseContractTest { | |
@Test | |
public void validate_retrieveAccountContract() throws Exception { | |
// given: | |
RequestSpecification request = given() | |
.header("Accept", "application/json"); | |
// when: | |
Response response = given().spec(request) | |
.queryParam("accountId","1") | |
.get("/api/v1/accounts"); | |
// then: | |
assertThat(response.statusCode()).isEqualTo(200); | |
assertThat(response.header("Content-Type")).matches("application/json.*"); | |
// and: | |
DocumentContext parsedJson = JsonPath.parse(response.getBody().asString()); | |
assertThatJson(parsedJson).field("['surname']").isEqualTo("Surname"); | |
assertThatJson(parsedJson).field("['updatedDate']").isEqualTo(1514851199); | |
assertThatJson(parsedJson).field("['gender']").isEqualTo("Gender"); | |
assertThatJson(parsedJson).field("['name']").isEqualTo("Name"); | |
assertThatJson(parsedJson).field("['createdDate']").isEqualTo(1514851199); | |
assertThatJson(parsedJson).field("['identifier']").isEqualTo("Identifier"); | |
assertThatJson(parsedJson).field("['gsmNumber']").isEqualTo("GsmNumber"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment