Tayeb,

The point of MockRoundTrip is to simplify the use of Stripe's other mock objects simulate an HTTP request/response. The set/ addParameter(...) methods are for defining the form properties that represent a form submission - so it can only take string parameters.

In your second bit of code, you are attempting to retrieve an ActionBean before the MockRoundTrip has been executed - but the JavaDoc for the MockRoundTrip class notes that getActionBean(Class) returns the ActionBean that was instantiated to handle the request. Your test code is trying to 'manually' inject your AuthorService and BrikManager - it won't work that way because you don't have control over the instantiation of the BrikActionBean.

Assuming AuthorService and BrikManager are Spring-managed beans, you need to set things up so that your BrikActionBean gets access to those instances by itself. One option is to use Stripe's Spring support, and another is to just have your ActionBean access the Spring context directly.

Stripe's Spring support relies on a Spring WebApplicationContext being available. This is common in Spring-based web apps - a Spring application context is configured and made available via the ServletContext. In a regular web app, you would do this by configuring Spring's org.springframework.web.context.ContextLoaderListener or a Filter/Servlet based alternative in your web.xml. For unit testing, you can set the context up in a test fixture: If you're not doing it already, the Stripes unit testing doc recommends that you have a test fixture that sets up a MockServletContext instance for use by all your unit tests' MockRoundTrips. This replaces what web.xml does for you in a real servlet container. In that fixture, you should set up the Stripes filter and also a Spring org.springframework.web.filter.RequestContextFilter .

Hope this helps,

Chris.

On Aug 27, 2008, at 9:33 AM, Tayeb Taouti DR Tes Appl. Java wrote:

Hello,

I use some diff. objects in an action bean I want to test (following http://www.stripesframework.org/display/stripes/Unit+Testing) .

I have bean able to test it only by calling the action bean directly:

        bean = new BrikActionBean();
        bean.setAuthorService(authorService);
        bean.setBrikManager(brikManager);
        bean.editObjectsButton();
        ...

but cannot run it using the MockRoundtrip.
If I use the it, I can't find a way to set the objects.
MockRoundtrip.set/addParameter(...) takes only strings, and I cannot set objects directly into the action bean,
nor pass a processed bean into MockRoundtrip e.g.:

    MockRoundtrip trip = new MockRoundtrip(ctx, BrikActionBean.class);
    BrikActionBean bean = trip.getActionBean(BrikActionBean.class);
    bean.setBrikManager(brikManager);
    bean.setAuthorService(authorService);
    trip.execute("editObjectsButton");

doesn't work.

I have had a hard time trying to use TestNG but dropped it and used JUnit and extend:
AbstractTransactionalSpringContextTests to set the beans.

Am I getting something wrong?

/Tayeb

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to