Hello Nathan,

I will present some code about an Application that hosts a set of resources,
but this will apply also for a Component.
Assuming there is an Application that declares a route called "/test1" to
resource:
    @Override
    public Restlet createInboundRoot() {
        Router router = new Router(getContext());
        router.attach("/test1", MyResource.class);
        return router;
    }

You can simply test it without any server by calling the
Application#handle(Request, Response) method:
        Request request = new Request(Method.GET, "/test1");
        // Complete the request
        request.getClientInfo().getPrincipals().add(...);
        [...]

        Response response = new Response(request);
        new MyApplication().handle(request, response);
        System.out.println(response.getStatus());
        System.out.println(response.getEntityAsText());

Best regards,
Thierry Boileau


We have a set up where the container manages the security.  The resources
> that are protected by the container use the user's principal that is stored
> in the ClientInfo.  My problem is that I don't know how to mock/set this in
> the client info for unit testing of our restlet resources.  Can this be
> done?
>
> Nathan
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2792944

Reply via email to