I am using the Spring application to download and auto-tuning is enabled. The main application file is marked as @EnableAutoConfiguration . The JNDI data source is configured using java config, and the class that creates the data source is marked as @Configuration .
I have a test class as shown below.
@RunWith( SpringJUnit4ClassRunner.class ) @WebAppConfiguration @ContextConfiguration( classes = Application.class ) public class TestSomeBusiness {}
The problem is that when I run the test case, it searches for datasource jndi, which does not work, because the test case does not work inside the server environment. As far as I know, the classes in the classpath marked with @Configuration are executing and that the reason causes the data source to be searched.
The work I found, instead of searching, JNDI creates the data source using DriverManagerDataSource , so even if its not a server environment, the search for the data source will not fail.
My questions:
1) How do we usually deal with a data source (when searching with JNDI) in a spring boot application for testing?
2) Is there a way to exclude the data source configuration class when invoked when running a test case?
3) Should I create an embedded server so that the JNDI search can be performed while running the test case?
java spring spring-boot
HereToLearn
source share