Search in sources :

Example 56 with ResultValidator

use of se.inera.intyg.webcert.web.integration.validators.ResultValidator in project webcert by sklintyg.

the class CreateDraftCertificateResponderImplTest method testCreateDraftCertificateHsaReturnsNoMIUs.

@Test
public void testCreateDraftCertificateHsaReturnsNoMIUs() {
    WebCertUser userWithNoMiu = buildWebCertUser();
    userWithNoMiu.setVardgivare(new ArrayList<>());
    when(webcertUserDetailsService.loadUserByHsaId(USER_HSAID)).thenReturn(userWithNoMiu);
    ResultValidator resultsValidator = new ResultValidator();
    CreateDraftCertificateType certificateType = createCertificateType();
    when(mockValidator.validate(any(Utlatande.class))).thenReturn(resultsValidator);
    CreateDraftCertificateResponseType response = responder.createDraftCertificate(LOGICAL_ADDR, certificateType);
    verifyZeroInteractions(mockUtkastService);
    verifyZeroInteractions(mockIntegreradeEnheterService);
    verify(monitoringLogService).logMissingMedarbetarUppdrag(USER_HSAID, UNIT_HSAID);
    assertNotNull(response);
    assertEquals(response.getResult().getResultCode(), ResultCodeType.ERROR);
    assertEquals(ErrorIdType.VALIDATION_ERROR, response.getResult().getErrorId());
    assertEquals("No valid MIU was found for person SE1234567890 on unit SE0987654321, can not create draft!", response.getResult().getResultText());
}
Also used : CreateDraftCertificateResponseType(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.CreateDraftCertificateResponseType) CreateDraftCertificateType(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.CreateDraftCertificateType) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) TypAvUtlatande(se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande) Utlatande(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) BaseCreateDraftCertificateTest(se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest) Test(org.junit.Test)

Example 57 with ResultValidator

use of se.inera.intyg.webcert.web.integration.validators.ResultValidator in project webcert by sklintyg.

the class CreateDraftCertificateResponderImplTest method whenNewCertificateDraftSuccessResponse.

/**
 * When a new certificate draft is being created the caller
 * should get a success response returned and any stakeholder
 * should be notified with a notification message.
 */
@Test
public void whenNewCertificateDraftSuccessResponse() {
    // Given
    ResultValidator resultsValidator = new ResultValidator();
    Vardgivare vardgivare = createVardgivare();
    Vardenhet vardenhet = createVardenhet(vardgivare);
    CreateNewDraftRequest draftRequest = createCreateNewDraftRequest(vardenhet);
    CreateDraftCertificateType certificateType = createCertificateType();
    VardpersonReferens vardperson = createVardpersonReferens(certificateType.getUtlatande().getSkapadAv().getPersonalId().getRoot(), certificateType.getUtlatande().getSkapadAv().getFullstandigtNamn());
    Utkast utkast = createUtkast(UTKAST_ID, Long.parseLong(UTKAST_VERSION), UTKAST_TYPE, UtkastStatus.DRAFT_INCOMPLETE, UTKAST_JSON, vardperson);
    // When
    when(mockValidator.validate(any(Utlatande.class))).thenReturn(resultsValidator);
    when(mockRequestBuilder.buildCreateNewDraftRequest(any(Utlatande.class), any(IntygUser.class))).thenReturn(draftRequest);
    when(mockUtkastService.createNewDraft(any(CreateNewDraftRequest.class))).thenReturn(utkast);
    when(takService.verifyTakningForCareUnit(any(String.class), any(String.class), any(SchemaVersion.class), any(IntygUser.class))).thenReturn(new TakResult(true, Lists.emptyList()));
    // Then
    CreateDraftCertificateResponseType response = responder.createDraftCertificate(LOGICAL_ADDR, certificateType);
    verify(mockUtkastService).createNewDraft(any(CreateNewDraftRequest.class));
    verify(mockIntegreradeEnheterService).putIntegreradEnhet(any(IntegreradEnhetEntry.class), eq(true), eq(false));
    verify(takService).verifyTakningForCareUnit(any(String.class), any(String.class), any(SchemaVersion.class), any(IntygUser.class));
    // Assert response content
    assertNotNull(response);
    assertEquals(response.getResult().getResultCode(), ResultCodeType.OK);
    assertEquals(response.getUtlatandeId().getExtension(), UTKAST_ID);
}
Also used : IntegreradEnhetEntry(se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry) CreateNewDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest) CreateDraftCertificateType(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.CreateDraftCertificateType) SchemaVersion(se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion) TakResult(se.inera.intyg.webcert.integration.tak.model.TakResult) Vardgivare(se.inera.intyg.common.support.model.common.internal.Vardgivare) Vardenhet(se.inera.intyg.common.support.model.common.internal.Vardenhet) IntygUser(se.inera.intyg.infra.security.common.model.IntygUser) CreateDraftCertificateResponseType(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.CreateDraftCertificateResponseType) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) TypAvUtlatande(se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande) Utlatande(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens) BaseCreateDraftCertificateTest(se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest) Test(org.junit.Test)

