Search in sources :

Example 1 with CreateReplacementCopyRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method testCreateReplacementCopy.

@Test
public void testCreateReplacementCopy() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.FALSE);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    when(createReplacementUtkastBuilder.populateCopyUtkastFromSignedIntyg(any(CreateReplacementCopyRequest.class), any(Person.class), eq(true), any(boolean.class), eq(true))).thenReturn(resp);
    CreateReplacementCopyRequest copyReq = buildReplacementCopyRequest();
    CreateReplacementCopyResponse copyResp = copyService.createReplacementCopy(copyReq);
    assertNotNull(copyResp);
    assertEquals(INTYG_COPY_ID, copyResp.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, copyResp.getNewDraftIntygType());
    verify(mockPUService).getPerson(PATIENT_SSN);
    verify(createReplacementUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateReplacementCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class), eq(true));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(referensService).saveReferens(eq(INTYG_COPY_ID), eq(reference));
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(logService).logCreateIntyg(any(LogRequest.class));
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateReplacementCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Person(se.inera.intyg.infra.integration.pu.model.Person) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) Test(org.junit.Test)

Example 2 with CreateReplacementCopyRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method testCreateReplacementCopyFailedIfAlreadyReplacedBySignedIntyg.

@Test(expected = WebCertServiceException.class)
public void testCreateReplacementCopyFailedIfAlreadyReplacedBySignedIntyg() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    WebcertCertificateRelation ersattRelation = new WebcertCertificateRelation(INTYG_ID, RelationKod.ERSATT, LocalDateTime.now(), UtkastStatus.SIGNED);
    when(certificateRelationService.getNewestRelationOfType(INTYG_ID, RelationKod.ERSATT, Arrays.asList(UtkastStatus.values()))).thenReturn(Optional.of(ersattRelation));
    CreateReplacementCopyRequest copyReq = buildReplacementCopyRequest();
    CreateReplacementCopyResponse copyResp = copyService.createReplacementCopy(copyReq);
    assertNotNull(copyResp);
    assertEquals(INTYG_COPY_ID, copyResp.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, copyResp.getNewDraftIntygType());
    verify(mockPUService).getPerson(PATIENT_SSN);
    verify(createReplacementUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateReplacementCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class), eq(true));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(userService).getUser();
    verify(logService).logCreateIntyg(any(LogRequest.class));
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateReplacementCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Person(se.inera.intyg.infra.integration.pu.model.Person) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) Test(org.junit.Test)

Example 3 with CreateReplacementCopyRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testReplaceIntyg.

@Test
public void testReplaceIntyg() {
    final String personnummer = "191212121212";
    final String newIntygId = "newIntygId";
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    WebCertUser user = new WebCertUser();
    addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_ERSATTA_INTYG);
    user.setOrigin("NORMAL");
    ArgumentCaptor<CreateReplacementCopyRequest> captor = ArgumentCaptor.forClass(CreateReplacementCopyRequest.class);
    when(copyUtkastService.createReplacementCopy(captor.capture())).thenReturn(new CreateReplacementCopyResponse(CERTIFICATE_TYPE, newIntygId, CERTIFICATE_ID));
    when(webcertUserService.getUser()).thenReturn(user);
    Response response = moduleApiController.createReplacement(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID);
    verify(copyUtkastService).createReplacementCopy(any());
    verifyNoMoreInteractions(copyUtkastService);
    assertEquals(newIntygId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId());
}
Also used : Response(javax.ws.rs.core.Response) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) CreateReplacementCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)3 CreateReplacementCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest)3 CreateReplacementCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Person (se.inera.intyg.infra.integration.pu.model.Person)2 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)2 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)2 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)2 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)2 Response (javax.ws.rs.core.Response)1 WebcertCertificateRelation (se.inera.intyg.webcert.common.model.WebcertCertificateRelation)1 CreateCompletionCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse)1 CreateRenewalCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse)1 CreateUtkastFromTemplateResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse)1 CopyIntygRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest)1 CopyIntygResponse (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse)1