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