use of org.restlet.Request 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.Request in project OpenAM by OpenRock.
the class RestletRealmRouterTest method shouldReturnNullWhenMissing.
@Test
public void shouldReturnNullWhenMissing() {
// Given
Request mockRequest = generateRequest();
// When
String result = RestletRealmRouter.getRealmFromRequest(mockRequest);
// Then
assertThat(result).isNull();
}
use of org.restlet.Request in project OpenAM by OpenRock.
the class RestletRealmRouterTest method shouldExtractRealmFromRequest.
@Test
public void shouldExtractRealmFromRequest() {
// Given
String key = "badger";
Request mockRequest = generateRequest();
mockRequest.getAttributes().put(RestletRealmRouter.REALM, key);
// When
String result = RestletRealmRouter.getRealmFromRequest(mockRequest);
// Then
assertThat(result).isEqualTo(key);
}
use of org.restlet.Request 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.Request 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