You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Juan E. Maya" <ma...@gmail.com> on 2009/07/20 16:51:25 UTC
Testify @ForComponent
I am trying to inject a service to one component using testifiy's
@ForComponent annotation and Mockito but the component doesn't get the
mocked service injected.
My test looks like this:
private static final TapestryTester TESTER = new
TapestryTester("com.rinco.security", "rincoSecurity",
"src/main/webapp", RincoCoreModule.class, RincoSecurityModule.class);
public AbstractRincoSecurityTest() {
super(TESTER);
}
@ForComponents
@Mock
UserFactory _userFactory;
@BeforeMethod
public void initTests(){
MockitoAnnotations.initMocks(this);
}
@Test(groups = { "pages" }, dependsOnMethods = { "singupFormRenderTest" })
public void singupFormSubmitTest() {
Document page = tester.renderPage("SignupTestPage");
Element form = page.getElementById("form");
page = tester.submitForm(form, populateSignupParams());
Assert.assertTrue(StringUtils.contains(page.toString(), "IndexPage"));
}
private Map<String, String> populateSignupParams() {
Map<String, String> params = CollectionFactory.newMap();
params.put("email", "rinco@rinco.com");
params.put("firstName", "rinco");
params.put("lastName", "perry");
params.put("password", "rincopassword");
params.put("verifyPassword", "rincopassword");
return params;
}
The mocked UserFactory is being created but during the execution of
the component is not being injected. am i missing something?
I am using Testng and tapestry 5.1.0.5
Thanks for your help
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Testify @ForComponent
Posted by "Juan E. Maya" <ma...@gmail.com>.
AJA! :) Thanks a lot Paul! I was using the AbstractClass but when
copying the code in the email i removed it :) I thought it was not so
important. Bad ME :) The problem in this case, as u pointed out, was
indeed caused by the @BeforeMethod. Thanks a lot!
Good point with the orchestration. Testify is REALLY useful (i love
the @ForComponent annotation) but that would more transparent.
Tomorrow i will be playing a lot with the tests so i may see
something...
Thanks a lot again
On Mon, Jul 20, 2009 at 8:28 PM, Paul Field<pa...@db.com> wrote:
> Hi Juan,
>
>> I am trying to inject a service to one component using testifiy's
>> @ForComponent annotation and Mockito but the component doesn't get the
>> mocked service injected.
>
> I think you have invalidated the warranty on Testify ;-)
>
> It is important to make sure your tests are setup using the inheritance
> hierarchy described in the Setup instructions:
> http://tapestry.formos.com/nightly/tapestry-testify/#Setup
>
> And then in your "AbstractMyApplicationTest" class you need to override
> setUpForAllTestMethods() as described in the Mockito instructions:
> http://tapestry.formos.com/nightly/tapestry-testify/#Mockito
>
> protected void setUpForAllTestMethods() throws Exception {
> MockitoAnnotations.initMocks(this);
> }
>
> And if you need any other setup per-method then it's best to override
> doSetUp() rather than using @BeforeMethod.
>
> Basically, there's a very specific sequence processing lifecycle that
> needs to be followed for all the Testify features to work in a seamless
> way. The "TapestryTest" base classes, use of an application-specific base
> class and use of template methods (setUpForAllTestMethods()) is all
> carefully designed to make this happen smoothly.
>
>
>
> So, for example, you have tried to use @BeforeMethod to initialise the
> Mocks:
>
>> @ForComponents
>> @Mock
>> UserFactory _userFactory;
>>
>> @BeforeMethod
>> public void initTests(){
>> MockitoAnnotations.initMocks(this);
>> }
>
> But, unfortunately, TestNG is now in charge of the lifecycle and it will
> get it wrong :-( It will initialise the mock *after* it processes
> @ForComponents - so that's why there is no mock for the component (the
> field is still 'null' when @ForComponents is processed).
>
>
> FYI, I am interested if anyone has any ideas for a less
> inheritance-oriented approach to solving the lifecycle orchestration -
> I've thought about it and I can't see a better way with TestNG and,
> although JUnit 4 has Runners (@RunWith), I don't think that solves the
> whole problem.
>
> Paul
>
>
>
> ---
>
> This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
>
> Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Testify @ForComponent
Posted by Paul Field <pa...@db.com>.
Hi Juan,
> I am trying to inject a service to one component using testifiy's
> @ForComponent annotation and Mockito but the component doesn't get the
> mocked service injected.
I think you have invalidated the warranty on Testify ;-)
It is important to make sure your tests are setup using the inheritance
hierarchy described in the Setup instructions:
http://tapestry.formos.com/nightly/tapestry-testify/#Setup
And then in your "AbstractMyApplicationTest" class you need to override
setUpForAllTestMethods() as described in the Mockito instructions:
http://tapestry.formos.com/nightly/tapestry-testify/#Mockito
protected void setUpForAllTestMethods() throws Exception {
MockitoAnnotations.initMocks(this);
}
And if you need any other setup per-method then it's best to override
doSetUp() rather than using @BeforeMethod.
Basically, there's a very specific sequence processing lifecycle that
needs to be followed for all the Testify features to work in a seamless
way. The "TapestryTest" base classes, use of an application-specific base
class and use of template methods (setUpForAllTestMethods()) is all
carefully designed to make this happen smoothly.
So, for example, you have tried to use @BeforeMethod to initialise the
Mocks:
> @ForComponents
> @Mock
> UserFactory _userFactory;
>
> @BeforeMethod
> public void initTests(){
> MockitoAnnotations.initMocks(this);
> }
But, unfortunately, TestNG is now in charge of the lifecycle and it will
get it wrong :-( It will initialise the mock *after* it processes
@ForComponents - so that's why there is no mock for the component (the
field is still 'null' when @ForComponents is processed).
FYI, I am interested if anyone has any ideas for a less
inheritance-oriented approach to solving the lifecycle orchestration -
I've thought about it and I can't see a better way with TestNG and,
although JUnit 4 has Runners (@RunWith), I don't think that solves the
whole problem.
Paul
---
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.