Paul,
   I tried the trick w/ the RequestCache; however, it blows up when I try to
cast the page instance that I pick up  from the cache. When I debug it, it
does show that it's the same class (as is stated in the exception); however,
because of the class transformations (or maybe some classloader issues) or
something else I can't cast to the original class.

   Any other ideas of I can get a page from this cache and invoke a method
on it ?


@Test
   public void testStupidPageUnitTest()  throws Exception {
       Object o = cache.get("stupid").getRootElement().getComponent();
       // this is where the cast  fails
       Stupid s = (Stupid)o;
       System.out.println("Found page : " + o);

   }

testStupidPageUnitTest(com.troymaxventures.zadachite.pagetests.StupidPageTest)
Time elapsed: 23.21 sec  <<< FAILURE!
*java.lang.ClassCastException: samples.pages.Stupid cannot be cast to
samples.pages.Stupid*
        at
com.troymaxventures.zadachite.pagetests.StupidPageTest.testStupidPageUnitTest(StupidPageTest.java:60)

Cheers,

Alex K

On Tue, Feb 2, 2010 at 9:27 AM, Paul Field <paul.fi...@db.com> wrote:

> akochnev <akoch...@gmail.com> wrote on 31/01/2010 11:26:53:
>
> >    The next thing I'm trying to work out is use  Testify for unit-like
> > testing. The idea was that I could possibly instantiate the page class
> > myself (e.g. w/o having to ask the tester to render the page), inject
> the
> > dependencies (using tester.injectInto(pageInstance) ) that are needed
> for a
> > particular method and then just invoke the method.
>
> The injectInto() method is designed to populate fields in a test *before*
> any of the setup is done - so it doesn't really expect to work with the
> @ForComponents annotations.
>
> You could let Tapestry do the instantiation of the page for you. I think
> this will work (although it uses internal services so it might work now
> but not in a future Tapestry version):
>
>    @Inject
>    private RequestPageCache cache;
>
>    public void test() {
>        StupidPage page =
>
> (StupidPage)cache.get("mypages/stupidPage").getRootElement().getComponent();
>        page.myMethod();
>    }
>
> This potentially has the advantage that all the transformations have been
> done on the class - so it behaves more like the page actually will.
>
> Out of interest, what kind of tests need the instance of the page class? I
> haven't felt the need so far so I wonder if I'm missing out on something
> :-)
>
> 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.
>

Reply via email to