@Test public void shouldThrowErrorIfDisplayNameOfParameterIsMissing() throws Exception { expectedException.expect(DataException.class); expectedException.expectMessage("Error Message"); MultipartFile file = mock(MultipartFile.class); when(file.getOriginalFilename()).thenReturn("file.jrxml"); mockStatic(JasperCompileManager.class); JasperReport report = mock(JasperReport.class); InputStream inputStream = mock(InputStream.class); when(file.getInputStream()).thenReturn(inputStream); JRParameter param1 = mock(JRParameter.class); JRParameter param2 = mock(JRParameter.class); JRPropertiesMap propertiesMap = mock(JRPropertiesMap.class); when(messageService.message("report.template.parameter.display.name.missing", param1.getName())).thenReturn("Error Message"); when(report.getParameters()).thenReturn(new JRParameter[]{param1, param2}); when(JasperCompileManager.compileReport(inputStream)).thenReturn(report); when(param1.getPropertiesMap()).thenReturn(propertiesMap); String[] propertyNames = {"name1"}; when(propertiesMap.getPropertyNames()).thenReturn(propertyNames); when(propertiesMap.getProperty("displayName")).thenReturn(null); Template template = new Template(); service.validateFileAndInsertTemplate(template, file); verify(repository, never()).insertWithParameters(template); }
public void validateFileAndInsertTemplate(Template template, MultipartFile file) throws IOException { throwIfTemplateWithSameNameAlreadyExists(template.getName()); validateFile(template, file); repository.insertWithParameters(template); Right right = new Right(template.getName(), REPORTING); rightService.insertRight(right); ReportRight reportRight = new ReportRight(template, right); reportRightService.insert(reportRight); }
TemplateService { public void validateFileAndInsertTemplate(Template template, MultipartFile file) throws IOException { throwIfTemplateWithSameNameAlreadyExists(template.getName()); validateFile(template, file); repository.insertWithParameters(template); Right right = new Right(template.getName(), REPORTING); rightService.insertRight(right); ReportRight reportRight = new ReportRight(template, right); reportRightService.insert(reportRight); } }
TemplateService { public void validateFileAndInsertTemplate(Template template, MultipartFile file) throws IOException { throwIfTemplateWithSameNameAlreadyExists(template.getName()); validateFile(template, file); repository.insertWithParameters(template); Right right = new Right(template.getName(), REPORTING); rightService.insertRight(right); ReportRight reportRight = new ReportRight(template, right); reportRightService.insert(reportRight); }  }
TemplateService { public void validateFileAndInsertTemplate(Template template, MultipartFile file) throws IOException { throwIfTemplateWithSameNameAlreadyExists(template.getName()); validateFile(template, file); repository.insertWithParameters(template); Right right = new Right(template.getName(), REPORTING); rightService.insertRight(right); ReportRight reportRight = new ReportRight(template, right); reportRightService.insert(reportRight); }  List<Template> getAllTemplatesForUser(Long userId); Template getByName(String name); Template getById(Long id); Template getLWById(Long id); void validateFileAndInsertTemplate(Template template, MultipartFile file); Map<String, Object> getParametersMap(Template template, int userId, HttpServletRequest request, String format); }
TemplateService { public void validateFileAndInsertTemplate(Template template, MultipartFile file) throws IOException { throwIfTemplateWithSameNameAlreadyExists(template.getName()); validateFile(template, file); repository.insertWithParameters(template); Right right = new Right(template.getName(), REPORTING); rightService.insertRight(right); ReportRight reportRight = new ReportRight(template, right); reportRightService.insert(reportRight); }  List<Template> getAllTemplatesForUser(Long userId); Template getByName(String name); Template getById(Long id); Template getLWById(Long id); void validateFileAndInsertTemplate(Template template, MultipartFile file); Map<String, Object> getParametersMap(Template template, int userId, HttpServletRequest request, String format); static final String PDF_VIEW; static final String USER_ID_PARAM; }