• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Spring Unit test help

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write a unit test for a spring application .


public class ProductTest extends AbstractDependencyInjectionSpringContextTests {

private ProductDao productDao;

public void setProductDao(ProductDao productDao) {
this.productDao = productDao;
}

protected String[] getConfigLocations() {

return new String[] { "classpath*:/WebContent/WEB-INF/xyz-servlet.xml" };
}

public void testProduct() throws Exception{

List list = null;
ProductManager productManager = new ProductManagerImpl();

list = productManager.getRelatedProductsByPartnumberUsingDao("test1",CommandConstants.CONSTANTS_MAX_RESULTS_TO_RETURN.intValue());
assertNotNull("not null",list);

}


xxx-servlet.xml

<bean id="productListController" class="com.svg.xyz.controllers.ProductListController">
<property name="productManager">
<ref bean="productManager"></ref>
</property>
<property name="maxResultsToReturn"><value>10000</value></property>
</bean>


<bean id="productManager" class="com.svg.xyz.managers.ProductManagerImpl">
<property name="productDao"><ref bean="productDao"></ref>
</property>
</bean>


<!-- DAOS -->
<bean id="productDao" class="com.svg.xyz.dao.ProductDaoImpl">
<property name="JDBCHelper"><ref bean="jdbcHelper"></ref>
</property>
</bean>


<bean id="jdbcHelper" class="com.svg.xyz.utils.JDBCHelper">
<property name="dataSource">
<ref bean="dataSource"></ref>
</property>
</bean>



<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="url" value="jdbc b2:xyz"/>
<property name="username" value="wcsadmin"/>
<property name="password" value="wcsadmin"/>
<property name="maxActive" value="30"/>
<property name="maxIdle" value="10"/>
<property name="maxWait" value="1000"/>
<property name="defaultAutoCommit" value="true"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="60"/>
<property name="logAbandoned" value="true"/>
</bean>


I am getting the following error


org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.svg.xyz.unittest.ProductTest': Unsatisfied dependency expressed through bean property 'productDao': Set this property value or disable dependency checking for this bean.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.checkDependencies(AbstractAutowireCapableBeanFactory.java:1038)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:273)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.injectDependencies(AbstractDependencyInjectionSpringContextTests.java:179)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.prepareTestInstance(AbstractDependencyInjectionSpringContextTests.java:158)
at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:88)
at junit.framework.TestCase.runBare(TestCase.java:125)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to write the following in the constructor of the Test Case class



 
He was expelled for perverse baking experiments. This tiny ad is a model student:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!