List of usage examples for org.springframework.http HttpMethod POST
HttpMethod POST
To view the source code for org.springframework.http HttpMethod POST.
Click Source Link
From source file:com.appglu.impl.SyncTemplateTest.java
@Test public void changesForTablesUsingCallback_NewProperties() { mockServer.expect(requestTo("http://localhost/appglu/v1/sync/changes")).andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", jsonMediaType.toString())) .andExpect(content().string(compactedJson("data/sync_changes_for_tables_request"))) .andRespond(withStatus(HttpStatus.OK).body(compactedJson("data/sync_parser_new_properties")) .headers(responseHeaders)); MemoryTableChangesCallback callback = new MemoryTableChangesCallback(); TableVersion loggedTable = new TableVersion("logged_table"); TableVersion otherTable = new TableVersion("other_table", 1); this.syncOperations.changesForTables(callback, loggedTable, otherTable); this.assertChanges(callback.getTableChanges()); mockServer.verify();//ww w. ja v a 2s . c o m }
From source file:access.test.PiazzaEnvironmentTests.java
@Test public void testResourceCreationServerError() { Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces/piazza.json"), Mockito.eq(HttpMethod.GET), Mockito.any(), Mockito.eq(String.class))) .thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces"), Mockito.eq(HttpMethod.POST), Mockito.any(), Mockito.eq(String.class))) .thenReturn(new ResponseEntity<>("{\"result\": \"all good\"}", HttpStatus.OK)) .thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR)) .thenThrow(new RuntimeException()); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces/piazza.xml"), Mockito.eq(HttpMethod.PUT), Mockito.any(), Mockito.eq(String.class))) .thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/datastores/piazza.json"), Mockito.eq(HttpMethod.GET), Mockito.any(), Mockito.eq(String.class))) .thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/datastores"), Mockito.eq(HttpMethod.POST), Mockito.any(), Mockito.eq(String.class))) .thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR)) .thenThrow(new RuntimeException()); this.piazzaEnvironment.initializeEnvironment(); this.piazzaEnvironment.initializeEnvironment(); this.piazzaEnvironment.initializeEnvironment(); }
From source file:com.netflix.genie.web.security.oauth2.pingfederate.PingFederateRemoteTokenServicesUnitTests.java
/** * Make sure we can validate a token.//w w w . jav a2s . co m */ @Test public void canLoadAuthentication() { final AccessTokenConverter converter = Mockito.mock(AccessTokenConverter.class); final RestTemplate restTemplate = Mockito.mock(RestTemplate.class); final PingFederateRemoteTokenServices services = new PingFederateRemoteTokenServices( this.resourceServerProperties, converter, this.registry); services.setRestTemplate(restTemplate); final String accessToken = UUID.randomUUID().toString(); final String clientId = UUID.randomUUID().toString(); final String scope1 = UUID.randomUUID().toString(); final String scope2 = UUID.randomUUID().toString(); final Map<String, Object> map = Maps.newHashMap(); map.put(PingFederateRemoteTokenServices.CLIENT_ID_KEY, clientId); map.put(PingFederateRemoteTokenServices.SCOPE_KEY, scope1 + " " + scope2); @SuppressWarnings("unchecked") final ResponseEntity<Map> response = Mockito.mock(ResponseEntity.class); Mockito.when(restTemplate.exchange(Mockito.eq(CHECK_TOKEN_ENDPOINT_URL), Mockito.eq(HttpMethod.POST), Mockito.any(HttpEntity.class), Mockito.eq(Map.class))).thenReturn(response); Mockito.when(response.getBody()).thenReturn(map); final SimpleGrantedAuthority scope1Authority = new SimpleGrantedAuthority(scope1); final SimpleGrantedAuthority scope2Authority = new SimpleGrantedAuthority(scope2); final Set<GrantedAuthority> authorities = Sets.newHashSet(scope1Authority, scope2Authority); final Authentication authentication = new UsernamePasswordAuthenticationToken(clientId, "NA", authorities); final OAuth2Authentication oauth2Authentication = new OAuth2Authentication( Mockito.mock(OAuth2Request.class), authentication); Mockito.when(converter.extractAuthentication(Mockito.eq(map))).thenReturn(oauth2Authentication); final OAuth2Authentication result = services.loadAuthentication(accessToken); Assert.assertThat(result, Matchers.is(oauth2Authentication)); Assert.assertThat(result.getPrincipal(), Matchers.is(clientId)); Assert.assertThat(result.getAuthorities().size(), Matchers.is(2)); Assert.assertTrue(result.getAuthorities().contains(scope1Authority)); Assert.assertTrue(result.getAuthorities().contains(scope2Authority)); Mockito.verify(this.authenticationTimer, Mockito.times(1)).record(Mockito.anyLong(), Mockito.eq(TimeUnit.NANOSECONDS)); }
From source file:org.appverse.web.framework.backend.test.util.frontfacade.mvc.tests.predefined.BasicAuthEndPointsServiceEnabledPredefinedTests.java
@Test public void basicAuthenticationFlowTest() throws Exception { // Login first TestLoginInfo loginInfo = login();//from w w w. ja v a 2s. com // Calling protected remotelog service RemoteLogRequestVO logRequestVO = new RemoteLogRequestVO(); logRequestVO.setMessage("Test mesage!"); logRequestVO.setLogLevel("DEBUG"); HttpHeaders headers = new HttpHeaders(); headers.set("Cookie", loginInfo.getJsessionid()); HttpEntity<RemoteLogRequestVO> entityRemotelog = new HttpEntity<RemoteLogRequestVO>(logRequestVO, headers); UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl("http://localhost:" + port + baseApiPath + remoteLogEndpointPath); // Try without token first - It should be 'Forbidden' // http://springinpractice.com/2012/04/08/sending-cookies-with-resttemplate ResponseEntity<String> responseEntityRemotelog = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, entityRemotelog, String.class); assertEquals(HttpStatus.FORBIDDEN, responseEntityRemotelog.getStatusCode()); // Try now with the CSRF token - It should work well // This implies passing JSESSIONID and CSRF Token headers.set(DEFAULT_CSRF_HEADER_NAME, loginInfo.getXsrfToken()); entityRemotelog = new HttpEntity<RemoteLogRequestVO>(logRequestVO, headers); responseEntityRemotelog = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, entityRemotelog, String.class); assertEquals(HttpStatus.OK, responseEntityRemotelog.getStatusCode()); // Calling here logout builder = UriComponentsBuilder .fromHttpUrl("http://localhost:" + port + basicAuthenticationLogoutEndpointPath); HttpEntity<Void> entityLogout = new HttpEntity<Void>(headers); responseEntityRemotelog = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, entityLogout, String.class); assertEquals(HttpStatus.OK, responseEntityRemotelog.getStatusCode()); // Try to call remotelog again (after logout) // This implies passing JSESSIONID and CSRF Token - We expect this not to work as the CSRF token has been removed and the session invalidated entityRemotelog = new HttpEntity<RemoteLogRequestVO>(logRequestVO, headers); responseEntityRemotelog = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, entityRemotelog, String.class); assertEquals(HttpStatus.FORBIDDEN, responseEntityRemotelog.getStatusCode()); }
From source file:com.garyclayburg.UserRestSmokeTest.java
@Test public void testHalJsonutf8Apache() throws Exception { RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory()); SimpleUser user1 = new SimpleUser(); user1.setFirstname("Tommy"); user1.setLastname("Deleteme"); user1.setId("112" + (int) (Math.floor(Math.random() * 10000))); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Content-Type", "application/hal+json;charset=UTF-8"); // HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); HttpEntity<?> requestEntity = new HttpEntity(user1, requestHeaders); ResponseEntity<SimpleUser> simpleUserResponseEntity = rest.exchange( "http://" + endpoint + "/audited-users/auditedsave", HttpMethod.POST, requestEntity, SimpleUser.class); // ResponseEntity<SimpleUser> userResponseEntity = // rest.postForEntity("http://" + endpoint + "/audited-users/auditedsave",user1,SimpleUser.class); log.info("got a response"); MatcherAssertionErrors.assertThat(simpleUserResponseEntity.getStatusCode(), Matchers.equalTo(HttpStatus.OK)); }
From source file:com.teradata.benchto.driver.DriverAppIntegrationTest.java
private void verifyBenchmarkFinish(String uniqueBenchmarkName, List<String> measurementNames) { restServiceServer//w ww . j a va 2s .co m .expect(matchAll( requestTo("http://benchmark-service:8080/v1/benchmark/" + uniqueBenchmarkName + "/BEN_SEQ_ID/finish"), method(HttpMethod.POST), jsonPath("$.status", ENDED_STATUS_MATCHER), jsonPath("$.measurements.[*].name", containsInAnyOrder(measurementNames.toArray())))) .andRespond(withSuccess()); restServiceServer.expect(matchAll(requestTo("http://graphite:18088/events/"), method(HttpMethod.POST), jsonPath("$.what", is("Benchmark " + uniqueBenchmarkName + " ended")), jsonPath("$.tags", is("benchmark ended TEST_ENV")), jsonPath("$.data", startsWith("successful")))) .andRespond(withSuccess()); }
From source file:com.embedler.moon.graphql.boot.sample.test.GenericTodoSchemaParserTest.java
@Test public void restUploadFileTest() throws IOException { LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); map.add("file", new ClassPathResource("application.yml")); String qlQuery = "mutation UploadFileMutation{uploadFile(input: {clientMutationId:\"m-123\"}){ filename }}"; map.add("query", qlQuery); map.add("variables", "{}"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers); ResponseEntity<GraphQLServerResult> responseEntity = restTemplate.exchange( "http://localhost:" + port + "/graphql", HttpMethod.POST, requestEntity, GraphQLServerResult.class); GraphQLServerResult result = responseEntity.getBody(); Assert.assertTrue(CollectionUtils.isEmpty(result.getErrors())); Assert.assertFalse(CollectionUtils.isEmpty(result.getData())); LOGGER.info(objectMapper.writeValueAsString(result.getData())); }
From source file:io.syndesis.runtime.BaseITCase.java
protected <T> ResponseEntity<T> post(String url, Object body, ParameterizedTypeReference<T> responseClass, String token, HttpStatus expectedStatus) { return http(HttpMethod.POST, url, body, responseClass, token, new HttpHeaders(), expectedStatus); }
From source file:com.orange.ngsi.client.NgsiClient.java
/** * Default POST request//from w w w. j ava 2 s . c om */ protected <T, U> ListenableFuture<T> request(String url, HttpHeaders httpHeaders, U body, Class<T> responseType) { return request(HttpMethod.POST, url, httpHeaders, body, responseType); }
From source file:fragment.web.AccessDecisionTest.java
@Test public void testUserUrls() { Object[][] valid = { { HttpMethod.GET, "/portal/portal/" }, { HttpMethod.GET, "/portal/portal/home" }, { HttpMethod.GET, "/portal/portal/profile" }, { HttpMethod.GET, "/portal/portal/profile/edit" }, { HttpMethod.POST, "/portal/portal/profile" }, { HttpMethod.POST, "/portal/portal/acceptCookies" } }; Object[][] invalid = { { HttpMethod.GET, "/portal/portal/users/1" }, { HttpMethod.PUT, "/portal/portal/users/1" }, { HttpMethod.GET, "/portal/portal/users" }, { HttpMethod.GET, "/portal/portal/users/new" }, { HttpMethod.POST, "/portal/portal/users" }, { HttpMethod.GET, "/portal/portal/tenants" }, { HttpMethod.POST, "/portal/portal/tenants" }, { HttpMethod.GET, "/portal/portal/tenants/new" }, { HttpMethod.GET, "/portal/portal/tenants/1/edit" }, { HttpMethod.PUT, "/portal/portal/tenants/1" } }; User user = createTestUserInTenant(getDefaultTenant()); Authentication auth = createAuthenticationToken(user); verify(auth, valid, invalid);// w ww.j ava 2 s . co m }