ConfigurationReloadController { @RequestMapping(method = GET) @ResponseBody public ResponseEntity<String> reloadConfigAndReinitializeApplication() { HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentType(MediaType.TEXT_PLAIN); if (!application.isConfigurationReloadSupported()) { return new ResponseEntity<String>("Forbidden.", responseHeaders, FORBIDDEN); } try { application.reinit(); return new ResponseEntity<String>("Configuration reloaded.", responseHeaders, OK); } catch (Exception e) { logger.error("Failed to reload configuration files.", e); return new ResponseEntity<String>("Internal error.", responseHeaders, INTERNAL_SERVER_ERROR); } } @Autowired  ConfigurationReloadController(final Application application); @RequestMapping(method = GET) @ResponseBody ResponseEntity<String> reloadConfigAndReinitializeApplication();  }
@Test public void reloadConfigFileHappyPath() throws Exception { ResponseEntity<String> response = controller.reloadConfigAndReinitializeApplication(); assertThat(response.getBody(), equalTo("Configuration reloaded.")); assertThat(response.getStatusCode(), equalTo(OK)); assertContentType(response); }
@Test public void reloadConfigFileWhenExceptionOccurs() throws Exception { doThrow(new CacheException("exception")).when(application).reinit(); ResponseEntity<String> response = controller.reloadConfigAndReinitializeApplication(); assertThat(response.getBody(), equalTo("Internal error.")); assertThat(response.getStatusCode(), equalTo(INTERNAL_SERVER_ERROR)); assertContentType(response); }
@Test public void toggleReloadSupportFalse() { when(application.isConfigurationReloadSupported()).thenReturn(false); ResponseEntity<String> response = controller.reloadConfigAndReinitializeApplication(); assertThat(response.getBody(), equalTo("Forbidden.")); assertThat(response.getStatusCode(), equalTo(HttpStatus.FORBIDDEN)); assertContentType(response); }