You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by Alex Ough <al...@sungard.com> on 2013/12/02 17:26:51 UTC

Re: Ask about 'Failed to load ApplicationContext' in unit tests during maven building

Thank Daan for your reply, but it looks like the issue is not in the test
program, but during initializing the application itself because the failing
test does not reference 'ActionEventInterceptor' class.

I have really hard time to figure this out because I just added '@Inject
private AccountDao _accountDao;' in 'ActionEventInterceptor' class and the
same injection was already included in 'ActionEventUtils' class that is in
the same package.

It is quite strange to me, so can you give me some light on this?
Thanks
Alex Ough



On Thu, Nov 28, 2013 at 4:46 AM, Daan Hoogland <da...@gmail.com>wrote:

> H Alex,
>
> I suppose you are no longer struggling with this but just in case;
> check which context xml is loaded in your test and make sure the
> appropriate classes are defined in that file. The tests don't
> necessarily load all the definitions.
>
> regards,
> Daan
>
> On Tue, Nov 19, 2013 at 10:38 PM, Alex Ough <al...@sungard.com> wrote:
> > All,
> >
> > I'm back to Java development after quite long years, so currently I have
> > difficulty finding out what causes this error.
> >
> > Basically, I'd like use 'DomainDao/AccountDao/UserDao' and/or
> > 'AccountMgr/DomainMgr' by 'Injecting' them in
> > 'com.cloud.event.ActionEventInterceptor' class to find
> domain/account/user
> > information.
> >
> > But strangely, the injections of all of the classes except 'AccountMgr'
> > cause the above error in the unit tests ('com.cloud.vpc.Site2SiteVpnTest'
> > and 'org.apache.cloudstack.lb.ApplicationLoadBalancerTest') during
> building
> > 'Server' project.
> >
> > I'm not familiar with 'inject' tag, so I'm not sure what the problem is,
> > but just defining a variable using 'inject' tag causes the failure.
> >
> > Your help will be very appreciate.
> > Thanks
> > Alex Ough
>
>

Re: Ask about 'Failed to load ApplicationContext' in unit tests during maven building

Posted by Daan Hoogland <da...@gmail.com>.
On Mon, Dec 2, 2013 at 5:26 PM, Alex Ough <al...@sungard.com> wrote:
> can you give me some light on this?


I hope so Alex,

In general I would advice to minimize the use of dao's if there is a
manager for the type of object; i.e. do your coding inside AccountMgr
and call its methods instead of calling dao's

> Basically, I'd like use 'DomainDao/AccountDao/UserDao' and/or 'AccountMgr/DomainMgr' by 'Injecting' them in


You say that the problem is in the main program not in the test and
this might be true but in the case of spring this may have a third
possibility. Spring usus a combination of annotations, reflection and
configuration to arrange for dependency injection (or inversion of
control). The @inject that causes the problem might indeed be in the
main program, but there also needs to be a spring context file, which
might be different for the program and its tests. In this way you can
easily inject mock object for use in test where heavy dependencies
would have been injected at runtime.

There are a lot of example context files for tests laying around. for
instance CreateNetworkOfferingTest.java
CreatePrivateNetworkTest.java is an example that uses only mock objects.


hope this helps,
Daan