Using dependency injection on action beans when I use MockRoundtrip

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Using dependency injection on action beans when I use MockRoundtrip

Dan Kaplan-2
I read about using the MockRoundtrip here: http://www.stripesframework.org/display/stripes/Unit+Testing

The problem I have is a few of my ActionBean's fields are EJBs that get populated from the app server.  How can I use dependency injection on the action bean's fields? 

mockRoundtrip = new MockRoundtrip(context, AnActionBean.class); mockRoundtrip.execute("event");  //I don't see a place to use DI

When I call execute here, it gives me a bunch of errors because the EJBs couldn't get created.  That's fine, but I don't see a way to implement these EJB interfaces as mock classes when I use the MockRoundtrip.  

--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Using dependency injection on action beans when I use MockRoundtrip

jockeeriksson
Just mock the initial context factory.


see http://stackoverflow.com/questions/10045466/how-to-fake-initialcontext-with-default-constructor.


Date: Mon, 11 Feb 2013 10:18:05 -0800
From: [hidden email]
To: [hidden email]
Subject: [Stripes-users] Using dependency injection on action beans when I use MockRoundtrip

I read about using the MockRoundtrip here: http://www.stripesframework.org/display/stripes/Unit+Testing

The problem I have is a few of my ActionBean's fields are EJBs that get populated from the app server.  How can I use dependency injection on the action bean's fields? 

mockRoundtrip = new MockRoundtrip(context, AnActionBean.class); mockRoundtrip.execute("event");  //I don't see a place to use DI

When I call execute here, it gives me a bunch of errors because the EJBs couldn't get created.  That's fine, but I don't see a way to implement these EJB interfaces as mock classes when I use the MockRoundtrip.  

--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.
------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________ Stripes-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Using dependency injection on action beans when I use MockRoundtrip

Dan Kaplan-2
That's making the assumption that stubbing the InitialContext will solve all my dependency injection needs.  But if my actionbean has a field in it that is like:

private PojoWithBusinessLogic bean = new PojoWithBusinessLogic();

Stubbing the InitialContext won't let me DI this bean.  


On Mon, Feb 11, 2013 at 12:18 PM, Jocke Eriksson <[hidden email]> wrote:
Just mock the initial context factory.


see http://stackoverflow.com/questions/10045466/how-to-fake-initialcontext-with-default-constructor.


Date: Mon, 11 Feb 2013 10:18:05 -0800
From: [hidden email]
To: [hidden email]
Subject: [Stripes-users] Using dependency injection on action beans when I use MockRoundtrip


I read about using the MockRoundtrip here: http://www.stripesframework.org/display/stripes/Unit+Testing

The problem I have is a few of my ActionBean's fields are EJBs that get populated from the app server.  How can I use dependency injection on the action bean's fields? 

mockRoundtrip = new MockRoundtrip(context, AnActionBean.class); mockRoundtrip.execute("event");  //I don't see a place to use DI

When I call execute here, it gives me a bunch of errors because the EJBs couldn't get created.  That's fine, but I don't see a way to implement these EJB interfaces as mock classes when I use the MockRoundtrip.  

--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.
------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________ Stripes-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users




--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Using dependency injection on action beans when I use MockRoundtrip

Dan Kaplan-2
BTW, half the answer seems to be in this post: http://planetjava.org/java-stripes-user/2007-02/msg00155.html

But the problem is he doesn't show us/me how to override the MockRoundtrip.  I can't figure out how his ActionBeanInitialization.initialize(T actionBeanInstance) gets called.


On Mon, Feb 11, 2013 at 12:34 PM, Dan Kaplan <[hidden email]> wrote:
That's making the assumption that stubbing the InitialContext will solve all my dependency injection needs.  But if my actionbean has a field in it that is like:

private PojoWithBusinessLogic bean = new PojoWithBusinessLogic();

Stubbing the InitialContext won't let me DI this bean.  


On Mon, Feb 11, 2013 at 12:18 PM, Jocke Eriksson <[hidden email]> wrote:
Just mock the initial context factory.


see http://stackoverflow.com/questions/10045466/how-to-fake-initialcontext-with-default-constructor.


