Search in sources :

Example 11 with CopyIntygRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testCreateRenewalCopyMissingPrivilege.

@Test(expected = AuthoritiesException.class)
public void testCreateRenewalCopyMissingPrivilege() {
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    WebCertUser user = new WebCertUser();
    addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    user.setOrigin("NORMAL");
    when(webcertUserService.getUser()).thenReturn(user);
    try {
        moduleApiController.createRenewal(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID);
    } finally {
        verifyZeroInteractions(copyUtkastService);
    }
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 12 with CopyIntygRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testCreateRenewalInvalidRequest.

@Test(expected = WebCertServiceException.class)
public void testCreateRenewalInvalidRequest() {
    WebCertUser user = new WebCertUser();
    addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_FORNYA_INTYG);
    user.setOrigin("NORMAL");
    when(webcertUserService.getUser()).thenReturn(user);
    try {
        moduleApiController.createRenewal(new CopyIntygRequest(), CERTIFICATE_TYPE, CERTIFICATE_ID);
    } finally {
        verifyZeroInteractions(copyUtkastService);
    }
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 13 with CopyIntygRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testCreateNewRenewWithCopyOkParamFalse.

@Test
public void testCreateNewRenewWithCopyOkParamFalse() {
    // Given
    final boolean copyOk = false;
    final String intygsTyp = "fk7263";
    setupUser(AuthoritiesConstants.PRIVILEGE_FORNYA_INTYG, intygsTyp, true, copyOk, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    // When
    try {
        moduleApiController.createRenewal(new CopyIntygRequest(), intygsTyp, "");
    } catch (WebCertServiceException wcse) {
        // Then an exception is thrown
        assertEquals(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, wcse.getErrorCode());
        assertEquals("Authorization failed due to false kopieraOK-parameter", wcse.getMessage());
        return;
    }
    fail("No or wrong exception was thrown");
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Test(org.junit.Test)

Example 14 with CopyIntygRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testCreateRenewalCopyMissingFeature.

@Test(expected = AuthoritiesException.class)
public void testCreateRenewalCopyMissingFeature() {
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    WebCertUser user = new WebCertUser();
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_FORNYA_INTYG);
    user.setOrigin("NORMAL");
    when(webcertUserService.getUser()).thenReturn(user);
    try {
        moduleApiController.createRenewal(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID);
    } finally {
        verifyZeroInteractions(copyUtkastService);
    }
}
Also used : CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 15 with CopyIntygRequest

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testCreateUtkastFromTemplate.

@Test
public void testCreateUtkastFromTemplate() {
    final String personnummer = "191212121212";
    final String newIntygId = "newIntygId";
    final String newCertificateType = "newCertificateType";
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    WebCertUser user = new WebCertUser();
    addFeatures(user, newCertificateType, AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST);
    addPrivileges(user, newCertificateType, AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG);
    user.setOrigin("NORMAL");
    ArgumentCaptor<CreateUtkastFromTemplateRequest> captor = ArgumentCaptor.forClass(CreateUtkastFromTemplateRequest.class);
    when(copyUtkastService.createUtkastFromTemplate(captor.capture())).thenReturn(new CreateUtkastFromTemplateResponse(newCertificateType, newIntygId, CERTIFICATE_ID));
    when(webcertUserService.getUser()).thenReturn(user);
    Response response = moduleApiController.createUtkastFromTemplate(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID, newCertificateType);
    verify(copyUtkastService).createUtkastFromTemplate(any());
    verifyNoMoreInteractions(copyUtkastService);
    assertEquals(newIntygId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId());
    assertEquals(newCertificateType, ((CopyIntygResponse) response.getEntity()).getIntygsTyp());
}
Also used : CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) Response(javax.ws.rs.core.Response) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) CreateUtkastFromTemplateRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)24 CopyIntygRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest)24 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)15 HashMap (java.util.HashMap)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)8 BaseRestIntegrationTest (se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)8 Response (javax.ws.rs.core.Response)6 CreateCompletionCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse)6 CreateRenewalCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse)6 CreateReplacementCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse)6 CreateUtkastFromTemplateResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse)6 CopyIntygResponse (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse)6 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)4 CreateRenewalCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest)3 JsonPath (com.jayway.restassured.path.json.JsonPath)2 Response (com.jayway.restassured.response.Response)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Personnummer (se.inera.intyg.schemas.contract.Personnummer)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1