Java Code Examples for org.springframework.boot.test.web.client.TestRestTemplate#getForEntity()
The following examples show how to use
org.springframework.boot.test.web.client.TestRestTemplate#getForEntity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: X509ApplicationTests.java From building-microservices with Apache License 2.0 | 8 votes |
@Test public void testAuthenticatedHello() throws Exception { TestRestTemplate restTemplate = new TestRestTemplate(); restTemplate.getRestTemplate() .setRequestFactory(new HttpComponentsClientHttpRequestFactory(HttpClients .custom().setSSLSocketFactory(socketFactory()).build())); ResponseEntity<String> httpsEntity = restTemplate .getForEntity("https://localhost:" + this.port + "/hi", String.class); assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(httpsEntity.getBody()).containsIgnoringCase("hello, rod"); }
Example 2
Source File: TestRestTemplateBasicLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenTestRestTemplateWithCredentials_whenSendGetForEntity_thenStatusOk() { TestRestTemplate testRestTemplate = new TestRestTemplate("user", "passwd"); ResponseEntity<String> response = testRestTemplate.getForEntity(URL_SECURED_BY_AUTHENTICATION, String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
Example 3
Source File: TestRestTemplateBasicLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenTestRestTemplateWithCredentialsAndEnabledCookies_whenSendGetForEntity_thenStatusOk() { TestRestTemplate testRestTemplate = new TestRestTemplate("user", "passwd", TestRestTemplate. HttpClientOption.ENABLE_COOKIES); ResponseEntity<String> response = testRestTemplate.getForEntity(URL_SECURED_BY_AUTHENTICATION, String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
Example 4
Source File: TestRestTemplateBasicLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenTestRestTemplateWithCredentials_whenSendGetForEntity_thenStatusOk() { TestRestTemplate testRestTemplate = new TestRestTemplate("user", "passwd"); ResponseEntity<String> response = testRestTemplate.getForEntity(URL_SECURED_BY_AUTHENTICATION, String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
Example 5
Source File: TestRestTemplateBasicLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRestTemplateWrapperWithCredentials_whenSendGetForEntity_thenStatusOk() { RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder(); restTemplateBuilder.configure(restTemplate); TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplateBuilder, "user", "passwd"); ResponseEntity<String> response = testRestTemplate.getForEntity(URL_SECURED_BY_AUTHENTICATION, String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
Example 6
Source File: TestRestTemplateBasicLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRestTemplateBuilderWrapper_whenSendGetForEntity_thenStatusOk() { RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder(); restTemplateBuilder.build(); TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplateBuilder); ResponseEntity<Foo> response = testRestTemplate.getForEntity(FOO_RESOURCE_URL + "/1", Foo.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
Example 7
Source File: TestRestTemplateBasicLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRestTemplateWrapper_whenSendGetForEntity_thenStatusOk() { RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder(); restTemplateBuilder.configure(restTemplate); TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplateBuilder); ResponseEntity<Foo> response = testRestTemplate.getForEntity(FOO_RESOURCE_URL + "/1", Foo.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
Example 8
Source File: BasicAuthConfigurationIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test public void givenWrongCredentials_whenRequestsHomePage_ThenUnauthorized() throws IllegalStateException, IOException { restTemplate = new TestRestTemplate("user", "wrongpassword"); ResponseEntity<String> response = restTemplate.getForEntity(base.toString()+"/user", String.class); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); assertTrue(response .getBody() .contains("Unauthorized")); }
Example 9
Source File: TestRestTemplateBasicLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenTestRestTemplateWithCredentialsAndEnabledCookies_whenSendGetForEntity_thenStatusOk() { TestRestTemplate testRestTemplate = new TestRestTemplate("user", "passwd", TestRestTemplate. HttpClientOption.ENABLE_COOKIES); ResponseEntity<String> response = testRestTemplate.getForEntity(URL_SECURED_BY_AUTHENTICATION, String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
Example 10
Source File: FunctionEndpointInitializerTests.java From spring-cloud-function with Apache License 2.0 | 5 votes |
@Test public void testGetWithtFunction() throws Exception { FunctionalSpringApplication.run(ApplicationConfiguration.class); TestRestTemplate testRestTemplate = new TestRestTemplate(); String port = System.getProperty("server.port"); Thread.sleep(2000); ResponseEntity<String> response = testRestTemplate .getForEntity(new URI("http://localhost:" + port + "/reverse/stressed"), String.class); System.out.println(); assertThat(response.getBody()).isEqualTo("desserts"); }
Example 11
Source File: TestRestTemplateBasicLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRestTemplateWrapperWithCredentials_whenSendGetForEntity_thenStatusOk() { RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder(); restTemplateBuilder.configure(restTemplate); TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplateBuilder, "user", "passwd"); ResponseEntity<String> response = testRestTemplate.getForEntity(URL_SECURED_BY_AUTHENTICATION, String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
Example 12
Source File: TestRestTemplateBasicLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRestTemplateBuilderWrapper_whenSendGetForEntity_thenStatusOk() { RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder(); restTemplateBuilder.build(); TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplateBuilder); ResponseEntity<String> response = testRestTemplate.getForEntity(FOO_RESOURCE_URL + "/1", String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
Example 13
Source File: TestRestTemplateBasicLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRestTemplateWrapper_whenSendGetForEntity_thenStatusOk() { RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder(); restTemplateBuilder.configure(restTemplate); TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplateBuilder); ResponseEntity<String> response = testRestTemplate.getForEntity(FOO_RESOURCE_URL + "/1", String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
Example 14
Source File: BasicConfigurationIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test public void whenUserWithWrongCredentials_thenUnauthorizedPage() throws IllegalStateException, IOException { restTemplate = new TestRestTemplate("user", "wrongpassword"); ResponseEntity<String> response = restTemplate.getForEntity(base.toString(), String.class); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); assertNull(response.getBody()); }
Example 15
Source File: BasicHttpsSecurityApplicationTests.java From building-microservices with Apache License 2.0 | 5 votes |
@Test public void testAuthenticatedHello() throws Exception { TestRestTemplate restTemplate = new TestRestTemplate(); restTemplate.getRestTemplate() .setRequestFactory(new HttpComponentsClientHttpRequestFactory(HttpClients .custom().setSSLSocketFactory(socketFactory()).build())); ResponseEntity<String> httpsEntity = restTemplate .getForEntity("https://localhost:" + this.port + "/hi", String.class); assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(httpsEntity.getBody()).containsIgnoringCase("hello, rod"); }
Example 16
Source File: FunctionEndpointInitializerTests.java From spring-cloud-function with Apache License 2.0 | 5 votes |
@Test public void testGetWithtSupplier() throws Exception { FunctionalSpringApplication.run(ApplicationConfiguration.class); TestRestTemplate testRestTemplate = new TestRestTemplate(); String port = System.getProperty("server.port"); Thread.sleep(200); ResponseEntity<String> response = testRestTemplate .getForEntity(new URI("http://localhost:" + port + "/supplier"), String.class); assertThat(response.getBody()).isEqualTo("Jim Lahey"); }
Example 17
Source File: TestRestTemplateBasicLiveTest.java From tutorials with MIT License | 4 votes |
@Test public void givenTestRestTemplate_whenSendGetForEntity_thenStatusOk() { TestRestTemplate testRestTemplate = new TestRestTemplate(); ResponseEntity<Foo> response = testRestTemplate.getForEntity(FOO_RESOURCE_URL + "/1", Foo.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }
Example 18
Source File: TestRestTemplateBasicLiveTest.java From tutorials with MIT License | 4 votes |
@Test public void givenTestRestTemplate_whenSendGetForEntity_thenStatusOk() { TestRestTemplate testRestTemplate = new TestRestTemplate(); ResponseEntity<String> response = testRestTemplate.getForEntity(FOO_RESOURCE_URL + "/1", String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); }