Search in sources :

Example 86 with WebCertUser

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

the class UtkastServiceImplTest method testSaveUpdatesChangedPatientName.

@Test
public void testSaveUpdatesChangedPatientName() throws Exception {
    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, "Tolvan", "Tolvansson"));
    when(utlatande.getGrundData()).thenReturn(grunddata);
    utkast.setPatientFornamn("Inte Tolvan");
    utkast.setPatientEfternamn("Inte Tolvansson");
    // 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).setPatientFornamn("Tolvan");
    verify(utkast).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) 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 87 with WebCertUser

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

the class PageControllerTest method createMockUser.

private WebCertUser createMockUser(boolean doctor, String... features) {
    Role role = AUTHORITIES_RESOLVER.getRole(AuthoritiesConstants.ROLE_LAKARE);
    if (!doctor) {
        role = AUTHORITIES_RESOLVER.getRole(AuthoritiesConstants.ROLE_ADMIN);
    }
    WebCertUser user = new WebCertUser();
    user.setRoles(AuthoritiesResolverUtil.toMap(role));
    user.setAuthorities(AuthoritiesResolverUtil.toMap(role.getPrivileges(), Privilege::getName));
    user.setVardgivare(Collections.singletonList(createMockVardgivare()));
    user.setFeatures(Stream.of(features).collect(Collectors.toMap(Function.identity(), s -> {
        Feature feature = new Feature();
        feature.setName(s);
        feature.setGlobal(true);
        feature.setIntygstyper(Collections.singletonList(INTYG_TYP_FK7263));
        return feature;
    })));
    return user;
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 88 with WebCertUser

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

the class UserOriginResourceTest method testGetUserOrigin.

@Test
public void testGetUserOrigin() throws Exception {
    String origin = UserOriginType.NORMAL.name();
    // Given
    WebCertUser user = Mockito.mock(WebCertUser.class);
    Mockito.when(user.getOrigin()).thenReturn(origin);
    Mockito.when(webCertUserService.getUser()).thenReturn(user);
    // When
    final String originResponse = (String) userResource.getOrigin().getEntity();
    // Then
    assertEquals(origin, originResponse);
}
Also used : WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 89 with WebCertUser

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

the class UtkastApiControllerTest method setupUser.

private void setupUser(String privilegeString, String intygType, String... features) {
    WebCertUser user = new WebCertUser();
    user.setAuthorities(new HashMap<>());
    user.getFeatures().putAll(Stream.of(features).collect(Collectors.toMap(Function.identity(), s -> {
        Feature feature = new Feature();
        feature.setName(s);
        feature.setIntygstyper(Arrays.asList(intygType));
        feature.setGlobal(true);
        return feature;
    })));
    Privilege privilege = new Privilege();
    privilege.setIntygstyper(Arrays.asList(intygType));
    RequestOrigin requestOrigin = new RequestOrigin();
    requestOrigin.setName("NORMAL");
    requestOrigin.setIntygstyper(privilege.getIntygstyper());
    privilege.setRequestOrigins(Arrays.asList(requestOrigin));
    user.getAuthorities().put(privilegeString, privilege);
    user.setOrigin("NORMAL");
    user.setValdVardenhet(buildVardenhet());
    user.setValdVardgivare(buildVardgivare());
    when(webcertUserService.getUser()).thenReturn(user);
}
Also used : RequestOrigin(se.inera.intyg.infra.security.common.model.RequestOrigin) Privilege(se.inera.intyg.infra.security.common.model.Privilege) Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 90 with WebCertUser

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

the class IntygIntegrationControllerTest method invalidParametersShouldNotFailOnNullPatientInfo.

@Test
public void invalidParametersShouldNotFailOnNullPatientInfo() {
    IntegrationParameters parameters = new IntegrationParameters(null, null, ALTERNATE_SSN, null, null, null, null, null, null, false, false, false, false);
    WebCertUser user = createDefaultUser();
    user.setParameters(parameters);
    Response res = testee.handleRedirectToIntyg(uriInfo, INTYGSTYP, INTYGSID, ENHETSID, user);
    assertEquals(Response.Status.TEMPORARY_REDIRECT.getStatusCode(), res.getStatus());
    verify(authoritiesResolver).getFeatures(Arrays.asList(user.getValdVardenhet().getId(), user.getValdVardgivare().getId()));
}
Also used : Response(javax.ws.rs.core.Response) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) 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