Search in sources :

Example 11 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class ArendeServiceTest method testProcessIncomingMessageSendsNotificationForAnswerRecieved.

@Test
public void testProcessIncomingMessageSendsNotificationForAnswerRecieved() throws WebCertServiceException {
    final String frageid = "frageid";
    Arende fragearende = new Arende();
    Arende svararende = new Arende();
    svararende.setIntygsId(INTYG_ID);
    svararende.setSvarPaId(frageid);
    Utkast utkast = buildUtkast();
    when(utkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
    when(arendeRepository.findOneByMeddelandeId(eq(frageid))).thenReturn(fragearende);
    Arende res = service.processIncomingMessage(svararende);
    assertNotNull(res);
    assertEquals(INTYG_ID, res.getIntygsId());
    verify(arendeRepository).findOneByMeddelandeId(eq(frageid));
    verify(arendeRepository, times(2)).save(any(Arende.class));
    verify(notificationService).sendNotificationForAnswerRecieved(any(Arende.class));
    verifyZeroInteractions(arendeDraftService);
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 12 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class ArendeServiceTest method testCreateQuestionIfCertificateIsRevoked.

@Test
public void testCreateQuestionIfCertificateIsRevoked() throws WebCertServiceException {
    Utkast utkast = buildUtkast();
    utkast.setAterkalladDatum(LocalDateTime.now());
    when(utkastRepository.findOne(anyString())).thenReturn(utkast);
    try {
        service.createMessage(INTYG_ID, ArendeAmne.KONTKT, "rubrik", "meddelande");
        fail("Should throw");
    } catch (WebCertServiceException e) {
        assertEquals(WebCertServiceErrorCodeEnum.CERTIFICATE_REVOKED, e.getErrorCode());
        verify(arendeRepository, never()).save(any(Arende.class));
        verifyZeroInteractions(notificationService);
        verifyZeroInteractions(arendeDraftService);
    }
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Test(org.junit.Test)

Example 13 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class ArendeServiceTest method createQuestionTest.

@Test
public void createQuestionTest() throws CertificateSenderException {
    LocalDateTime now = LocalDateTime.now();
    Utkast utkast = buildUtkast();
    doReturn(utkast).when(utkastRepository).findOne(anyString());
    when(webcertUserService.isAuthorizedForUnit(isNull(), anyBoolean())).thenReturn(true);
    when(webcertUserService.getUser()).thenReturn(new WebCertUser());
    Arende arende = new Arende();
    arende.setSenasteHandelse(now);
    ArendeConversationView result = service.createMessage(INTYG_ID, ArendeAmne.KONTKT, "rubrik", "meddelande");
    assertNotNull(result.getFraga());
    assertNull(result.getSvar());
    assertEquals(FIXED_TIME_INSTANT, result.getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
    verify(webcertUserService).isAuthorizedForUnit(isNull(), anyBoolean());
    verify(arendeRepository).save(any(Arende.class));
    verify(monitoringLog).logArendeCreated(anyString(), isNull(), isNull(), any(ArendeAmne.class), anyBoolean());
    verify(certificateSenderService).sendMessageToRecipient(anyString(), anyString());
    verify(notificationService).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_QUESTION_FROM_CARE);
    verify(arendeDraftService).delete(INTYG_ID, null);
}
Also used : LocalDateTime(java.time.LocalDateTime) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 14 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class ArendeServiceTest method testProcessIncomingMessageCertificateNotSigned.

@Test
public void testProcessIncomingMessageCertificateNotSigned() {
    when(utkastRepository.findOne(isNull())).thenReturn(new Utkast());
    try {
        service.processIncomingMessage(new Arende());
        fail("Should throw");
    } catch (WebCertServiceException e) {
        assertEquals(WebCertServiceErrorCodeEnum.INVALID_STATE, e.getErrorCode());
        verify(arendeRepository, never()).save(any(Arende.class));
        verifyZeroInteractions(notificationService);
        verifyZeroInteractions(arendeDraftService);
    }
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Test(org.junit.Test)

Example 15 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class ArendeServiceTest method testProcessIncomingMessageSendsNotificationForQuestionReceived.

@Test
public void testProcessIncomingMessageSendsNotificationForQuestionReceived() throws WebCertServiceException {
    Arende arende = new Arende();
    arende.setIntygsId(INTYG_ID);
    Utkast utkast = buildUtkast();
    when(utkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
    Arende res = service.processIncomingMessage(arende);
    assertNotNull(res);
    assertEquals(INTYG_ID, res.getIntygsId());
    verify(utkastRepository).findOne(INTYG_ID);
    verify(notificationService).sendNotificationForQuestionReceived(any(Arende.class));
    verifyZeroInteractions(arendeDraftService);
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Test(org.junit.Test)

Aggregations

Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)171 Test (org.junit.Test)88 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)34 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)24 Personnummer (se.inera.intyg.schemas.contract.Personnummer)21 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)21 VardpersonReferens (se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)21 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)18 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)17 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)16 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)14 CreateNewDraftRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest)13 Patient (se.inera.intyg.common.support.model.common.internal.Patient)12 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)12 ListIntygEntry (se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry)12 Transactional (org.springframework.transaction.annotation.Transactional)11 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)11 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)11 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)10 ArrayList (java.util.ArrayList)9