use of se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse 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.ValidateDraftResponse 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.ValidateDraftResponse in project webcert by sklintyg.
the class AbstractUtkastBuilder method validateDraft.
private UtkastStatus validateDraft(ModuleApi moduleApi, String draftCopyJson) throws ModuleException {
ValidateDraftResponse validationResponse = moduleApi.validateDraft(draftCopyJson);
ValidationStatus validationStatus = validationResponse.getStatus();
return ValidationStatus.VALID.equals(validationStatus) ? UtkastStatus.DRAFT_COMPLETE : UtkastStatus.DRAFT_INCOMPLETE;
}
Aggregations