Search in sources :

Example 16 with ValidateDraftResponse

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());
}
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 17 with ValidateDraftResponse

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]);
}
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 18 with ValidateDraftResponse

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

Aggregations

ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)18 Test (org.junit.Test)15 CreateDraftCopyHolder (se.inera.intyg.common.support.modules.support.api.dto.CreateDraftCopyHolder)9 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)9 Person (se.inera.intyg.infra.integration.pu.model.Person)8 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)8 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)5 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)4 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)4 ValidationMessage (se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage)4 IntygContentHolder (se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder)4 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)4 CreateCompletionCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyRequest)4 CreateRenewalCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ArrayList (java.util.ArrayList)2 Personnummer (se.inera.intyg.schemas.contract.Personnummer)2 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)2 CreateUtkastFromTemplateRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateRequest)2 SaveDraftResponse (se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse)2