Search in sources :

Example 56 with WebCertUser

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

the class IntygServiceRevokeTest method setup.

@Before
public void setup() throws Exception {
    HoSPersonal person = buildHosPerson();
    VardpersonReferens vardperson = buildVardpersonReferens(person);
    WebCertUser user = buildWebCertUser(person);
    signedUtkast = buildUtkast(INTYG_ID, INTYG_TYPE, UtkastStatus.SIGNED, INTYG_JSON, vardperson);
    revokedUtkast = buildUtkast(INTYG_ID, INTYG_TYPE, UtkastStatus.SIGNED, json, vardperson);
    revokedUtkast.setAterkalladDatum(LocalDateTime.now());
    when(webCertUserService.getUser()).thenReturn(user);
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Before(org.junit.Before)

Example 57 with WebCertUser

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

the class IntygServiceRevokeTest method buildWebCertUser.

private WebCertUser buildWebCertUser(HoSPersonal person) {
    Role role = AUTHORITIES_RESOLVER.getRole(AuthoritiesConstants.ROLE_LAKARE);
    WebCertUser user = new WebCertUser();
    user.setRoles(AuthoritiesResolverUtil.toMap(role));
    user.setOrigin(UserOriginType.DJUPINTEGRATION.name());
    user.setParameters(new IntegrationParameters(USER_REFERENCE, "", "", "", "", "", "", "", "", false, false, false, true));
    user.setAuthorities(AuthoritiesResolverUtil.toMap(role.getPrivileges(), Privilege::getName));
    user.setNamn(person.getFullstandigtNamn());
    user.setHsaId(person.getPersonId());
    return user;
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 58 with WebCertUser

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

the class IntygServiceSendTest method testSendIntygThrowsExceptionForOldFk7263WithSekretessmarkeradPatient.

@Test(expected = WebCertServiceException.class)
public void testSendIntygThrowsExceptionForOldFk7263WithSekretessmarkeradPatient() throws Exception {
    final String completionMeddelandeId = "meddelandeId";
    intygService.setSekretessmarkeringStartDatum(LocalDateTime.now().plusMonths(1L));
    WebCertUser webCertUser = createUser();
    Utlatande completionUtlatande = utlatande;
    completionUtlatande.getGrundData().setRelation(new Relation());
    completionUtlatande.getGrundData().getRelation().setRelationKod(RelationKod.KOMPLT);
    completionUtlatande.getGrundData().getRelation().setMeddelandeId(completionMeddelandeId);
    when(moduleFacade.getUtlatandeFromInternalModel(isNull(), anyString())).thenReturn(completionUtlatande);
    when(webCertUserService.isAuthorizedForUnit(anyString(), anyString(), anyBoolean())).thenReturn(true);
    when(patientDetailsResolver.getSekretessStatus(any(Personnummer.class))).thenReturn(SekretessStatus.TRUE);
    when(webCertUserService.getUser()).thenReturn(webCertUser);
    when(intygRepository.findOne(INTYG_ID)).thenReturn(getUtkast(INTYG_ID));
    try {
        intygService.sendIntyg(INTYG_ID, INTYG_TYP_FK, "FKASSA", false);
    } catch (Exception e) {
        verifyZeroInteractions(logService);
        throw e;
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) Relation(se.inera.intyg.common.support.model.common.internal.Relation) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) IOException(java.io.IOException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 59 with WebCertUser

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

the class IntygServiceSendTest method testSendIntyg.

@Test
public void testSendIntyg() throws Exception {
    final String completionMeddelandeId = "meddelandeId";
    WebCertUser webCertUser = createUser();
    Utlatande completionUtlatande = utlatande;
    completionUtlatande.getGrundData().setRelation(new Relation());
    completionUtlatande.getGrundData().getRelation().setRelationKod(RelationKod.KOMPLT);
    completionUtlatande.getGrundData().getRelation().setMeddelandeId(completionMeddelandeId);
    when(moduleFacade.getUtlatandeFromInternalModel(isNull(), anyString())).thenReturn(completionUtlatande);
    when(webCertUserService.isAuthorizedForUnit(anyString(), anyString(), anyBoolean())).thenReturn(true);
    when(patientDetailsResolver.getSekretessStatus(any(Personnummer.class))).thenReturn(SekretessStatus.FALSE);
    when(webCertUserService.getUser()).thenReturn(webCertUser);
    when(intygRepository.findOne(INTYG_ID)).thenReturn(getUtkast(INTYG_ID));
    IntygServiceResult res = intygService.sendIntyg(INTYG_ID, INTYG_TYP_FK, "FKASSA", false);
    assertEquals(IntygServiceResult.OK, res);
    verify(logService).logSendIntygToRecipient(any(LogRequest.class));
    verify(certificateSenderService).sendCertificate(anyString(), any(Personnummer.class), anyString(), anyString(), eq(false));
    verify(intygRepository, times(2)).findOne(INTYG_ID);
    verify(intygRepository).save(any(Utkast.class));
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Relation(se.inera.intyg.common.support.model.common.internal.Relation) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) IntygServiceResult(se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 60 with WebCertUser

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

the class IntygServiceSendTest method testSendIntygFailsForReplacedCertificate.

@Test(expected = WebCertServiceException.class)
public void testSendIntygFailsForReplacedCertificate() throws Exception {
    final String completionMeddelandeId = "meddelandeId";
    WebCertUser webCertUser = createUser();
    Utlatande completionUtlatande = utlatande;
    completionUtlatande.getGrundData().setRelation(new Relation());
    completionUtlatande.getGrundData().getRelation().setRelationKod(RelationKod.KOMPLT);
    completionUtlatande.getGrundData().getRelation().setMeddelandeId(completionMeddelandeId);
    when(webCertUserService.isAuthorizedForUnit(anyString(), anyString(), anyBoolean())).thenReturn(true);
    when(webCertUserService.getUser()).thenReturn(webCertUser);
    when(intygRepository.findOne(INTYG_ID)).thenReturn(getUtkast(INTYG_ID));
    WebcertCertificateRelation ersattRelation = new WebcertCertificateRelation(INTYG_ID, RelationKod.ERSATT, LocalDateTime.now(), UtkastStatus.SIGNED);
    when(certificateRelationService.getNewestRelationOfType(eq(INTYG_ID), eq(RelationKod.ERSATT), eq(Arrays.asList(UtkastStatus.SIGNED)))).thenReturn(Optional.of(ersattRelation));
    CertificateMetaData metaData = new CertificateMetaData();
    metaData.setStatus(new ArrayList<>());
    CertificateResponse revokedCertificateResponse = new CertificateResponse(json, utlatande, metaData, false);
    when(moduleFacade.getCertificate(any(String.class), any(String.class))).thenReturn(revokedCertificateResponse);
    when(moduleFacade.getUtlatandeFromInternalModel(any(), any())).thenReturn(utlatande);
    intygService.sendIntyg(INTYG_ID, INTYG_TYP_FK, "FKASSA", false);
    verifyZeroInteractions(logService);
}
Also used : Relation(se.inera.intyg.common.support.model.common.internal.Relation) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) CertificateResponse(se.inera.intyg.common.support.modules.support.api.dto.CertificateResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CertificateMetaData(se.inera.intyg.common.support.modules.support.api.dto.CertificateMetaData) 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