Miguel Almeida | 17 May 11:29 2012
Picon

Re: Re: Testing Java Annotations - is this unit test or integration?

Hi Avi,

On a follow up from long ago, I'm having a hard time implementing this
on a Struts project (in the actions, more specifically).
Struts has IoC and a set of xAware interfaces - each providing a setter
for x and thus injecting it on the object seamlessly. So
ServletRequestAware provides a setRequest, so your object gets access to
the request object.

The problem arises when you have superclasses for Common information
(eg, for common services, common methods) (and maybe also when you
implement interfaces). I exemplify with both. 

Imagine this: 
RealAction extends CommonAction implements IAction(){ 
...} 

CommonAction implements ServletRequestAware(){ 
public void setRequest(HttpRequest request){
 _request = request;
} 

AuthorizingDecorator implements IAction(){ 
//injected decorated IAction, see Avi's code
... 
} 

Now, when the application starts a http request-response with a regular
RealAction implementation, the request object exists: 
RealAction extends CommonAction, so the request is injected through its
(Continue reading)

avinap77 | 23 May 12:00 2012
Picon

Re: Testing Java Annotations - is this unit test or integration?

Hi Miguel

It's been a long time (a year!) so my memory is a bit out of context - pardon if I'll totally miss the point :)

I admit I don't know Struts, but from what you describe - maybe if you have the AuthorizingDecorator extend
CommonAction it might work?
Or maybe have struts instantiate the AuthorizingDecorator?

(again I might be writing total nonsense here)

The idea is to have the autorizingDecorator decorate an action object, and it gets the decorated
(authorized) action object in some way - it might be in the constructor or in a setter or through an IoC framework.

So in your tests you'd use an authorizingDecorator with a decorated dummy action just to test the authorization,
whereas in the real application you'd decorate a real action object. 

Maybe others can tell if and how this can be done with Struts..?
I imagine it should be doable.

All the best,
Avi

--- In testdrivendevelopment <at> yahoogroups.com, Miguel Almeida <miguel <at> ...> wrote:
>
> Hi Avi,
> 
> On a follow up from long ago, I'm having a hard time implementing this
> on a Struts project (in the actions, more specifically).
> Struts has IoC and a set of xAware interfaces - each providing a setter
> for x and thus injecting it on the object seamlessly. So
(Continue reading)


Gmane