use of se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage in project webcert by sklintyg.
the class UtkastServiceImplTest method testSaveDraftDraftFirstSave.
@Test
public void testSaveDraftDraftFirstSave() throws Exception {
ValidationMessage valMsg = new ValidationMessage("a.category", "a.field.somewhere", ValidationMessageType.OTHER, "This is soooo wrong!");
ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.INVALID, Collections.singletonList(valMsg));
WebCertUser user = createUser();
Utlatande utlatande = mock(Utlatande.class);
GrundData grunddata = new GrundData();
grunddata.setSkapadAv(new HoSPersonal());
grunddata.setPatient(defaultPatient);
when(utlatande.getGrundData()).thenReturn(grunddata);
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(mockModuleApi.shouldNotify(any(String.class), any(String.class))).thenReturn(true);
when(userService.getUser()).thenReturn(user);
when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
SaveDraftResponse res = draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, true);
verify(mockUtkastRepository).save(any(Utkast.class));
// Assert notification message
verify(notificationService).sendNotificationForDraftChanged(any(Utkast.class));
// Assert pdl log
verify(logService).logUpdateIntyg(any(LogRequest.class));
verify(mockMonitoringService).logUtkastEdited(INTYG_ID, INTYG_TYPE);
assertNotNull("An DraftValidation should be returned", res);
assertEquals("Validation should fail", UtkastStatus.DRAFT_INCOMPLETE, res.getStatus());
}
use of se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage in project webcert by sklintyg.
the class UtkastServiceImplTest method testValidateDraft.
@Test
public void testValidateDraft() throws Exception {
ValidationMessage valMsg = new ValidationMessage("a", "field.somewhere", ValidationMessageType.OTHER, "This is soooo wrong!");
ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.INVALID, Collections.singletonList(valMsg));
when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
when(mockModuleApi.validateDraft(INTYG_JSON)).thenReturn(validationResponse);
DraftValidation res = draftService.validateDraft(INTYG_ID, INTYG_TYPE, INTYG_JSON);
assertNotNull(res);
assertFalse(res.isDraftValid());
assertEquals(1, res.getMessages().size());
verify(mockModuleApi).validateDraft(INTYG_JSON);
}
use of se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage in project webcert by sklintyg.
the class UtkastServiceImplTest method testSaveDraftSecondSave.
@Test
public void testSaveDraftSecondSave() throws Exception {
ValidationMessage valMsg = new ValidationMessage("a.category", "a.field.somewhere", ValidationMessageType.OTHER, "This is soooo wrong!");
ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.INVALID, Collections.singletonList(valMsg));
WebCertUser user = createUser();
Utlatande utlatande = mock(Utlatande.class);
GrundData grunddata = new GrundData();
grunddata.setSkapadAv(new HoSPersonal());
grunddata.setPatient(defaultPatient);
when(utlatande.getGrundData()).thenReturn(grunddata);
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(mockModuleApi.shouldNotify(any(String.class), any(String.class))).thenReturn(true);
when(userService.getUser()).thenReturn(user);
when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
SaveDraftResponse res = draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, false);
verify(mockUtkastRepository).save(any(Utkast.class));
// Assert notification message
verify(notificationService).sendNotificationForDraftChanged(any(Utkast.class));
// Assert that no logs are called
verifyZeroInteractions(logService);
verifyZeroInteractions(mockMonitoringService);
assertNotNull("An DraftValidation should be returned", res);
assertEquals("Validation should fail", UtkastStatus.DRAFT_INCOMPLETE, res.getStatus());
}
use of se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage in project webcert by sklintyg.
the class UtkastServiceImplTest method setupReferensMocks.
private void setupReferensMocks() throws ModuleNotFoundException, ModuleException, IOException {
ValidationMessage valMsg = new ValidationMessage("a.category", "a.field.somewhere", ValidationMessageType.OTHER, "This is soooo wrong!");
ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.INVALID, Collections.singletonList(valMsg));
Utlatande utlatande = mock(Utlatande.class);
when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
when(mockUtkastRepository.save(any(Utkast.class))).then(invocation -> invocation.getArguments()[0]);
}
use of se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage in project webcert by sklintyg.
the class UtkastServiceImpl method convertToDraftValidation.
private DraftValidation convertToDraftValidation(ValidateDraftResponse dr) {
DraftValidation draftValidation = new DraftValidation();
ValidationStatus validationStatus = dr.getStatus();
// Always return the warning messages
for (ValidationMessage validationWarning : dr.getValidationWarnings()) {
draftValidation.addWarning(new DraftValidationMessage(validationWarning.getCategory(), validationWarning.getField(), validationWarning.getType(), validationWarning.getMessage(), validationWarning.getDynamicKey()));
}
if (ValidationStatus.VALID.equals(validationStatus)) {
LOG.debug("Validation is OK");
return draftValidation;
}
draftValidation.setStatus(ValidationStatus.INVALID);
// Only bother with returning validation (e.g. error) messages if the ArendeDraft is INVALID.
for (ValidationMessage validationMsg : dr.getValidationErrors()) {
draftValidation.addMessage(new DraftValidationMessage(validationMsg.getCategory(), validationMsg.getField(), validationMsg.getType(), validationMsg.getMessage(), validationMsg.getDynamicKey()));
}
LOG.debug("Validation failed with {} validation messages", draftValidation.getMessages().size());
return draftValidation;
}
Aggregations