Search in sources :

Example 1 with Status

use of org.restlet.data.Status in project OpenAM by OpenRock.

the class ResourceSetRegistrationEndpointTest method shouldDeleteResourceSetDescription.

@Test
public void shouldDeleteResourceSetDescription() throws Exception {
    //Given
    setUriResourceSetId();
    addCondition();
    //When
    Representation responseRep = endpoint.deleteResourceSet();
    //Then
    verify(store).delete("RESOURCE_SET_ID", "RESOURCE_OWNER_ID");
    assertThat(responseRep.getText()).isNull();
    ArgumentCaptor<Status> responseStatusCaptor = ArgumentCaptor.forClass(Status.class);
    verify(response).setStatus(responseStatusCaptor.capture());
    assertThat(responseStatusCaptor.getValue().getCode()).isEqualTo(204);
    verify(labelRegistration).updateLabelsForDeletedResourceSet(any(ResourceSetDescription.class));
}
Also used : Status(org.restlet.data.Status) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) Representation(org.restlet.representation.Representation) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Test(org.testng.annotations.Test)

Example 2 with Status

use of org.restlet.data.Status in project OpenAM by OpenRock.

the class ResourceSetRegistrationExceptionFilterTest method shouldSet405ExceptionResponse.

@Test
@SuppressWarnings("unchecked")
public void shouldSet405ExceptionResponse() throws Exception {
    //Given
    Request request = mock(Request.class);
    Response response = mock(Response.class);
    Status status = new Status(405);
    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", "unsupported_method_type"));
}
Also used : Response(org.restlet.Response) Status(org.restlet.data.Status) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Request(org.restlet.Request) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 3 with Status

use of org.restlet.data.Status 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);
}
Also used : Response(org.restlet.Response) Status(org.restlet.data.Status) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Request(org.restlet.Request) BadRequestException(org.forgerock.oauth2.core.exceptions.BadRequestException) Map(java.util.Map) BadRequestException(org.forgerock.oauth2.core.exceptions.BadRequestException) Test(org.testng.annotations.Test)

Example 4 with Status

use of org.restlet.data.Status 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());
}
Also used : Response(org.restlet.Response) Status(org.restlet.data.Status) Request(org.restlet.Request) Test(org.testng.annotations.Test)

Example 5 with Status

use of org.restlet.data.Status in project OpenAM by OpenRock.

the class JSONRestStatusServiceTest method shouldGetJsonResourceException.

@Test
public void shouldGetJsonResourceException() throws IOException {
    //Given
    Status status = Status.CLIENT_ERROR_BAD_REQUEST;
    Request request = mock(Request.class);
    Response response = mock(Response.class);
    //When
    Representation representation = restStatusService.toRepresentation(status, request, response);
    //Then
    assertTrue(representation.getText().contains("\"code\":400"));
}
Also used : Status(org.restlet.data.Status) Response(org.restlet.Response) Request(org.restlet.Request) Representation(org.restlet.representation.Representation) Test(org.testng.annotations.Test)

Aggregations

Status (org.restlet.data.Status)26 Test (org.testng.annotations.Test)19 Response (org.restlet.Response)17 Request (org.restlet.Request)15 JacksonRepresentation (org.restlet.ext.jackson.JacksonRepresentation)11 Map (java.util.Map)9 Representation (org.restlet.representation.Representation)8 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)7 ChallengeResponse (org.restlet.data.ChallengeResponse)6 IOException (java.io.IOException)5 ResourceException (org.forgerock.json.resource.ResourceException)4 HashMap (java.util.HashMap)3 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)3 EntitlementException (com.sun.identity.entitlement.EntitlementException)2 ArrayList (java.util.ArrayList)2 AccessToken (org.forgerock.oauth2.core.AccessToken)2 BadRequestException (org.forgerock.oauth2.core.exceptions.BadRequestException)2 ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)2 Post (org.restlet.resource.Post)2 ResourceException (org.restlet.resource.ResourceException)2