Search in sources :

Example 6 with Response

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

Example 7 with Response

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");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(org.restlet.Response) SSOToken(com.iplanet.sso.SSOToken) Restlet(org.restlet.Restlet) Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) HttpRequest(org.restlet.engine.adapter.HttpRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.restlet.Request) Test(org.testng.annotations.Test)

Example 8 with Response

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");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(org.restlet.Response) SSOToken(com.iplanet.sso.SSOToken) Restlet(org.restlet.Restlet) HttpRequest(org.restlet.engine.adapter.HttpRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.restlet.Request) Test(org.testng.annotations.Test)

Example 9 with Response

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

Example 10 with Response

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\""));
}
Also used : Response(org.restlet.Response) Status(org.restlet.data.Status) Request(org.restlet.Request) ResourceException(org.forgerock.json.resource.ResourceException) Representation(org.restlet.representation.Representation) Test(org.testng.annotations.Test)

Aggregations

Response (org.restlet.Response)82 Request (org.restlet.Request)64 Test (org.testng.annotations.Test)28 Reference (org.restlet.data.Reference)26 Representation (org.restlet.representation.Representation)24 Status (org.restlet.data.Status)17 StringWriter (java.io.StringWriter)16 ChallengeResponse (org.restlet.data.ChallengeResponse)15 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)12 ResponseHandler (org.qi4j.library.rest.client.spi.ResponseHandler)12 HashMap (java.util.HashMap)11 ZNRecord (org.apache.helix.ZNRecord)11 StringReader (java.io.StringReader)10 Map (java.util.Map)10 TypeReference (org.codehaus.jackson.type.TypeReference)10 Test (org.junit.Test)10 Client (org.restlet.Client)10 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)9 ContextResourceClient (org.qi4j.library.rest.client.api.ContextResourceClient)7 HandlerCommand (org.qi4j.library.rest.client.api.HandlerCommand)7