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");
}
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>"));
}
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);
}
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));
}
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\"}");
}
Aggregations