Date: Mon, 11 Feb 2013 10:18:05 -0800
From: [hidden email]
To: [hidden email]
Subject: [Stripes-users] Using dependency injection on action beans when I use MockRoundtrip


I read about using the MockRoundtrip here: http://www.stripesframework.org/display/stripes/Unit+Testing

The problem I have is a few of my ActionBean's fields are EJBs that get populated from the app server.  How can I use dependency injection on the action bean's fields? 

mockRoundtrip = new MockRoundtrip(context, AnActionBean.class); mockRoundtrip.execute("event");  //I don't see a place to use DI

When I call execute here, it gives me a bunch of errors because the EJBs couldn't get created.  That's fine, but I don't see a way to implement these EJB interfaces as mock classes when I use the MockRoundtrip.  

--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.
------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________ Stripes-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users




--
Thanks,
Dan



--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Using dependency injection on action beans when I use MockRoundtrip

VANKEISBELCK Remi
Hi,

Apparently the guy uses an Interceptor for his tests. 

I think that's what you want too. Write a Stripes Interceptor that performs the "injection" as you want, and only register this one for your unit tests. You don't have to stub anything IMO. 

Btw that's what @SpringBean does: it's based on Interception as well.

Cheers

Remi 

 
Le 11 févr. 2013 à 21:36, Dan Kaplan a écrit :

BTW, half the answer seems to be in this post: http://planetjava.org/java-stripes-user/2007-02/msg00155.html

But the problem is he doesn't show us/me how to override the MockRoundtrip.  I can't figure out how his ActionBeanInitialization.initialize(T actionBeanInstance) gets called.


On Mon, Feb 11, 2013 at 12:34 PM, Dan Kaplan <[hidden email]> wrote:
That's making the assumption that stubbing the InitialContext will solve all my dependency injection needs.  But if my actionbean has a field in it that is like:

private PojoWithBusinessLogic bean = new PojoWithBusinessLogic();

Stubbing the InitialContext won't let me DI this bean.  


On Mon, Feb 11, 2013 at 12:18 PM, Jocke Eriksson <[hidden email]> wrote:
Just mock the initial context factory.


see http://stackoverflow.com/questions/10045466/how-to-fake-initialcontext-with-default-constructor.


Date: Mon, 11 Feb 2013 10:18:05 -0800
From: [hidden email]
To: [hidden email]
Subject: [Stripes-users] Using dependency injection on action beans when I use MockRoundtrip


I read about using the MockRoundtrip here: http://www.stripesframework.org/display/stripes/Unit+Testing

The problem I have is a few of my ActionBean's fields are EJBs that get populated from the app server.  How can I use dependency injection on the action bean's fields? 

mockRoundtrip = new MockRoundtrip(context, AnActionBean.class); mockRoundtrip.execute("event");  //I don't see a place to use DI

When I call execute here, it gives me a bunch of errors because the EJBs couldn't get created.  That's fine, but I don't see a way to implement these EJB interfaces as mock classes when I use the MockRoundtrip.  

--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.
------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________ Stripes-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users




--
Thanks,
Dan



--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Using dependency injection on action beans when I use MockRoundtrip

Dan Kaplan-2
Ah, cool.  I was on IRC and in the convo we came to the same conclusion.  So is "extending" the MockRoundtrip an unnecessary step?


On Tue, Feb 12, 2013 at 12:43 AM, Remi VANKEISBELCK <[hidden email]> wrote:
Hi,

Apparently the guy uses an Interceptor for his tests. 

I think that's what you want too. Write a Stripes Interceptor that performs the "injection" as you want, and only register this one for your unit tests. You don't have to stub anything IMO. 

Btw that's what @SpringBean does: it's based on Interception as well.

Cheers

Remi 

 
Le 11 févr. 2013 à 21:36, Dan Kaplan a écrit :

BTW, half the answer seems to be in this post: http://planetjava.org/java-stripes-user/2007-02/msg00155.html

But the problem is he doesn't show us/me how to override the MockRoundtrip.  I can't figure out how his ActionBeanInitialization.initialize(T actionBeanInstance) gets called.


