On Mon, 4 Aug 2003, Mark Leicester wrote:
> On 4/08/2003 15:15, "Stephan Michels" <[EMAIL PROTECTED]> wrote:
>
> > Have you take a look into
> > src/test/org/apache/cocoon/AbstractCompositeTestCase.java
>
> Heh, no I haven't seen this at all! Cool! Wow, this is the real thing! Is
> this quite new? I looked earlier this year and didn't see anything. I'll try
> it out immediately! Are there any docs for these unit testing classes yet? I
> looked quickly on the wiki and didn't find anything. If there aren't, I'm
> definitely keen to help!
Sorry, no docu. But I think it is pretty easy.
public void testGenerator() {
String src = "resource://input.xml";
String result = "resource://result.xml";
assertEqual(load(result),
generate("mygenerator", src, EMPTY_PARAMS));
}
You can also test pipelines.
assertEqual(load(result),
transform("mytransformer", src2, EMPTY_PARAMS,
generate("mygenerator", src, EMPTY_PARAMS)));
If you're using request paramters etc. you can easily change them by
public void testRequestAction() {
getRequest().setRequestURI("test.xml?abc=def&ghi=jkl");
getRequest().setQueryString("abc=def&ghi=jkl");
getRequest().setContextPath("servlet");
getRequest().addParameter("abc", "def");
Parameters parameters = new Parameters();
parameters.setParameter("parameters", "true");
Map result = act("request", null, parameters);
assertNull("Test for parameter", (String)result.get("ghi"));
}
The setup of the xtest file is a bit difficult, but using the
ExcaliburTestCase ensures that all lifecycle methods will be handled
correct.
Stephan.