You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by mraible <ma...@raibledesigns.com> on 2008/12/17 18:20:26 UTC
[T5] Testing Pages with injected Spring beans
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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5] Testing Pages with injected Spring beans
Posted by Howard Lewis Ship <hl...@gmail.com>.
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 <ma...@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 <ma...@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 <ma...@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-unsubscribe@tapestry.apache.org
>>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Olle Hallin
>>>>> Senior Java Developer and Architect
>>>>> olle.hallin@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-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Howard M. Lewis Ship
Creator Apache Tapestry and Apache HiveMind
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5] Testing Pages with injected Spring beans
Posted by mraible <ma...@raibledesigns.com>.
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 <ma...@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 <ma...@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-unsubscribe@tapestry.apache.org
>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Olle Hallin
>>>> Senior Java Developer and Architect
>>>> olle.hallin@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-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5] Testing Pages with injected Spring beans
Posted by mraible <ma...@raibledesigns.com>.
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 <ma...@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 <ma...@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-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>
>>>>
>>>
>>>
>>> --
>>> Olle Hallin
>>> Senior Java Developer and Architect
>>> olle.hallin@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-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/-T5--Testing-Pages-with-injected-Spring-beans-tp21057429p21058779.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5] Testing Pages with injected Spring beans
Posted by Mark Horn <ma...@agilesrc.com>.
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 <ma...@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 <ma...@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-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>>
>> --
>> Olle Hallin
>> Senior Java Developer and Architect
>> olle.hallin@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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5] Testing Pages with injected Spring beans
Posted by mraible <ma...@raibledesigns.com>.
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 <ma...@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-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> Olle Hallin
> Senior Java Developer and Architect
> olle.hallin@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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5] Testing Pages with injected Spring beans
Posted by Olle Hallin <ol...@gmail.com>.
Is there a problem using tapestry-spring.jar?
Olle
2008/12/17 mraible <ma...@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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Olle Hallin
Senior Java Developer and Architect
olle.hallin@crisp.se
www.crisp.se
Re: [T5] Testing Pages with injected Spring beans
Posted by mraible <ma...@raibledesigns.com>.
Thiago H. de Paula Figueiredo wrote:
>
> Em Wed, 17 Dec 2008 14:20:26 -0300, mraible <ma...@raibledesigns.com>
> escreveu:
>
>> Is the following still the best way to inject Spring beans into a page
>> when testing?
>>
>> http://wiki.apache.org/tapestry/Tapestry5SpringIntegrationAlternative1
>
> This page is quite old . . . it talks about Tapestry 5.0.2, released at
> least one year and a half ago.
> I would simply use a dedicated Tapestry-IoC module and mock the services
> there. Don't forget that, regardless where the services come from
> (Tapestry-IoC, Spring, whatever), Tapestry-IoC injects them the same way.
>
>> 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)?
>
> You can add service setters for you page classes (they're POJOs!) and
> inject them yourself easily. ;)
>
Is it possible to get the Page class itself from PageTester? I only see the
ability to get the Document using renderPage.
You're right about POJOs, I guess I can just create a new instance, inject
the mock services and call methods that way. I guess I was hoping for better
built-in integration testing support.
Matt
--
View this message in context: http://www.nabble.com/-T5--Testing-Pages-with-injected-Spring-beans-tp21057429p21058383.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5] Testing Pages with injected Spring beans
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Wed, 17 Dec 2008 14:20:26 -0300, mraible <ma...@raibledesigns.com>
escreveu:
> Is the following still the best way to inject Spring beans into a page
> when testing?
>
> http://wiki.apache.org/tapestry/Tapestry5SpringIntegrationAlternative1
This page is quite old . . . it talks about Tapestry 5.0.2, released at
least one year and a half ago.
I would simply use a dedicated Tapestry-IoC module and mock the services
there. Don't forget that, regardless where the services come from
(Tapestry-IoC, Spring, whatever), Tapestry-IoC injects them the same way.
> 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)?
You can add service setters for you page classes (they're POJOs!) and
inject them yourself easily. ;)
--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
Consultor, desenvolvedor e instrutor em Java
http://www.arsmachina.com.br/thiago
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org