2

Is there any convenience stuff in spring that would allow executing SQL scripts during Spring integration tests BUT you could also pass names parameters?

@Sql annotations works very good however for the same set of data I would preferably wish to pass record ID so that I could have controlled environment for testing.

Point is I did not find any utility in Spring that is able to fulfill exactly that so if Spring is not up to snuff, perhaps there are other libraries that could do something like that? There are ScriptUtils but as far as I can tell they are meant for executing SQL resource, not interpolate query parameters.

1 Answer 1

2

As you see @Sql doesn't support. But you can create custom annotation @SqlWithParams and set the logic that you need. For custom test annotation you need to create a listener that handles this annotation. For handling @Sql spring test uses SqlScriptsTestExecutionListener. For @SqlWithParams you need to create a similar listener and register it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.