Search in sources :

Example 1 with Fk7263EntryPoint

use of se.inera.intyg.common.fk7263.support.Fk7263EntryPoint in project webcert by sklintyg.

the class IntygServiceTest method testHandleSignedWithSigneraSkickaDirekt.

@Test
public void testHandleSignedWithSigneraSkickaDirekt() throws Exception {
    final String intygId = "intygId";
    final String intygTyp = "intygTyp";
    final String relationIntygId = "relationIntygId";
    final String recipient = new Fk7263EntryPoint().getDefaultRecipient();
    final Personnummer personnummer = PERSNR;
    Fk7263Utlatande utlatande = objectMapper.readValue(json, Fk7263Utlatande.class);
    utlatande.setId(intygId);
    utlatande.setTyp(intygTyp);
    utlatande.getGrundData().getPatient().setPersonId(personnummer);
    Utkast utkast = new Utkast();
    utkast.setIntygsId(intygId);
    utkast.setIntygsTyp(intygTyp);
    utkast.setModel(json);
    when(utkastRepository.findOne(intygId)).thenReturn(utkast);
    when(moduleFacade.getUtlatandeFromInternalModel(eq(intygTyp), anyString())).thenReturn(utlatande);
    when(certificateRelationService.getNewestRelationOfType(eq(intygId), eq(RelationKod.ERSATT), eq(Arrays.asList(UtkastStatus.SIGNED)))).thenReturn(Optional.empty());
    when(moduleRegistry.getModuleEntryPoint(intygTyp)).thenReturn(new Fk7263EntryPoint());
    when(authoritiesHelper.isFeatureActive(AuthoritiesConstants.FEATURE_SIGNERA_SKICKA_DIREKT, intygTyp)).thenReturn(true);
    intygService.handleAfterSigned(utkast);
    verify(certificateSenderService).sendCertificate(eq(intygId), eq(personnummer), anyString(), eq(recipient), eq(true));
    verify(mockMonitoringService).logIntygSent(intygId, recipient);
    verify(logservice).logSendIntygToRecipient(any(LogRequest.class));
    verify(arendeService, never()).closeCompletionsAsHandled(relationIntygId, intygTyp);
    verify(notificationService).sendNotificationForIntygSent(intygId);
    ArgumentCaptor<Utkast> utkastCaptor = ArgumentCaptor.forClass(Utkast.class);
    verify(utkastRepository).save(utkastCaptor.capture());
    assertNotNull(utkastCaptor.getValue().getSkickadTillMottagareDatum());
    assertEquals(recipient, utkastCaptor.getValue().getSkickadTillMottagare());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) Test(org.junit.Test)

Example 2 with Fk7263EntryPoint

use of se.inera.intyg.common.fk7263.support.Fk7263EntryPoint in project webcert by sklintyg.

the class IntygServiceTest method testHandleSignedCompletion.

@Test
public void testHandleSignedCompletion() throws Exception {
    final String intygId = "intygId";
    final String intygTyp = "intygTyp";
    final String relationIntygId = "relationIntygId";
    final String recipient = new Fk7263EntryPoint().getDefaultRecipient();
    final Personnummer personnummer = PERSNR;
    Fk7263Utlatande utlatande = objectMapper.readValue(json, Fk7263Utlatande.class);
    utlatande.setId(intygId);
    utlatande.setTyp(intygTyp);
    utlatande.getGrundData().getPatient().setPersonId(personnummer);
    Utkast utkast = new Utkast();
    utkast.setIntygsId(intygId);
    utkast.setIntygsTyp(intygTyp);
    utkast.setRelationKod(RelationKod.KOMPLT);
    utkast.setRelationIntygsId(relationIntygId);
    utkast.setModel(json);
    when(utkastRepository.findOne(intygId)).thenReturn(utkast);
    when(moduleFacade.getUtlatandeFromInternalModel(eq(intygTyp), anyString())).thenReturn(utlatande);
    when(certificateRelationService.getNewestRelationOfType(eq(intygId), eq(RelationKod.ERSATT), eq(Arrays.asList(UtkastStatus.SIGNED)))).thenReturn(Optional.empty());
    when(moduleRegistry.getModuleEntryPoint(intygTyp)).thenReturn(new Fk7263EntryPoint());
    intygService.handleAfterSigned(utkast);
    verify(certificateSenderService).sendCertificate(eq(intygId), eq(personnummer), anyString(), eq(recipient), eq(true));
    verify(mockMonitoringService).logIntygSent(intygId, recipient);
    verify(logservice).logSendIntygToRecipient(any(LogRequest.class));
    verify(arendeService).closeCompletionsAsHandled(relationIntygId, intygTyp);
    verify(notificationService).sendNotificationForIntygSent(intygId);
    ArgumentCaptor<Utkast> utkastCaptor = ArgumentCaptor.forClass(Utkast.class);
    verify(utkastRepository).save(utkastCaptor.capture());
    assertNotNull(utkastCaptor.getValue().getSkickadTillMottagareDatum());
    assertEquals(recipient, utkastCaptor.getValue().getSkickadTillMottagare());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)2 Fk7263EntryPoint (se.inera.intyg.common.fk7263.support.Fk7263EntryPoint)2 Personnummer (se.inera.intyg.schemas.contract.Personnummer)2 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)2 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)2