List of usage examples for org.springframework.boot.test.web.client TestRestTemplate exchange
public <T> ResponseEntity<T> exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType) throws RestClientException
From source file:edu.infsci2560.LoginHelper.java
public static ResponseEntity<String> login(TestRestTemplate template, String route, String userName, String password) {//from ww w .ja v a2s .c o m HttpHeaders headers = getHeaders(template, route); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); form.set("username", userName); form.set("password", password); ResponseEntity<String> entity = template.exchange(route, HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class); return entity; }
From source file:io.fabric8.quickstarts.camel.ApplicationOpenshiftIT.java
@Test @RunAsClient/*from ww w.ja v a 2s .c o m*/ @InSequence(2) public void booksTest() { TestRestTemplate restTemplate = new TestRestTemplate(); ResponseEntity<List<Book>> response = restTemplate.exchange( "http://" + client.adapt(OpenShiftClient.class).routes().withName("camel-rest-jpa").get().getSpec() .getHost() + "/camel-rest-jpa/books", HttpMethod.GET, null, new ParameterizedTypeReference<List<Book>>() { }); Assertions.assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); List<Book> books = response.getBody(); Assertions.assertThat(books).hasSize(2); Assertions.assertThat(books).element(0).hasFieldOrPropertyWithValue("item", "Camel") .hasFieldOrPropertyWithValue("description", "Camel in Action"); Assertions.assertThat(books).element(1).hasFieldOrPropertyWithValue("item", "ActiveMQ") .hasFieldOrPropertyWithValue("description", "ActiveMQ in Action"); }