use of se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest in project webcert by sklintyg.
the class IntygModuleApiControllerTest method testCreateRenewal.
@Test
public void testCreateRenewal() {
final String newDraftIntygId = "newDraftIntygId";
final String personnummer = "191212121212";
final String newPersonnummer = "201212121212";
final String efternamn = "efternamn";
final String fornamn = "fornamn";
final String mellannamn = "mellannamn";
final String postadress = "postadress";
final String postort = "postort";
final String postnummer = "postnummer";
CopyIntygRequest request = new CopyIntygRequest();
request.setPatientPersonnummer(createPnr(personnummer));
WebCertUser user = new WebCertUser();
user.setParameters(new IntegrationParameters(null, null, newPersonnummer, fornamn, mellannamn, efternamn, postadress, postnummer, postort, false, false, false, true));
addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_FORNYA_INTYG);
user.setOrigin("NORMAL");
ArgumentCaptor<CreateRenewalCopyRequest> captor = ArgumentCaptor.forClass(CreateRenewalCopyRequest.class);
when(copyUtkastService.createRenewalCopy(captor.capture())).thenReturn(new CreateRenewalCopyResponse(CERTIFICATE_TYPE, newDraftIntygId, CERTIFICATE_ID));
when(webcertUserService.getUser()).thenReturn(user);
Response response = moduleApiController.createRenewal(request, CERTIFICATE_TYPE, CERTIFICATE_ID);
verify(copyUtkastService).createRenewalCopy(any());
verifyNoMoreInteractions(copyUtkastService);
assertEquals(newDraftIntygId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId());
assertEquals(personnummer, captor.getValue().getPatient().getPersonId().getPersonnummer());
assertEquals(fornamn, captor.getValue().getPatient().getFornamn());
assertEquals(efternamn, captor.getValue().getPatient().getEfternamn());
assertEquals(mellannamn, captor.getValue().getPatient().getMellannamn());
assertEquals(postadress, captor.getValue().getPatient().getPostadress());
assertEquals(postnummer, captor.getValue().getPatient().getPostnummer());
assertEquals(postort, captor.getValue().getPatient().getPostort());
assertEquals(newPersonnummer, captor.getValue().getNyttPatientPersonnummer().getPersonnummer());
}
use of se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest in project webcert by sklintyg.
the class IntygModuleApiControllerTest method testCreateRenewalWithNewPatientInfo.
@Test
public void testCreateRenewalWithNewPatientInfo() {
final String personnummer = "191212121212";
final String newIntygId = "newIntygId";
final String efternamn = "efternamn";
final String fornamn = "fornamn";
final String mellannamn = "mellannamn";
final String postadress = "postadress";
final String postort = "postort";
final String postnummer = "postnummer";
final String newPersonnummer = "201212121212";
CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
WebCertUser user = new WebCertUser();
user.setParameters(new IntegrationParameters(null, null, newPersonnummer, fornamn, mellannamn, efternamn, postadress, postnummer, postort, false, false, false, true));
addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_FORNYA_INTYG);
user.setOrigin("NORMAL");
ArgumentCaptor<CreateRenewalCopyRequest> captor = ArgumentCaptor.forClass(CreateRenewalCopyRequest.class);
when(copyUtkastService.createRenewalCopy(captor.capture())).thenReturn(new CreateRenewalCopyResponse(CERTIFICATE_TYPE, newIntygId, CERTIFICATE_ID));
when(webcertUserService.getUser()).thenReturn(user);
Response response = moduleApiController.createRenewal(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID);
verify(copyUtkastService).createRenewalCopy(any());
verifyNoMoreInteractions(copyUtkastService);
assertEquals(newIntygId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId());
assertEquals(personnummer, captor.getValue().getPatient().getPersonId().getPersonnummer());
assertEquals(fornamn, captor.getValue().getPatient().getFornamn());
assertEquals(efternamn, captor.getValue().getPatient().getEfternamn());
assertEquals(mellannamn, captor.getValue().getPatient().getMellannamn());
assertEquals(postadress, captor.getValue().getPatient().getPostadress());
assertEquals(postnummer, captor.getValue().getPatient().getPostnummer());
assertEquals(postort, captor.getValue().getPatient().getPostort());
assertEquals(newPersonnummer, captor.getValue().getNyttPatientPersonnummer().getPersonnummer());
}
use of se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest in project webcert by sklintyg.
the class CopyUtkastServiceImplTest method testCreateRenewalFailsWhenReplacedBySignedIntyg.
@Test(expected = WebCertServiceException.class)
public void testCreateRenewalFailsWhenReplacedBySignedIntyg() throws Exception {
final String reference = "ref";
WebCertUser user = new WebCertUser();
user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
when(userService.getUser()).thenReturn(user);
WebcertCertificateRelation ersattRelation = new WebcertCertificateRelation(INTYG_ID, RelationKod.ERSATT, LocalDateTime.now(), UtkastStatus.SIGNED);
when(certificateRelationService.getNewestRelationOfType(INTYG_ID, RelationKod.ERSATT, Arrays.asList(UtkastStatus.SIGNED))).thenReturn(Optional.of(ersattRelation));
CreateRenewalCopyRequest copyReq = buildRenewalRequest();
try {
copyService.createRenewalCopy(copyReq);
fail("An exception should have been thrown.");
} catch (Exception e) {
verifyZeroInteractions(mockUtkastRepository);
verifyZeroInteractions(mockNotificationService);
verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
// Assert no pdl logging
verifyZeroInteractions(logService);
throw e;
}
}
use of se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest in project webcert by sklintyg.
the class CopyUtkastServiceImplTest method testRenewThrowsExceptionWhenOriginalCertificateIsRevoked.
@Test(expected = WebCertServiceException.class)
public void testRenewThrowsExceptionWhenOriginalCertificateIsRevoked() throws ModuleException, ModuleNotFoundException {
when(intygService.isRevoked(anyString(), anyString(), anyBoolean())).thenReturn(true);
CreateRenewalCopyRequest copyReq = buildRenewalRequest();
copyService.createRenewalCopy(copyReq);
}
use of se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest in project webcert by sklintyg.
the class CopyUtkastServiceImplTest method testRenewalThrowsExceptionWhenOriginalCertificateIsRevoked.
@Test(expected = WebCertServiceException.class)
public void testRenewalThrowsExceptionWhenOriginalCertificateIsRevoked() throws ModuleException, ModuleNotFoundException {
when(intygService.isRevoked(anyString(), anyString(), anyBoolean())).thenReturn(true);
CreateRenewalCopyRequest renewalRequest = buildRenewalRequest();
copyService.createRenewalCopy(renewalRequest);
}
Aggregations