Search in sources :

Example 81 with WebCertUser

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

the class UtkastServiceImplTest method testSaveDraftDraftFirstSave.

@Test
public void testSaveDraftDraftFirstSave() throws Exception {
    ValidationMessage valMsg = new ValidationMessage("a.category", "a.field.somewhere", ValidationMessageType.OTHER, "This is soooo wrong!");
    ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.INVALID, Collections.singletonList(valMsg));
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setSkapadAv(new HoSPersonal());
    grunddata.setPatient(defaultPatient);
    when(utlatande.getGrundData()).thenReturn(grunddata);
    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(mockModuleApi.shouldNotify(any(String.class), any(String.class))).thenReturn(true);
    when(userService.getUser()).thenReturn(user);
    when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
    SaveDraftResponse res = draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, true);
    verify(mockUtkastRepository).save(any(Utkast.class));
    // Assert notification message
    verify(notificationService).sendNotificationForDraftChanged(any(Utkast.class));
    // Assert pdl log
    verify(logService).logUpdateIntyg(any(LogRequest.class));
    verify(mockMonitoringService).logUtkastEdited(INTYG_ID, INTYG_TYPE);
    assertNotNull("An DraftValidation should be returned", res);
    assertEquals("Validation should fail", UtkastStatus.DRAFT_INCOMPLETE, res.getStatus());
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) ValidationMessage(se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) SaveDraftResponse(se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse) 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 82 with WebCertUser

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

the class LogServiceImplTest method createUser.

private WebCertUser createUser() {
    Role role = AUTHORITIES_RESOLVER.getRole(AuthoritiesConstants.ROLE_LAKARE);
    Vardenhet ve = new Vardenhet("VARDENHET_ID", "Vårdenheten");
    Vardgivare vg = new Vardgivare("VARDGIVARE_ID", "Vårdgivaren");
    vg.setVardenheter(Collections.singletonList(ve));
    WebCertUser user = new WebCertUser();
    user.setRoles(AuthoritiesResolverUtil.toMap(role));
    user.setAuthorities(AuthoritiesResolverUtil.toMap(role.getPrivileges(), Privilege::getName));
    user.setHsaId("HSAID");
    user.setNamn("Markus Gran");
    user.setVardgivare(Collections.singletonList(vg));
    user.changeValdVardenhet("VARDENHET_ID");
    user.setTitel("Överläkare");
    user.setMiuNamnPerEnhetsId(buildMiUMap());
    return user;
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) Vardenhet(se.inera.intyg.infra.integration.hsa.model.Vardenhet) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 83 with WebCertUser

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

the class GrpCollectPollerTest method buildAuthentication.

private SecurityContext buildAuthentication() {
    Role role = AUTHORITIES_RESOLVER.getRole(AuthoritiesConstants.ROLE_LAKARE);
    WebCertUser user = new WebCertUser();
    user.setRoles(AuthoritiesResolverUtil.toMap(role));
    user.setAuthorities(AuthoritiesResolverUtil.toMap(role.getPrivileges(), Privilege::getName));
    user.setPersonId(PERSON_ID);
    Authentication authentication = new TestingAuthenticationToken(user, null);
    SecurityContext securityContext = new SecurityContextImpl();
    securityContext.setAuthentication(authentication);
    return securityContext;
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 84 with WebCertUser

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

the class UtkastServiceImplTest method testUpdatePatientOnDraftNoMedarbetaruppdragThrowsException.

@Test(expected = WebCertServiceException.class)
public void testUpdatePatientOnDraftNoMedarbetaruppdragThrowsException() throws Exception {
    utkast.setEnhetsId("<unknownenhet>");
    Patient newPatient = getUpdatedPatient();
    UpdatePatientOnDraftRequest request = new UpdatePatientOnDraftRequest(newPatient.getPersonId(), utkast.getIntygsId(), utkast.getVersion());
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setPatient(defaultPatient);
    grunddata.setSkapadAv(new HoSPersonal());
    // 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(userService.getUser()).thenReturn(user);
    draftService.updatePatientOnDraft(request);
    verifyNoMoreInteractions(mockUtkastRepository, notificationService);
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Patient(se.inera.intyg.common.support.model.common.internal.Patient) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) UpdatePatientOnDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 85 with WebCertUser

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

the class UtkastServiceImplTest method testSaveDraftWithExceptionInModule.

@SuppressWarnings("unchecked")
@Test(expected = WebCertServiceException.class)
public void testSaveDraftWithExceptionInModule() throws Exception {
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setSkapadAv(new HoSPersonal());
    grunddata.setPatient(defaultPatient);
    when(utlatande.getGrundData()).thenReturn(grunddata);
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
    when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
    when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
    when(mockModuleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    when(mockModuleApi.validateDraft(anyString())).thenThrow(ModuleException.class);
    draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, false);
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) 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