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.formulaone.controller.merchant.MerchantControllerTest.java
/** * Test successful merchant creation//from www . j ava2 s . c o m * * @throws Exception */ @Test public void test_1_SuccessfulMerchantCreation() throws Exception { request = createMerchant(); HttpEntity<MerchantRequest> entity = new HttpEntity<MerchantRequest>(request, httpHeaders); try { ResponseEntity<MerchantResponse> response = restTemplate.exchange(base.toString(), HttpMethod.POST, entity, MerchantResponse.class); MerchantResponse merchantResponse = response.getBody(); assertThat(merchantResponse, notNullValue()); assertThat(merchantResponse.getCompanyName(), equalTo(request.getCompany().getName())); assertThat(merchantResponse.getDescription(), equalTo(request.getBusinessDescription())); assertThat(merchantResponse.getFirstName(), equalTo(request.getOwnershipDetails().getFirstName())); assertThat(merchantResponse.getLastName(), equalTo(request.getOwnershipDetails().getLastName())); assertThat(merchantResponse.getMid(), notNullValue()); assertThat(response.getStatusCode(), equalTo(HttpStatus.CREATED)); createdId = merchantResponse.getId(); } catch (Exception e) { fail("Unexpected exception happened: " + e.getMessage()); } }
From source file:org.echocat.marquardt.example.ServiceLoginIntegrationTest.java
private void whenAccessingProtectedResourceOnService() throws IOException { getClient().sendSignedPayloadTo(baseUriOfApp() + "/exampleservice/someProtectedResource", HttpMethod.POST.name(), null, Void.class, _certificate); }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppRouteCreatingStepTest.java
@Before public void setUp() { this.restTemplateMock = mock(RestTemplate.class); this.domainsResponseMock = mock(ResponseEntity.class); when(restTemplateMock.exchange(testCfDomainsEndpoint, HttpMethod.GET, HttpCommunication.simpleJsonRequest(), String.class)).thenReturn(domainsResponseMock); this.routesResponseMock = mock(ResponseEntity.class); when(restTemplateMock.exchange(testCfGetRoutesEndpoint, HttpMethod.GET, HttpCommunication.simpleJsonRequest(), String.class, testSubdomain, testDomainGuid)) .thenReturn(routesResponseMock); this.routeCreatedResponseMock = mock(ResponseEntity.class); when(restTemplateMock.exchange(testCfCreateRouteEndpoint, HttpMethod.POST, HttpCommunication.postRequest(createRouteRequestBody), String.class)) .thenReturn(routeCreatedResponseMock); }
From source file:org.appverse.web.framework.backend.test.util.frontfacade.BaseAbstractAuthenticationRequiredTest.java
protected TestLoginInfo login() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Basic " + new String(Base64.encode((getUsername() + ":" + getPassword()).getBytes("UTF-8")))); HttpEntity<String> entity = new HttpEntity<String>("headers", headers); ResponseEntity<AuthorizationData> responseEntity = restTemplate.exchange( "http://localhost:" + port + baseApiPath + basicAuthenticationEndpointPath, HttpMethod.POST, entity, AuthorizationData.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); List<String> xsrfTokenHeaders = responseEntity.getHeaders().get(DEFAULT_CSRF_HEADER_NAME); assertNotNull(xsrfTokenHeaders);//from ww w .ja va2 s. c o m assertEquals(xsrfTokenHeaders.size(), 1); assertNotNull(xsrfTokenHeaders.get(0)); AuthorizationData authorizationData = responseEntity.getBody(); assertNotNull(authorizationData); List<String> roles = authorizationData.getRoles(); assertNotNull(roles); assertEquals(roles.size() > 0, true); assertEquals(roles.contains(getAnUserRole()), true); TestLoginInfo loginInfo = new TestLoginInfo(); loginInfo.setXsrfToken(xsrfTokenHeaders.get(0)); loginInfo.setAuthorizationData(authorizationData); loginInfo.setJsessionid(responseEntity.getHeaders().getFirst("Set-Cookie")); return loginInfo; }
From source file:org.androidannotations.test15.rest.HttpMethodServiceTest.java
@Test public void usePostHttpMethod() { HttpMethodsService_ service = new HttpMethodsService_(null); RestTemplate restTemplate = mock(RestTemplate.class); service.setRestTemplate(restTemplate); service.post();//w ww. j a va 2 s .c o m verify(restTemplate).exchange(Matchers.anyString(), Matchers.<HttpMethod>eq(HttpMethod.POST), Matchers.<HttpEntity<?>>any(), Matchers.<Class<Object>>any()); }
From source file:com.cisco.cta.taxii.adapter.httpclient.BasicAuthHttpRequestFactoryTest.java
@Test(expected = SocketTimeoutException.class) public void timeoutConnection() throws Exception { BasicAuthHttpRequestFactory factoryImpl = (BasicAuthHttpRequestFactory) factory; factoryImpl.setReadTimeout(10);//from w w w.j ava2s . co m Thread server = null; try (ServerRunnable serverRunnable = new ServerRunnable()) { server = new Thread(serverRunnable); ClientHttpRequest req = factory.createRequest(connSettings.getPollEndpoint().toURI(), HttpMethod.POST); req.execute(); } finally { server.join(10); } }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaAuthenticationManager.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = authentication.getName(); String password = (String) authentication.getCredentials(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>(); parameters.set("username", username); parameters.set("password", password); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = restTemplate.exchange(loginUrl, HttpMethod.POST, new HttpEntity<MultiValueMap<String, Object>>(parameters, headers), Map.class); if (response.getStatusCode() == HttpStatus.OK) { String userFromUaa = (String) response.getBody().get("username"); if (userFromUaa.equals(userFromUaa)) { logger.info("Successful authentication request for " + authentication.getName()); return new UsernamePasswordAuthenticationToken(username, null, UaaAuthority.USER_AUTHORITIES); }/* ww w. ja v a 2 s . com*/ } else if (response.getStatusCode() == HttpStatus.UNAUTHORIZED) { logger.info("Failed authentication request"); throw new BadCredentialsException("Authentication failed"); } else if (response.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) { logger.info("Internal error from UAA. Please Check the UAA logs."); } else { logger.error("Unexpected status code " + response.getStatusCode() + " from the UAA." + " Is a compatible version running?"); } throw new RuntimeException("Could not authenticate with remote server"); }
From source file:access.test.PiazzaEnvironmentTests.java
@Test public void testResourcesDoNotExist() { 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<String>("{\"result\": \"all good\"}", HttpStatus.OK)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces/piazza.xml"), Mockito.eq(HttpMethod.PUT), Mockito.any(), Mockito.eq(String.class))) .thenReturn(new ResponseEntity<String>("{\"result\": \"all good\"}", HttpStatus.OK)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/datastores/piazza.json"), Mockito.eq(HttpMethod.GET), Mockito.any(), Mockito.eq(String.class))) .thenReturn(new ResponseEntity<String>("{invalid JSON}", HttpStatus.OK)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/datastores"), Mockito.eq(HttpMethod.POST), Mockito.any(), Mockito.eq(String.class))) .thenReturn(new ResponseEntity<String>("{\"result\": \"all good\"}", HttpStatus.OK)); piazzaEnvironment.initializeEnvironment(); assertTrue(true); // no error occurred }
From source file:com.appglu.impl.SavedQueriesTemplateTest.java
@Test public void runQueryNullQueryParams() { mockServer.expect(requestTo("http://localhost/appglu/v1/queries/queryName/run")) .andExpect(method(HttpMethod.POST)).andExpect(header("Content-Type", jsonMediaType.toString())) .andExpect(content().string(compactedJson("data/saved_queries_params_empty"))) .andRespond(withSuccess().body(compactedJson("data/saved_queries_update_result")) .headers(responseHeaders)); savedQueriesOperations.runQuery("queryName"); mockServer.verify();//from ww w . java2 s.c om }
From source file:com.appglu.impl.AnalyticsTemplateTest.java
@Test public void emptySession() { mockServer.expect(requestTo("http://localhost/appglu/v1/analytics")).andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", jsonMediaType.toString())) .andExpect(content().string(compactedJson("data/analytics_empty_session"))) .andRespond(withStatus(HttpStatus.CREATED).body("").headers(responseHeaders)); analyticsOperations.uploadSession(new AnalyticsSession()); mockServer.verify();//from www. ja v a 2s.c om }