I have a spring boot 2.2.4 project with a REST controller, a service and a JPA repository. I can use the karate mock servlet to define a mock for the controller and service, but I don't know what to do for the repository. The controller @Autowired the service. The service @Autowired the repository.
As a result I get this message when I run my karate test:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'repository.EmployeeRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
The MockServlet I am using is exactly this class from demo: MockSpringMvcServlet
With the MockConfig class similar to this: MockDemoConfig
Finally the karate-config.js file bootstraps the MockSpringMvServlet this way (as given in karate demo code):
function fn() {
var config = {
baseUrl: 'http://localhost:8080'
};
var Factory = Java.type('demo.MockSpringMvcServlet');
karate.configure('httpClientInstance', Factory.getMock());
return config;
}
Note: if i remove the JPA repository from the API call, then the Karate Mock Servlet works fine without the server running and the Karate test passes successfully.
Any idea how I would do this? If anyone can point me in the right direction I would appreciate it.