RE: T5: testing using PageTester and EasyMock

2008-09-17 Thread Russell Brown
Right. I done it. I'll write a wiki post about it this evening.

In short, only services with an interface are wrapped in the
ObjectCreator proxy. I just use reflection to grab the ObjectCreator
field from the proxy and fire its create method and use the resultant
service.

Sweet

Russell



-Original Message-
From: Russell Brown [mailto:[EMAIL PROTECTED] 
Sent: 17 September 2008 16:09
To: Tapestry users
Subject: RE: T5: testing using PageTester and EasyMock

Alex,
Yeah. I think that the approach you outline may well work but is
unworkable   (if you know what I mean). I hold out for some way of
stripping the proxy from my mock service (using reflection to fire the
Object Creators create method and using the un proxied mock).

The problem with training the mock in the test case is that you don't
get the mock from the registry, you get a proxy wrapped mock.

Cheers

Russell

-Original Message-
From: Alex Kotchnev [mailto:[EMAIL PROTECTED] 
Sent: 17 September 2008 15:27
To: Tapestry users
Subject: Re: T5: testing using PageTester and EasyMock

Russell,
   this is just speculation, as I haven't tried this on my own, but it
seems
to me that you'll have to do the EasyMock setup & training inside your
test
module, e.g. :

@SubModule( { MyAppModule.class })
MyAppTestModule

public static MyService buildMyService () {
   MyService myMockService =
EasyMock.createMock(MyService.class);
   EasyMock.expect(myMockService.
expensiveExternalMethodCallToCreditCardGatewayIdontReallyWantToTest(myCa
rdNumber)).andReturn(authCode);

}

Unfortunately, with an approach like this, you'd have to have different
"buildMyService" method for each test case for which you need to train
the
Mock... I'm not sure how that would work, maybe you can have your
MyAppTestModule use something from the test case that will train the
myMockService based on the individual testcase expectations.

 Keep us posted on how this works.

Cheers,

Alex Kotchnev


On Wed, Sep 17, 2008 at 10:16 AM, Russell Brown
<[EMAIL PROTECTED]>wrote:

> Hi Peter,
> Thanks for that. That is just normal EasyMock testing isn't it? I
don't see
> where tapestry comes into that at all? You are creating the instances
of all
> the classes and you are creating the instance of the class under test
aren't
> you? Where is the PageTester and Tapestry IoC and all that (or have
you
> missed some code, or am I missing something?)
>
>
>
> What I meant was this:- In the src/main/java tree I have MyAppModule
which
> has some services like
>
> Binder.bind(MyService.class, MyExpensiveExternalImpl.class)
>
> But in my src/test/java tree I have
>
> @SubModule( { MyAppModule.class })
> MyAppTestModule
>
> public static MyService buildMyService () {
>return EasyMock.createMock(MyService.class);
> }
>
>
> (In the actual App the MyService Impl will be provided by Spring but
that
> is by the by)
>
> So that when I use PageTester in my tests I can go
>
> MyService myMockService =
> pageTester.getRegistry().getService(MyService.class);
>
>
>
EasyMock.expect(myMockService.expensiveExternalMethodCallToCreditCardGat
ewayIdontReallyWantToTest(myCardNumber)).andReturn(authCode);
>
>
> But the problem is...the registry returns a Proxy that contains a
> JustInTimeObjectCreator so EasyMock won't have no truck with my mock
> service. Boo.
>
> Cheers
>
> Russell
>
>
>
>
>
> -Original Message-
> From: Peter Stavrinides [mailto:[EMAIL PROTECTED]
> Sent: 17 September 2008 14:08
> To: Tapestry users
> Subject: Re: T5: testing using PageTester and EasyMock
>
> Sorry about that hit the send by accident, here is the rest of it:
>@BeforeClass
>public static void setup() {
>
>// tapestry interfaces
>_mockAsm = createMock(ApplicationStateManager.class);
>_mockContext = createMock(Context.class);
>_mockResponse = createMock(Response.class);
>_mockRequest = createMock(Request.class);
>
>// an interface of my own
>_mockSiteError = createMock(ISiteError.class);
>
>_transport = new SMTPTransport("mailrelay",25);
>}
>
>/**
> * Test the properties for the service are set correctly and
that
> the
> * service can be constructed
> */
>@Test
>public final void testConstruction() {
>
>  expect(_mockContext.getInitParameter("DevelopmentMode")).andReturn(
>"false");
>
>  expect(_mockContext.getInitParameter("MailServer")).andReturn(
>  

RE: T5: testing using PageTester and EasyMock

2008-09-17 Thread Russell Brown
Alex,
Yeah. I think that the approach you outline may well work but is
unworkable   (if you know what I mean). I hold out for some way of
stripping the proxy from my mock service (using reflection to fire the
Object Creators create method and using the un proxied mock).

The problem with training the mock in the test case is that you don't
get the mock from the registry, you get a proxy wrapped mock.

Cheers

Russell

-Original Message-
From: Alex Kotchnev [mailto:[EMAIL PROTECTED] 
Sent: 17 September 2008 15:27
To: Tapestry users
Subject: Re: T5: testing using PageTester and EasyMock

Russell,
   this is just speculation, as I haven't tried this on my own, but it
seems
to me that you'll have to do the EasyMock setup & training inside your
test
module, e.g. :

@SubModule( { MyAppModule.class })
MyAppTestModule

public static MyService buildMyService () {
   MyService myMockService =
EasyMock.createMock(MyService.class);
   EasyMock.expect(myMockService.
expensiveExternalMethodCallToCreditCardGatewayIdontReallyWantToTest(myCa
rdNumber)).andReturn(authCode);

}

Unfortunately, with an approach like this, you'd have to have different
"buildMyService" method for each test case for which you need to train
the
Mock... I'm not sure how that would work, maybe you can have your
MyAppTestModule use something from the test case that will train the
myMockService based on the individual testcase expectations.

 Keep us posted on how this works.

Cheers,

Alex Kotchnev


On Wed, Sep 17, 2008 at 10:16 AM, Russell Brown
<[EMAIL PROTECTED]>wrote:

> Hi Peter,
> Thanks for that. That is just normal EasyMock testing isn't it? I
don't see
> where tapestry comes into that at all? You are creating the instances
of all
> the classes and you are creating the instance of the class under test
aren't
> you? Where is the PageTester and Tapestry IoC and all that (or have
you
> missed some code, or am I missing something?)
>
>
>
> What I meant was this:- In the src/main/java tree I have MyAppModule
which
> has some services like
>
> Binder.bind(MyService.class, MyExpensiveExternalImpl.class)
>
> But in my src/test/java tree I have
>
> @SubModule( { MyAppModule.class })
> MyAppTestModule
>
> public static MyService buildMyService () {
>return EasyMock.createMock(MyService.class);
> }
>
>
> (In the actual App the MyService Impl will be provided by Spring but
that
> is by the by)
>
> So that when I use PageTester in my tests I can go
>
> MyService myMockService =
> pageTester.getRegistry().getService(MyService.class);
>
>
>
EasyMock.expect(myMockService.expensiveExternalMethodCallToCreditCardGat
ewayIdontReallyWantToTest(myCardNumber)).andReturn(authCode);
>
>
> But the problem is...the registry returns a Proxy that contains a
> JustInTimeObjectCreator so EasyMock won't have no truck with my mock
> service. Boo.
>
> Cheers
>
> Russell
>
>
>
>
>
> -Original Message-
> From: Peter Stavrinides [mailto:[EMAIL PROTECTED]
> Sent: 17 September 2008 14:08
> To: Tapestry users
> Subject: Re: T5: testing using PageTester and EasyMock
>
> Sorry about that hit the send by accident, here is the rest of it:
>@BeforeClass
>public static void setup() {
>
>// tapestry interfaces
>_mockAsm = createMock(ApplicationStateManager.class);
>_mockContext = createMock(Context.class);
>_mockResponse = createMock(Response.class);
>_mockRequest = createMock(Request.class);
>
>// an interface of my own
>_mockSiteError = createMock(ISiteError.class);
>
>_transport = new SMTPTransport("mailrelay",25);
>}
>
>/**
> * Test the properties for the service are set correctly and
that
> the
> * service can be constructed
> */
>@Test
>public final void testConstruction() {
>
>  expect(_mockContext.getInitParameter("DevelopmentMode")).andReturn(
>"false");
>
>  expect(_mockContext.getInitParameter("MailServer")).andReturn(
>"mailrelay");
>replay(_mockContext);
>
>// now see if we can construct an instance of the class
> under test
>_mockSiteErrorImpl = new SiteErrorImpl(_mockAsm,
> _mockContext,
>        _mockResponse, _mockRequest);
>// run the verify
>verify(_mockContext);
>}
>
>
>
>
> - Original Message -
> From: "Russell Brown" 

Re: T5: testing using PageTester and EasyMock

2008-09-17 Thread Peter Stavrinides
Hi Russell,

Now I see what you mean, like I said though I haven't used PageTester yet. 

I only use Easymock to test my IoC services that implement Tapestry interfaces, 
you appear to have an unsatisfied class dependency... just a shot in the dark, 
but have you tried the EasyMock Class Extension. 

cheers,
Peter

- Original Message -
From: "Russell Brown" <[EMAIL PROTECTED]>
To: "Tapestry users" 
Sent: Wednesday, 17 September, 2008 5:16:33 PM GMT +02:00 Athens, Beirut, 
Bucharest, Istanbul
Subject: RE: T5: testing using PageTester and EasyMock

Hi Peter,
Thanks for that. That is just normal EasyMock testing isn't it? I don't see 
where tapestry comes into that at all? You are creating the instances of all 
the classes and you are creating the instance of the class under test aren't 
you? Where is the PageTester and Tapestry IoC and all that (or have you missed 
some code, or am I missing something?)



What I meant was this:- In the src/main/java tree I have MyAppModule which has 
some services like

Binder.bind(MyService.class, MyExpensiveExternalImpl.class)

But in my src/test/java tree I have 

@SubModule( { MyAppModule.class })
MyAppTestModule

public static MyService buildMyService () {
return EasyMock.createMock(MyService.class);
}


(In the actual App the MyService Impl will be provided by Spring but that is by 
the by)

So that when I use PageTester in my tests I can go

MyService myMockService = pageTester.getRegistry().getService(MyService.class);

EasyMock.expect(myMockService.expensiveExternalMethodCallToCreditCardGatewayIdontReallyWantToTest(myCardNumber)).andReturn(authCode);


But the problem is...the registry returns a Proxy that contains a 
JustInTimeObjectCreator so EasyMock won't have no truck with my mock service. 
Boo.

Cheers

Russell





-Original Message-
From: Peter Stavrinides [mailto:[EMAIL PROTECTED] 
Sent: 17 September 2008 14:08
To: Tapestry users
Subject: Re: T5: testing using PageTester and EasyMock

Sorry about that hit the send by accident, here is the rest of it:
@BeforeClass
public static void setup() {

// tapestry interfaces
_mockAsm = createMock(ApplicationStateManager.class);
_mockContext = createMock(Context.class);
_mockResponse = createMock(Response.class);
_mockRequest = createMock(Request.class);

// an interface of my own
_mockSiteError = createMock(ISiteError.class);

_transport = new SMTPTransport("mailrelay",25);
}

/**
 * Test the properties for the service are set correctly and that the
 * service can be constructed
 */
@Test
public final void testConstruction() {

expect(_mockContext.getInitParameter("DevelopmentMode")).andReturn(
"false");
expect(_mockContext.getInitParameter("MailServer")).andReturn(
"mailrelay");
replay(_mockContext);

// now see if we can construct an instance of the class under 
test
_mockSiteErrorImpl = new SiteErrorImpl(_mockAsm, _mockContext,
_mockResponse, _mockRequest);
// run the verify
verify(_mockContext);
}




- Original Message -
From: "Russell Brown" <[EMAIL PROTECTED]>
To: "Tapestry users" 
Sent: Wednesday, 17 September, 2008 2:00:12 PM GMT +02:00 Athens, Beirut, 
Bucharest, Istanbul
Subject: RE: T5: testing using PageTester and EasyMock

Hi Peter,
How have you done this? When I try to use Tapestry to "Build" my EasyMock 
services the resultant proxies are rejected by EasyMock as not being EasyMock 
proxies...

Cheers

Russell

-----Original Message-
From: Peter Stavrinides [mailto:[EMAIL PROTECTED] 
Sent: 17 September 2008 11:47
To: Tapestry users
Subject: Re: T5: testing using PageTester and EasyMock

Hi all,

I haven't got around to using PageTester yet, but I started using Easymock for 
my IoC services recently... Its quite amazing how you can create a full blown 
IoC service with all dependencies satisfied so easily, it just works since 
service proxies are all interfaces in Tapestry.



- Original Message -
From: "Angelo Chen" <[EMAIL PROTECTED]>
To: users@tapestry.apache.org
Sent: Wednesday, 17 September, 2008 1:16:57 PM GMT +02:00 Athens, Beirut, 
Bucharest, Istanbul
Subject: Re: T5: testing using PageTester and EasyMock


Hi,

This will be a very interesting topic, I'd like to see how TDD can be used
in the development of T5 pages, my experience with T5 page tester isn't so
successful, now I try to do everything in the services as it is a easy place
to test.

angelo



Re: T5: testing using PageTester and EasyMock

2008-09-17 Thread Alex Kotchnev
Russell,
   this is just speculation, as I haven't tried this on my own, but it seems
to me that you'll have to do the EasyMock setup & training inside your test
module, e.g. :

@SubModule( { MyAppModule.class })
MyAppTestModule

public static MyService buildMyService () {
   MyService myMockService =
EasyMock.createMock(MyService.class);
   EasyMock.expect(myMockService.
expensiveExternalMethodCallToCreditCardGatewayIdontReallyWantToTest(myCardNumber)).andReturn(authCode);

}

Unfortunately, with an approach like this, you'd have to have different
"buildMyService" method for each test case for which you need to train the
Mock... I'm not sure how that would work, maybe you can have your
MyAppTestModule use something from the test case that will train the
myMockService based on the individual testcase expectations.

 Keep us posted on how this works.

Cheers,

Alex Kotchnev


On Wed, Sep 17, 2008 at 10:16 AM, Russell Brown <[EMAIL PROTECTED]>wrote:

> Hi Peter,
> Thanks for that. That is just normal EasyMock testing isn't it? I don't see
> where tapestry comes into that at all? You are creating the instances of all
> the classes and you are creating the instance of the class under test aren't
> you? Where is the PageTester and Tapestry IoC and all that (or have you
> missed some code, or am I missing something?)
>
>
>
> What I meant was this:- In the src/main/java tree I have MyAppModule which
> has some services like
>
> Binder.bind(MyService.class, MyExpensiveExternalImpl.class)
>
> But in my src/test/java tree I have
>
> @SubModule( { MyAppModule.class })
> MyAppTestModule
>
> public static MyService buildMyService () {
>return EasyMock.createMock(MyService.class);
> }
>
>
> (In the actual App the MyService Impl will be provided by Spring but that
> is by the by)
>
> So that when I use PageTester in my tests I can go
>
> MyService myMockService =
> pageTester.getRegistry().getService(MyService.class);
>
>
> EasyMock.expect(myMockService.expensiveExternalMethodCallToCreditCardGatewayIdontReallyWantToTest(myCardNumber)).andReturn(authCode);
>
>
> But the problem is...the registry returns a Proxy that contains a
> JustInTimeObjectCreator so EasyMock won't have no truck with my mock
> service. Boo.
>
> Cheers
>
> Russell
>
>
>
>
>
> -Original Message-
> From: Peter Stavrinides [mailto:[EMAIL PROTECTED]
> Sent: 17 September 2008 14:08
> To: Tapestry users
> Subject: Re: T5: testing using PageTester and EasyMock
>
> Sorry about that hit the send by accident, here is the rest of it:
>@BeforeClass
>public static void setup() {
>
>// tapestry interfaces
>_mockAsm = createMock(ApplicationStateManager.class);
>_mockContext = createMock(Context.class);
>_mockResponse = createMock(Response.class);
>_mockRequest = createMock(Request.class);
>
>// an interface of my own
>_mockSiteError = createMock(ISiteError.class);
>
>_transport = new SMTPTransport("mailrelay",25);
>}
>
>/**
> * Test the properties for the service are set correctly and that
> the
> * service can be constructed
> */
>@Test
>public final void testConstruction() {
>
>  expect(_mockContext.getInitParameter("DevelopmentMode")).andReturn(
>"false");
>
>  expect(_mockContext.getInitParameter("MailServer")).andReturn(
>"mailrelay");
>replay(_mockContext);
>
>// now see if we can construct an instance of the class
> under test
>_mockSiteErrorImpl = new SiteErrorImpl(_mockAsm,
> _mockContext,
>        _mockResponse, _mockRequest);
>// run the verify
>verify(_mockContext);
>}
>
>
>
>
> - Original Message -
> From: "Russell Brown" <[EMAIL PROTECTED]>
> To: "Tapestry users" 
> Sent: Wednesday, 17 September, 2008 2:00:12 PM GMT +02:00 Athens, Beirut,
> Bucharest, Istanbul
> Subject: RE: T5: testing using PageTester and EasyMock
>
> Hi Peter,
> How have you done this? When I try to use Tapestry to "Build" my EasyMock
> services the resultant proxies are rejected by EasyMock as not being
> EasyMock proxies...
>
> Cheers
>
> Russell
>
> -Original Message-
> From: Peter Stavrinides [mailto:[EMAIL PROTECTED]
> Sent: 17 September 2008 11:47
>

RE: T5: testing using PageTester and EasyMock

2008-09-17 Thread Russell Brown
Hi Peter,
Thanks for that. That is just normal EasyMock testing isn't it? I don't see 
where tapestry comes into that at all? You are creating the instances of all 
the classes and you are creating the instance of the class under test aren't 
you? Where is the PageTester and Tapestry IoC and all that (or have you missed 
some code, or am I missing something?)



What I meant was this:- In the src/main/java tree I have MyAppModule which has 
some services like

Binder.bind(MyService.class, MyExpensiveExternalImpl.class)

But in my src/test/java tree I have 

@SubModule( { MyAppModule.class })
MyAppTestModule

public static MyService buildMyService () {
return EasyMock.createMock(MyService.class);
}


(In the actual App the MyService Impl will be provided by Spring but that is by 
the by)

So that when I use PageTester in my tests I can go

MyService myMockService = pageTester.getRegistry().getService(MyService.class);

EasyMock.expect(myMockService.expensiveExternalMethodCallToCreditCardGatewayIdontReallyWantToTest(myCardNumber)).andReturn(authCode);


But the problem is...the registry returns a Proxy that contains a 
JustInTimeObjectCreator so EasyMock won't have no truck with my mock service. 
Boo.

Cheers

Russell





-Original Message-
From: Peter Stavrinides [mailto:[EMAIL PROTECTED] 
Sent: 17 September 2008 14:08
To: Tapestry users
Subject: Re: T5: testing using PageTester and EasyMock

Sorry about that hit the send by accident, here is the rest of it:
@BeforeClass
public static void setup() {

// tapestry interfaces
_mockAsm = createMock(ApplicationStateManager.class);
_mockContext = createMock(Context.class);
_mockResponse = createMock(Response.class);
_mockRequest = createMock(Request.class);

// an interface of my own
_mockSiteError = createMock(ISiteError.class);

_transport = new SMTPTransport("mailrelay",25);
}

/**
 * Test the properties for the service are set correctly and that the
 * service can be constructed
 */
@Test
public final void testConstruction() {

expect(_mockContext.getInitParameter("DevelopmentMode")).andReturn(
"false");
expect(_mockContext.getInitParameter("MailServer")).andReturn(
"mailrelay");
replay(_mockContext);

// now see if we can construct an instance of the class under 
test
_mockSiteErrorImpl = new SiteErrorImpl(_mockAsm, _mockContext,
_mockResponse, _mockRequest);
// run the verify
verify(_mockContext);
}




- Original Message -
From: "Russell Brown" <[EMAIL PROTECTED]>
To: "Tapestry users" 
Sent: Wednesday, 17 September, 2008 2:00:12 PM GMT +02:00 Athens, Beirut, 
Bucharest, Istanbul
Subject: RE: T5: testing using PageTester and EasyMock

Hi Peter,
How have you done this? When I try to use Tapestry to "Build" my EasyMock 
services the resultant proxies are rejected by EasyMock as not being EasyMock 
proxies...

Cheers

Russell

-Original Message-
From: Peter Stavrinides [mailto:[EMAIL PROTECTED] 
Sent: 17 September 2008 11:47
To: Tapestry users
Subject: Re: T5: testing using PageTester and EasyMock

Hi all,

I haven't got around to using PageTester yet, but I started using Easymock for 
my IoC services recently... Its quite amazing how you can create a full blown 
IoC service with all dependencies satisfied so easily, it just works since 
service proxies are all interfaces in Tapestry.



- Original Message -
From: "Angelo Chen" <[EMAIL PROTECTED]>
To: users@tapestry.apache.org
Sent: Wednesday, 17 September, 2008 1:16:57 PM GMT +02:00 Athens, Beirut, 
Bucharest, Istanbul
Subject: Re: T5: testing using PageTester and EasyMock


Hi,

This will be a very interesting topic, I'd like to see how TDD can be used
in the development of T5 pages, my experience with T5 page tester isn't so
successful, now I try to do everything in the services as it is a easy place
to test.

angelo


akochnev wrote:
> 
> 
> Let's keep this discussion rolling, we certainly need a little more info
> on
> testing in T5.
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/T5%3A-testing-using-PageTester-and-EasyMock-tp19496126p19529056.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, 

Re: T5: testing using PageTester and EasyMock

2008-09-17 Thread Peter Stavrinides
Sorry about that hit the send by accident, here is the rest of it:
@BeforeClass
public static void setup() {

// tapestry interfaces
_mockAsm = createMock(ApplicationStateManager.class);
_mockContext = createMock(Context.class);
_mockResponse = createMock(Response.class);
_mockRequest = createMock(Request.class);

// an interface of my own
_mockSiteError = createMock(ISiteError.class);

_transport = new SMTPTransport("mailrelay",25);
}

/**
 * Test the properties for the service are set correctly and that the
 * service can be constructed
 */
@Test
public final void testConstruction() {

expect(_mockContext.getInitParameter("DevelopmentMode")).andReturn(
"false");
expect(_mockContext.getInitParameter("MailServer")).andReturn(
"mailrelay");
replay(_mockContext);

// now see if we can construct an instance of the class under 
test
_mockSiteErrorImpl = new SiteErrorImpl(_mockAsm, _mockContext,
_mockResponse, _mockRequest);
// run the verify
verify(_mockContext);
}




- Original Message -
From: "Russell Brown" <[EMAIL PROTECTED]>
To: "Tapestry users" 
Sent: Wednesday, 17 September, 2008 2:00:12 PM GMT +02:00 Athens, Beirut, 
Bucharest, Istanbul
Subject: RE: T5: testing using PageTester and EasyMock

Hi Peter,
How have you done this? When I try to use Tapestry to "Build" my EasyMock 
services the resultant proxies are rejected by EasyMock as not being EasyMock 
proxies...

Cheers

Russell

-Original Message-
From: Peter Stavrinides [mailto:[EMAIL PROTECTED] 
Sent: 17 September 2008 11:47
To: Tapestry users
Subject: Re: T5: testing using PageTester and EasyMock

Hi all,

I haven't got around to using PageTester yet, but I started using Easymock for 
my IoC services recently... Its quite amazing how you can create a full blown 
IoC service with all dependencies satisfied so easily, it just works since 
service proxies are all interfaces in Tapestry.



- Original Message -
From: "Angelo Chen" <[EMAIL PROTECTED]>
To: users@tapestry.apache.org
Sent: Wednesday, 17 September, 2008 1:16:57 PM GMT +02:00 Athens, Beirut, 
Bucharest, Istanbul
Subject: Re: T5: testing using PageTester and EasyMock


Hi,

This will be a very interesting topic, I'd like to see how TDD can be used
in the development of T5 pages, my experience with T5 page tester isn't so
successful, now I try to do everything in the services as it is a easy place
to test.

angelo


akochnev wrote:
> 
> 
> Let's keep this discussion rolling, we certainly need a little more info
> on
> testing in T5.
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/T5%3A-testing-using-PageTester-and-EasyMock-tp19496126p19529056.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: T5: testing using PageTester and EasyMock

2008-09-17 Thread Peter Stavrinides
Hi Russell

I am not sure exactly what you mean that you couldn't "build Tapestry Easymock 
services", but let me explain what I am doing:

I am running a Maven setup, so if my tapestry services are in: 
scr.main.java.web.services the relevant tests are in 
scr.test.java.web.services. They are written and run as Unit tests, but after I 
read your comments I used them in my Tapestry AppModule and they just worked. 

So an Easymock unit test for a Tapestry service looks something like this:




- Original Message -
From: "Russell Brown" <[EMAIL PROTECTED]>
To: "Tapestry users" 
Sent: Wednesday, 17 September, 2008 2:00:12 PM GMT +02:00 Athens, Beirut, 
Bucharest, Istanbul
Subject: RE: T5: testing using PageTester and EasyMock

Hi Peter,
How have you done this? When I try to use Tapestry to "Build" my EasyMock 
services the resultant proxies are rejected by EasyMock as not being EasyMock 
proxies...

Cheers

Russell

-Original Message-
From: Peter Stavrinides [mailto:[EMAIL PROTECTED] 
Sent: 17 September 2008 11:47
To: Tapestry users
Subject: Re: T5: testing using PageTester and EasyMock

Hi all,

I haven't got around to using PageTester yet, but I started using Easymock for 
my IoC services recently... Its quite amazing how you can create a full blown 
IoC service with all dependencies satisfied so easily, it just works since 
service proxies are all interfaces in Tapestry.



- Original Message -
From: "Angelo Chen" <[EMAIL PROTECTED]>
To: users@tapestry.apache.org
Sent: Wednesday, 17 September, 2008 1:16:57 PM GMT +02:00 Athens, Beirut, 
Bucharest, Istanbul
Subject: Re: T5: testing using PageTester and EasyMock


Hi,

This will be a very interesting topic, I'd like to see how TDD can be used
in the development of T5 pages, my experience with T5 page tester isn't so
successful, now I try to do everything in the services as it is a easy place
to test.

angelo


akochnev wrote:
> 
> 
> Let's keep this discussion rolling, we certainly need a little more info
> on
> testing in T5.
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/T5%3A-testing-using-PageTester-and-EasyMock-tp19496126p19529056.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: T5: testing using PageTester and EasyMock

2008-09-17 Thread Angelo Chen

Hi Russel,

Very interesting! possible to have a very simple sample project that get us
started? thanks.

Angelo


Russell Brown-6 wrote:
> 
> Hi Alex,
> Testing pages as POJOs is quite simple. You can roll your own very,
> very, very simple service injector and inject EasyMock services into the
> pojo. I have done it using reflection. So I have a class that takes the
> page instance being tested in the constructor (and the test class too)
> and for each field annotated with @Inject it creates a strict mock and
> sets the field to that value. It also adds the mock to an internal List
> if mocks. Then the class provides convenience replay, reset, verify
> methods that iterate over the whole list. The test class also has fields
> that use a custom annotation (@Mock) these are injected with the same
> values as those added to the page under test. So you end up with a test
> class with populated mocks, a page class with populated services and a
> helper class with the same mocks held in an iterable fashion for
> convenience.
> 
> 
> 
> Russell
> 
> 

-- 
View this message in context: 
http://www.nabble.com/T5%3A-testing-using-PageTester-and-EasyMock-tp19496126p19531051.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: T5: testing using PageTester and EasyMock

2008-09-17 Thread Russell Brown
Hi Peter,
How have you done this? When I try to use Tapestry to "Build" my EasyMock 
services the resultant proxies are rejected by EasyMock as not being EasyMock 
proxies...

Cheers

Russell

-Original Message-
From: Peter Stavrinides [mailto:[EMAIL PROTECTED] 
Sent: 17 September 2008 11:47
To: Tapestry users
Subject: Re: T5: testing using PageTester and EasyMock

Hi all,

I haven't got around to using PageTester yet, but I started using Easymock for 
my IoC services recently... Its quite amazing how you can create a full blown 
IoC service with all dependencies satisfied so easily, it just works since 
service proxies are all interfaces in Tapestry.



- Original Message -
From: "Angelo Chen" <[EMAIL PROTECTED]>
To: users@tapestry.apache.org
Sent: Wednesday, 17 September, 2008 1:16:57 PM GMT +02:00 Athens, Beirut, 
Bucharest, Istanbul
Subject: Re: T5: testing using PageTester and EasyMock


Hi,

This will be a very interesting topic, I'd like to see how TDD can be used
in the development of T5 pages, my experience with T5 page tester isn't so
successful, now I try to do everything in the services as it is a easy place
to test.

angelo


akochnev wrote:
> 
> 
> Let's keep this discussion rolling, we certainly need a little more info
> on
> testing in T5.
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/T5%3A-testing-using-PageTester-and-EasyMock-tp19496126p19529056.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: T5: testing using PageTester and EasyMock

2008-09-17 Thread Russell Brown
Hi Alex,
Testing pages as POJOs is quite simple. You can roll your own very,
very, very simple service injector and inject EasyMock services into the
pojo. I have done it using reflection. So I have a class that takes the
page instance being tested in the constructor (and the test class too)
and for each field annotated with @Inject it creates a strict mock and
sets the field to that value. It also adds the mock to an internal List
if mocks. Then the class provides convenience replay, reset, verify
methods that iterate over the whole list. The test class also has fields
that use a custom annotation (@Mock) these are injected with the same
values as those added to the page under test. So you end up with a test
class with populated mocks, a page class with populated services and a
helper class with the same mocks held in an iterable fashion for
convenience.



Russell

-Original Message-
From: Alex Kotchnev [mailto:[EMAIL PROTECTED] 
Sent: 16 September 2008 17:39
To: Tapestry users
Subject: Re: T5: testing using PageTester and EasyMock

I was grappling with this issue myself, I still don't have a good answer
to
it. Because T5 is so heavily annotation driven (with the IoC and the
framework doing a lot of the magic heavy lifting behind the scenes),
testing
the pages as POJOs (e.g. setting some properties, performing an action,
inspecting the state of the page) is  not immediately obvious.

I've looked through some of the T5 unit tests (w/ EasyMock), and often
times
a page has a special (e.g. package private) method to inject services
that
otherwise the framework would inject. So, for example, if the page used
to
have an :

@Inject
FooService fooService

@Inject
BarService barService

Then, the page class would usually have a package private method like
this :


void setServices(FooService fs, BarService bs) {
   this.fooService = fs;
   this.barService = bs;
}

Anyway, there certainly is room for improvement, most advanced web
framework
have a way of testing pages/components as Pojos. Although the solution
above
works OK (and if you think about it, it's still pojos), it certainly
isn't
the first thing to think of once you get used to having Tapestry
injecting a
bunch of things into your pages. From a conceptual point of view, when
you're *unit *testing a page, you really DON'T want to have the "real"
services injected, and you'd probably just want to have
mocks/stubs/fakes in
their place that return the data needed to unit test the page. Now, if
you
were doing more of an "integration" type of test (e.g. where you test
how
the page works with the *real* service), then it's a different ball
game,
you do need the real services injected (for which you can still use the
above approach and not depend on the IoC to do it for you).

I guess the alternative would be to have a "test context" for binding
test/mock instances of the dependent services and somehow ask T5 to
inject
them into the page being tested. But then, it wouldn't really be unit
testing as the tests would depend on a whole bunch of things other than
the
unit being tested.

Let's keep this discussion rolling, we certainly need a little more info
on
testing in T5.

Cheers,

Alex Kotchnev

On Tue, Sep 16, 2008 at 10:32 AM, SergeEby <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I had a similar question a few weeks ago and didn't get any response.
> Can someone else chime in?
> It would be nice to have "real world" example in the documentation to
> showcase TDD features of T5.
>
> /Serge
>
>
> Russell Brown-6 wrote:
> >
> > One more related question would be this: in the docs at
> > http://tapestry.apache.org/tapestry5/guide/unit-testing-pages.html
you
> > tell the PageTester class the name of your "filter" so it can load
your
> > module. But how can you tell the PageTester to use the Spring filter
not
> > the plain tapestry filter? All my services are Spring services so as
> > soon as I try and run a test I get a load of errors about no service
> > realizing interface XXX (which is the type of a field annotated with
> > @Inject).
> >
> > Any ideas on this one either?
> >
> > I'm having quite a hard time testing anything beyond the most
> > rudimentary. I notice that tap core and tap ioc have themselves very
> > high test coverage indeed.
> >
> > Cheers
> >
> > Russell
> >
> > -Original Message-
> > From: Russell Brown [mailto:[EMAIL PROTECTED]
> > Sent: 15 September 2008 17:09
> > To: Tapestry users
> > Subject: T5: testing using PageTester and EasyMock
> >
> > Hi,
> >
> > Does anyone have any ideas for testing components using mock
services? I
> > can create a MyAppMockModule class and use that to configure the
page
&

Re: T5: testing using PageTester and EasyMock

2008-09-17 Thread Peter Stavrinides
Hi all,

I haven't got around to using PageTester yet, but I started using Easymock for 
my IoC services recently... Its quite amazing how you can create a full blown 
IoC service with all dependencies satisfied so easily, it just works since 
service proxies are all interfaces in Tapestry.



- Original Message -
From: "Angelo Chen" <[EMAIL PROTECTED]>
To: users@tapestry.apache.org
Sent: Wednesday, 17 September, 2008 1:16:57 PM GMT +02:00 Athens, Beirut, 
Bucharest, Istanbul
Subject: Re: T5: testing using PageTester and EasyMock


Hi,

This will be a very interesting topic, I'd like to see how TDD can be used
in the development of T5 pages, my experience with T5 page tester isn't so
successful, now I try to do everything in the services as it is a easy place
to test.

angelo


akochnev wrote:
> 
> 
> Let's keep this discussion rolling, we certainly need a little more info
> on
> testing in T5.
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/T5%3A-testing-using-PageTester-and-EasyMock-tp19496126p19529056.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: T5: testing using PageTester and EasyMock

2008-09-17 Thread Angelo Chen

Hi,

This will be a very interesting topic, I'd like to see how TDD can be used
in the development of T5 pages, my experience with T5 page tester isn't so
successful, now I try to do everything in the services as it is a easy place
to test.

angelo


akochnev wrote:
> 
> 
> Let's keep this discussion rolling, we certainly need a little more info
> on
> testing in T5.
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/T5%3A-testing-using-PageTester-and-EasyMock-tp19496126p19529056.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: T5: testing using PageTester and EasyMock

2008-09-16 Thread Alex Kotchnev
I was grappling with this issue myself, I still don't have a good answer to
it. Because T5 is so heavily annotation driven (with the IoC and the
framework doing a lot of the magic heavy lifting behind the scenes), testing
the pages as POJOs (e.g. setting some properties, performing an action,
inspecting the state of the page) is  not immediately obvious.

I've looked through some of the T5 unit tests (w/ EasyMock), and often times
a page has a special (e.g. package private) method to inject services that
otherwise the framework would inject. So, for example, if the page used to
have an :

@Inject
FooService fooService

@Inject
BarService barService

Then, the page class would usually have a package private method like this :


void setServices(FooService fs, BarService bs) {
   this.fooService = fs;
   this.barService = bs;
}

Anyway, there certainly is room for improvement, most advanced web framework
have a way of testing pages/components as Pojos. Although the solution above
works OK (and if you think about it, it's still pojos), it certainly isn't
the first thing to think of once you get used to having Tapestry injecting a
bunch of things into your pages. From a conceptual point of view, when
you're *unit *testing a page, you really DON'T want to have the "real"
services injected, and you'd probably just want to have mocks/stubs/fakes in
their place that return the data needed to unit test the page. Now, if you
were doing more of an "integration" type of test (e.g. where you test how
the page works with the *real* service), then it's a different ball game,
you do need the real services injected (for which you can still use the
above approach and not depend on the IoC to do it for you).

I guess the alternative would be to have a "test context" for binding
test/mock instances of the dependent services and somehow ask T5 to inject
them into the page being tested. But then, it wouldn't really be unit
testing as the tests would depend on a whole bunch of things other than the
unit being tested.

Let's keep this discussion rolling, we certainly need a little more info on
testing in T5.

Cheers,

Alex Kotchnev

On Tue, Sep 16, 2008 at 10:32 AM, SergeEby <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I had a similar question a few weeks ago and didn't get any response.
> Can someone else chime in?
> It would be nice to have "real world" example in the documentation to
> showcase TDD features of T5.
>
> /Serge
>
>
> Russell Brown-6 wrote:
> >
> > One more related question would be this: in the docs at
> > http://tapestry.apache.org/tapestry5/guide/unit-testing-pages.html you
> > tell the PageTester class the name of your "filter" so it can load your
> > module. But how can you tell the PageTester to use the Spring filter not
> > the plain tapestry filter? All my services are Spring services so as
> > soon as I try and run a test I get a load of errors about no service
> > realizing interface XXX (which is the type of a field annotated with
> > @Inject).
> >
> > Any ideas on this one either?
> >
> > I'm having quite a hard time testing anything beyond the most
> > rudimentary. I notice that tap core and tap ioc have themselves very
> > high test coverage indeed.
> >
> > Cheers
> >
> > Russell
> >
> > -Original Message-
> > From: Russell Brown [mailto:[EMAIL PROTECTED]
> > Sent: 15 September 2008 17:09
> > To: Tapestry users
> > Subject: T5: testing using PageTester and EasyMock
> >
> > Hi,
> >
> > Does anyone have any ideas for testing components using mock services? I
> > can create a MyAppMockModule class and use that to configure the page
> > tester. This class builds mocks of my services, so far so good. I use
> > PageTester.getRegistry() and then Registry.getService(MyService.class)
> > and then I have my mock to set up in my test. No? No! I have a proxy
> > wrapped instance instead which I can't use at all.
> >
> >
> >
> > Any ideas out there? How are you testing your components pages when you
> > have expense to construct services with complex external dependencies?
> >
> >
> >
> > Cheers
> >
> >
> >
> > Russell
> >
> >
> > -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/T5%3A-testing-using-PageTester-and-EasyMock-tp19496126p19513126.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


RE: T5: testing using PageTester and EasyMock

2008-09-16 Thread SergeEby

Hi,

I had a similar question a few weeks ago and didn't get any response.
Can someone else chime in?
It would be nice to have "real world" example in the documentation to
showcase TDD features of T5.

/Serge


Russell Brown-6 wrote:
> 
> One more related question would be this: in the docs at
> http://tapestry.apache.org/tapestry5/guide/unit-testing-pages.html you
> tell the PageTester class the name of your "filter" so it can load your
> module. But how can you tell the PageTester to use the Spring filter not
> the plain tapestry filter? All my services are Spring services so as
> soon as I try and run a test I get a load of errors about no service
> realizing interface XXX (which is the type of a field annotated with
> @Inject).
> 
> Any ideas on this one either?
> 
> I'm having quite a hard time testing anything beyond the most
> rudimentary. I notice that tap core and tap ioc have themselves very
> high test coverage indeed.
> 
> Cheers
> 
> Russell
> 
> -Original Message-
> From: Russell Brown [mailto:[EMAIL PROTECTED] 
> Sent: 15 September 2008 17:09
> To: Tapestry users
> Subject: T5: testing using PageTester and EasyMock
> 
> Hi,
> 
> Does anyone have any ideas for testing components using mock services? I
> can create a MyAppMockModule class and use that to configure the page
> tester. This class builds mocks of my services, so far so good. I use
> PageTester.getRegistry() and then Registry.getService(MyService.class)
> and then I have my mock to set up in my test. No? No! I have a proxy
> wrapped instance instead which I can't use at all.
> 
>  
> 
> Any ideas out there? How are you testing your components pages when you
> have expense to construct services with complex external dependencies?
> 
>  
> 
> Cheers
> 
>  
> 
> Russell
> 
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/T5%3A-testing-using-PageTester-and-EasyMock-tp19496126p19513126.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]