Example 58 with ResultValidator

use of se.inera.intyg.webcert.web.integration.validators.ResultValidator in project webcert by sklintyg.

the class CreateDraftCertificateResponderImplTest method testCreateDraftCertificateApplicationError.

@Test
public void testCreateDraftCertificateApplicationError() {
    final String validationError = "error";
    ResultValidator resultsValidator = new ResultValidator();
    resultsValidator.addError(validationError);
    CreateDraftCertificateType certificateType = createCertificateType();
    when(mockValidator.validate(any(Utlatande.class))).thenReturn(new ResultValidator());
    when(mockValidator.validateApplicationErrors(any(Utlatande.class), any(IntygUser.class))).thenReturn(resultsValidator);
    CreateDraftCertificateResponseType response = responder.createDraftCertificate(LOGICAL_ADDR, certificateType);
    verifyZeroInteractions(mockUtkastService);
    verifyZeroInteractions(mockIntegreradeEnheterService);
    assertNotNull(response);
    assertEquals(response.getResult().getResultCode(), ResultCodeType.ERROR);
    assertEquals(ErrorIdType.APPLICATION_ERROR, response.getResult().getErrorId());
    assertEquals(validationError, response.getResult().getResultText());
}
Also used : CreateDraftCertificateResponseType(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.CreateDraftCertificateResponseType) CreateDraftCertificateType(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.CreateDraftCertificateType) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) TypAvUtlatande(se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande) Utlatande(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande) IntygUser(se.inera.intyg.infra.security.common.model.IntygUser) BaseCreateDraftCertificateTest(se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest) Test(org.junit.Test)

Example 59 with ResultValidator

use of se.inera.intyg.webcert.web.integration.validators.ResultValidator in project webcert by sklintyg.

the class CreateDraftCertificateValidatorImplTest method testValidateEnhetEnhetsIdMissing.

@Test
public void testValidateEnhetEnhetsIdMissing() {
    ResultValidator result = validator.validate(buildIntyg(LUSE, "efternamn", "förnamn", "19121212-1212", "fullständigt namn", "hosHsaId", "enhetsnamn", null, true));
    assertTrue(result.hasErrors());
}
Also used : ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) Test(org.junit.Test) BaseCreateDraftCertificateValidatorTest(se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateValidatorTest)

Example 60 with ResultValidator

use of se.inera.intyg.webcert.web.integration.validators.ResultValidator in project webcert by sklintyg.

the class CreateDraftCertificateValidatorImplTest method testCreateOtherTypesNotAllowedWhenPatientIsDeceased.

@Test
public void testCreateOtherTypesNotAllowedWhenPatientIsDeceased() {
    List<String> typesToTest = Arrays.asList(Fk7263EntryPoint.MODULE_ID, TsBasEntryPoint.MODULE_ID, TsDiabetesEntryPoint.MODULE_ID, LisjpEntryPoint.MODULE_ID, LuaefsEntryPoint.MODULE_ID, LuseEntryPoint.MODULE_ID, LuaenaEntryPoint.MODULE_ID);
    when(patientDetailsResolver.getPersonFromPUService(any(Personnummer.class))).thenReturn(buildPersonSvar(PersonSvar.Status.FOUND));
    when(patientDetailsResolver.isAvliden(any(Personnummer.class))).thenReturn(true);
    when(patientDetailsResolver.getSekretessStatus(any(Personnummer.class))).thenReturn(SekretessStatus.FALSE);
    for (String type : typesToTest) {
        ResultValidator result = validator.validateApplicationErrors(buildIntyg(type, "efternamn", "förnamn", "fullständigt namn", "enhetsnamn", true), user);
        assertTrue(result.hasErrors());
    }
    verify(patientDetailsResolver, times(typesToTest.size())).isAvliden(any(Personnummer.class));
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) Test(org.junit.Test) BaseCreateDraftCertificateValidatorTest(se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateValidatorTest)

Aggregations

ResultValidator (se.inera.intyg.webcert.web.integration.validators.ResultValidator)61 Test (org.junit.Test)55 BaseCreateDraftCertificateValidatorTest (se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateValidatorTest)44 Personnummer (se.inera.intyg.schemas.contract.Personnummer)17 BaseCreateDraftCertificateTest (se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest)11 IntygUser (se.inera.intyg.infra.security.common.model.IntygUser)9 TakResult (se.inera.intyg.webcert.integration.tak.model.TakResult)8 SchemaVersion (se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion)7 Intyg (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.Intyg)7 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)6 Utlatande (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande)6 CreateDraftCertificateResponseType (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateResponseType)6 CreateDraftCertificateType (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateType)6 TypAvIntyg (se.riv.clinicalprocess.healthcond.certificate.types.v3.TypAvIntyg)6 CreateDraftCertificateResponseType (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.CreateDraftCertificateResponseType)5 CreateDraftCertificateType (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.CreateDraftCertificateType)5 TypAvUtlatande (se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande)5 VardpersonReferens (se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)4 IntegreradEnhetEntry (se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry)4 CreateNewDraftRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest)4