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 :)
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.
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.
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
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.
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.
Re: How can I Initialize getJdbcTemplate()?
Quote:
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).
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.