@Test public void verifyMacro() { List<CompilationMessage> errors = Lists.newArrayList( new CompilationMessage(CompilationMessage.Type.ERROR, 1, 2, 3, 4, "message1"), new CompilationMessage(CompilationMessage.Type.WARNING, 5, 6, 7, 8, "message2")); when(macroFactory.verifyGroovyMacro(CODE)).thenReturn(errors); Map<String, Object> result = controller.verifyMacro(CODE); @SuppressWarnings("unchecked") List<Map<String, Object>> messages = (List<Map<String, Object>>) result.get("messages"); Map<String, Object> message = messages.get(0); assertEquals(CompilationMessage.Type.ERROR.name(), message.get("type")); assertEquals(1, (int) ((Integer) message.get("startLine"))); assertEquals(2, (int) ((Integer) message.get("startColumn"))); assertEquals(3, (int) ((Integer) message.get("endLine"))); assertEquals(4, (int) ((Integer) message.get("endColumn"))); assertEquals("message1", message.get("message")); message = messages.get(1); assertEquals(CompilationMessage.Type.WARNING.name(), message.get("type")); assertEquals(5, (int) ((Integer) message.get("startLine"))); assertEquals(6, (int) ((Integer) message.get("startColumn"))); assertEquals(7, (int) ((Integer) message.get("endLine"))); assertEquals(8, (int) ((Integer) message.get("endColumn"))); assertEquals("message2", message.get("message")); }
@RequestMapping(value="/verify/json", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") @ResponseBody public Map<String, Object> verifyMacro(@RequestParam String code) { Map<String, Object> result = Maps.newHashMap(); List<CompilationMessage> verificationMessages = macroFactory.verifyGroovyMacro(code); if (!verificationMessages.isEmpty()) { Function<CompilationMessage, Map<String, Object>> function = new Function<CompilationMessage, Map<String, Object>>() { @Override public Map<String, Object> apply(CompilationMessage message) { return toJson(message); } }; List<Map<String, Object>> messages = Lists.transform(verificationMessages, function); result.put("messages", messages); } return result; }
MacroController { @RequestMapping(value="/verify/json", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") @ResponseBody public Map<String, Object> verifyMacro(@RequestParam String code) { Map<String, Object> result = Maps.newHashMap(); List<CompilationMessage> verificationMessages = macroFactory.verifyGroovyMacro(code); if (!verificationMessages.isEmpty()) { Function<CompilationMessage, Map<String, Object>> function = new Function<CompilationMessage, Map<String, Object>>() { @Override public Map<String, Object> apply(CompilationMessage message) { return toJson(message); } }; List<Map<String, Object>> messages = Lists.transform(verificationMessages, function); result.put("messages", messages); } return result; } }
MacroController { @RequestMapping(value="/verify/json", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") @ResponseBody public Map<String, Object> verifyMacro(@RequestParam String code) { Map<String, Object> result = Maps.newHashMap(); List<CompilationMessage> verificationMessages = macroFactory.verifyGroovyMacro(code); if (!verificationMessages.isEmpty()) { Function<CompilationMessage, Map<String, Object>> function = new Function<CompilationMessage, Map<String, Object>>() { @Override public Map<String, Object> apply(CompilationMessage message) { return toJson(message); } }; List<Map<String, Object>> messages = Lists.transform(verificationMessages, function); result.put("messages", messages); } return result; }  }
MacroController { @RequestMapping(value="/verify/json", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") @ResponseBody public Map<String, Object> verifyMacro(@RequestParam String code) { Map<String, Object> result = Maps.newHashMap(); List<CompilationMessage> verificationMessages = macroFactory.verifyGroovyMacro(code); if (!verificationMessages.isEmpty()) { Function<CompilationMessage, Map<String, Object>> function = new Function<CompilationMessage, Map<String, Object>>() { @Override public Map<String, Object> apply(CompilationMessage message) { return toJson(message); } }; List<Map<String, Object>> messages = Lists.transform(verificationMessages, function); result.put("messages", messages); } return result; }  @RequestMapping(value="/create", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") String createMacro(Model model); @RequestMapping(value="/edit/{name:" + DocumentrConstants.MACRO_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") String editMacro(@PathVariable String name, Model model); @RequestMapping(value="/verify/json", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") @ResponseBody Map<String, Object> verifyMacro(@RequestParam String code); @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") String saveMacro(@ModelAttribute @Valid MacroForm form, BindingResult bindingResult); @RequestMapping(value="/delete/{name:" + DocumentrConstants.MACRO_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") String deleteMacro(@PathVariable String name); @ModelAttribute MacroForm createMacroForm(@RequestParam(required=false) String name,
			@RequestParam(required=false) String code); }
MacroController { @RequestMapping(value="/verify/json", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") @ResponseBody public Map<String, Object> verifyMacro(@RequestParam String code) { Map<String, Object> result = Maps.newHashMap(); List<CompilationMessage> verificationMessages = macroFactory.verifyGroovyMacro(code); if (!verificationMessages.isEmpty()) { Function<CompilationMessage, Map<String, Object>> function = new Function<CompilationMessage, Map<String, Object>>() { @Override public Map<String, Object> apply(CompilationMessage message) { return toJson(message); } }; List<Map<String, Object>> messages = Lists.transform(verificationMessages, function); result.put("messages", messages); } return result; }  @RequestMapping(value="/create", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") String createMacro(Model model); @RequestMapping(value="/edit/{name:" + DocumentrConstants.MACRO_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") String editMacro(@PathVariable String name, Model model); @RequestMapping(value="/verify/json", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") @ResponseBody Map<String, Object> verifyMacro(@RequestParam String code); @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") String saveMacro(@ModelAttribute @Valid MacroForm form, BindingResult bindingResult); @RequestMapping(value="/delete/{name:" + DocumentrConstants.MACRO_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") String deleteMacro(@PathVariable String name); @ModelAttribute MacroForm createMacroForm(@RequestParam(required=false) String name,
			@RequestParam(required=false) String code);  }