use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.
the class DevToolsIntegrationTests method createAController.
@Test
public void createAController() throws Exception {
TestRestTemplate template = new TestRestTemplate();
String urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForEntity(urlBase + "/two", String.class).getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
controller("com.example.ControllerTwo").withRequestMapping("two").build();
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/two", String.class)).isEqualTo("two");
}
use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-boot by spring-projects.
the class DevToolsIntegrationTests method deleteAController.
@Test
public void deleteAController() throws Exception {
TestRestTemplate template = new TestRestTemplate();
assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/one", String.class)).isEqualTo("one");
assertThat(new File(this.launchedApplication.getClassesDirectory(), "com/example/ControllerOne.class").delete()).isTrue();
assertThat(template.getForEntity("http://localhost:" + awaitServerPort() + "/one", String.class).getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-security-oauth by spring-projects.
the class ResourceOwnerPasswordProviderTests method testCheckToken.
@Test
@OAuth2ContextConfiguration(ResourceOwner.class)
public void testCheckToken() throws Exception {
TestRestTemplate template = new TestRestTemplate("my-trusted-client", "");
ResponseEntity<String> response = template.getForEntity(http.getUrl("/oauth/check_token?token={token}"), String.class, context.getAccessToken().getValue());
assertEquals(HttpStatus.OK, response.getStatusCode());
}
use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-security-oauth by spring-projects.
the class ClientCredentialsProviderTests method testCheckToken.
/**
* tests the check_token endpoint
*/
@Test
@OAuth2ContextConfiguration(ClientCredentials.class)
public void testCheckToken() throws Exception {
OAuth2AccessToken token = context.getAccessToken();
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
@SuppressWarnings("rawtypes") ResponseEntity<Map> response = new TestRestTemplate("my-client-with-secret", "secret").exchange(http.getUrl(checkTokenPath()), HttpMethod.POST, new HttpEntity<String>("token=" + token.getValue(), headers), Map.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
@SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) response.getBody();
assertTrue(map.containsKey(AccessTokenConverter.EXP));
assertEquals("my-client-with-secret", map.get(AccessTokenConverter.CLIENT_ID));
}
use of org.springframework.boot.test.web.client.TestRestTemplate in project spring-security-oauth by spring-projects.
the class ClientCredentialsProviderTests method testTokenKey.
@Test
public void testTokenKey() throws Exception {
@SuppressWarnings("rawtypes") ResponseEntity<Map> response = new TestRestTemplate("my-client-with-secret", "secret").getForEntity(http.getUrl(tokenKeyPath()), Map.class);
// This app has no token key.
assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
}
Aggregations