Jerome Louvel wrote:
The routing assumes that your request contains an absolute target URI that
identifies a target resource. During the routing process the resource's base
URI is continuously updated to implement a hierarchical URI routing
approach, as described here:
http://www.restlet.org/documentation/1.1/tutorial#part11

Ah, I didn't realize. I was thinking those items didn't change during processing. It might be good to make that more explicit in the tutorial or in the docs. A little example of request processing in that section of the tutorial would be great.

Now that you explain it, though, that makes perfect sense.


If you want to test the routing logic per-se, and not just test the outcome
of the processing of routed requests, it seems like your approach is fine.
Please continue to give us feed-back along the road. This is an interesting
use case for the API.

Sure thing. Currently, my tests are looking like this:

   public void testListRoutes() {
       assertThat(route("/list/111"), is(ListRestlet.class));
assertThat(routeAttributes("/list/111"), hasEntry(ListRestlet.LIST_ID, "111"));
       assertThat(route("/list/create"), is(CreateListRestlet.class));
assertThat(route("/list/create/12345"), is(CreateListRestlet.class)); assertThat(routeAttributes("/list/create/12345"), hasEntry(CreateListRestlet.CATEGORY_ID, "12345"));
   }

As an example of the plumbing, the routeAttributes method looks like this:

   private Map<String, String> routeAttributes(String path) {
       Router router = makeRouter();
       Request request = makeGet(path);
       router.handle(request, new TestableResponse(request));
       HashMap<String, String> result = new HashMap<String, String>();
       Map<String, Object> requestAttribs = request.getAttributes();
       for (String key : requestAttribs.keySet()) {
           result.put(key, (String) requestAttribs.get(key));
       }
       return result;
   }


It's working fine for me, but since this is actually processing requests, I think others could have issues, especially if they aren't so good at dependency injection, or if they don't have good substitutes for heavyweight dependencies like databases.

From a testing perspective, it would be nice to have a call that just returns the information of selected Restlet and the parameters that the Router is feeding to it. And by "just", I mean without actually invoking the Restlet.

Thanks,

William



--
William Pietri - [EMAIL PROTECTED] - +1-415-643-1024
Agile consulting, coaching, and development: http://www.scissor.com/
Use your geek-fu to fight poverty: http://www.mifos.org/

Reply via email to