Search in sources :

Example 76 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method testCreateReplacementCopyFailedIfAlreadyReplacedBySignedIntyg.

@Test(expected = WebCertServiceException.class)
public void testCreateReplacementCopyFailedIfAlreadyReplacedBySignedIntyg() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    WebcertCertificateRelation ersattRelation = new WebcertCertificateRelation(INTYG_ID, RelationKod.ERSATT, LocalDateTime.now(), UtkastStatus.SIGNED);
    when(certificateRelationService.getNewestRelationOfType(INTYG_ID, RelationKod.ERSATT, Arrays.asList(UtkastStatus.values()))).thenReturn(Optional.of(ersattRelation));
    CreateReplacementCopyRequest copyReq = buildReplacementCopyRequest();
    CreateReplacementCopyResponse copyResp = copyService.createReplacementCopy(copyReq);
    assertNotNull(copyResp);
    assertEquals(INTYG_COPY_ID, copyResp.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, copyResp.getNewDraftIntygType());
    verify(mockPUService).getPerson(PATIENT_SSN);
    verify(createReplacementUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateReplacementCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class), eq(true));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(userService).getUser();
    verify(logService).logCreateIntyg(any(LogRequest.class));
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateReplacementCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Person(se.inera.intyg.infra.integration.pu.model.Person) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) Test(org.junit.Test)

Example 77 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method testCreateRenewalWhenIntegrated.

@Test
public void testCreateRenewalWhenIntegrated() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.FALSE);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    when(createRenewalCopyUtkastBuilder.populateCopyUtkastFromSignedIntyg(any(CreateRenewalCopyRequest.class), isNull(), eq(false), eq(false), eq(false))).thenReturn(resp);
    CreateRenewalCopyRequest renewRequest = buildRenewalRequest();
    renewRequest.setDjupintegrerad(true);
    CreateRenewalCopyResponse renewalCopyResponse = copyService.createRenewalCopy(renewRequest);
    assertNotNull(renewalCopyResponse);
    assertEquals(INTYG_COPY_ID, renewalCopyResponse.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, renewalCopyResponse.getNewDraftIntygType());
    verifyZeroInteractions(mockPUService);
    verify(createRenewalCopyUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateRenewalCopyRequest.class), isNull(), eq(false), eq(false), eq(false));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(referensService).saveReferens(eq(INTYG_COPY_ID), eq(reference));
    verify(mockIntegreradeEnheterRegistry).addIfSameVardgivareButDifferentUnits(any(String.class), any(IntegreradEnhetEntry.class), anyString());
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(userService).getUser();
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
    // Assert pdl log
    verify(logService).logCreateIntyg(any(LogRequest.class));
}
Also used : IntegreradEnhetEntry(se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 78 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method testCreateCopyWhenIntegratedAndWithUpdatedSSN.

@Test
public void testCreateCopyWhenIntegratedAndWithUpdatedSSN() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.FALSE);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    when(createRenewalCopyUtkastBuilder.populateCopyUtkastFromSignedIntyg(any(CreateRenewalCopyRequest.class), isNull(), eq(false), eq(false), eq(false))).thenReturn(resp);
    CreateRenewalCopyRequest copyReq = buildRenewalRequest();
    copyReq.setNyttPatientPersonnummer(PATIENT_NEW_SSN);
    copyReq.setDjupintegrerad(true);
    CreateRenewalCopyResponse renewalCopyResponse = copyService.createRenewalCopy(copyReq);
    assertNotNull(renewalCopyResponse);
    assertEquals(INTYG_COPY_ID, renewalCopyResponse.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, renewalCopyResponse.getNewDraftIntygType());
    verifyZeroInteractions(mockPUService);
    verify(createRenewalCopyUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateRenewalCopyRequest.class), isNull(), eq(false), eq(false), eq(false));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(mockIntegreradeEnheterRegistry).addIfSameVardgivareButDifferentUnits(any(String.class), any(IntegreradEnhetEntry.class), anyString());
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(userService).getUser();
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
    // Assert pdl log
    verify(logService).logCreateIntyg(any(LogRequest.class));
}
Also used : IntegreradEnhetEntry(se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 79 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class UtkastServiceImplTest method testSaveDoesNotUpdateOnEmptyFornamn.

@Test
public void testSaveDoesNotUpdateOnEmptyFornamn() throws Exception {
    final String utkastFornamn = "fornamn";
    final String utkastEfternamn = "efternamn";
    ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.VALID, Collections.emptyList());
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setSkapadAv(new HoSPersonal());
    grunddata.setPatient(buildPatient(PERSON_ID, null, "Tolvansson"));
    when(utlatande.getGrundData()).thenReturn(grunddata);
    utkast.setPatientFornamn(utkastFornamn);
    utkast.setPatientEfternamn(utkastEfternamn);
    // Make a spy out of the utkast so we can verify invocations on the setters with proper names further down.
    utkast = spy(utkast);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
    when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
    when(mockModuleApi.validateDraft(anyString())).thenReturn(validationResponse);
    when(mockModuleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    when(mockUtkastRepository.save(utkast)).thenReturn(utkast);
    when(userService.getUser()).thenReturn(user);
    when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
    draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, false);
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(utkast, times(0)).setPatientFornamn(null);
    verify(utkast, times(0)).setPatientEfternamn("Tolvansson");
    verify(utkast).setPatientPersonnummer(any(Personnummer.class));
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 80 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class UtkastServiceImplTest method testDeleteDraftThatIsUnsigned.

@Test
public void testDeleteDraftThatIsUnsigned() {
    WebCertUser user = createUser();
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
    draftService.deleteUnsignedDraft(INTYG_ID, utkast.getVersion());
    verify(mockUtkastRepository).findOne(INTYG_ID);
    verify(mockUtkastRepository).delete(utkast);
    // Assert notification message
    verify(notificationService).sendNotificationForDraftDeleted(any(Utkast.class));
    // Assert pdl log
    verify(logService).logDeleteIntyg(any(LogRequest.class));
    verify(mockMonitoringService).logUtkastDeleted(INTYG_ID, INTYG_TYPE);
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Aggregations

WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)217 Test (org.junit.Test)123 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)32 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)31 Personnummer (se.inera.intyg.schemas.contract.Personnummer)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)23 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)23 Role (se.inera.intyg.infra.security.common.model.Role)18 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)16 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)15 CopyIntygRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest)15 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)14 Vardenhet (se.inera.intyg.infra.integration.hsa.model.Vardenhet)14 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)14 Vardgivare (se.inera.intyg.infra.integration.hsa.model.Vardgivare)13 Feature (se.inera.intyg.infra.security.common.model.Feature)13 HashMap (java.util.HashMap)12 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)12 Transactional (org.springframework.transaction.annotation.Transactional)11 Path (javax.ws.rs.Path)10