4

Im trying to mock the HttpClient implementation using the Spring 3.1 profiles and by using EasyMock, but the Spring container complains it cant find a bean with right type. Have I configured the mock wrong? If I replace the EasyMock bean with the actually implementation it is injected correctly, it seems like the EasyMock method doesnt create a bean of right type. All help very appreciated!

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.apache.http.client.HttpClient] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:986)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:856)

<beans profile="development,developmentthomas,test,integration,webtest,accept">
    <bean id="httpClient" class="org.easymock.EasyMock" factory-method="createMock">
        <constructor-arg value="org.apache.http.client.HttpClient" />
    </bean>
</beans>

<beans profile="thomasciserver,testserverlocaloleg,testservercioleg,preprod,production,testservercithomas,testserverlocalthomas,localthomasclean,testserver,productionthomas">
    <bean id="httpClient" class="org.apache.http.impl.client.DefaultHttpClient"/>
</beans>
Thomas Vervik
  • 4,325
  • 9
  • 36
  • 64
  • forgot to meantion this, but I read this one upfront, and right type interference should had been fixed in Spring 3.2, which Im using now – Thomas Vervik Apr 29 '13 at 00:04
  • Described under paragraph "GENERIC FACTORY METHODS" http://blog.springsource.org/2012/11/07/spring-framework-3-2-rc1-new-testing-features/ – Thomas Vervik Apr 29 '13 at 00:05

2 Answers2

0

i think the problem lies within the factory method.

have a look at this post Autowiring of beans generated by EasyMock factory-method? ithink this will solve your problem

Community
  • 1
  • 1
Philipp Sander
  • 10,139
  • 6
  • 45
  • 78
  • Agree, but in Spring 3.2 this type issue should have been fixed, not sure why it doesnt work. http://blog.springsource.org/2012/11/07/spring-framework-3-2-rc1-new-testing-features/ – Thomas Vervik May 02 '13 at 16:32
0

See the spring-test. It has org.springframework.mock.http.client.MockClientHttpRequest. The org.springframework.mock package has a whole bushel of things that will save you from reinventing the wheel.

Xenson
  • 192
  • 7