You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Yury Luneff <bi...@ya.ru> on 2009/12/18 03:57:21 UTC

testify forcomponents problem

hello!

I'm experiencing a sort of difficulty coping with testify.

I have the following:

public class ServTest extends TapestryTest {
    private static final TapestryTester SHARED_TESTER = new TapestryTester("serv", "app", "src/main/webapp");

    public ServTest() {
        super(SHARED_TESTER);
    }
}

public class SmokeTest extends ServTest {
    @ForComponents HttpServletRequest request;

    protected void setUpForAllTestMethods() {
        request = createNiceMock(HttpServletRequest.class);
        expect(request.getServerName()).andReturn("localhost");
        expect(request.getServerPort()).andReturn(8080);
        expect(request.getContextPath()).andReturn("serv");
        replay(request);
    }

    @Test
    public void smoke() {
        assertEquals(request.getServerName(), "localhost");
        HttpServletRequest rs = tester.getService(HttpServletRequest.class);
        assertNotNull(rs);
        assertEquals(rs.getServerName(), "localhost");
... skipped from here to the end ...

Last assert fails, I can not understand why.
@Inject  works for tests, but not the @ForComponents. Or am I using it
in a wrong way?



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: testify forcomponents problem

Posted by Yury Luneff <bi...@ya.ru>.
ok, that's a bit of great clarification :) but here is what i'm having
now:

public class SmokeTest extends ServTest {
    @ForComponents public HttpServletRequest request;

    @Override
    protected void doSetUp() {
        request = createNiceMock(HttpServletRequest.class);
        expect(request.getServerName()).andReturn("localhost");
        expect(request.getServerPort()).andReturn(8080);
        expect(request.getContextPath()).andReturn("serv");
        replay(request);
    }

    @Test
    public void smoke() {
        Info info = tester.getService(Info.class);
        assertEquals(info.getServerUrl(), "http://localhost:8080/serv/");
    }
}

So,   as   you've  said,  any components (here I stopped writing, as I
was expected for Inject to be processed for a _service_ and that is my
problem :) thank you :)

Now it's simply
@ForComponents public Info info;

    @Override
    protected void doSetUp() {
        info = createNiceMock(Info.class);
        expect(info.getServerUrl()).andReturn("http://localhost:8080/serv");
        replay(info);
    }

    @Test
    public void smoke() {
        Document doc = tester.renderPage("/index");
        assertNotNull(doc.getElementById("aboutdialog"));
    }

    And it's working :) Thank you for your time. Testify works :)


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: testify forcomponents problem

Posted by Paul Field <ta...@cloudinthesky.co.uk>.
Hi Yury,

I don't really understand what you are trying to actually test with your
test.

Anyway, let me explain why you are seeing the behaviour that you are seeing.
In Testify, you create the IOC registry and that registry remains constant
throughout all the tests. Testify does not let you mock or replace a
service. So therefore, when you call tester.getService() it will return the
service from the registry.

What Testify does is change the semantics of @Inject so that it prefers to
look up objects from a pool of test objects and that pool of objects is
populated by @ForComponents and is cleaned up for every test.

This change in semantics means that you can render a page and control the
objects that get @injected into the page and its components - and that
control includes using mock objects.

Hope that helps. If not, let me know a bit about what you are trying to
achieve with your test.

Paul




Yury Luneff-2 wrote:
> 
> hello!
> 
> I'm experiencing a sort of difficulty coping with testify.
> 
> I have the following:
> 
> public class ServTest extends TapestryTest {
>     private static final TapestryTester SHARED_TESTER = new
> TapestryTester("serv", "app", "src/main/webapp");
> 
>     public ServTest() {
>         super(SHARED_TESTER);
>     }
> }
> 
> public class SmokeTest extends ServTest {
>     @ForComponents HttpServletRequest request;
> 
>     protected void setUpForAllTestMethods() {
>         request = createNiceMock(HttpServletRequest.class);
>         expect(request.getServerName()).andReturn("localhost");
>         expect(request.getServerPort()).andReturn(8080);
>         expect(request.getContextPath()).andReturn("serv");
>         replay(request);
>     }
> 
>     @Test
>     public void smoke() {
>         assertEquals(request.getServerName(), "localhost");
>         HttpServletRequest rs =
> tester.getService(HttpServletRequest.class);
>         assertNotNull(rs);
>         assertEquals(rs.getServerName(), "localhost");
> ... skipped from here to the end ...
> 
> Last assert fails, I can not understand why.
> @Inject  works for tests, but not the @ForComponents. Or am I using it
> in a wrong way?
> 
> 
> 
> ---------------------------------------------------------------------
> 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://old.nabble.com/testify-forcomponents-problem-tp26838462p26856206.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