use of org.restlet.Response 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.Response in project OpenAM by OpenRock.
the class RestletRealmRouterTest method shouldHandleQueryParamRealmWithNoLeadingSlash.
@Test
public void shouldHandleQueryParamRealmWithNoLeadingSlash() throws IdRepoException, SSOException {
//Given
SSOToken adminToken = mock(SSOToken.class);
Restlet next = mock(Restlet.class);
HttpServletRequest httpRequest = mock(HttpServletRequest.class);
Request request = setUpRequest(httpRequest, adminToken);
Response response = mock(Response.class);
setUpServerName(request, adminToken, "/");
Reference reference = mock(Reference.class);
given(request.getResourceRef()).willReturn(reference);
Reference baseRef = mock(Reference.class);
given(reference.getBaseRef()).willReturn(baseRef);
given(baseRef.toString()).willReturn("The base url");
Form queryForm = mock(Form.class);
given(reference.getQueryAsForm()).willReturn(queryForm);
given(queryForm.getFirstValue("realm")).willReturn("REALM");
setUpRealmValidator("REALM", false, adminToken);
//When
router.doHandle(next, request, response);
//Then
assertThat(request.getAttributes()).containsEntry("realm", "/REALM");
verify(httpRequest).setAttribute("realm", "/REALM");
}
use of org.restlet.Response in project OpenAM by OpenRock.
the class RestletRealmRouterTest method shouldRouteToRealm.
@Test(dataProvider = "realmRoutingDataProvider")
public void shouldRouteToRealm(String realmLocation, boolean isRealmAlias) throws Exception {
//Given
SSOToken adminToken = mock(SSOToken.class);
Restlet next = mock(Restlet.class);
HttpServletRequest httpRequest = mock(HttpServletRequest.class);
Request request = setUpRequest(httpRequest, adminToken);
Response response = mock(Response.class);
String realm;
if (!isRealmAlias) {
realm = "REALM";
} else {
realm = "REALM_ALIAS";
}
if ("dns".equalsIgnoreCase(realmLocation)) {
//set up server name
setUpServerName(request, adminToken, realm);
}
if ("query".equalsIgnoreCase(realmLocation)) {
//set up query string
setUpServerName(request, adminToken, "/");
setUpQueryString(request, realm);
}
if ("uri".equalsIgnoreCase(realmLocation)) {
//set up uri
setUpServerName(request, adminToken, "/");
setUpUri(request, realm);
}
//set up validate realm
setUpRealmValidator(realm, isRealmAlias, adminToken);
//When
router.doHandle(next, request, response);
//Then
assertThat(request.getAttributes()).containsEntry("realm", "/REALM");
verify(httpRequest).setAttribute("realm", "/REALM");
assertThat(request.getAttributes()).containsEntry("realmUrl", "The base url");
}
use of org.restlet.Response 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"));
}
use of org.restlet.Response in project OpenAM by OpenRock.
the class JSONRestStatusServiceTest method shouldReturnThrowableJsonValueIfResourceException.
@Test
public void shouldReturnThrowableJsonValueIfResourceException() throws IOException {
//Given
Request request = mock(Request.class);
Response response = mock(Response.class);
ResourceException exception = ResourceException.newResourceException(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\""));
}
Aggregations