Search in sources :

Example 6 with ValidateDraftResponse

use of se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse in project webcert by sklintyg.

the class CreateRenewalCopyUtkastBuilderImplTest method testPopulateRenewalUtkastFromOriginalWhenIntegratedAndWithUpdatedSSN.

@Test
public void testPopulateRenewalUtkastFromOriginalWhenIntegratedAndWithUpdatedSSN() throws Exception {
    Utkast orgUtkast = createOriginalUtkast();
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(orgUtkast);
    CreateRenewalCopyRequest renewalRequest = buildRenewalRequest();
    renewalRequest.setNyttPatientPersonnummer(PATIENT_NEW_SSN);
    renewalRequest.setDjupintegrerad(true);
    when(mockModuleApi.createRenewalFromTemplate(any(CreateDraftCopyHolder.class), any())).thenReturn(INTYG_JSON);
    ValidateDraftResponse vdr = new ValidateDraftResponse(ValidationStatus.VALID, new ArrayList<>());
    when(mockModuleApi.validateDraft(anyString())).thenReturn(vdr);
    CopyUtkastBuilderResponse builderResponse = renewalBuilder.populateCopyUtkastFromOrignalUtkast(renewalRequest, null, false, false, false);
    assertNotNull(builderResponse.getUtkastCopy());
    assertNotNull(builderResponse.getUtkastCopy().getModel());
    assertEquals(INTYG_TYPE, builderResponse.getUtkastCopy().getIntygsTyp());
    assertEquals(PATIENT_NEW_SSN, builderResponse.getUtkastCopy().getPatientPersonnummer());
    assertEquals(PATIENT_FNAME, builderResponse.getUtkastCopy().getPatientFornamn());
    assertNotNull(builderResponse.getUtkastCopy().getPatientMellannamn());
    assertEquals(PATIENT_LNAME, builderResponse.getUtkastCopy().getPatientEfternamn());
}
Also used : CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateDraftCopyHolder(se.inera.intyg.common.support.modules.support.api.dto.CreateDraftCopyHolder) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) Test(org.junit.Test)

Example 7 with ValidateDraftResponse

use of se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse in project webcert by sklintyg.

the class CreateUtkastFromTemplateBuilderTest method testPopulateRenewalUtkastFromSignedIntyg.

@Test
public void testPopulateRenewalUtkastFromSignedIntyg() throws Exception {
    IntygContentHolder ich = createIntygContentHolder();
    when(mockIntygService.fetchIntygData(INTYG_ID, INTYG_TYPE_1, false)).thenReturn(ich);
    CreateUtkastFromTemplateRequest createUtkastFromTemplateRequest = buildCreateUtkastFromTemplateRequest();
    Person patientDetails = new Person(PATIENT_SSN, false, false, PATIENT_FNAME, PATIENT_MNAME, PATIENT_LNAME, "Postadr", "12345", "postort");
    when(mockModuleApi2.createNewInternalFromTemplate(any(CreateDraftCopyHolder.class), any())).thenReturn(INTYG_JSON);
    ValidateDraftResponse vdr = new ValidateDraftResponse(ValidationStatus.VALID, new ArrayList<>());
    when(mockModuleApi2.validateDraft(anyString())).thenReturn(vdr);
    CopyUtkastBuilderResponse builderResponse = createUtkastFromTemplateBuilder.populateCopyUtkastFromSignedIntyg(createUtkastFromTemplateRequest, patientDetails, false, false, false);
    assertNotNull(builderResponse.getUtkastCopy());
    assertNotNull(builderResponse.getUtkastCopy().getModel());
    assertEquals(INTYG_TYPE_2, builderResponse.getUtkastCopy().getIntygsTyp());
    assertEquals(PATIENT_SSN, builderResponse.getUtkastCopy().getPatientPersonnummer());
    assertEquals(PATIENT_FNAME, builderResponse.getUtkastCopy().getPatientFornamn());
    assertEquals(PATIENT_MNAME, builderResponse.getUtkastCopy().getPatientMellannamn());
    assertEquals(PATIENT_LNAME, builderResponse.getUtkastCopy().getPatientEfternamn());
    ArgumentCaptor<CreateDraftCopyHolder> requestCaptor = ArgumentCaptor.forClass(CreateDraftCopyHolder.class);
    verify(mockModuleApi2).createNewInternalFromTemplate(requestCaptor.capture(), any());
    // verify full name is set
    assertNotNull(requestCaptor.getValue().getPatient().getFullstandigtNamn());
    assertEquals(PATIENT_FNAME + " " + PATIENT_MNAME + " " + PATIENT_LNAME, requestCaptor.getValue().getPatient().getFullstandigtNamn());
}
Also used : CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) CreateDraftCopyHolder(se.inera.intyg.common.support.modules.support.api.dto.CreateDraftCopyHolder) CreateUtkastFromTemplateRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateRequest) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) Person(se.inera.intyg.infra.integration.pu.model.Person) Test(org.junit.Test)

Example 8 with ValidateDraftResponse

use of se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse in project webcert by sklintyg.

the class UtkastServiceImplTest method testSaveDoesNotUpdateOnEmptyFornamn.

@Test
public void testSaveDoesNotUpdateOnEmptyFornamn() throws Exception {
    final String utkastFornamn = "fornamn";
    final String utkastEfternamn = "efternamn";
    ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.VALID, Collections.emptyList());
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setSkapadAv(new HoSPersonal());
    grunddata.setPatient(buildPatient(PERSON_ID, null, "Tolvansson"));
    when(utlatande.getGrundData()).thenReturn(grunddata);
    utkast.setPatientFornamn(utkastFornamn);
    utkast.setPatientEfternamn(utkastEfternamn);
    // Make a spy out of the utkast so we can verify invocations on the setters with proper names further down.
    utkast = spy(utkast);
    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(userService.getUser()).thenReturn(user);
    when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
    draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, false);
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(utkast, times(0)).setPatientFornamn(null);
    verify(utkast, times(0)).setPatientEfternamn("Tolvansson");
    verify(utkast).setPatientPersonnummer(any(Personnummer.class));
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) 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 9 with ValidateDraftResponse

use of se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse 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 10 with ValidateDraftResponse

use of se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse 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)

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