Search in sources :

Example 6 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturServiceImplTest method clientGrpSignatureKOMPLTSuccess.

@Test
public void clientGrpSignatureKOMPLTSuccess() throws IOException, ModuleNotFoundException {
    completedUtkast.setRelationKod(RelationKod.KOMPLT);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    SignaturTicket ticket = intygSignatureService.createDraftHash(INTYG_ID, completedUtkast.getVersion());
    SignaturTicket status = intygSignatureService.ticketStatus(ticket.getId());
    assertEquals(SignaturTicket.Status.BEARBETAR, status.getStatus());
    String signature = "{\"signatur\":\"SIGNATURE\"}";
    when(mockUtkastRepository.save(any(Utkast.class))).thenReturn(completedUtkast);
    // Do the call
    SignaturTicket signatureTicket = intygSignatureService.clientGrpSignature(ticket.getId(), signature, user);
    verify(intygService).storeIntyg(completedUtkast);
    verify(notificationService).sendNotificationForDraftSigned(any(Utkast.class));
    // Assert pdl log
    verify(logService).logSignIntyg(any(LogRequest.class), isNull());
    assertNotNull(signatureTicket);
    assertNotNull(completedUtkast.getSignatur());
    assertEquals(UtkastStatus.SIGNED, completedUtkast.getStatus());
    // Assert ticket status has changed from BEARBETAR to SIGNERAD
    status = intygSignatureService.ticketStatus(ticket.getId());
    assertEquals(SignaturTicket.Status.SIGNERAD, status.getStatus());
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Example 7 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturServiceImplTest method serverSignatureSuccessUniqueIntyg.

@Test
public void serverSignatureSuccessUniqueIntyg() {
    Feature f = new Feature();
    f.setIntygstyper(ImmutableList.of(INTYG_TYPE));
    f.setGlobal(true);
    user.getFeatures().put(AuthoritiesConstants.FEATURE_UNIKT_INTYG, f);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    when(mockUtkastRepository.save(any(Utkast.class))).thenReturn(completedUtkast);
    when(mockUtkastRepository.findAllByPatientPersonnummerAndIntygsTypIn(any(String.class), anySet())).thenReturn(Collections.emptyList());
    SignaturTicket signatureTicket = intygSignatureService.serverSignature(INTYG_ID, completedUtkast.getVersion());
    verify(intygService).storeIntyg(completedUtkast);
    verify(notificationService).sendNotificationForDraftSigned(any(Utkast.class));
    verify(logService).logSignIntyg(any(LogRequest.class));
    assertNotNull(signatureTicket);
    assertNotNull(completedUtkast.getSignatur());
    assertEquals(UtkastStatus.SIGNED, completedUtkast.getStatus());
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Feature(se.inera.intyg.infra.security.common.model.Feature) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Example 8 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturServiceImplTest method serverSignatureKOMPLTSuccess.

@Test
public void serverSignatureKOMPLTSuccess() throws IOException, ModuleNotFoundException {
    completedUtkast.setRelationKod(RelationKod.KOMPLT);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    when(mockUtkastRepository.save(any(Utkast.class))).thenReturn(completedUtkast);
    // Do the call
    SignaturTicket signatureTicket = intygSignatureService.serverSignature(INTYG_ID, completedUtkast.getVersion());
    verify(intygService).storeIntyg(completedUtkast);
    verify(notificationService).sendNotificationForDraftSigned(any(Utkast.class));
    // Assert pdl log
    verify(logService).logSignIntyg(any(LogRequest.class));
    assertNotNull(signatureTicket);
    assertNotNull(completedUtkast.getSignatur());
    assertEquals(UtkastStatus.SIGNED, completedUtkast.getStatus());
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Example 9 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturServiceImplTest method userIsNotDoctorClientSignature.

@Test(expected = WebCertServiceException.class)
public void userIsNotDoctorClientSignature() throws IOException {
    user = createWebCertUser(false);
    when(webcertUserService.getUser()).thenReturn(user);
    SignaturTicket ticket = intygSignatureService.createDraftHash(INTYG_ID, completedUtkast.getVersion());
    intygSignatureService.clientSignature(ticket.getId(), "test");
}
Also used : SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Example 10 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturServiceImplTest method clientGrpSignatureSuccess.

@Test
public void clientGrpSignatureSuccess() throws IOException {
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    when(mockUtkastRepository.save(any(Utkast.class))).thenReturn(completedUtkast);
    SignaturTicket ticket = intygSignatureService.createDraftHash(INTYG_ID, completedUtkast.getVersion());
    SignaturTicket status = intygSignatureService.ticketStatus(ticket.getId());
    assertEquals(SignaturTicket.Status.BEARBETAR, status.getStatus());
    String signature = "{\"signatur\":\"SIGNATURE\"}";
    // Do the call
    SignaturTicket signatureTicket = intygSignatureService.clientGrpSignature(ticket.getId(), signature, user);
    verify(intygService).storeIntyg(completedUtkast);
    verify(notificationService).sendNotificationForDraftSigned(any(Utkast.class));
    // Assert pdl log
    verify(logService).logSignIntyg(any(LogRequest.class), isNull());
    assertNotNull(signatureTicket);
    assertNotNull(completedUtkast.getSignatur());
    assertEquals(UtkastStatus.SIGNED, completedUtkast.getStatus());
    // Assert ticket status has changed from BEARBETAR to SIGNERAD
    status = intygSignatureService.ticketStatus(ticket.getId());
    assertEquals(SignaturTicket.Status.SIGNERAD, status.getStatus());
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Aggregations

SignaturTicket (se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket)28 Test (org.junit.Test)15 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)12 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)10 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 SignaturTicketResponse (se.inera.intyg.webcert.web.web.controller.moduleapi.dto.SignaturTicketResponse)6 OptimisticLockException (javax.persistence.OptimisticLockException)5 POST (javax.ws.rs.POST)5 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)5 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)3 SignResponse (com.secmaker.netid.nias.v1.SignResponse)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Optional (java.util.Optional)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Transactional (org.springframework.transaction.annotation.Transactional)1