You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Martijn Kaag <ma...@kaag.eu> on 2010/04/09 23:48:28 UTC

Obtaining the actual service instead of the interface/proxy

hi

For unittest purposes i'd like to be able to obtain the actual service instatiation instead of the proxy/interface.

Any idea how to achieve this?

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


Re: Obtaining the actual service instead of the interface/proxy

Posted by Howard Lewis Ship <hl...@gmail.com>.
I suspect that Marijn has non-public API on his implementation class
related to his testing.  There's a philosophy that if a class can not
be tested via its public interface, it needs refactoring. I do find
that extreme, but if you are using IoC to obtain the service, it is by
definition an integration test. Non public method (or even field)
access is fine (in my book) in a unit test, but in an integration
test, much less so.

I would suggest to Martjn that he either refactor out the difficult to
reach code into its own, more testable service ... or restrict the
need to access non-public methods to unit, not integration, tests.

Another option is to have the service public events that expose the
inner structure of the service in a controlled way.

On Sat, Apr 10, 2010 at 3:46 PM, Robert Zeigler <ro...@scazdl.org> wrote:
> But the object as injected by tapestry /is/ the proxy... not sure I follow
> what you need.
> You can use T5 IOC to grab the various services you need to instantiate the
> object manually, though, so it will be "just like" the service injected by
> tapestry, minus the proxy.
>
> I'm curious: what's wrong with having the proxy as a barrier between your
> unit test and your object? It's basically just delegating all calls, anyway,
> so...?
>
> Robert
>
> On Apr 10, 2010, at 4/105:04 PM , Martijn Kaag wrote:
>
>> Hi Thiago,
>>
>> I am aware of that. Unfortunately that does not fit the use case: i need
>> to be able to obtain the (unit test) object as injected by tapestry.
>>
>> This can be implemented by adding a method getInstance() {return this;} to
>> the interface and implementation. But I hoped there would be a way of
>> achieving this without altering the service interface.
>>
>> Martijn
>>
>>
>>
>> -----Original Message-----
>> From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com]
>> Sent: 09 April 2010 23:53
>> To: Tapestry users
>> Subject: Re: Obtaining the actual service instead of the interface/proxy
>>
>> On Fri, 09 Apr 2010 18:48:28 -0300, Martijn Kaag <ma...@kaag.eu> wrote:
>>
>>> hi
>>
>> Hi!
>>
>>> For unittest purposes i'd like to be able to obtain the actual service
>>> instatiation instead of the proxy/interface.
>>> Any idea how to achieve this?
>>
>> No. But your can instantiate the service implementation directly.
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
>> and instructor
>> Owner, software architect and developer, Ars Machina Tecnologia da
>> Informação Ltda.
>> http://www.arsmachina.com.br
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: Obtaining the actual service instead of the interface/proxy

Posted by Robert Zeigler <ro...@scazdl.org>.
But the object as injected by tapestry /is/ the proxy... not sure I  
follow what you need.
You can use T5 IOC to grab the various services you need to  
instantiate the object manually, though, so it will be "just like" the  
service injected by tapestry, minus the proxy.

I'm curious: what's wrong with having the proxy as a barrier between  
your unit test and your object? It's basically just delegating all  
calls, anyway, so...?

Robert

On Apr 10, 2010, at 4/105:04 PM , Martijn Kaag wrote:

> Hi Thiago,
>
> I am aware of that. Unfortunately that does not fit the use case: i  
> need to be able to obtain the (unit test) object as injected by  
> tapestry.
>
> This can be implemented by adding a method getInstance() {return  
> this;} to the interface and implementation. But I hoped there would  
> be a way of achieving this without altering the service interface.
>
> Martijn
>
>
>
> -----Original Message-----
> From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com]
> Sent: 09 April 2010 23:53
> To: Tapestry users
> Subject: Re: Obtaining the actual service instead of the interface/ 
> proxy
>
> On Fri, 09 Apr 2010 18:48:28 -0300, Martijn Kaag <ma...@kaag.eu>  
> wrote:
>
>> hi
>
> Hi!
>
>> For unittest purposes i'd like to be able to obtain the actual  
>> service
>> instatiation instead of the proxy/interface.
>> Any idea how to achieve this?
>
> No. But your can instantiate the service implementation directly.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant,  
> developer,
> and instructor
> Owner, software architect and developer, Ars Machina Tecnologia da
> Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


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


RE: Obtaining the actual service instead of the interface/proxy

Posted by Martijn Kaag <ma...@kaag.eu>.
Hi Thiago,

I am aware of that. Unfortunately that does not fit the use case: i need to be able to obtain the (unit test) object as injected by tapestry.

This can be implemented by adding a method getInstance() {return this;} to the interface and implementation. But I hoped there would be a way of achieving this without altering the service interface.

Martijn



-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com]
Sent: 09 April 2010 23:53
To: Tapestry users
Subject: Re: Obtaining the actual service instead of the interface/proxy

On Fri, 09 Apr 2010 18:48:28 -0300, Martijn Kaag <ma...@kaag.eu> wrote:

> hi

Hi!

> For unittest purposes i'd like to be able to obtain the actual service
> instatiation instead of the proxy/interface.
> Any idea how to achieve this?

No. But your can instantiate the service implementation directly.

--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da
Informação Ltda.
http://www.arsmachina.com.br

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


Re: Obtaining the actual service instead of the interface/proxy

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 09 Apr 2010 18:48:28 -0300, Martijn Kaag <ma...@kaag.eu> wrote:

> hi

Hi!

> For unittest purposes i'd like to be able to obtain the actual service  
> instatiation instead of the proxy/interface.
> Any idea how to achieve this?

No. But your can instantiate the service implementation directly.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

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