List of usage examples for org.springframework.boot.test.web.client TestRestTemplate TestRestTemplate
TestRestTemplate
From source file:com.example.SampleApplicationTests.java
@Test public void words() { assertThat(new TestRestTemplate().getForObject("http://localhost:" + port + "/words", String.class)) .isEqualTo("{\"value\":\"foo\"}{\"value\":\"bar\"}"); }
From source file:com.redhat.ipaas.runtime.ITConfig.java
@Bean public TestRestTemplate restTemplate(ObjectProvider<RestTemplateBuilder> builderProvider, Environment environment) { RestTemplateBuilder builder = builderProvider.getIfAvailable(); TestRestTemplate template = builder == null ? new TestRestTemplate() : new TestRestTemplate(builder.build()); template.setUriTemplateHandler(new LocalHostUriTemplateHandler(environment)); return template; }
From source file:com.example.SampleApplicationTests.java
@Test public void uppercase() { assertThat(new TestRestTemplate().postForObject("http://localhost:" + port + "/uppercase", "{\"value\":\"foo\"}", String.class)).isEqualTo("{\"value\":\"FOO\"}"); }
From source file:SampleWebStaticApplicationTests.java
@Test public void testHome() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("<title>Static"); }
From source file:io.fabric8.quickstarts.camel.ApplicationOpenshiftIT.java
@Test @RunAsClient// w ww .j a va 2s.c om @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"); }
From source file:com.crazyacking.learn.spring.actuator.ManagementAddressActuatorApplicationTests.java
@Test public void testHome() { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); }
From source file:SampleWebStaticApplicationTests.java
@Test public void testCss() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/webjars/bootstrap/3.0.3/css/bootstrap.min.css", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("body"); assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.valueOf("text/css")); }
From source file:de.codecentric.boot.admin.AdminApplicationTest.java
@Test public void testGetApplications() { @SuppressWarnings("rawtypes") ResponseEntity<List> entity = new TestRestTemplate() .getForEntity("http://localhost:" + port + "/api/applications", List.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); }
From source file:com.crazyacking.learn.spring.actuator.ManagementAddressActuatorApplicationTests.java
@Test public void testHealth() { ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) .getForEntity("http://localhost:" + this.managementPort + "/admin/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); }
From source file:com.crazyacking.learn.spring.actuator.ManagementPortSampleActuatorApplicationTests.java
@Test public void testMetrics() { testHome(); // makes sure some requests have been made @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); }