Search in sources :

Example 6 with CopyIntygRequest

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

the class IntygModuleApiControllerIT method testCompletionContainsCommentStringInOvrigt.

@Test
public void testCompletionContainsCommentStringInOvrigt() throws Exception {
    final String personnummer = "19121212-1212";
    final String kommentar = "Testkommentar";
    Personnummer pers = Personnummer.createPersonnummer(personnummer).get();
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    String intygsTyp = "lisjp";
    String intygsId = createSignedIntyg(intygsTyp, personnummer);
    createArendeQuestion(intygsTyp, intygsId, personnummer, ArendeAmne.KOMPLT);
    Map<String, String> pathParams = new HashMap<>();
    pathParams.put("intygsTyp", intygsTyp);
    pathParams.put("intygsId", intygsId);
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(pers);
    copyIntygRequest.setKommentar(kommentar);
    final Response response = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).and().pathParams(pathParams).and().body(copyIntygRequest).expect().statusCode(200).when().post("moduleapi/intyg/{intygsTyp}/{intygsId}/komplettera").then().body("intygsUtkastId", not(isEmptyString())).body("intygsUtkastId", not(equalTo(intygsId))).body("intygsTyp", equalTo(intygsTyp)).extract().response();
    JsonPath intygJson = new JsonPath(response.body().asString());
    String newUtkastId = intygJson.getString("intygsUtkastId");
    given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).expect().statusCode(200).when().get("moduleapi/intyg/" + intygsTyp + "/" + newUtkastId).then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-get-intyg-response-schema.json")).body("contents.ovrigt", containsString(kommentar));
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) Response(com.jayway.restassured.response.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) 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) JsonPath(com.jayway.restassured.path.json.JsonPath) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest) Test(org.junit.Test)

Example 7 with CopyIntygRequest

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

the class IntygModuleApiControllerTest method testReplaceIntygWithInvalidOrigin.

@Test(expected = AuthoritiesException.class)
public void testReplaceIntygWithInvalidOrigin() {
    final String personnummer = "191212121212";
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    WebCertUser user = new WebCertUser();
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_ERSATTA_INTYG);
    user.setOrigin("UTHOPP");
    when(webcertUserService.getUser()).thenReturn(user);
    try {
        moduleApiController.createReplacement(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID);
        fail("Expected exception!");
    } finally {
        verifyZeroInteractions(copyUtkastService);
    }
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 8 with CopyIntygRequest

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

the class IntygModuleApiControllerTest method testCreateRenewal.

@Test
public void testCreateRenewal() {
    final String newDraftIntygId = "newDraftIntygId";
    final String personnummer = "191212121212";
    final String newPersonnummer = "201212121212";
    final String efternamn = "efternamn";
    final String fornamn = "fornamn";
    final String mellannamn = "mellannamn";
    final String postadress = "postadress";
    final String postort = "postort";
    final String postnummer = "postnummer";
    CopyIntygRequest request = new CopyIntygRequest();
    request.setPatientPersonnummer(createPnr(personnummer));
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(null, null, newPersonnummer, fornamn, mellannamn, efternamn, postadress, postnummer, postort, false, false, false, true));
    addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_FORNYA_INTYG);
    user.setOrigin("NORMAL");
    ArgumentCaptor<CreateRenewalCopyRequest> captor = ArgumentCaptor.forClass(CreateRenewalCopyRequest.class);
    when(copyUtkastService.createRenewalCopy(captor.capture())).thenReturn(new CreateRenewalCopyResponse(CERTIFICATE_TYPE, newDraftIntygId, CERTIFICATE_ID));
    when(webcertUserService.getUser()).thenReturn(user);
    Response response = moduleApiController.createRenewal(request, CERTIFICATE_TYPE, CERTIFICATE_ID);
    verify(copyUtkastService).createRenewalCopy(any());
    verifyNoMoreInteractions(copyUtkastService);
    assertEquals(newDraftIntygId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId());
    assertEquals(personnummer, captor.getValue().getPatient().getPersonId().getPersonnummer());
    assertEquals(fornamn, captor.getValue().getPatient().getFornamn());
    assertEquals(efternamn, captor.getValue().getPatient().getEfternamn());
    assertEquals(mellannamn, captor.getValue().getPatient().getMellannamn());
    assertEquals(postadress, captor.getValue().getPatient().getPostadress());
    assertEquals(postnummer, captor.getValue().getPatient().getPostnummer());
    assertEquals(postort, captor.getValue().getPatient().getPostort());
    assertEquals(newPersonnummer, captor.getValue().getNyttPatientPersonnummer().getPersonnummer());
}
Also used : Response(javax.ws.rs.core.Response) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 9 with CopyIntygRequest

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

the class IntygModuleApiControllerTest method testReplaceIntygWithInvalidPriviledge.

@Test(expected = AuthoritiesException.class)
public void testReplaceIntygWithInvalidPriviledge() {
    final String personnummer = "191212121212";
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    WebCertUser user = new WebCertUser();
    user.setOrigin("NORMAL");
    when(webcertUserService.getUser()).thenReturn(user);
    try {
        moduleApiController.createReplacement(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID);
        fail("Expected exception!");
    } finally {
        verifyZeroInteractions(copyUtkastService);
    }
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 10 with CopyIntygRequest

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

the class IntygModuleApiControllerTest method testCreateRenewalWithNewPatientInfo.

@Test
public void testCreateRenewalWithNewPatientInfo() {
    final String personnummer = "191212121212";
    final String newIntygId = "newIntygId";
    final String efternamn = "efternamn";
    final String fornamn = "fornamn";
    final String mellannamn = "mellannamn";
    final String postadress = "postadress";
    final String postort = "postort";
    final String postnummer = "postnummer";
    final String newPersonnummer = "201212121212";
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(null, null, newPersonnummer, fornamn, mellannamn, efternamn, postadress, postnummer, postort, false, false, false, true));
    addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_FORNYA_INTYG);
    user.setOrigin("NORMAL");
    ArgumentCaptor<CreateRenewalCopyRequest> captor = ArgumentCaptor.forClass(CreateRenewalCopyRequest.class);
    when(copyUtkastService.createRenewalCopy(captor.capture())).thenReturn(new CreateRenewalCopyResponse(CERTIFICATE_TYPE, newIntygId, CERTIFICATE_ID));
    when(webcertUserService.getUser()).thenReturn(user);
    Response response = moduleApiController.createRenewal(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID);
    verify(copyUtkastService).createRenewalCopy(any());
    verifyNoMoreInteractions(copyUtkastService);
    assertEquals(newIntygId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId());
    assertEquals(personnummer, captor.getValue().getPatient().getPersonId().getPersonnummer());
    assertEquals(fornamn, captor.getValue().getPatient().getFornamn());
    assertEquals(efternamn, captor.getValue().getPatient().getEfternamn());
    assertEquals(mellannamn, captor.getValue().getPatient().getMellannamn());
    assertEquals(postadress, captor.getValue().getPatient().getPostadress());
    assertEquals(postnummer, captor.getValue().getPatient().getPostnummer());
    assertEquals(postort, captor.getValue().getPatient().getPostort());
    assertEquals(newPersonnummer, captor.getValue().getNyttPatientPersonnummer().getPersonnummer());
}
Also used : Response(javax.ws.rs.core.Response) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) 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