use of org.restlet.Request in project OpenAM by OpenRock.
the class ResourceSetRegistrationExceptionFilterTest method shouldSet412ExceptionResponse.
@Test
@SuppressWarnings("unchecked")
public void shouldSet412ExceptionResponse() throws Exception {
//Given
Request request = mock(Request.class);
Response response = mock(Response.class);
Status status = new Status(412);
given(response.getStatus()).willReturn(status);
//When
exceptionFilter.afterHandle(request, response);
//Then
ArgumentCaptor<JacksonRepresentation> exceptionResponseCaptor = ArgumentCaptor.forClass(JacksonRepresentation.class);
verify(response).setEntity(exceptionResponseCaptor.capture());
Map<String, String> responseBody = (Map<String, String>) exceptionResponseCaptor.getValue().getObject();
assertThat(responseBody).containsOnly(entry("error", "precondition_failed"));
}
use of org.restlet.Request in project OpenAM by OpenRock.
the class ResourceSetRegistrationExceptionFilterTest method shouldSetAnyOtherExceptionResponse.
@Test
@SuppressWarnings("unchecked")
public void shouldSetAnyOtherExceptionResponse() throws Exception {
//Given
Request request = mock(Request.class);
Response response = mock(Response.class);
Exception exception = new Exception("MESSAGE");
Status status = new Status(444, exception);
given(response.getStatus()).willReturn(status);
//When
exceptionFilter.afterHandle(request, response);
//Then
ArgumentCaptor<JacksonRepresentation> exceptionResponseCaptor = ArgumentCaptor.forClass(JacksonRepresentation.class);
verify(response).setEntity(exceptionResponseCaptor.capture());
Map<String, String> responseBody = (Map<String, String>) exceptionResponseCaptor.getValue().getObject();
assertThat(responseBody).containsOnly(entry("error", "server_error"), entry("error_description", "MESSAGE"));
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
verify(response).setStatus(statusCaptor.capture());
assertThat(statusCaptor.getValue().getCode()).isEqualTo(500);
assertThat(statusCaptor.getValue().getThrowable()).isEqualTo(exception);
}
use of org.restlet.Request in project OpenAM by OpenRock.
the class RestletFormBodyAccessTokenVerifierTest method shouldLookupValue.
@Test
public void shouldLookupValue() throws Exception {
// Given
Form form = new Form();
form.add("access_token", "freddy");
Request request = new Request();
request.setEntity(form.getWebRepresentation());
OAuth2Request req = new RestletOAuth2Request(null, request);
// When
AccessTokenVerifier.TokenState result = verifier.verify(req);
// Then
assertThat(result.isValid()).isFalse();
verify(tokenStore).readAccessToken(req, "freddy");
}
use of org.restlet.Request in project camel by apache.
the class RestletProducer method process.
@Override
public void process(Exchange exchange) throws Exception {
RestletEndpoint endpoint = (RestletEndpoint) getEndpoint();
final RestletBinding binding = endpoint.getRestletBinding();
Request request;
String resourceUri = buildUri(endpoint, exchange);
URI uri = new URI(resourceUri);
request = new Request(endpoint.getRestletMethod(), resourceUri);
binding.populateRestletRequestFromExchange(request, exchange);
loadCookies(exchange, uri, request);
LOG.debug("Sending request synchronously: {} for exchangeId: {}", request, exchange.getExchangeId());
Response response = client.handle(request);
LOG.debug("Received response synchronously: {} for exchangeId: {}", response, exchange.getExchangeId());
if (response != null) {
Integer respCode = response.getStatus().getCode();
storeCookies(exchange, uri, response);
if (respCode > 207 && throwException) {
exchange.setException(populateRestletProducerException(exchange, response, respCode));
} else {
binding.populateExchangeFromRestletResponse(exchange, response);
}
}
}
use of org.restlet.Request in project camel by apache.
the class RestletRouteBuilderTest method testNotFound.
@Test
public void testNotFound() throws IOException {
Client client = new Client(Protocol.HTTP);
Response response = client.handle(new Request(Method.POST, "http://localhost:" + portNum + "/unknown"));
// expect error status as no Restlet consumer to handle POST method
assertEquals(Status.CLIENT_ERROR_NOT_FOUND, response.getStatus());
assertNotNull(response.getEntity().getText());
}
Aggregations