List of usage examples for org.springframework.http HttpMethod PATCH
HttpMethod PATCH
To view the source code for org.springframework.http HttpMethod PATCH.
Click Source Link
From source file:com.jiwhiz.rest.author.AuthorBlogCommentRestControllerTest.java
@Test public void updateCommentPost_ShouldUpdateCommentPostAndReturn204() throws Exception { UserAccount user = getTestLoggedInUserWithAuthorRole(); when(userAccountServiceMock.getCurrentUser()).thenReturn(user); BlogPost blogPost = getTestSinglePublishedBlogPost(); when(blogPostRepositoryMock.findOne(BLOG_ID)).thenReturn(blogPost); CommentPost commentPost = getTestApprovedCommentPost(); when(commentPostRepositoryMock.findOne(COMMENT_ID)).thenReturn(commentPost); when(commentPostRepositoryMock.save(commentPost)).thenReturn(commentPost); Map<String, String> testUpdates = new HashMap<String, String>(); testUpdates.put("content", "Updated blog text..."); mockMvc.perform(/* ww w . jav a2 s. c o m*/ request(HttpMethod.PATCH, API_ROOT + URL_AUTHOR_BLOGS_BLOG_COMMENTS_COMMENT, BLOG_ID, COMMENT_ID) .contentType(MediaType.APPLICATION_JSON) .content(TestUtils.convertObjectToJsonBytes(testUpdates))) .andExpect(status().isNoContent()); }
From source file:com.jiwhiz.rest.user.UserCommentRestControllerTest.java
@Test public void updateComment_ShouldReturn403IfCurrentUserIsNotAuthorOfComment() throws Exception { UserAccount user = getTestLoggedInUserWithAdminRole(); CommentPost comment = getTestApprovedCommentPost(); when(userAccountServiceMock.getCurrentUser()).thenReturn(user); when(commentPostRepositoryMock.findOne(eq(COMMENT_ID))).thenReturn(comment); Map<String, String> testUpdates = new HashMap<String, String>(); testUpdates.put("content", "Updated blog text..."); mockMvc.perform(request(HttpMethod.PATCH, API_ROOT + URL_USER_COMMENTS_COMMENT, COMMENT_ID) .contentType(MediaType.APPLICATION_JSON).content(TestUtils.convertObjectToJsonBytes(testUpdates))) .andExpect(status().isForbidden()).andExpect(content().string("")); }
From source file:com.logsniffer.event.publisher.http.HttpPublisherTest.java
@Test public void testPatch() throws PublishException { stubFor(patch(urlEqualTo("/eventId/123456789012")).willReturn(aResponse().withStatus(201))); publisher.setMethod(HttpMethod.PATCH); publisher.setUrl("http://localhost:" + port + "/eventId/123456789012"); Event event = new Event(); event.setId("123"); publisher.publish(event);/*from w ww . ja v a 2 s . c om*/ }
From source file:com.jiwhiz.rest.user.UserCommentRestControllerTest.java
@Test public void updateComment_ShouldReturn401IfUserNotLoggedIn() throws Exception { when(userAccountServiceMock.getCurrentUser()).thenReturn(null); CommentPost comment = getTestApprovedCommentPost(); when(commentPostRepositoryMock.findOne(eq(COMMENT_ID))).thenReturn(comment); Map<String, String> testUpdates = new HashMap<String, String>(); testUpdates.put("content", "Updated blog text..."); mockMvc.perform(request(HttpMethod.PATCH, API_ROOT + URL_USER_COMMENTS_COMMENT, COMMENT_ID) .contentType(MediaType.APPLICATION_JSON).content(TestUtils.convertObjectToJsonBytes(testUpdates))) .andExpect(status().isUnauthorized()).andExpect(content().string("")); }
From source file:com.frequentis.maritime.mcsr.config.SecurityConfiguration.java
@Override protected void configure(HttpSecurity http) throws Exception { //super.configure(http); log.debug("Configuring HttpSecurity"); log.debug("RememberMe service {}", rememberMeServices); http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) .sessionAuthenticationStrategy(sessionAuthenticationStrategy()).and() .addFilterBefore(basicAuthenticationFilter(), LogoutFilter.class) .addFilterBefore(new SkippingFilter(keycloakPreAuthActionsFilter()), LogoutFilter.class) .addFilterBefore(new SkippingFilter(keycloakAuthenticationProcessingFilter()), X509AuthenticationFilter.class) .exceptionHandling().authenticationEntryPoint(authenticationEntryPoint()).and() // .addFilterAfter(new CsrfCookieGeneratorFilter(), CsrfFilter.class) // .exceptionHandling() // .accessDeniedHandler(new CustomAccessDeniedHandler()) // .authenticationEntryPoint(authenticationEntryPoint) // .and() .rememberMe().rememberMeServices(rememberMeServices).rememberMeParameter("remember-me") .key(jHipsterProperties.getSecurity().getRememberMe().getKey()).and().formLogin() .loginProcessingUrl("/api/authentication").successHandler(ajaxAuthenticationSuccessHandler) .failureHandler(ajaxAuthenticationFailureHandler).usernameParameter("j_username") .passwordParameter("j_password").permitAll().and().logout().logoutUrl("/api/logout") .logoutSuccessHandler(ajaxLogoutSuccessHandler).deleteCookies("JSESSIONID", "CSRF-TOKEN") .permitAll().and().headers().frameOptions().disable().and().authorizeRequests() .antMatchers("/api/register").hasAuthority(AuthoritiesConstants.ADMIN) .antMatchers("/api/elasticsearch/**").permitAll().antMatchers("/api/activate").permitAll() .antMatchers("/api/authenticate").permitAll() .antMatchers("/api/account/reset_password/inactivateit").permitAll() .antMatchers("/api/account/reset_password/finish").permitAll().antMatchers("/api/profile-info") .permitAll().antMatchers("/websocket/tracker").hasAuthority(AuthoritiesConstants.ADMIN) .antMatchers("/websocket/**").permitAll().antMatchers("/management/**") .hasAuthority(AuthoritiesConstants.ADMIN).antMatchers("/v2/api-docs/**").permitAll() .antMatchers(HttpMethod.PUT, "/api/**").authenticated().antMatchers(HttpMethod.POST, "/api/**") .authenticated().antMatchers(HttpMethod.DELETE, "/api/**").authenticated() .antMatchers(HttpMethod.TRACE, "/api/**").authenticated().antMatchers(HttpMethod.HEAD, "/api/**") .authenticated().antMatchers(HttpMethod.PATCH, "/api/**").authenticated() .antMatchers(HttpMethod.OPTIONS, "/api/**").permitAll().antMatchers(HttpMethod.GET, "/api/**") .permitAll().antMatchers("/swagger-resources/configuration/ui").permitAll() .antMatchers("/swagger-ui/index.html").permitAll().and().csrf().disable(); }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Update the registration by registration ID * @param registrationId the registration ID * @return// w ww . j a v a 2 s. co m */ public ListenableFuture<Void> updateRegistration(String registrationId, Registration registration) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/registrations/{registrationId}"); return adapt(request(HttpMethod.PATCH, builder.buildAndExpand(registrationId).toUriString(), registration, Void.class)); }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testUpdateRegistration_OK() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/registrations/abcdef")).andExpect(method(HttpMethod.PATCH)) .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE)) .andExpect(jsonPath("$.duration").value("PT1M")).andRespond(withNoContent()); Registration registration = new Registration(); registration.setDuration("PT1M"); ngsiClient.updateRegistration("abcdef", registration).get(); }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Update the subscription by subscription ID * @param subscriptionId the subscription ID * @return// www.j a v a 2 s . c om */ public ListenableFuture<Void> updateSubscription(String subscriptionId, Subscription subscription) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/subscriptions/{subscriptionId}"); return adapt(request(HttpMethod.PATCH, builder.buildAndExpand(subscriptionId).toUriString(), subscription, Void.class)); }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testUpdateSubscription_OK() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/subscriptions/abcdef")).andExpect(method(HttpMethod.PATCH)) .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE)) .andExpect(jsonPath("$.expires").value("2017-04-05T14:00:00.200Z")).andRespond(withNoContent()); Subscription subscription = new Subscription(); subscription.setExpires(Instant.parse("2017-04-05T14:00:00.200Z")); ngsiClient.updateSubscription("abcdef", subscription).get(); }
From source file:org.apache.servicecomb.demo.springmvc.client.CodeFirstRestTemplateSpringmvc.java
private void testResponseEntity(String microserviceName, RestTemplate template, String cseUrlPrefix) { Map<String, Object> body = new HashMap<>(); Date date = new Date(); body.put("date", date); CseHttpEntity<Map<String, Object>> httpEntity = new CseHttpEntity<>(body); httpEntity.addContext("contextKey", "contextValue"); String srcName = RegistryUtils.getMicroservice().getServiceName(); ResponseEntity<Date> responseEntity = template.exchange(cseUrlPrefix + "responseEntity", HttpMethod.POST, httpEntity, Date.class); TestMgr.check(date, responseEntity.getBody()); TestMgr.check("h1v " + srcName, responseEntity.getHeaders().getFirst("h1")); TestMgr.check("h2v " + srcName, responseEntity.getHeaders().getFirst("h2")); checkStatusCode(microserviceName, 202, responseEntity.getStatusCode()); responseEntity = template.exchange(cseUrlPrefix + "responseEntity", HttpMethod.PATCH, httpEntity, Date.class); TestMgr.check(date, responseEntity.getBody()); TestMgr.check("h1v " + srcName, responseEntity.getHeaders().getFirst("h1")); TestMgr.check("h2v " + srcName, responseEntity.getHeaders().getFirst("h2")); checkStatusCode(microserviceName, 202, responseEntity.getStatusCode()); int retryResult = template.getForObject(cseUrlPrefix + "retrySuccess?a=2&b=3", Integer.class); TestMgr.check(retryResult, 5);//from w ww . ja v a 2 s .c o m }