1

this is my first post on this forum so please go easy on me if a made mistake or else. I'm using spring-boot batch with mongdb and everything works fine but I running in trouble when I have to test my batch. My Batchconfiguration is based on multiple jobs (4 jobs), so

  1. 1st trouble when I used JobLauncherTestUtils spring doesn't know which job to inject and I don't know how to specify that to test the jobs one by one.
  2. 2nd trouble when I separate my configuration to testing only one job, JobLauncherTestUtils couldn't been creating because it's need dataSource, as I used MongoDb with mongotemplate I don't use dataSource.

the stack error look like :

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobRepositoryTestUtils': Unsatisfied dependency expressed through method 'setDataSource' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

Hope anybody will help me to find a solution. Thanks in advance.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Souraji
  • 13
  • 3

1 Answers1

1

1st trouble when i used JobLauncherTestUtils spring don't know wich job to inject and i don't know how to specify that to test the jobs one by one.

You can specify which job to launch using JobLauncherTestUtils#setJob. Please see JobLauncherTestUtils throws NoUniqueBeanDefinitionException while trying to test spring batch steps

2nd trouble when I separate my configuration to testing only one job, JobLauncherTestUtils couldn't been creating because it's need dataSource, as I used MongoDb with mongotemplate I don't use dataSource.

According to the error Error creating bean with name 'jobRepositoryTestUtils', it is not JobLauncherTestUtils that could not be created but jobRepositoryTestUtils. The repository test utils is a convenience class to create and remove job executions from a database (See its javadoc). So it requires a datasource. If you don't have a data source in your test context, you need to remove this bean declaration.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50