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);
}
}
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);
}
}
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");
}
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);
}
}
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());
}
Aggregations