Search in sources :

Example 1 with AccessTokenService

use of org.forgerock.oauth2.core.AccessTokenService in project OpenAM by OpenRock.

the class TokenEndpointResourceTest method testToken.

@Test
public void testToken() throws Exception {
    //Given
    Context context = new Context();
    Request request = new Request();
    Response response = new Response(request);
    tokenEndpointResource.init(context, request, response);
    doReturn(new AccessToken(null, OAUTH_ACCESS_TOKEN, null)).when(accessTokenService).requestAccessToken(any(OAuth2Request.class));
    //When
    tokenEndpointResource.token(new EmptyRepresentation());
    //Then
    verify(hook).afterTokenHandling(any(OAuth2Request.class), eq(request), eq(response));
}
Also used : Context(org.restlet.Context) Response(org.restlet.Response) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) EmptyRepresentation(org.restlet.representation.EmptyRepresentation) AccessToken(org.forgerock.oauth2.core.AccessToken) Request(org.restlet.Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Test(org.testng.annotations.Test)

Example 2 with AccessTokenService

use of org.forgerock.oauth2.core.AccessTokenService in project OpenAM by OpenRock.

the class TokenEndpointResourceTest method setUp.

@BeforeClass
@SuppressWarnings("unchecked")
public void setUp() {
    JacksonRepresentationFactory jacksonRepresentationFactory = new JacksonRepresentationFactory(new ObjectMapper());
    requestFactory = mock(OAuth2RequestFactory.class);
    accessTokenService = mock(AccessTokenService.class);
    OAuth2Representation representation = new OAuth2Representation(null);
    exceptionHandler = new ExceptionHandler(representation, null, null, jacksonRepresentationFactory);
    hook = mock(TokenRequestHook.class);
    tokenEndpointResource = new TokenEndpointResource(requestFactory, accessTokenService, exceptionHandler, CollectionUtils.asSet(hook), jacksonRepresentationFactory);
}
Also used : OAuth2RequestFactory(org.forgerock.oauth2.core.OAuth2RequestFactory) AccessTokenService(org.forgerock.oauth2.core.AccessTokenService) JacksonRepresentationFactory(org.forgerock.openam.rest.representations.JacksonRepresentationFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AccessToken (org.forgerock.oauth2.core.AccessToken)1 AccessTokenService (org.forgerock.oauth2.core.AccessTokenService)1 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)1 OAuth2RequestFactory (org.forgerock.oauth2.core.OAuth2RequestFactory)1 JacksonRepresentationFactory (org.forgerock.openam.rest.representations.JacksonRepresentationFactory)1 Context (org.restlet.Context)1 Request (org.restlet.Request)1 Response (org.restlet.Response)1 EmptyRepresentation (org.restlet.representation.EmptyRepresentation)1 BeforeClass (org.testng.annotations.BeforeClass)1 Test (org.testng.annotations.Test)1