use of org.restlet.Request in project OpenAM by OpenRock.
the class ResourceSetRegistrationExceptionFilterTest method shouldSetBadRequestExceptionResponse.
@Test
@SuppressWarnings("unchecked")
public void shouldSetBadRequestExceptionResponse() throws Exception {
//Given
Request request = mock(Request.class);
Response response = mock(Response.class);
Exception exception = new BadRequestException("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", "bad_request"), entry("error_description", "MESSAGE"));
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
verify(response).setStatus(statusCaptor.capture());
assertThat(statusCaptor.getValue().getCode()).isEqualTo(400);
assertThat(statusCaptor.getValue().getThrowable()).isEqualTo(exception);
}
use of org.restlet.Request in project OpenAM by OpenRock.
the class ResourceSetRegistrationExceptionFilterTest method shouldNotSetExceptionResponse.
@Test
public void shouldNotSetExceptionResponse() {
//Given
Request request = mock(Request.class);
Response response = mock(Response.class);
Status status = new Status(111);
given(response.getStatus()).willReturn(status);
//When
exceptionFilter.afterHandle(request, response);
//Then
verify(response, never()).setEntity(Matchers.<Representation>anyObject());
verify(response, never()).setStatus(Matchers.<Status>anyObject());
}
use of org.restlet.Request in project OpenAM by OpenRock.
the class RestletFormBodyAccessTokenVerifierTest method shouldCheckParameter.
@Test
public void shouldCheckParameter() throws Exception {
// Given
Form form = new Form();
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();
}
use of org.restlet.Request in project OpenAM by OpenRock.
the class RestletHeaderAccessTokenVerifierTest method shouldCheckHeader.
@Test
public void shouldCheckHeader() throws Exception {
// Given
Request request = new Request();
OAuth2Request req = new RestletOAuth2Request(null, request);
// When
AccessTokenVerifier.TokenState result = verifier.verify(req);
// Then
assertThat(result.isValid()).isFalse();
}
use of org.restlet.Request in project OpenAM by OpenRock.
the class RestletHeaderAccessTokenVerifierTest method shouldLookupValue.
@Test
public void shouldLookupValue() throws Exception {
// Given
ChallengeResponse challengeResponse = new ChallengeResponse(ChallengeScheme.CUSTOM, "foo", "bar");
challengeResponse.setRawValue("freddy");
Request request = new Request();
request.setChallengeResponse(challengeResponse);
OAuth2Request req = new RestletOAuth2Request(null, request);
// When
AccessTokenVerifier.TokenState result = verifier.verify(req);
// Then
assertThat(result.isValid()).isFalse();
verify(tokenStore).readAccessToken(req, "freddy");
}
Aggregations