Datasource is not injected with @CitrusEndpoint annotation
Citrus Version 2.8.0
Expected behavior
Annotating a DataSource with @CitrusEndpoint injects a Datasource bean into the test case.
This is not an issue with Junit4 and TestNG as you could simply use the @Autowired annotation but with Junit5, you have to use @CitrusEndpoint for endpoint injections which leads to this issue.
Actual behavior
Currently the DataSource field annotated with @CitrusEndpoint is null.
Test case sample
@ExtendWith(CitrusExtension.class)
class testDatasourceInjection{
@CitrusEndpoint
private DataSource dataSource;
@CitrusTest
@Test
void testAddNewXingAccount(@CitrusResource final TestRunner runner){
assertNotNull(dataSource);
}
}
One could argue that a DataSource is not an endpoint from a technical perspective but in this case, Citrus uses the DataSource to create a connection to the database.
Maybe it would make sense to create an SQL endpoint which just wraps the DataSource for further usage.
Another more hot-fixish attempt would be to inject DataSoruces in addition to Endpoints from the Spring context. But I think an dedicated endpoint wrapping the DataSource would improve the convention of using endpoints for communication.
If you add the SpringExtension for JUnit5 you should be able to use @Autowired here, too. So not sure if this is an issue.
Hi, this does not work unfortunately. That's why I opened that issue.
The sample test case in the problem description does not use the SpringExtension nor @Autowired so I could not tell by the sample that this is not working.
If you are using those Spring features and it still does not work it implies that the combination of extensions is not working?
I'll double check that just to be sure. It's too long ago that I tested it.
I exactly have the same problem with 2.8.0.
I populated the Datasource in a citrus config class but no injection is possible in a test case.
@Bean public DataSource dataSource() { ..}
This is the only solution, how I got it working...
` @ExtendWith({SpringExtension.class,CitrusExtension.class}) @ContextConfiguration(classes = {CitrusConfig.class}) public class testDatasourceInjection {
@Autowired private DataSource dataSource;
} `