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);
}
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);
}
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());
}
Aggregations