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));
}
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;
}
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);
}
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);
}
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()));
}
Aggregations