On Mon, Feb 11, 2013 at 12:34 PM, Dan Kaplan <[hidden email]> wrote:
That's making the assumption that stubbing the InitialContext will solve all my dependency injection needs.  But if my actionbean has a field in it that is like:

private PojoWithBusinessLogic bean = new PojoWithBusinessLogic();

Stubbing the InitialContext won't let me DI this bean.  


On Mon, Feb 11, 2013 at 12:18 PM, Jocke Eriksson <[hidden email]> wrote:
Just mock the initial context factory.


see http://stackoverflow.com/questions/10045466/how-to-fake-initialcontext-with-default-constructor.


Date: Mon, 11 Feb 2013 10:18:05 -0800
From: [hidden email]
To: [hidden email]
Subject: [Stripes-users] Using dependency injection on action beans when I use MockRoundtrip


I read about using the MockRoundtrip here: http://www.stripesframework.org/display/stripes/Unit+Testing

The problem I have is a few of my ActionBean's fields are EJBs that get populated from the app server.  How can I use dependency injection on the action bean's fields? 

mockRoundtrip = new MockRoundtrip(context, AnActionBean.class); mockRoundtrip.execute("event");  //I don't see a place to use DI

When I call execute here, it gives me a bunch of errors because the EJBs couldn't get created.  That's fine, but I don't see a way to implement these EJB interfaces as mock classes when I use the MockRoundtrip.  

--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.
------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________ Stripes-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users




--
Thanks,
Dan



--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users




--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Using dependency injection on action beans when I use MockRoundtrip

VANKEISBELCK Remi
Yep, I think so. 

I've never done exactly what you want but I've had my share of Stripes Interceptors :)

So I'd say that you just need a custom Interceptor in your tests that performs the "injection" of some mock collaborators in your ActionBeans. 

There are many ways to implement it but that's the idea : the interceptor gets called even when you use MockRoundtrip, this is for sure. So just add the interceptor to the list of Stripes extension pkgs for your test, and let it create and assign your mock objects to your ActionBeans. 

Look at how it's done for Spring :

Cheers

Remi



Le 12 févr. 2013 à 18:53, Dan Kaplan a écrit :

Ah, cool.  I was on IRC and in the convo we came to the same conclusion.  So is "extending" the MockRoundtrip an unnecessary step?


On Tue, Feb 12, 2013 at 12:43 AM, Remi VANKEISBELCK <[hidden email]> wrote:
Hi,

Apparently the guy uses an Interceptor for his tests. 

I think that's what you want too. Write a Stripes Interceptor that performs the "injection" as you want, and only register this one for your unit tests. You don't have to stub anything IMO. 

Btw that's what @SpringBean does: it's based on Interception as well.

Cheers

Remi 

 
Le 11 févr. 2013 à 21:36, Dan Kaplan a écrit :

BTW, half the answer seems to be in this post: http://planetjava.org/java-stripes-user/2007-02/msg00155.html

But the problem is he doesn't show us/me how to override the MockRoundtrip.  I can't figure out how his ActionBeanInitialization.initialize(T actionBeanInstance) gets called.


On Mon, Feb 11, 2013 at 12:34 PM, Dan Kaplan <[hidden email]> wrote:
That's making the assumption that stubbing the InitialContext will solve all my dependency injection needs.  But if my actionbean has a field in it that is like:

private PojoWithBusinessLogic bean = new PojoWithBusinessLogic();

Stubbing the InitialContext won't let me DI this bean.  


On Mon, Feb 11, 2013 at 12:18 PM, Jocke Eriksson <[hidden email]> wrote:
Just mock the initial context factory.


see http://stackoverflow.com/questions/10045466/how-to-fake-initialcontext-with-default-constructor.


Date: Mon, 11 Feb 2013 10:18:05 -0800
From: [hidden email]
To: [hidden email]
Subject: [Stripes-users] Using dependency injection on action beans when I use MockRoundtrip


I read about using the MockRoundtrip here: http://www.stripesframework.org/display/stripes/Unit+Testing

