use of se.inera.intyg.webcert.common.model.WebcertCertificateRelation in project webcert by sklintyg.
the class IntygServiceSendTest method testSendIntygFailsForReplacedCertificate.
@Test(expected = WebCertServiceException.class)
public void testSendIntygFailsForReplacedCertificate() throws Exception {
final String completionMeddelandeId = "meddelandeId";
WebCertUser webCertUser = createUser();
Utlatande completionUtlatande = utlatande;
completionUtlatande.getGrundData().setRelation(new Relation());
completionUtlatande.getGrundData().getRelation().setRelationKod(RelationKod.KOMPLT);
completionUtlatande.getGrundData().getRelation().setMeddelandeId(completionMeddelandeId);
when(webCertUserService.isAuthorizedForUnit(anyString(), anyString(), anyBoolean())).thenReturn(true);
when(webCertUserService.getUser()).thenReturn(webCertUser);
when(intygRepository.findOne(INTYG_ID)).thenReturn(getUtkast(INTYG_ID));
WebcertCertificateRelation ersattRelation = new WebcertCertificateRelation(INTYG_ID, RelationKod.ERSATT, LocalDateTime.now(), UtkastStatus.SIGNED);
when(certificateRelationService.getNewestRelationOfType(eq(INTYG_ID), eq(RelationKod.ERSATT), eq(Arrays.asList(UtkastStatus.SIGNED)))).thenReturn(Optional.of(ersattRelation));
CertificateMetaData metaData = new CertificateMetaData();
metaData.setStatus(new ArrayList<>());
CertificateResponse revokedCertificateResponse = new CertificateResponse(json, utlatande, metaData, false);
when(moduleFacade.getCertificate(any(String.class), any(String.class))).thenReturn(revokedCertificateResponse);
when(moduleFacade.getUtlatandeFromInternalModel(any(), any())).thenReturn(utlatande);
intygService.sendIntyg(INTYG_ID, INTYG_TYP_FK, "FKASSA", false);
verifyZeroInteractions(logService);
}
use of se.inera.intyg.webcert.common.model.WebcertCertificateRelation in project webcert by sklintyg.
the class CopyUtkastServiceImplTest method testRenewalCopyFailIfSignedReplacementExists.
@Test(expected = WebCertServiceException.class)
public void testRenewalCopyFailIfSignedReplacementExists() throws Exception {
final String reference = "ref";
WebCertUser user = new WebCertUser();
user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
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 renewalCopyRequest = buildRenewalRequest();
try {
CreateRenewalCopyResponse copyResp = copyService.createRenewalCopy(renewalCopyRequest);
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.common.model.WebcertCertificateRelation 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.common.model.WebcertCertificateRelation in project webcert by sklintyg.
the class IntygRelationHelperImplTest method testGetRelationsForIntygNothingInITWithMergeFromWebcert.
@Test
public void testGetRelationsForIntygNothingInITWithMergeFromWebcert() {
when(listRelationsForCertificateResponderInterface.listRelationsForCertificate(isNull(), any(ListRelationsForCertificateType.class))).thenReturn(new ListRelationsForCertificateResponseType());
Relations webcertRelations = new Relations();
Relations.FrontendRelations fr = webcertRelations.getLatestChildRelations();
fr.setReplacedByIntyg(new WebcertCertificateRelation(OTHER_INTYG_ID_2, RelationKod.ERSATT, LocalDateTime.now().minusDays(1), UtkastStatus.SIGNED));
fr.setReplacedByUtkast(new WebcertCertificateRelation(OTHER_INTYG_ID_2, RelationKod.ERSATT, LocalDateTime.now().minusDays(1), UtkastStatus.DRAFT_COMPLETE));
fr.setComplementedByIntyg(new WebcertCertificateRelation(OTHER_INTYG_ID_2, RelationKod.KOMPLT, LocalDateTime.now().minusDays(2), UtkastStatus.SIGNED));
fr.setComplementedByUtkast(new WebcertCertificateRelation(OTHER_INTYG_ID_2, RelationKod.KOMPLT, LocalDateTime.now().minusDays(2), UtkastStatus.DRAFT_INCOMPLETE));
webcertRelations.setParent(new WebcertCertificateRelation(PARENT_INTYG_1, RelationKod.KOMPLT, LocalDateTime.now().minusDays(3), UtkastStatus.SIGNED));
when(certificateRelationService.getRelations(INTYG_ID)).thenReturn(webcertRelations);
Relations relationsForIntyg = testee.getRelationsForIntyg(INTYG_ID);
assertNotNull(relationsForIntyg);
assertFrontendRelations(relationsForIntyg.getLatestChildRelations(), webcertRelations.getLatestChildRelations().getComplementedByIntyg(), webcertRelations.getLatestChildRelations().getComplementedByUtkast(), webcertRelations.getLatestChildRelations().getReplacedByIntyg(), webcertRelations.getLatestChildRelations().getReplacedByUtkast());
}
use of se.inera.intyg.webcert.common.model.WebcertCertificateRelation in project webcert by sklintyg.
the class IntygRelationHelperImplTest method buildWebcertRelations.
private Relations buildWebcertRelations() {
Relations relations = new Relations();
Relations.FrontendRelations fr = relations.getLatestChildRelations();
fr.setReplacedByUtkast(new WebcertCertificateRelation(OTHER_INTYG_ID_2, RelationKod.ERSATT, LocalDateTime.now().minusDays(1), UtkastStatus.DRAFT_COMPLETE));
fr.setComplementedByIntyg(new WebcertCertificateRelation(OTHER_INTYG_ID_3, RelationKod.KOMPLT, LocalDateTime.now().minusDays(2), UtkastStatus.SIGNED));
return relations;
}
Aggregations