-
October 26th, 2009, 09:06 AM
#31
Re: How can I Initialize getJdbcTemplate()?
Have you annotated your JUnit test class one way or another to tell it to load the application context that it needs to wire the beans that you plan to use for testing. I have a feeling that your job bean is probably null at this point.
Code:
@RunWith (SpringJUnit4ClassRunner.class)
@ContextConfiguration (locations={"/application-context.xml"})
assuming that you have an 'application-context.xml' in the same project, otherwise you have to use
Code:
classpath*:out-of-scope-context.xml
note that these names application-context.xml and out-of-scope-context.xml need to match your contexts
Last edited by Deliverance; October 26th, 2009 at 09:22 AM.
------
If you are satisfied with the responses, add to the user's rep!
-
October 29th, 2009, 08:28 AM
#32
Re: How can I Initialize getJdbcTemplate()?
I am using JDK 1.4.x
Code:
@RunWith (SpringJUnit4ClassRunner.class)
@ContextConfiguration (locations={"/application-context.xml"})
annotation is not allowing. What I need to do with out changing JDK version?
Thanks in advance.
-
October 30th, 2009, 01:04 PM
#33
Re: How can I Initialize getJdbcTemplate()?
Ok, so in this case I guess you would have to create your own application context inside of each unit test.
something like this
Code:
AbstractApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");
then from there, you can request things by bean id by default.
Code:
MyCustomBean myBean = (MyCustomBean)context.getBean("myBeanId");
and then invoke that way.
------
If you are satisfied with the responses, add to the user's rep!
-
November 4th, 2009, 08:22 AM
#34
Re: How can I Initialize getJdbcTemplate()?
CGenerationScheduledJobTestCase.java
Code:
public void testRunScheduledJob() {
AbstractApplicationContext context = new
ClassPathXmlApplicationContext("????");
.
.
}
WEB-INF\Integration-dao.xml
Code:
.
.
<bean id="cListDAO" class="com…..cc.business.dao.CCCListDAO">
</bean>
.
.
WEB-INF/Integration-webapp.xml
Code:
<beans>
<context:property-placeholder
location="classpath:jdbc.properties,
classpath:com/././././mail.properties" />
<import resource="/Integration-dao.xml" />
<import resource="/Integration-datasource.xml" />
</beans>
WEB-INF\web.xml
Code:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/Integration-webapp.xml</param-value>
</context-param>
Above is the xml mapping in my project.
Here I want object of cListDAO using getBean() method.
To achieve this what I need to give for ClassPathXmlApplicationContext(“????”)
Thanks
-
November 4th, 2009, 09:18 AM
#35
Re: How can I Initialize getJdbcTemplate()?
So since the entry point of this web application is through servlet API context initialized, the web application context is good enough since it is importing the other contexts that you may require.
Code:
public void testRunScheduledJob() {
AbstractApplicationContext context = new
ClassPathXmlApplicationContext("Integration-webapp.xml);
.
.
}
That should find it that way, then you can use the getBean methods as i showed you before.
------
If you are satisfied with the responses, add to the user's rep!
-
November 4th, 2009, 09:41 AM
#36
Re: How can I Initialize getJdbcTemplate()?
but "Integration-webapp.xml" is also not in classpath
it is in WEB-INF folder. I tried but file not found exception is comming. I belive loading is happening using web.xml.
Code:
WEB-INF/Integration-webapp.xml
Please help.
-
November 4th, 2009, 12:48 PM
#37
Re: How can I Initialize getJdbcTemplate()?
Originally Posted by java_dev
but "Integration-webapp.xml" is also not in classpath
it is in WEB-INF folder. I tried but file not found exception is comming. I belive loading is happening using web.xml.
Code:
WEB-INF/Integration-webapp.xml
Please help.
well the only problem here is a file lookup.
create another context under say src/test/resources
for unit tests which does what integration-webapp does then. This is usually the preferred way to do 'unit testing' and not 'integration testing' where you use another datasource (in memory database, etc).
------
If you are satisfied with the responses, add to the user's rep!
-
November 10th, 2009, 10:48 PM
#38
Re: How can I Initialize getJdbcTemplate()?
Currently I am working on more priority work! Please give me some time to reply.
Deliverance, i posted new request/thread on webservices. Can you please help me on this.
Thread Link:
---------------
http://www.codeguru.com/forum/showth...18#post1894318
Thanks In advance.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|