AdminController extends AbstractController { @RequestMapping(value = "/downloadPdf.html", method = RequestMethod.GET) public String downloadConsentPdfFile(HttpServletRequest request, HttpServletResponse response, @RequestParam("consentId") long consentId) { AbstractPdfDto pdfDto = consentService.findConsentContentDto(consentId); try { OutputStream out = response.getOutputStream(); response.setContentType("application/pdf"); IOUtils.copy(new ByteArrayInputStream(pdfDto.getContent()), out); out.flush(); out.close(); eventService.raiseSecurityEvent(new FileDownloadedEvent(request .getRemoteAddr(), "Admin_User_" + userContext.getCurrentUser().getUsername(), "Consent_" + consentId)); } catch (IOException e) { logger.warn("Error while reading pdf file."); logger.warn("The exception is: ", e); } return null; }  @RequestMapping(value = "adminHome.html") String adminHome(Model model, HttpServletRequest request,
			BasicPatientAccountDto basicPatientAccountDto); @RequestMapping(value = "adminPatientView.html") String adminPatientViewByPatientId(
			Model model,
			@RequestParam(value = "id", required = false, defaultValue = "-1") long patientId,
			@RequestParam(value = "username", required = false) String userName,
			@RequestParam(value = "notify", required = false) String notify,
			@RequestParam(value = "status", required = false) String status,
			@RequestParam(value = "duplicateconsent", required = false) String duplicateConsent); @RequestMapping(value = "adminPatientViewSubmitConsent.html", method = RequestMethod.POST) String adminPatientViewSubmitConsent(
			@RequestParam(value = "consentId") long consentId,
			@RequestParam(value = "patientId") long patientId); @RequestMapping(value = "adminPatientViewDeleteConsent", method = RequestMethod.POST) String adminPatientViewDeleteConsent(
			@RequestParam(value = "consentId") long consentId,
			@RequestParam(value = "patientId") long patientId); @RequestMapping(value = "adminEditPatientProfile.html", method = RequestMethod.POST) String adminEditPatientProfile(
			@Valid PatientProfileDto patientProfileDto,
			BindingResult bindingResult, Model model); @RequestMapping(value = "adminPatientViewCreateConsent.html") String adminPatientViewCreateConsent(
			@RequestParam(value = "id", defaultValue = "-1") long patientId,
			Model model); @RequestMapping(value = "adminPatientViewCreateConsent.html", method = RequestMethod.POST) @ResponseBody String adminPatientViewCreateConsent(
			@Valid ConsentDto consentDto,
			@RequestParam("patientId") long patientId,
			BindingResult bindingResult,
			Model model,
			@RequestParam(value = "ICD9", required = false) HashSet<String> icd9,
			@RequestParam(value = "isAddConsent") boolean isAddConsent); @RequestMapping(value = "adminPatientViewRevokeConsent.html", method = RequestMethod.POST) String signConsentRevokation(
			@RequestParam("consentId") long consentId,
			@RequestParam("revokationType") String revokationType,
			@RequestParam("patientId") long patientId); @RequestMapping(value = "adminPatientViewEditConsent.html") String adminPatientViewEditConsent(
			@RequestParam(value = "consentId", defaultValue = "-1") long consentId,
			@RequestParam("patientId") long patientId, Model model); @RequestMapping(value = "editAdminProfile.html") String editAdminProfile(Model model); @RequestMapping(value = "editAdminProfile.html", method = RequestMethod.POST) String profile(@Valid AdminProfileDto adminProfileDto,
			BindingResult bindingResult, Model model); @RequestMapping(value = "/downloadPdf.html", method = RequestMethod.GET) String downloadConsentPdfFile(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam("consentId") long consentId); @RequestMapping(value = "adminCreatePatientAccount.html", method = RequestMethod.POST) String adminCreatePatientAccount(
			@Valid BasicPatientAccountDto basicPatientAccountDto,
			BindingResult result, RedirectAttributes redirectAttributes,
			Model model); @RequestMapping(value = "sendLoginInformation.html", method = RequestMethod.GET) @ResponseBody String adminSendLoginInfoEmail(
			@RequestParam("patientId") long patientId,
			HttpServletRequest request); @RequestMapping("/patientlookup/query") @ResponseStatus(HttpStatus.OK) @ResponseBody List<PatientAdminDto> getByFirstAndLastName(
			@RequestParam(value = "token", required = true) String token); @RequestMapping(value = "connectionProviderAdd.html", method = RequestMethod.POST) @ResponseBody String addProvider(
			@RequestParam("npi") String npi,
			@RequestParam(value = "patientusername", defaultValue = "") String patientUserName,
			@RequestParam("patientId") String patientId); @RequestMapping(value = "/deleteIndividualProvider", method = RequestMethod.POST) @ResponseBody String deleteIndividualProvider(
			@RequestParam("individualProviderid") long individualProviderid,
			@RequestParam("patientId") String patientId, Model model); @RequestMapping(value = "/deleteOrganizationalProvider", method = RequestMethod.POST) @ResponseBody String deleteOrganizationalProvider(
			@RequestParam("organizationalProviderid") long organizationalProviderid,
			@RequestParam("patientId") String patientId, Model model); @RequestMapping(value = "/addStaffFavoriteIndividualProvider", method = RequestMethod.POST) @ResponseBody String addStaffFavoriteIndividualProvider(
			@RequestParam("providerid") long providerId); @RequestMapping(value = "/isStaffFavoriteIndividualProvider", method = RequestMethod.GET) @ResponseBody String isStaffFavoriteIndividualProvider(
			@RequestParam("providerid") long providerId); @RequestMapping(value = "/isStaffFavoriteOrganizationalProvider", method = RequestMethod.GET) @ResponseBody String isStaffFavoriteOrganizationalProvider(
			@RequestParam("providerid") long providerId); @RequestMapping(value = "/addStaffFavoriteOrganizationalProvider", method = RequestMethod.POST) @ResponseBody String addStaffFavoriteOrganizationalProvider(
			@RequestParam("providerid") long providerId); @RequestMapping(value = "providerSearch.html", method = RequestMethod.GET) String ajaxProviderSearch(HttpServletRequest request,
			HttpServletResponse response); HashMap<String, String> deserializeResult(String providerDtoJSON); static final int NPI_LENGTH; }
@Test public void testDownloadConsentPdfFile() throws Exception { AuthenticatedUser user = mock(AuthenticatedUser.class); doReturn(user).when(userContext).getCurrentUser(); doReturn("user1").when(user).getUsername(); AbstractPdfDto pdfDto = mock(AbstractPdfDto.class); byte[] byteArray = new byte[] { 1, 2, 3 }; when(pdfDto.getContent()).thenReturn(byteArray); when(consentService.findConsentContentDto(anyLong())) .thenReturn(pdfDto); mockMvc.perform( get("/Administrator/downloadPdf.html").param("consentId", "1")) .andExpect(status().isOk()); verify(consentService).findConsentContentDto((long) 1); }