Search in sources :

Example 71 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 72 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)

Example 73 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project java-function-invoker by projectriff.

the class FatJarPlainTests method init.

@Before
public void init() {
    runner = new JavaFunctionInvokerApplication();
    rest = new TestRestTemplate();
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Before(org.junit.Before)

Example 74 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project java-function-invoker by projectriff.

the class FatJarPofTests method init.

@Before
public void init() {
    runner = new JavaFunctionInvokerApplication();
    rest = new TestRestTemplate();
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Before(org.junit.Before)

Example 75 with TestRestTemplate

use of org.springframework.boot.test.web.client.TestRestTemplate in project java-function-invoker by projectriff.

the class IsolatedTests method init.

@Before
public void init() {
    runner = new JavaFunctionInvokerApplication();
    rest = new TestRestTemplate();
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Before(org.junit.Before)

Aggregations

TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)75 Test (org.junit.Test)67 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)53 Map (java.util.Map)23 HttpHeaders (org.springframework.http.HttpHeaders)15 Before (org.junit.Before)5 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