Search in sources :

Example 6 with CreateUtkastRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CreateUtkastRequest in project webcert by sklintyg.

the class UtkastApiControllerTest method testCreateUtkastFornamnTooLong.

@Test
public void testCreateUtkastFornamnTooLong() {
    String intygsTyp = "luse";
    setupUser(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG, intygsTyp, AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST);
    CreateUtkastRequest utkastRequest = buildRequest(intygsTyp);
    utkastRequest.setPatientFornamn(Strings.repeat("a", 256));
    Response response = utkastController.createUtkast(intygsTyp, utkastRequest);
    assertEquals(BAD_REQUEST.getStatusCode(), response.getStatus());
}
Also used : CreateUtkastRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CreateUtkastRequest) Response(javax.ws.rs.core.Response) QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 7 with CreateUtkastRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CreateUtkastRequest in project webcert by sklintyg.

the class BaseRestIntegrationTest method createUtkastRequest.

/**
 * Create Utkast Request with default values for all but type and patient
 *
 * @param intygsType
 *            type to create
 * @param patientPersonNummer
 *            patient to create it for
 * @return a new CreateUtkastRequest
 */
protected CreateUtkastRequest createUtkastRequest(String intygsType, String patientPersonNummer) {
    CreateUtkastRequest utkastRequest = new CreateUtkastRequest();
    utkastRequest.setIntygType(intygsType);
    utkastRequest.setPatientFornamn(DEFAULT_UTKAST_PATIENT_FORNAMN);
    utkastRequest.setPatientEfternamn(DEFAULT_UTKAST_PATIENT_EFTERNAMN);
    utkastRequest.setPatientPersonnummer(Personnummer.createPersonnummer(patientPersonNummer).get());
    utkastRequest.setPatientPostadress("Blåbärsvägen 14");
    utkastRequest.setPatientPostort("Molnet");
    utkastRequest.setPatientPostnummer("44837");
    return utkastRequest;
}
Also used : CreateUtkastRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CreateUtkastRequest)

Example 8 with CreateUtkastRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CreateUtkastRequest 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 9 with CreateUtkastRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CreateUtkastRequest 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 10 with CreateUtkastRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CreateUtkastRequest in project webcert by sklintyg.

the class UtkastApiControllerIT method testCannotCreateUtkastOfDeprecatedType.

@Test
public void testCannotCreateUtkastOfDeprecatedType() {
    String utkastType = "fk7263";
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    CreateUtkastRequest utkastRequest = createUtkastRequest(utkastType, DEFAULT_PATIENT_PERSONNUMMER);
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).body(utkastRequest).expect().statusCode(400).when().post("api/utkast/" + utkastType);
}
Also used : CreateUtkastRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CreateUtkastRequest) Test(org.junit.Test) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)

Aggregations

CreateUtkastRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CreateUtkastRequest)10 Test (org.junit.Test)6 QueryIntygResponse (se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse)6 Response (javax.ws.rs.core.Response)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)3 CreateNewDraftRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest)3 JsonPath (com.jayway.restassured.path.json.JsonPath)2 Response (com.jayway.restassured.response.Response)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 BaseRestIntegrationTest (se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)1