Search in sources :

Example 71 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project joynr by bmwcarit.

the class ServersUtil method areBounceProxiesRegisteredWithController.

private static boolean areBounceProxiesRegisteredWithController(String bpControllerUrl, String... bpIds) {
    List<Matcher<? super JsonPath>> containsBounceProxyMatcher = new LinkedList<Matcher<? super JsonPath>>();
    for (String bpId : bpIds) {
        Matcher<? super JsonPath> matcher = CoreMatchers.anyOf(containsBounceProxy(bpId, "ALIVE"), containsBounceProxy(bpId, "ACTIVE"));
        containsBounceProxyMatcher.add(matcher);
    }
    Matcher<JsonPath> matcher = CoreMatchers.allOf(containsBounceProxyMatcher);
    Response bounceProxiesResponse = getBounceProxies(bpControllerUrl);
    return matcher.matches(bounceProxiesResponse.jsonPath());
}
Also used : Response(com.jayway.restassured.response.Response) Matcher(org.hamcrest.Matcher) JsonPath(com.jayway.restassured.path.json.JsonPath) LinkedList(java.util.LinkedList)

Example 72 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project webcert by sklintyg.

the class BaseRestIntegrationTest method createUtkast.

/**
 * Helper method to create an utkast of a given type for a given patient.
 * The request will be made with the current auth session.
 *
 * @param intygsTyp
 *            Type to create
 * @param patientPersonNummer
 *            the patient to create the utkast for
 * @return Id for the new utkast
 */
protected String createUtkast(String intygsTyp, String patientPersonNummer) {
    CreateUtkastRequest utkastRequest = createUtkastRequest(intygsTyp, patientPersonNummer);
    Response response = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).pathParam("intygstyp", intygsTyp).contentType(ContentType.JSON).body(utkastRequest).expect().statusCode(200).when().post("api/utkast/{intygstyp}").then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-generic-utkast-response-schema.json")).body("intygsTyp", equalTo(utkastRequest.getIntygType())).extract().response();
    // The type-specific model is a serialized json within the model property, need to extract that first.
    JsonPath draft = new JsonPath(response.body().asString());
    JsonPath model = new JsonPath(draft.getString("model"));
    assertEquals(formatPersonnummer(patientPersonNummer), model.getString("grundData.patient.personId"));
    final String utkastId = model.getString("id");
    assertTrue(utkastId.length() > 0);
    return utkastId;
}
Also used : CreateUtkastRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CreateUtkastRequest) Response(com.jayway.restassured.response.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonPath(com.jayway.restassured.path.json.JsonPath)

Example 73 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project webcert by sklintyg.

the class BaseRestIntegrationTest method createQuestion.

/**
 * Inserts a question for an existing certificate
 *
 * @param typ
 *            type to create
 * @param intygId
 *            id of the intyg to create the question for
 * @param personnummer
 *            patient to create it for
 * @return
 */
protected int createQuestion(String typ, String intygId, String personnummer) {
    FragaSvar fs = createTestQuestion(typ, intygId, personnummer);
    Response response = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).body(fs).expect().statusCode(200).when().post("testability/fragasvar").then().extract().response();
    JsonPath model = new JsonPath(response.body().asString());
    return model.get("internReferens");
}
Also used : Response(com.jayway.restassured.response.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonPath(com.jayway.restassured.path.json.JsonPath)

Example 74 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project webcert by sklintyg.

the class UtkastApiControllerIT method testCreateUtkast.

/**
 * Generic method that created an utkast of given type and validates basic generic model properties
 *
 * @param utkastType
 *            The type of utkast to create
 */
private JsonPath testCreateUtkast(String utkastType) {
    // Set up auth precondition
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    CreateUtkastRequest utkastRequest = createUtkastRequest(utkastType, DEFAULT_PATIENT_PERSONNUMMER);
    Response response = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).body(utkastRequest).expect().statusCode(200).when().post("api/utkast/" + utkastType).then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-generic-utkast-response-schema.json")).body("intygsTyp", equalTo(utkastRequest.getIntygType())).body("skapadAv.hsaId", equalTo(DEFAULT_LAKARE.getHsaId())).body("enhetsId", equalTo(DEFAULT_LAKARE.getEnhetId())).body("version", equalTo(0)).body("skapadAv.namn", equalTo(DEFAULT_LAKARE_NAME)).body("patientFornamn", equalTo(utkastRequest.getPatientFornamn())).body("patientEfternamn", equalTo(utkastRequest.getPatientEfternamn())).extract().response();
    // The type-specific model is a serialized json "within" the model property, need to extract that first and then
    // we can assert some basic things.
    JsonPath draft = new JsonPath(response.body().asString());
    JsonPath model = new JsonPath(draft.getString("model"));
    assertTrue(model.getString("id").length() > 0);
    assertEquals(utkastRequest.getPatientPersonnummer().getPersonnummer(), model.getString("grundData.patient.personId"));
    return model;
}
Also used : CreateUtkastRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CreateUtkastRequest) QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) Response(com.jayway.restassured.response.Response) JsonPath(com.jayway.restassured.path.json.JsonPath)

Example 75 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project webcert by sklintyg.

the class UtkastApiControllerIT method testGetTsBasUtkast.

@Test
public void testGetTsBasUtkast() {
    JsonPath model = testCreateUtkast("ts-bas");
    // INTYG-4086 - do NOT store name or address for FK intyg in DB
    assertEquals(DEFAULT_UTKAST_PATIENT_FORNAMN, model.getString("grundData.patient.fornamn"));
    assertEquals(DEFAULT_UTKAST_PATIENT_EFTERNAMN, model.getString("grundData.patient.efternamn"));
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)

Aggregations

JsonPath (com.jayway.restassured.path.json.JsonPath)87 Test (org.junit.Test)56 Response (com.jayway.restassured.response.Response)29 BaseRestTest (integration.BaseRestTest)11 BaseRestIntegrationTest (se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)10 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)9 Matchers.anyString (org.mockito.Matchers.anyString)8 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Ignore (org.junit.Ignore)5 MongoDbSeed (integration.MongoDbSeed)4 HashMap (java.util.HashMap)3 Then (cucumber.api.java.en.Then)2 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)2 BaseMatcher (org.hamcrest.BaseMatcher)2 Description (org.hamcrest.Description)2 PreparationDTO (org.talend.dataprep.api.preparation.PreparationDTO)2