Search in sources :

Example 1 with CopyIntygRequest

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

the class IntygModuleApiControllerIT method testCreateRenewalBasedOnIntygFromDifferentCareUnitWithCoherentJournalingFail.

@Test
public void testCreateRenewalBasedOnIntygFromDifferentCareUnitWithCoherentJournalingFail() throws IOException {
    // First use DEFAULT_LAKARE to create a signed certificate on care unit A.
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    String intygsId = createUtkast("lisjp", DEFAULT_PATIENT_PERSONNUMMER);
    // Then logout
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).redirects().follow(false).expect().statusCode(HttpServletResponse.SC_FOUND).when().get("logout");
    // Next, create new user credentials with another care unit B, and attempt to access the certificate created in
    // previous step.
    RestAssured.sessionId = getAuthSession(LEONIE_KOEHL);
    changeOriginTo("DJUPINTEGRATION");
    // coherentJournaling defaults to false, so don't set it here.
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(DEFAULT_PATIENT_PERSONNUMMER));
    Map<String, String> pathParams = new HashMap<>();
    pathParams.put("intygsTyp", "lisjp");
    pathParams.put("intygsId", intygsId);
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).and().pathParams(pathParams).and().body(copyIntygRequest).expect().statusCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).when().post("moduleapi/intyg/{intygsTyp}/{intygsId}/fornya").then().body("errorCode", equalTo(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM.name())).body("message", not(isEmptyString()));
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) HashMap(java.util.HashMap) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest) Test(org.junit.Test)

Example 2 with CopyIntygRequest

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

the class IntygModuleApiControllerIT method testCreateRenewalBasedOnExistingUtkastWithInvalidPatientpersonNummer.

/**
 * Check that trying to copy utkast with bad input gives error response.
 */
@Test
public void testCreateRenewalBasedOnExistingUtkastWithInvalidPatientpersonNummer() {
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    changeOriginTo("DJUPINTEGRATION");
    String utkastId = createUtkast("lisjp", DEFAULT_PATIENT_PERSONNUMMER);
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(null);
    Map<String, String> pathParams = new HashMap<>();
    pathParams.put("intygsTyp", "lisjp");
    pathParams.put("intygsId", utkastId);
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).and().pathParams(pathParams).and().body(copyIntygRequest).expect().statusCode(500).when().post("moduleapi/intyg/{intygsTyp}/{intygsId}/fornya").then().body("errorCode", equalTo(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM.name())).body("message", not(isEmptyString()));
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) HashMap(java.util.HashMap) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest) Test(org.junit.Test)

Example 3 with CopyIntygRequest

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

the class IntygModuleApiControllerIT method testCreateRenewalBasedOnExistingUtkast.

@Test
public void testCreateRenewalBasedOnExistingUtkast() {
    final String personnummer = "19121212-1212";
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    changeOriginTo("DJUPINTEGRATION");
    String utkastId = createUtkast("lisjp", personnummer);
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    Map<String, String> pathParams = new HashMap<>();
    pathParams.put("intygsTyp", "lisjp");
    pathParams.put("intygsId", utkastId);
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).and().pathParams(pathParams).and().body(copyIntygRequest).expect().statusCode(200).when().post("moduleapi/intyg/{intygsTyp}/{intygsId}/fornya").then().body("intygsUtkastId", not(isEmptyString())).body("intygsUtkastId", not(equalTo(utkastId))).body("intygsTyp", equalTo("lisjp"));
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) HashMap(java.util.HashMap) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest) Test(org.junit.Test)

Example 4 with CopyIntygRequest

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

the class IntygModuleApiControllerIT method testCreateRenewalBasedOnExistingUtkastFailsForMissingPriveliges.

@Test
public void testCreateRenewalBasedOnExistingUtkastFailsForMissingPriveliges() {
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    String utkastId = createUtkast("lisjp", DEFAULT_PATIENT_PERSONNUMMER);
    // Lakare role has the FORNYA_INTYG priviledge, but the privilege is restricted to origintype=NORMAL /
    // DJUPINTEGRERAD.
    // We change the current users origin to be uthop which should trigger an auth exception response.
    changeOriginTo(UserOriginType.UTHOPP.name());
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(DEFAULT_PATIENT_PERSONNUMMER));
    Map<String, String> pathParams = new HashMap<>();
    pathParams.put("intygsTyp", "lisjp");
    pathParams.put("intygsId", utkastId);
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).and().pathParams(pathParams).and().body(copyIntygRequest).expect().statusCode(500).when().post("moduleapi/intyg/{intygsTyp}/{intygsId}/fornya").then().body("errorCode", equalTo(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM.name())).body("message", not(isEmptyString()));
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) HashMap(java.util.HashMap) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest) Test(org.junit.Test)

Example 5 with CopyIntygRequest

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

the class IntygModuleApiControllerIT method testCreateRenewalBasedOnIntygFromDifferentCareUnitWithCoherentJournalingSuccess.

@Test
public void testCreateRenewalBasedOnIntygFromDifferentCareUnitWithCoherentJournalingSuccess() throws IOException {
    // First use DEFAULT_LAKARE to create a signed certificate on care unit A.
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    String intygsId = createUtkast("lisjp", DEFAULT_PATIENT_PERSONNUMMER);
    // Then logout
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).redirects().follow(false).expect().statusCode(HttpServletResponse.SC_FOUND).when().get("logout");
    // Next, create new user credentials with another care unit B, and attempt to access the certificate created in
    // previous step.
    RestAssured.sessionId = getAuthSession(LEONIE_KOEHL);
    changeOriginTo("DJUPINTEGRATION");
    setSjf();
    // Set coherentJournaling=true in copyIntygRequest, this is normally done in the js using the copyService.
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(DEFAULT_PATIENT_PERSONNUMMER));
    Map<String, String> pathParams = new HashMap<>();
    pathParams.put("intygsTyp", "lisjp");
    pathParams.put("intygsId", intygsId);
    String newIntygsId = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).and().pathParams(pathParams).and().body(copyIntygRequest).expect().statusCode(HttpServletResponse.SC_OK).when().post("moduleapi/intyg/{intygsTyp}/{intygsId}/fornya").then().body("intygsUtkastId", not(isEmptyString())).body("intygsUtkastId", not(equalTo(intygsId))).body("intygsTyp", equalTo("lisjp")).extract().path("intygsUtkastId");
    // Check that the copy contains the correct stuff
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).expect().statusCode(200).when().get("moduleapi/intyg/lisjp/" + newIntygsId).then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-get-intyg-response-schema.json")).body("contents.grundData.skapadAv.personId", equalTo(LEONIE_KOEHL.getHsaId())).body("contents.grundData.patient.personId", equalTo(formatPersonnummer(DEFAULT_PATIENT_PERSONNUMMER)));
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) HashMap(java.util.HashMap) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)24 CopyIntygRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest)24 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)15 HashMap (java.util.HashMap)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)8 BaseRestIntegrationTest (se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)8 Response (javax.ws.rs.core.Response)6 CreateCompletionCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse)6 CreateRenewalCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse)6 CreateReplacementCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse)6 CreateUtkastFromTemplateResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse)6 CopyIntygResponse (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse)6 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)4 CreateRenewalCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest)3 JsonPath (com.jayway.restassured.path.json.JsonPath)2 Response (com.jayway.restassured.response.Response)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Personnummer (se.inera.intyg.schemas.contract.Personnummer)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1