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