Matt, Glad you're getting a chance to go under the covers with T5. I'd like to follow up on this issue ... but I'm working on some performance improvements for T5 right now; hopefully we can check back next week.
Howard On Wed, Dec 17, 2008 at 8:02 PM, mraible <m...@raibledesigns.com> wrote: > > To complete this thread, here's the source for both my unit and integration > tests. The test is the same for both, but the integration test uses Spring > instead of a mock implementation. > > http://source.appfuse.org/browse/appfuse-light/trunk/tapestry/src/test/java/org/appfuse/web/pages > > Please let me know if you think these can be improved. > > Thanks, > > Matt > > > mraible wrote: >> >> Thanks, that works when I create a MockUserManagerImpl. >> >> import org.apache.tapestry5.ioc.ServiceBinder; >> import org.appfuse.service.UserManager; >> >> public class MockTestModule { >> >> public static void bind(final ServiceBinder binder) { >> binder.bind(UserManager.class, MockUserManagerImpl.class); >> } >> } >> >> It'd be great if it was possible to use JMock, but no dice: >> >> import org.apache.tapestry5.ioc.ServiceBinder; >> import org.appfuse.service.UserManager; >> import org.jmock.Mockery; >> import org.jmock.integration.junit4.JUnit4Mockery; >> >> public class MockTestModule { >> static Mockery context = new JUnit4Mockery(); >> >> public static void bind(final ServiceBinder binder) { >> binder.bind(UserManager.class, context.mock(UserManager.class)); >> } >> } >> >> Of course, if I could get the ApplicationContext from my PageTester, that >> would also make things easier. >> >> Matt >> >> >> Mark Horn-2 wrote: >>> >>> 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 >>> >>> >>> >> >> > > -- > View this message in context: > http://www.nabble.com/-T5--Testing-Pages-with-injected-Spring-beans-tp21057429p21066246.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 > > -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org