citrusframework / citrusframework/citrus

Datasource is not injected with @CitrusEndpoint annotation

Open
#656 6 comments 0 reactions 0 assignees View on GitHub
bug prio-medium
Dominant language
Java
Stars
485
Forks
155
Avg merge
4d 22h
Merged PRs (30d)
6

Description

**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**
```java
@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.

Contributor guide

Open the contributing guide

Research direction

Start with the JUnit 5 CitrusExtension and the @CitrusEndpoint injection path, then inspect how endpoint beans are resolved from the Spring context. Reproduce the provided DataSource example and add a regression test; done means the annotated field is non-null during the Citrus test, with the chosen injection or endpoint behavior documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.