Search in sources :

Example 66 with TestRestTemplate

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");
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Test(org.junit.Test)

Example 67 with TestRestTemplate

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);
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) File(java.io.File) Test(org.junit.Test)

Example 68 with TestRestTemplate

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());
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) OAuth2ContextConfiguration(org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration) Test(org.junit.Test)

Example 69 with TestRestTemplate

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));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) Map(java.util.Map) OAuth2ContextConfiguration(org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration) Test(org.junit.Test)

Example 70 with TestRestTemplate

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());
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Map(java.util.Map) Test(org.junit.Test)

Aggregations

TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)70 Test (org.junit.Test)67 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)53 Map (java.util.Map)23 HttpHeaders (org.springframework.http.HttpHeaders)15 RequestEntity (org.springframework.http.RequestEntity)2 OAuth2ContextConfiguration (org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 JSONArray (net.minidev.json.JSONArray)1 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)1 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)1