Skip to Content
author's profile photo Former Member
Former Member

Loading Spring web application context in tests using "ant yunitweb"

Hi everyone,

I am using Hybris 4.5.x and I have problems creating Spring's web application context defined in myExtension-web-spring.xml when running an integration test using "ant yunitweb".

The problem has been posted in the wiki forum some time ago (https://wiki.hybris.com/display/forum/JUnit+using+spring+in+web+testsrc), but the answer given there is not satisfying, since it suggests to create beans manually one by one within the test, if I'm right. I'd rather prefer that the context is build based on the xml config file. Is there any way to accomplish this?

As an additional question, is there any way to debug tests running with "ant yunitweb" using Ee IDE?

Many thanks in advance!

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 28, 2014 at 03:13 PM

    With the wiki link you've provided, you can still use the xml to define the beans, and then use the following:

     return (T) Registry.getApplicationContext().getBean(<YOUR_BEAN_ID>);
    
    
    

    And it should inject the bean as intended. Not the most ideal solution ever, but at least you can turn this into a util that is similar to @Resource or @Autowired, perhaps even a custom annotation.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 28, 2014 at 03:58 PM

    Thank you. Indeed that's how I assign the bean to the object in my test after I registered it using the suggested solution mentioned above.

    I guess the test runner simply does not know about the xml config file (which, as far as I can see, is only mentioned in WEB-INF/web.xml) where the web application context is defined. So I am basically looking for a way to specify in the test the path to where I defined the web application context. I originally expected ant yunitweb to process the information specified in web.xml concerning the application context.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.