MessageController extends AbstractOhfController { private ResponseEntity restartMessage(Long id, boolean totalRestart) { messageOperationService.restartMessage(id, totalRestart); return new ResponseEntity<>( new ActionResultRpc(MESSAGE_ACTION_OK, "Successful message restart."), HttpStatus.OK); }  @GetMapping(produces = {"application/xml", "application/json"}) @ResponseStatus(HttpStatus.OK) @ResponseBody MessageCollectionWrapper list(final MessageFilterRpc messageFilter); @GetMapping(path = "/{id}", produces = {"application/xml", "application/json"}) ResponseEntity<MessageRpc> detail(@PathVariable final Long id); @PostMapping(path = "/{id}/action", produces = {"application/xml", "application/json"}) ResponseEntity<ActionResultRpc> action(
            @PathVariable final Long id,
            @RequestBody @Valid final ActionRequestRpc actionRequestRpc); static final String REST_URI; }
@Test public void action_restart_ok() throws Exception { final URIBuilder uriBuilder = createGetUrl(ROOT_URI + "/42/action"); JsonObject request = createJson() .add("type", "RESTART") .add("data", createJson() .add("totalRestart", "false")) .build(); mockMvc.perform(post(toUrl(uriBuilder)) .content(request.toString()) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .with(SecurityMockMvcRequestPostProcessors.authentication(mockAuthentication("ADMIN")))) .andExpect(status().isOk()) .andExpect(jsonPath("result", is("OK"))) ; Mockito.verify(messageOperationService, times(1)).restartMessage(eq(42L), eq(false)); }
@Test public void action_restart_totalRestart() throws Exception { final URIBuilder uriBuilder = createGetUrl(ROOT_URI + "/42/action"); JsonObject request = createJson() .add("type", "RESTART") .add("data", createJson() .add("totalRestart", "true")) .build(); mockMvc.perform(post(toUrl(uriBuilder)) .content(request.toString()) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .with(SecurityMockMvcRequestPostProcessors.authentication(mockAuthentication("ADMIN")))) .andExpect(status().isOk()) .andExpect(jsonPath("result", is("OK"))) ; Mockito.verify(messageOperationService, times(1)).restartMessage(eq(42L), eq(true)); }
@Test public void action_restart_exception() throws Exception { Mockito.doThrow(new IllegalStateException("Restart failed")) .when(messageOperationService).restartMessage(eq(42L), eq(true)); final URIBuilder uriBuilder = createGetUrl(ROOT_URI + "/42/action"); JsonObject request = createJson() .add("type", "RESTART") .add("data", createJson() .add("totalRestart", "true")) .build(); mockMvc.perform(post(toUrl(uriBuilder)) .content(request.toString()) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .with(SecurityMockMvcRequestPostProcessors.authentication(mockAuthentication("ADMIN")))) .andExpect(status().isConflict()) .andExpect(jsonPath("result", is("ERROR"))) ; Mockito.verify(messageOperationService, times(1)).restartMessage(eq(42L), eq(true)); }