Search in sources :

Example 61 with Request

use of org.restlet.Request in project OpenAM by OpenRock.

the class AbstractRestletAccessAuditFilterTest method shouldCaptureRequestBodyProperties.

@Test
public void shouldCaptureRequestBodyProperties() throws Exception {
    // Given
    auditFilter = new RestletAccessAuditFilterTest(restlet, eventPublisher, eventFactory, RestletBodyAuditor.jsonAuditor("fred"), RestletBodyAuditor.jsonAuditor("gary"));
    Request request = new Request();
    request.setDate(new Date());
    Response response = new Response(request);
    request.setEntity(new JsonRepresentation((Map<String, Object>) object(field("fred", "v"), field("gary", 7))));
    when(eventPublisher.isAuditing(anyString(), anyString(), any(EventName.class))).thenReturn(true);
    // When
    auditFilter.beforeHandle(request, response);
    // Then
    ArgumentCaptor<AuditEvent> captor = ArgumentCaptor.forClass(AuditEvent.class);
    verify(eventPublisher).tryPublish(anyString(), captor.capture());
    assertThat(captor.getValue().getValue()).isObject().hasObject("request").hasObject("detail").contains("fred", "v");
}
Also used : Response(org.restlet.Response) Request(org.restlet.Request) AuditEvent(org.forgerock.audit.events.AuditEvent) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 62 with Request

use of org.restlet.Request in project OpenAM by OpenRock.

the class XMLRestStatusServiceTest method shouldReturnThrowableXmlValueIfResourceException.

@Test
public void shouldReturnThrowableXmlValueIfResourceException() throws IOException {
    //Given
    Request request = mock(Request.class);
    Response response = mock(Response.class);
    ResourceException exception = ResourceException.getException(401);
    exception.setDetail(json(object(field("bing", "bong"))));
    Status status = new Status(exception.getCode(), exception);
    //When
    Representation representation = restStatusService.toRepresentation(status, request, response);
    //Then
    assertTrue(representation.getText().contains("<bing>bong</bing>"));
}
Also used : Response(org.restlet.Response) Status(org.restlet.data.Status) Request(org.restlet.Request) ResourceException(org.forgerock.json.resource.ResourceException) Representation(org.restlet.representation.Representation) Test(org.testng.annotations.Test)

Example 63 with Request

use of org.restlet.Request in project OpenAM by OpenRock.

the class RestletOAuth2RequestTest method theSetUp.

@BeforeMethod
private void theSetUp() {
    //you need this
    request = new Request();
    Reference reference = new Reference("http://127.0.0.1:8080/test");
    request.setResourceRef(reference);
    request.setMethod(Method.POST);
    JacksonRepresentationFactory jacksonRepresentationFactory = new JacksonRepresentationFactory(new ObjectMapper());
    requestUnderTest = new RestletOAuth2Request(jacksonRepresentationFactory, request);
}
Also used : Reference(org.restlet.data.Reference) JacksonRepresentationFactory(org.forgerock.openam.rest.representations.JacksonRepresentationFactory) Request(org.restlet.Request) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 64 with Request

use of org.restlet.Request 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 65 with Request

use of org.restlet.Request in project OpenAM by OpenRock.

the class TokenEndpointResourceTest method shouldThrowServerErrorForExceptionsThatAreNotOAuth2RestletExceptions.

@Test
public void shouldThrowServerErrorForExceptionsThatAreNotOAuth2RestletExceptions() {
    //Given
    Context context = new Context();
    Request request = new Request();
    Response response = new Response(request);
    tokenEndpointResource.init(context, request, response);
    //When
    tokenEndpointResource.doCatch(new NullPointerException());
    //Then
    assertEquals(response.getStatus(), Status.CLIENT_ERROR_BAD_REQUEST);
    assertEquals(response.getEntityAsText(), "{\"error\":\"server_error\"}");
}
Also used : Context(org.restlet.Context) Response(org.restlet.Response) Request(org.restlet.Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Test(org.testng.annotations.Test)

Aggregations

Request (org.restlet.Request)79 Response (org.restlet.Response)44 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)37 Test (org.testng.annotations.Test)36 ChallengeResponse (org.restlet.data.ChallengeResponse)18 Status (org.restlet.data.Status)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 AccessToken (org.forgerock.oauth2.core.AccessToken)11 AccessTokenVerifier (org.forgerock.oauth2.core.AccessTokenVerifier)11 HttpRequest (org.restlet.engine.adapter.HttpRequest)9 Representation (org.restlet.representation.Representation)9 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)8 Form (org.restlet.data.Form)8 Reference (org.restlet.data.Reference)8 BeforeMethod (org.testng.annotations.BeforeMethod)8 Map (java.util.Map)7 OAuth2ProviderSettingsFactory (org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory)6 Test (org.junit.Test)6 Client (org.restlet.Client)6 URI (java.net.URI)4