Search in sources :

Example 1 with ValidationMessage

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());
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) ValidationMessage(se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) SaveDraftResponse(se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 2 with ValidationMessage

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);
}
Also used : ValidationMessage(se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage) DraftValidation(se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) Test(org.junit.Test)

Example 3 with ValidationMessage

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());
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) ValidationMessage(se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) SaveDraftResponse(se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 4 with ValidationMessage

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]);
}
Also used : ValidationMessage(se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)

Example 5 with ValidationMessage

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;
}
Also used : ValidationStatus(se.inera.intyg.common.support.modules.support.api.dto.ValidationStatus) ValidationMessage(se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage)

Aggregations

ValidationMessage (se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage)5 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)4 Test (org.junit.Test)3 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)3 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)2 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)2 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)2 SaveDraftResponse (se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse)2 ValidationStatus (se.inera.intyg.common.support.modules.support.api.dto.ValidationStatus)1 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)1 DraftValidation (se.inera.intyg.webcert.web.service.utkast.dto.DraftValidation)1