use of se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf in project webcert by sklintyg.
the class IntygModuleApiControllerTest method testGetIntygAsPdf.
@Test
public void testGetIntygAsPdf() {
final String intygType = "fk7263";
setupUser(AuthoritiesConstants.PRIVILEGE_VISA_INTYG, intygType, false, true, AuthoritiesConstants.FEATURE_UTSKRIFT);
IntygPdf pdfResponse = new IntygPdf(PDF_DATA, PDF_NAME);
when(intygService.fetchIntygAsPdf(CERTIFICATE_ID, intygType, false)).thenReturn(pdfResponse);
Response response = moduleApiController.getIntygAsPdf(intygType, CERTIFICATE_ID);
verify(intygService).fetchIntygAsPdf(CERTIFICATE_ID, intygType, false);
assertEquals(OK.getStatusCode(), response.getStatus());
assertEquals(PDF_DATA, response.getEntity());
assertNotNull(response.getHeaders().get(CONTENT_DISPOSITION));
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf in project webcert by sklintyg.
the class IntygModuleApiControllerTest method testGetIntygAsPdfForEmployer.
@Test
public void testGetIntygAsPdfForEmployer() {
final String intygType = "fk7263";
setupUser(AuthoritiesConstants.PRIVILEGE_VISA_INTYG, intygType, false, true, AuthoritiesConstants.FEATURE_ARBETSGIVARUTSKRIFT);
IntygPdf pdfResponse = new IntygPdf(PDF_DATA, PDF_NAME);
when(intygService.fetchIntygAsPdf(CERTIFICATE_ID, intygType, true)).thenReturn(pdfResponse);
Response response = moduleApiController.getIntygAsPdfForEmployer(intygType, CERTIFICATE_ID);
verify(intygService).fetchIntygAsPdf(CERTIFICATE_ID, intygType, true);
assertEquals(OK.getStatusCode(), response.getStatus());
assertEquals(PDF_DATA, response.getEntity());
assertNotNull(response.getHeaders().get(CONTENT_DISPOSITION));
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf in project webcert by sklintyg.
the class IntygServiceTest method testFetchIntygAsPdfFromWebCert.
@SuppressWarnings("unchecked")
@Test
public void testFetchIntygAsPdfFromWebCert() throws IOException, IntygModuleFacadeException {
when(utkastRepository.findOne(CERTIFICATE_ID)).thenReturn(getIntyg(CERTIFICATE_ID, LocalDateTime.now(), null));
when(moduleFacade.convertFromInternalToPdfDocument(anyString(), anyString(), anyList(), anyBoolean())).thenReturn(buildPdfDocument());
IntygPdf intygPdf = intygService.fetchIntygAsPdf(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
assertNotNull(intygPdf);
verify(utkastRepository, times(1)).findOne(anyString());
verify(logservice).logPrintIntygAsPDF(any(LogRequest.class));
verifyNoMoreInteractions(logservice);
verify(moduleFacade, times(0)).getCertificate(CERTIFICATE_ID, CERTIFICATE_TYPE);
// Verify that the enhetsAuth verification was performed.
verify(webCertUserService, times(1)).isAuthorizedForUnit(anyString(), anyString(), anyBoolean());
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf in project webcert by sklintyg.
the class IntygServiceTest method testFetchRevokedIntygAsPdfFromWebCert.
@SuppressWarnings("unchecked")
@Test
public void testFetchRevokedIntygAsPdfFromWebCert() throws IOException, IntygModuleFacadeException {
when(utkastRepository.findOne(CERTIFICATE_ID)).thenReturn(getIntyg(CERTIFICATE_ID, LocalDateTime.now(), LocalDateTime.now()));
when(moduleFacade.convertFromInternalToPdfDocument(anyString(), anyString(), anyList(), anyBoolean())).thenReturn(buildPdfDocument());
IntygPdf intygPdf = intygService.fetchIntygAsPdf(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
assertNotNull(intygPdf);
verify(utkastRepository, times(1)).findOne(anyString());
verify(logservice).logPrintRevokedIntygAsPDF(any(LogRequest.class));
verifyNoMoreInteractions(logservice);
verify(moduleFacade, times(0)).getCertificate(CERTIFICATE_ID, CERTIFICATE_TYPE);
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf in project webcert by sklintyg.
the class IntygModuleFacadeImpl method convertFromInternalToPdfDocument.
@Override
public IntygPdf convertFromInternalToPdfDocument(String intygType, String internalIntygJsonModel, List<Status> statuses, boolean isEmployer) throws IntygModuleFacadeException {
boolean isUtkast = isUtkast(statuses);
try {
ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
PdfResponse pdfResponse;
if (!isEmployer) {
pdfResponse = moduleApi.pdf(internalIntygJsonModel, statuses, ApplicationOrigin.WEBCERT, isUtkast);
} else {
pdfResponse = moduleApi.pdfEmployer(internalIntygJsonModel, statuses, ApplicationOrigin.WEBCERT, Collections.emptyList(), isUtkast);
}
return new IntygPdf(pdfResponse.getPdfData(), pdfResponse.getFilename());
} catch (ModuleException me) {
LOG.error("ModuleException occured when when generating PDF document from internal");
throw new IntygModuleFacadeException("ModuleException occured when generating PDF document from internal", me);
} catch (ModuleNotFoundException e) {
LOG.error("ModuleNotFoundException occured for intygstyp '{}' when generating PDF document from internal", intygType);
throw new IntygModuleFacadeException("ModuleNotFoundException occured when registering certificate", e);
}
}
Aggregations