We use tapestry-spring and use PageTester to test our pages and this
is how we get around the Spring injection.

For testing we create a new AppModule (TestHarnessModule) that binds
some "dummy" classes for testing

TestHarnessModule.java

 public static void bind(final ServiceBinder binder) {
        binder.bind(IUserService.class,DummyUserService.class);
}

Then we have an abstract Page test class that creates the PageTester
object and loads in the TestHarnessModule

@Before
public void setUp() {
    _pageTester = new
PageTester(appPackage,appName,"src/main/webapp",TestHarnessModule.class);
}

works well for us.  It does mean that we have created some 'dummy'
classes w/ test data in them.

Hope that helps.

-Mark

On Wed, Dec 17, 2008 at 1:07 PM, mraible <m...@raibledesigns.com> wrote:
>
> I have tapestry-spring in my pom.xml and TapestrySpringFilter in my web.xml,
> but neither of those helps me with testing. The following test:
>
>    @Test
>    public void testListUsers() {
>        String appPackage = "org.appfuse.web";
>        String appName = "App";
>        PageTester tester = new PageTester(appPackage, appName,
> "src/main/webapp");
>        Document doc = tester.renderPage("UserList");
>        assertNotNull(doc.getElementById("userList"));
>    }
>
> Results in the following error:
>
> Caused by: java.lang.RuntimeException: Error obtaining injected value for
> field org.appfuse.web.pages.UserList.userManager: No service implements the
> interface org.appfuse.service.UserManager.
>        at
> org.apache.tapestry5.internal.transform.InjectWorker.transform(InjectWorker.java:68)
>        at
> $ComponentClassTransformWorker_11e45efc856.transform($ComponentClassTransformWorker_11e45efc856.java)
>        at
> $ComponentClassTransformWorker_11e45efc84c.transform($ComponentClassTransformWorker_11e45efc84c.java)
>        at
> org.apache.tapestry5.internal.services.ComponentClassTransformerImpl.transformComponentClass(ComponentClassTransformerImpl.java:170)
>        ... 53 more
>
> I was able to get it working by creating a
> src/test/**/services/SpringObjectProvider and
> src/test/**/services/TestModule. Is that the easiest way to populate @Inject
> dependencies from Spring when testing?
>
> If so, is it possible to get beans (or the ApplicationContext) in a test
> from the SpringObjectProvider?
>
> Also, I'd be interested in seeing an example where EasyMock or jMock is used
> to create the objects and set expectations.
>
> Thanks,
>
> Matt
>
>
> Olle Hallin wrote:
>>
>> Is there a problem using tapestry-spring.jar?
>>
>> Olle
>>
>> 2008/12/17 mraible <m...@raibledesigns.com>
>>
>>>
>>> Is the following still the best way to inject Spring beans into a page
>>> when
>>> testing?
>>>
>>> http://wiki.apache.org/tapestry/Tapestry5SpringIntegrationAlternative1
>>>
>>> With Tapestry 4, I could populate a Map with with the bean name and a
>>> real
>>> (or mock) implementation and instantiate the page, then call methods
>>> accordingly. Is this possible with Tapestry 5 w/o creating a lot of
>>> infrastructure code (which the above seems to require)?
>>>
>>> Thanks,
>>>
>>> Matt
>>> --
>>> View this message in context:
>>> http://www.nabble.com/-T5--Testing-Pages-with-injected-Spring-beans-tp21057429p21057429.html
>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>
>>>
>>
>>
>> --
>> Olle Hallin
>> Senior Java Developer and Architect
>> olle.hal...@crisp.se
>> www.crisp.se
>>
>>
>
> --
> View this message in context: 
> http://www.nabble.com/-T5--Testing-Pages-with-injected-Spring-beans-tp21057429p21058304.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to