The problem I have is a few of my ActionBean's fields are EJBs that get populated from the app server.  How can I use dependency injection on the action bean's fields? 

mockRoundtrip = new MockRoundtrip(context, AnActionBean.class); mockRoundtrip.execute("event");  //I don't see a place to use DI

When I call execute here, it gives me a bunch of errors because the EJBs couldn't get created.  That's fine, but I don't see a way to implement these EJB interfaces as mock classes when I use the MockRoundtrip.  

--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.
------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________ Stripes-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users




--
Thanks,
Dan



--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users




--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Using dependency injection on action beans when I use MockRoundtrip

Dan Kaplan-2
Cool, thanks a lot


On Tue, Feb 12, 2013 at 10:07 AM, Remi VANKEISBELCK <[hidden email]> wrote:
Yep, I think so. 

I've never done exactly what you want but I've had my share of Stripes Interceptors :)

So I'd say that you just need a custom Interceptor in your tests that performs the "injection" of some mock collaborators in your ActionBeans. 

There are many ways to implement it but that's the idea : the interceptor gets called even when you use MockRoundtrip, this is for sure. So just add the interceptor to the list of Stripes extension pkgs for your test, and let it create and assign your mock objects to your ActionBeans. 

Look at how it's done for Spring :

Cheers

Remi



Le 12 févr. 2013 à 18:53, Dan Kaplan a écrit :

Ah, cool.  I was on IRC and in the convo we came to the same conclusion.  So is "extending" the MockRoundtrip an unnecessary step?


On Tue, Feb 12, 2013 at 12:43 AM, Remi VANKEISBELCK <[hidden email]> wrote:
Hi,

Apparently the guy uses an Interceptor for his tests. 

I think that's what you want too. Write a Stripes Interceptor that performs the "injection" as you want, and only register this one for your unit tests. You don't have to stub anything IMO. 

Btw that's what @SpringBean does: it's based on Interception as well.

Cheers

Remi 

 
Le 11 févr. 2013 à 21:36, Dan Kaplan a écrit :

BTW, half the answer seems to be in this post: http://planetjava.org/java-stripes-user/2007-02/msg00155.html

But the problem is he doesn't show us/me how to override the MockRoundtrip.  I can't figure out how his ActionBeanInitialization.initialize(T actionBeanInstance) gets called.


On Mon, Feb 11, 2013 at 12:34 PM, Dan Kaplan <[hidden email]> wrote:
That's making the assumption that stubbing the InitialContext will solve all my dependency injection needs.  But if my actionbean has a field in it that is like:

private PojoWithBusinessLogic bean = new PojoWithBusinessLogic();

Stubbing the InitialContext won't let me DI this bean.  


On Mon, Feb 11, 2013 at 12:18 PM, Jocke Eriksson <[hidden email]> wrote:
Just mock the initial context factory.


see http://stackoverflow.com/questions/10045466/how-to-fake-initialcontext-with-default-constructor.


Date: Mon, 11 Feb 2013 10:18:05 -0800
From: [hidden email]
To: [hidden email]
Subject: [Stripes-users] Using dependency injection on action beans when I use MockRoundtrip


I read about using the MockRoundtrip here: http://www.stripesframework.org/display/stripes/Unit+Testing

The problem I have is a few of my ActionBean's fields are EJBs that get populated from the app server.  How can I use dependency injection on the action bean's fields? 

mockRoundtrip = new MockRoundtrip(context, AnActionBean.class); mockRoundtrip.execute("event");  //I don't see a place to use DI

When I call execute here, it gives me a bunch of errors because the EJBs couldn't get created.  That's fine, but I don't see a way to implement these EJB interfaces as mock classes when I use the MockRoundtrip.  

--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.
------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________ Stripes-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users




--
Thanks,
Dan



--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users




--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users




--
Thanks,
Dan

CONFIDENTIALITY NOTICE: The information contained in this electronic transmission may be confidential. If you are not an intended recipient, be aware that any disclosure, copying, distribution or use of the information contained in this transmission is prohibited and may be unlawful. If you have received this transmission in error, please notify us by email reply and then erase it from your computer system.
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users