Search in sources :

Example 16 with CopyIntygRequest

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

the class IntygModuleApiControllerTest method testCreateNewCompletion.

@Test
public void testCreateNewCompletion() {
    final String personnummer = "191212121212";
    final String newIntygId = "newIntygId";
    final String meddelandeId = "meddelandeId";
    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";
    final 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_SVARA_MED_NYTT_INTYG);
    user.setOrigin("NORMAL");
    ArgumentCaptor<CreateCompletionCopyRequest> captor = ArgumentCaptor.forClass(CreateCompletionCopyRequest.class);
    when(copyUtkastService.createCompletion(captor.capture())).thenReturn(new CreateCompletionCopyResponse(CERTIFICATE_TYPE, newIntygId, CERTIFICATE_ID));
    when(webcertUserService.getUser()).thenReturn(user);
    Response response = moduleApiController.createCompletion(request, CERTIFICATE_TYPE, CERTIFICATE_ID);
    verify(copyUtkastService).createCompletion(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) CreateCompletionCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyRequest) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 17 with CopyIntygRequest

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

the class IntygModuleApiControllerTest method testCreateNewCompletionMissingRequest.

@Test(expected = WebCertServiceException.class)
public void testCreateNewCompletionMissingRequest() {
    WebCertUser user = new WebCertUser();
    addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_SVARA_MED_NYTT_INTYG);
    user.setOrigin("NORMAL");
    when(webcertUserService.getUser()).thenReturn(user);
    try {
        moduleApiController.createCompletion(new CopyIntygRequest(), CERTIFICATE_TYPE, null);
    } 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 18 with CopyIntygRequest

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

the class IntygModuleApiControllerTest method testCreateRenewalCopyWithNewPatientReservnummerDefaultsToPreviousPersonnummer.

/**
 * Verify that a non-valid personnr/samordningsnummer (i.e a "reservnummer") supplied as NyttPatientPersonnummer
 * will not be applied to the new utkast.
 */
@Test
public void testCreateRenewalCopyWithNewPatientReservnummerDefaultsToPreviousPersonnummer() {
    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 newReservnummer = "A20090122";
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(null, null, newReservnummer, 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());
    assertNull(captor.getValue().getNyttPatientPersonnummer());
}
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 19 with CopyIntygRequest

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

the class IntygModuleApiControllerTest method testCreateRenewalCopyInvalidRequest.

@Test(expected = WebCertServiceException.class)
public void testCreateRenewalCopyInvalidRequest() {
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    WebCertUser user = new WebCertUser();
    addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_FORNYA_INTYG);
    user.setOrigin("NORMAL");
    when(webcertUserService.getUser()).thenReturn(user);
    try {
        moduleApiController.createRenewal(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID);
    } 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 20 with CopyIntygRequest

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

the class IntygModuleApiControllerTest method testCreateUtkastFromTemplateInvalidRequest.

@Test(expected = WebCertServiceException.class)
public void testCreateUtkastFromTemplateInvalidRequest() {
    WebCertUser user = new WebCertUser();
    addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST);
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG);
    user.setOrigin("NORMAL");
    when(webcertUserService.getUser()).thenReturn(user);
    try {
        moduleApiController.createUtkastFromTemplate(new CopyIntygRequest(), CERTIFICATE_TYPE, CERTIFICATE_ID, CERTIFICATE_TYPE);
    } 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)

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