Odd - it looks like the @ForComponents objects should be created and 
collected (because setup/doSetUp are called); it looks like the 
setup/teardown methods are called in the right way (from the call trace in 
your other email). I'm having trouble seeing what's wrong.

At this point I would probably reach for a debugger... If you can simplify 
the project to something you wouldn't mind zipping up and sending to me 
I'll be happy to take a look.


If you want to have a go yourself, then put breakpoints on the methods of 
SimpleObjectsForComponentStore - which is the service that stores the 
objects that you specify with @ForComponents so you can see objects being 
stored and requested. Also put a breakpoint in ThreadLocalPerTestDataStore
#cleanup() so you can see when the test ends and the data is dropped from 
the SimpleObjectsForComponentsStore.

The sequence should be:
Data collected from @ForComponents  -  calls to 
SimpleObjectsForComponentStore#put()
Page rendering, @Inject fields accessed -  calls to 
SimpleObjectsForComponentStore#get()
Test complete, tearDown() called - call to ThreadLocalPerTestDataStore
#cleanup()

As well as checking the sequence is correct, you can see what is in the 
store when get is being called (and what is being requested).

- Paul


akochnev <akoch...@gmail.com> wrote on 29/01/2010 13:33:00:

> 
> Paul, 
>    thanks for the quick response. Now, down the checklist : 
> 
> 1. I am extending from the testng version of the class: 
> package com.troymaxventures.zadachite.pagetestsupport;
> 
> 
> 
> import com.formos.tapestry.testify.core.TapestryTester;
> import com.formos.tapestry.testify.testng.TapestryTest;
> 
> public abstract class AbstractZdTapTest extends TapestryTest {
>     private static final TapestryTester SHARED_TESTER = new
> TapestryTester("foo", ZdTestAppModule.class);
> 
>     public AbstractZdTapTest() {
>         super(SHARED_TESTER);
>     }
> }
> 
> 2. doSetUp() is indeed being called, I added a breakpoint and a println 
: 
> 
>    @Override
>    protected void doSetUp() {
>        userRepo = EasyMock.createMock(UserRepository.class);
>        System.out.println("The doSetUp() is called by TestNG");
>    }
> 
> The doSetUp() is called by TestNG
> Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 5.051 
sec
> <<< FAILURE!
> 
> 3. The testng config file : 
> I run the test from Maven, this is the suite file that gets generated : 
> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd";>
> <suite thread-count="5" skipfailedinvocationCounts="false" verbose="0"
> name="Failed suite [Command line suite]" junit="false" 
annotations="JDK">
>   <test name="Command line test(failed)" junit="false" 
annotations="JDK">
>     <classes>
>       <class 
name="com.troymaxventures.zadachite.pagetests.StupidPageTest">
>         <methods>
>           <include name="processInjectAnnotation"/>
>           <include name="testElementIsOnPage"/>
>           <include name="tearDown"/>
>           <include name="testStupidPageUnitTest"/>
>           <include name="setUp"/>
>         </methods>
>       </class>
>     </classes>
>   </test>
> </suite>
> 
> 4. I added an extra test where I explicitly use the pageTester to try to
> inject the dependencies into my page. When I specify a totally bogus 
package
> name ( so that Testify doesn't pick up the AppModule from my app), the 
test
> fails w/ an error that it can't find my page (understandable, as I had 
the
> bogus package name, so it can't find the page) when I render the page 
using
> the tester; however, when I try to inject the dependencies directly into 
the
> object instance, it fails that there is no instance of UserRepository . 
When
> I include the full package name (so that testify picks up the 
AppModule),
> the injectInto populates the service from the AppModule and not with the
> implementation that I provide in the test. When I use the
> tester.renderPage("stupid") and debug the page, I see nulls set on all 
the
> services (e.g. in my example, userRepo is null), and I also see non-null
> values in some mangled names in the class (e.g. something like
> _$nonTestUserRepo)
> 
> 
> 
-------------------------------------------------------------------------------
> Test set: TestSuite
> 
-------------------------------------------------------------------------------
> Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 5.052 
sec
> <<< FAILURE!
> 
testElementIsOnPage(com.troymaxventures.zadachite.pagetests.StupidPageTest) 

> Time elapsed: 0.966 sec  <<< FAILURE!
> java.lang.RuntimeException: Request was not handled: 'stupid' may not be 
a
> valid page name.
>         at
> org.apache.tapestry5.test.PageTester.renderPage(PageTester.java:177)
>         at
> com.troymaxventures.zadachite.pagetests.StupidPageTest.
> testElementIsOnPage(StupidPageTest.java:40)
> 
> testStupidPageUnitTest(com.troymaxventures.zadachite.pagetests.
> StupidPageTest) 
> Time elapsed: 0.01 sec  <<< FAILURE!
> java.lang.RuntimeException: No service implements the interface
> com.troymaxventures.zadachite.services.UserRepository.
>         at
> org.apache.tapestry5.ioc.internal.RegistryImpl.
> getService(RegistryImpl.java:575)
>         at
> org.apache.tapestry5.ioc.internal.RegistryWrapper.
> getService(RegistryWrapper.java:58)
>         at
> org.apache.tapestry5.test.PageTester.getService(PageTester.java:154)
>         at
> com.formos.tapestry.testify.core.TapestryTester$FieldInjector.
> process(TapestryTester.java:125)
>         at
> com.formos.tapestry.testify.core.TapestryTester.
> processField(TapestryTester.java:106)
>         at
> com.formos.tapestry.testify.core.TapestryTester.
> processFieldsAnnotatedWith(TapestryTester.java:96)
>         at
> com.formos.tapestry.testify.core.TapestryTester.
> injectInto(TapestryTester.java:74)
>         at
> com.troymaxventures.zadachite.pagetests.StupidPageTest.
> testStupidPageUnitTest(StupidPageTest.java:53)
> 
> The superclass w/ a bogus package name: 
> import com.formos.tapestry.testify.core.TapestryTester;
> import com.formos.tapestry.testify.testng.TapestryTest;
> 
> public abstract class AbstractZdTapTest extends TapestryTest {
>     private static final TapestryTester SHARED_TESTER = new
> TapestryTester("foo", ZdTestAppModule.class);
> 
>     public AbstractZdTapTest() {
>         super(SHARED_TESTER);
>     }
> }
> 
> import com.formos.tapestry.testify.core.ForComponents;
> import com.troymaxventures.zadachite.model.EmailAddress;
> import com.troymaxventures.zadachite.model.UserRegistration;
> import com.troymaxventures.zadachite.model.ZdUser;
> import com.troymaxventures.zadachite.pages.Stupid;
> import com.troymaxventures.zadachite.pagetestsupport.AbstractZdTapTest;
> import com.troymaxventures.zadachite.services.UserRepository;
> import org.apache.tapestry5.dom.Document;
> import org.easymock.EasyMock;
> import org.testng.Assert;
> import org.testng.annotations.Test;
> import static org.easymock.EasyMock.*;
> 
> /**
>  *
>  * @author polrtex
>  */
> public class StupidPageTest extends AbstractZdTapTest {
>    @ForComponents
>    UserRepository userRepo;
> 
> 
>    @Override
>    protected void doSetUp() {
>        userRepo = EasyMock.createMock(UserRepository.class);
>        System.out.println("The doSetUp() is called by TestNG");
>    }
> 
> 
>    @Test
>    public void testElementIsOnPage()  throws Exception {
> 
> expect(userRepo.userRegistered((EmailAddress)anyObject())).
> andStubReturn(Boolean.FALSE);
>        ZdUser testUser = new ZdUser(new EmailAddress("f...@bar.com"));
> 
> expect(userRepo.registerUser(isA(UserRegistration.class))).
> andStubReturn(testUser); 
> 
>        replay(userRepo);
> 
>        Document page = tester.renderPage("stupid");
>        Assert.assertTrue(page.toString().contains("I should be empty"));
>    }
> 
>    @Test
>    public void testStupidPageUnitTest()  throws Exception {
> 
> expect(userRepo.userRegistered((EmailAddress)anyObject())).
> andStubReturn(Boolean.FALSE);
>        ZdUser testUser = new ZdUser(new EmailAddress("f...@bar.com"));
> 
> expect(userRepo.registerUser(isA(UserRegistration.class))).
> andStubReturn(testUser);
> 
>        replay(userRepo);
> 
>        Stupid s = new Stupid();
>        // when I have a bogus package name,  this fails w/ a message 
that
> there are no UserRepository-ies to inject
>        tester.injectInto(s);
>        s.setupRender();
> 
>    }
> }
> 
> 
> 
> 
> Paul Field-4 wrote:
> > 
> > 
> > The next thing is probably to check that the various setup methods are 

> > being called. Can you put a print statement into doSetUp() and check 
it's 
> > actually being called? This will let us see whether the setup isn't 
being 
> > called, or the @ForComponents processing isn't working properly. I 
suspect 
> > the doSetUp()isn't being called and that's going to be a TestNG thing: 
it 
> > should be calling TapestryTest#setUp() method... Can you check the 
TestNG 
> > output reports - I seem to remember that one of them outputs the 
sequence 
> > of setup methods and tests? If you're still stuck can you also send 
the 
> > testng configuration (xml) file?
> > 
> > Let me know what you find.
> > 
> > - Paul
> > 
> > 
> > 
> > 
> > akochnev <akoch...@gmail.com> wrote on 29/01/2010 11:24:01:
> > 
> >> 
> >> I'm running into trouble with using services declared inside of a 
> > Testify
> >> TestNG test case with @ForComponents into my pages - when I ask the 
> > tester
> >> to render a page, the services that were supposed to be injected, are 

> > null.
> >> Any tips on what I'm doing wrong ? 
> >> 
> >> 
> >> Here is the sample code: 
> >> 
> >> public class StupidPageTest extends AbstractZdTapTest {
> >>    @ForComponents
> >>    private UserRepository userRepo;
> >> 
> >> 
> >>    @Override
> >>    protected void doSetUp() {
> >>        userRepo = EasyMock.createMock(UserRepository.class);
> >>    }
> >> 
> >> 
> >>    @Test
> >>    public void testElementIsOnPage()  throws Exception {
> >> 
> >> expect(userRepo.userRegistered((EmailAddress)anyObject())).
> >> andStubReturn(Boolean.FALSE);
> >>        ZdUser testUser = new ZdUser(new 
EmailAddress("f...@bar.com"));;
> >> 
> >> expect(userRepo.registerUser(isA(UserRegistration.class))).
> >> andStubReturn(testUser); 
> >>        replay(userRepo);
> >>        Document page = tester.renderPage("stupid");
> >>        System.out.println("Rendered page: " + page.toString());
> >> 
> >>    }
> >> }
> >> 
> >> public abstract class AbstractZdTapTest extends TapestryTest {
> >>     private static final TapestryTester SHARED_TESTER = new
> >> TapestryTester("com.troymaxventures.zadachite",
> >> ZdTestAppModule.class,AppModule.class);
> >> 
> >>     public AbstractZdTapTest() {
> >>         super(SHARED_TESTER);
> >>     }
> >> }
> >> 
> >> public abstract class AbstractZdTapTest extends TapestryTest {
> >>     private static final TapestryTester SHARED_TESTER = new
> >> TapestryTester("com.troymaxventures.zadachite", 
ZdTestAppModule.class);
> >> 
> >>     public AbstractZdTapTest() {
> >>         super(SHARED_TESTER);
> >>     }
> >> }
> >> 
> >> public class ZdTestAppModule {
> >> 
> >>     /**
> >>      * Ensure that there are valid HTTP request/response objects in 
the
> >>     test, otherwise the ACEGI integration tends to blow up.
> >>      */
> >>     public static void
> >> contributeRequestHandler(OrderedConfiguration<RequestFilter> config, 
> > final
> >> RequestGlobals requestGlobals) {
> >>         RequestFilter filter = new RequestFilter() {
> >> 
> >>             @Override
> >>             public boolean service(Request request, Response 
response,
> >>                     RequestHandler handler) throws IOException {
> >> 
> >> requestGlobals.storeServletRequestResponse(EasyMock.
> >> createMock(HttpServletRequest.class),
> >> EasyMock.createMock(HttpServletResponse.class));
> >>                 return handler.service(request, response);
> >>             }
> >>         };
> >>         config.add("EnsureNonNullHttpRequestAndResponse", filter,
> >>                 "before:*");
> >>     }
> >> }
> >> 
> >> public class Stupid {
> >>     @Inject
> >>     private UserRepository userRepo;
> >>     void setupRender() throws StorageException { 
> >>      // the userRepo is null here during the test
> >>             userRepo.getUser(new EmailAddress("f...@bar.com")); 
> >>     }
> >> }
> >> 
> >> 
> >> -- 
> >> View this message in context: http://old.nabble.com/TestNG---
> >> Injecting-Testify-services-into-pages-tp27370621p27370621.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
> >> 
> > 
> > 
> > 
> > ---
> > 
> > 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.
> > 
> 
> -- 
> View this message in context: http://old.nabble.com/TestNG---
> Injecting-Testify-services-into-pages-tp27370621p27371994.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
> 



---

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.

Reply via email to