@Test public void testGetTemplateConfigurations() throws Exception { List<EmailTemplateConfiguration> configurationList = new ArrayList<>(); EmailTemplateConfiguration configuration = setupConfiguration(EMAIL_PATTERN, Arrays.asList(CASE_FILE, COMPLAINT), EmailSource.MANUAL, TEMPLATE_NAME, Arrays.asList(SEND_AS_ATTACHMENTS, SEND_AS_LINKS)); configurationList.add(configuration); when(mailService.getTemplateConfigurations()).thenReturn(configurationList); MvcResult result = mockMvc.perform(get(CONTROLLER_PATH).accept(MediaType.parseMediaType("application/json;charset=UTF-8"))) .andReturn(); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); assertTrue(result.getResponse().getContentType().startsWith(MediaType.APPLICATION_JSON_VALUE)); String responseString = result.getResponse().getContentAsString(); log.info("results: " + responseString); ObjectMapper objectMapper = new ObjectMapper(); List<EmailTemplateConfiguration> readConfigurationList = objectMapper.readValue(responseString, objectMapper.getTypeFactory().constructParametricType(List.class, EmailTemplateConfiguration.class)); assertThat(readConfigurationList.size(), is(1)); EmailTemplateConfiguration readConfiguration = readConfigurationList.get(0); assertThat(readConfiguration.getEmailPattern(), is(EMAIL_PATTERN)); assertThat(readConfiguration.getSource(), is(EmailSource.MANUAL)); assertThat(readConfiguration.getTemplateName(), is(TEMPLATE_NAME)); assertThat(readConfiguration.getObjectTypes().size(), is(2)); assertThat(readConfiguration.getObjectTypes().contains(CASE_FILE), is(true)); assertThat(readConfiguration.getObjectTypes().contains(COMPLAINT), is(true)); assertThat(readConfiguration.getActions().size(), is(2)); assertThat(readConfiguration.getActions().contains(SEND_AS_ATTACHMENTS), is(true)); assertThat(readConfiguration.getActions().contains(SEND_AS_LINKS), is(true)); }
@RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public List<EmailTemplateConfiguration> getTemplateConfigurations() throws AcmEmailConfigurationException { return mailService.getTemplateConfigurations(); }
AcmMailTemplateConfigurationServiceAPIController { @RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public List<EmailTemplateConfiguration> getTemplateConfigurations() throws AcmEmailConfigurationException { return mailService.getTemplateConfigurations(); } }
AcmMailTemplateConfigurationServiceAPIController { @RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public List<EmailTemplateConfiguration> getTemplateConfigurations() throws AcmEmailConfigurationException { return mailService.getTemplateConfigurations(); }  }
AcmMailTemplateConfigurationServiceAPIController { @RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public List<EmailTemplateConfiguration> getTemplateConfigurations() throws AcmEmailConfigurationException { return mailService.getTemplateConfigurations(); }  @RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody List<EmailTemplateConfiguration> getTemplateConfigurations(); @RequestMapping(method = RequestMethod.PUT, consumes = { "multipart/mixed", MediaType.MULTIPART_FORM_DATA_VALUE }) ResponseEntity<?> updateEmailTemplate(@RequestPart("data") EmailTemplateConfiguration templateConfiguration,
            @RequestPart(value = "file", required = false) MultipartFile template); @RequestMapping(path = "/validate", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody EmailTemplateValidationResponse validateEmailTemplate(@RequestBody EmailTemplateConfiguration templateConfiguration); @RequestMapping(path = "/{templateName:.+}", method = RequestMethod.DELETE) ResponseEntity<?> deleteEmailTemplate(@PathVariable(value = "templateName") String templateName); @RequestMapping(path = "/{templateName:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody Map<String, String> getEmailTemplate(@PathVariable(value = "templateName") String templateName); @ExceptionHandler(AcmEmailConfigurationException.class) @ResponseBody ResponseEntity<?> handleConfigurationException(AcmEmailServiceException ce); void setMailService(AcmMailTemplateConfigurationService mailService); }
AcmMailTemplateConfigurationServiceAPIController { @RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public List<EmailTemplateConfiguration> getTemplateConfigurations() throws AcmEmailConfigurationException { return mailService.getTemplateConfigurations(); }  @RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody List<EmailTemplateConfiguration> getTemplateConfigurations(); @RequestMapping(method = RequestMethod.PUT, consumes = { "multipart/mixed", MediaType.MULTIPART_FORM_DATA_VALUE }) ResponseEntity<?> updateEmailTemplate(@RequestPart("data") EmailTemplateConfiguration templateConfiguration,
            @RequestPart(value = "file", required = false) MultipartFile template); @RequestMapping(path = "/validate", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody EmailTemplateValidationResponse validateEmailTemplate(@RequestBody EmailTemplateConfiguration templateConfiguration); @RequestMapping(path = "/{templateName:.+}", method = RequestMethod.DELETE) ResponseEntity<?> deleteEmailTemplate(@PathVariable(value = "templateName") String templateName); @RequestMapping(path = "/{templateName:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody Map<String, String> getEmailTemplate(@PathVariable(value = "templateName") String templateName); @ExceptionHandler(AcmEmailConfigurationException.class) @ResponseBody ResponseEntity<?> handleConfigurationException(AcmEmailServiceException ce); void setMailService(AcmMailTemplateConfigurationService mailService);  }