public ResponseEntity<String> handleHttpEntity(HttpEntity<byte[]> httpEntity) throws Exception { String responseBody = "Handled requestBody=[" + new String(httpEntity.getBody(), "UTF-8") + "]"; return ResponseEntity.accepted() .header("header", "headerValue") .body(responseBody); }
@Test // SPR-14939 public void acceptedNoBodyWithAlternativeBodyType() throws URISyntaxException { ResponseEntity<String> responseEntity = ResponseEntity.accepted().build(); assertNotNull(responseEntity); assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); assertNull(responseEntity.getBody()); }
@Test public void acceptedNoBody() throws URISyntaxException { ResponseEntity<Void> responseEntity = ResponseEntity.accepted().build(); assertNotNull(responseEntity); assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); assertNull(responseEntity.getBody()); }
@RequestMapping(value = "/change-password", method = RequestMethod.POST) @PreAuthorize("hasRole('USER')") public ResponseEntity<?> changePassword(@RequestBody PasswordChanger passwordChanger) { userDetailsService.changePassword(passwordChanger.oldPassword, passwordChanger.newPassword); Map<String, String> result = new HashMap<>(); result.put( "result", "success" ); return ResponseEntity.accepted().body(result); }
private ResponseEntity<?> validateAndStoreSpans(Codec codec, @RequestBody byte[] body) { List<Span> spans; try { spans = codec.readSpans(body); } catch (IllegalArgumentException e) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, e.getMessage(), e); } return ResponseEntity.badRequest().body(e.getMessage() + "\n"); // newline for prettier curl } spanWriter.write(spanStore, spans); return ResponseEntity.accepted().build(); }
@ApiOperation(value = "Cancel payment by it`s ASPSP identifier", authorizations = {@Authorization(value = "oauth2", scopes = {@AuthorizationScope(scope = "read", description = "Access read API")})}) @ApiResponses(value = { @ApiResponse(code = 202, message = "ACCEPTED", response = AspspPaymentCancellationResponse.class), @ApiResponse(code = 404, message = "Payment Not Found")}) @DeleteMapping("/{payment-id}") public ResponseEntity<Void> cancelPayment(@PathVariable("payment-id") String paymentId) { return paymentService.cancelPayment(paymentId).isPresent() ? ResponseEntity.accepted().build() : ResponseEntity.notFound().build(); }
@Override @PreAuthorize("hasRole('TECHNICAL')") public ResponseEntity<Void> depositCash(String accountId, AmountTO amount) { try { middlewareAccountService.depositCash(accountId, amount); return ResponseEntity.accepted().build(); } catch (AccountNotFoundMiddlewareException e) { throw notFoundRestException(e); } } }
@PreAuthorize("hasAuthority('ADMIN')") @ResponseBody @RequestMapping(value = "/post/{postId}/json", method = RequestMethod.GET, produces = "application/json") public ResponseEntity<Map<String, Object>> getPostJson(@PathVariable Long postId) { if (null == postId) { return ResponseEntity.badRequest().build(); } Map<String, Object> attributes = this.dashboardService.getPostEditJson(postId); if (null == attributes) { return ResponseEntity.noContent().build(); } return ResponseEntity.accepted().body(attributes); }
@RequestMapping(value = "/{item}", method = DELETE) public ResponseEntity<?> remove(@PathVariable("item") String id) throws InvalidSubscriptionException, ResourceNotFoundException { final User user; try { user = securityService.resolveCurrentUser(); } catch (NotAuthenticatedException ex) { LOG.warn(ex.getMessage()); LOG.trace(ex.getMessage(), ex); throw new ResourceNotFoundException(); } this.manager.removeSubscription(id, user); return ResponseEntity.accepted().build(); }
@PostMapping(headers = "X-Github-Event=pull_request") @ResponseBody @ResponseStatus(HttpStatus.OK) public ResponseEntity<?> onGitHubPullRequestEvent(HttpEntity<String> rawPullRequestEvent){ //Mapping the event manually, because we need to forward the original message at the end PullRequestEvent pullRequestEvent= mapTo(PullRequestEvent.class,rawPullRequestEvent); if(shouldNotProcess(pullRequestEvent)){ return ResponseEntity.accepted().build(); } Message rawPullRequestEventMessage=MessageBuilder.withPayload(rawPullRequestEvent.getBody()).build(); log.info("sending to consumers : PullRequestEvent for PR #{} on repo {}", pullRequestEvent.getPrNumber(), pullRequestEvent.getRepository().getFullName()); pullRequestEventChannel.send(rawPullRequestEventMessage); return ResponseEntity.accepted().build(); }
@Test public void testUpdateStory() throws Exception { UUID boardUuid = UUID.randomUUID(); UUID storyUuid = UUID.randomUUID(); when( this.commandClient.updateStory( any( UUID.class ), any( UUID.class ), anyString() ) ).thenReturn( ResponseEntity.accepted().build() ); ResponseEntity response = this.service.updateStory( boardUuid, storyUuid, "My Story Updated" ); assertThat( response.getStatusCode() ).isEqualTo( HttpStatus.ACCEPTED ); verify( this.commandClient, times( 1 ) ).updateStory( any( UUID.class ), any( UUID.class ), anyString() ); }
@RequestMapping(value = "/refresh", method = RequestMethod.POST) public ResponseEntity<?> refreshAuthenticationToken( HttpServletRequest request, HttpServletResponse response, Principal principal ) { String authToken = tokenHelper.getToken( request ); Device device = deviceProvider.getCurrentDevice(request); if (authToken != null && principal != null) { // TODO check user password last update String refreshedToken = tokenHelper.refreshToken(authToken, device); int expiresIn = tokenHelper.getExpiredIn(device); return ResponseEntity.ok(new UserTokenState(refreshedToken, expiresIn)); } else { UserTokenState userTokenState = new UserTokenState(); return ResponseEntity.accepted().body(userTokenState); } }
@Test public void testDeleteStory() throws Exception { UUID boardUuid = UUID.randomUUID(); UUID storyUuid = UUID.randomUUID(); when( this.commandClient.deleteStory( any( UUID.class ), any( UUID.class ) ) ).thenReturn( ResponseEntity.accepted().build() ); ResponseEntity response = this.service.deleteStory( boardUuid, storyUuid ); assertThat( response.getStatusCode() ).isEqualTo( HttpStatus.ACCEPTED ); verify( this.commandClient, times( 1 ) ).deleteStory( any( UUID.class ), any( UUID.class ) ); }
@Test public void testRenameBoard() throws Exception { UUID boardUuid = UUID.randomUUID(); when( this.commandClient.renameBoard( any( UUID.class ), anyString() ) ).thenReturn( ResponseEntity.accepted().build() ); ResponseEntity response = this.service.renameBoard( boardUuid, "My Board" ); assertThat( response.getStatusCode() ).isEqualTo( HttpStatus.ACCEPTED ); verify( this.commandClient, times( 1 ) ).renameBoard( any( UUID.class ), anyString() ); }
@Test public void testAddStory() throws Exception { UUID boardUuid = UUID.randomUUID(); when( this.commandClient.addStory( any( UUID.class ), anyString() ) ).thenReturn( ResponseEntity.accepted().build() ); ResponseEntity response = this.service.addStory( boardUuid, "My Story 1" ); assertThat( response.getStatusCode() ).isEqualTo( HttpStatus.ACCEPTED ); verify( this.commandClient, times( 1 ) ).addStory( any( UUID.class ), anyString() ); }
@PostMapping(headers = "X-Github-Event=push") @ResponseBody @ResponseStatus(HttpStatus.OK) public ResponseEntity<?> onGitHubPushEvent(HttpEntity<String> rawPushEvent){ //Mapping the event manually, because we need to forward the original message at the end PushEvent pushEvent = mapTo(PushEvent.class,rawPushEvent); if(shouldNotProcess(pushEvent)){ return ResponseEntity.accepted().build(); } String repoDefaultBranch = pushEvent.getRepository().getDefaultBranch(); String eventRef = pushEvent.getRef(); Message rawPushEventMessage=MessageBuilder.withPayload(rawPushEvent.getBody()).build(); if (eventRef.endsWith(repoDefaultBranch)) { log.info("sending to consumers : Pushevent on default branch {} on repo {}", repoDefaultBranch, pushEvent.getRepository().getFullName()); pushOnDefaultBranchChannel.send(rawPushEventMessage); } else{ log.info("Not sending pushevent on NON default branch {} on repo {}", repoDefaultBranch, pushEvent.getRepository().getFullName()); } return ResponseEntity.accepted().build(); }
@Test public void testSave() throws Exception { UUID boardUuid = UUID.randomUUID(); Board board = createTestBoard( boardUuid ); when( this.eventStoreClient.addNewDomainEvent( any( DomainEvent.class ) ) ).thenReturn( ResponseEntity.accepted().build() ); this.boardClient.save( board ); verify( this.eventStoreClient, times( 1 ) ).addNewDomainEvent( any( DomainEvent.class ) ); }
@Test public void testDeleteStoryOnBoard() throws Exception { UUID boardUuid = UUID.randomUUID(); UUID storyUuid = UUID.randomUUID(); when( this.service.deleteStory( any( UUID.class ), any( UUID.class ) ) ).thenReturn( ResponseEntity.accepted().build() ); this.mockMvc.perform( RestDocumentationRequestBuilders.delete( "/boards/{boardUuid}/stories/{storyUuid}", boardUuid, storyUuid ) ) .andDo( print() ) .andExpect( status().isAccepted() ) .andDo( document("delete-story", pathParameters( parameterWithName( "boardUuid" ).description( "The unique id of the board" ), parameterWithName( "storyUuid" ).description( "The unique id of the story on the board to be deleted" ) ) )); verify( this.service, times( 1 ) ).deleteStory( any( UUID.class ), any( UUID.class ) ); }
@Test public void testUpdateStoryOnBoard() throws Exception { UUID boardUuid = UUID.randomUUID(); UUID storyUuid = UUID.randomUUID(); when( this.service.updateStory( any( UUID.class ), any( UUID.class ), anyString() ) ).thenReturn( ResponseEntity.accepted().build() ); this.mockMvc.perform( put( "/boards/{boardUuid}/stories/{storyUuid}", boardUuid, storyUuid ).param( "name", "Test Story Updated" ) ) .andDo( print() ) .andExpect( status().isAccepted() ) .andDo( document("update-story", pathParameters( parameterWithName( "boardUuid" ).description( "The unique id of the board" ), parameterWithName( "storyUuid" ).description( "The unique id of the story on the board" ) ), requestParameters( parameterWithName( "name" ).description( "The new name of the Board" ) ) )); verify( this.service, times( 1 ) ).updateStory( any( UUID.class ), any( UUID.class ), anyString() ); }
@Test public void testRenameBoard() throws Exception { UUID boardUuid = UUID.randomUUID(); when( this.service.renameBoard( any( UUID.class ), anyString() ) ).thenReturn( ResponseEntity.accepted().build() ); this.mockMvc.perform( patch( "/boards/{boardUuid}", boardUuid ).param( "name", "Test Board" ) ) .andDo( print() ) .andExpect( status().isAccepted() ) .andDo( document("rename-board", pathParameters( parameterWithName( "boardUuid" ).description( "The unique id of the board" ) ), requestParameters( parameterWithName( "name" ).description( "The new name of the Board" ) ) )); verify( this.service, times( 1 ) ).renameBoard( any( UUID.class ), anyString() ); }