Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBRider support #624

Closed
Jenson3210 opened this issue Oct 30, 2024 · 4 comments · Fixed by #627
Closed

DBRider support #624

Jenson3210 opened this issue Oct 30, 2024 · 4 comments · Fixed by #627
Labels
recipe Recipe request

Comments

@Jenson3210
Copy link
Contributor

What problem are you trying to solve?

Internally, we're using dbrider for integration test that assert db state. It's an extension on top of dbunit that allows for csv datasource annotations on top of test cases.
Between junit4 and 5, there are some changes to the usage.
We could try and create support for this.

Describe the situation before applying the recipe

@AutoConfigureMockMvc
@ActiveProfiles(INTEGRATION_TEST)
@SpringBootTest
@TestExecutionListeners(mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS, listeners = {DBRiderTestExecutionListener.class})
@DBUnit(mergeDataSets = true, mergingStrategy = DataSetMergingStrategy.CLASS)
@DataSet(cleanBefore = true, cleanAfter = true, value = "")
public abstract class AbstractIntegrationTest {
    ...
}

Describe the situation after applying the recipe

@AutoConfigureMockMvc
@ActiveProfiles(INTEGRATION_TEST)
@SpringBootTest
@DBRider
@DBUnit(mergeDataSets = true, mergingStrategy = DataSetMergingStrategy.CLASS)
@DataSet(cleanBefore = true, cleanAfter = true, value = "")
public abstract class AbstractIntegrationTest {
    ...
}

Have you considered any alternatives or workarounds?

Manual changes? 🤢

Any additional context

see docs on dbrider here

Are you interested in contributing this recipe to OpenRewrite?

I will try to come up with certain aspects, but additional support is always welcome as this is completely greenfielded topic from open rewrite perspective.

@timtebeek timtebeek added the recipe Recipe request label Oct 30, 2024
@timtebeek timtebeek moved this to Recipes Wanted in OpenRewrite Oct 30, 2024
@timtebeek
Copy link
Contributor

Reading between the lines it looks like you'll have to match @TestExecutionListeners, remove that, and replace it with @DBRider; correct? I see @DBRider can have arguments, but none that come from the old annotation I suppose, making this a fairly straightforward visitor. You can then combine the recipe you'll create with some declarative recipes to bump to the next minor or patch version, just so there's a single recipe we can hook into a JUnit 4 to 5 upgrade.

@Jenson3210
Copy link
Contributor Author

yes, that's indeed what is the case here...

Only thing. I only want to remove the specific listener and then remove the annotation if no listeners remain.
If there is another listener also, that should be a different recipe.

Jenson3210 pushed a commit to Jenson3210/rewrite-testing-frameworks that referenced this issue Oct 31, 2024
@Jenson3210
Copy link
Contributor Author

@timtebeek
I started on an implementation (see branch)

I am facing 3 issues which I do not understand/do not know how I could start solving:

  • doNotTouchIfDbRiderAlreadyPresent and removeListenerFromOtherListeners -> LST contains missing or invalid type information
    Screenshot 2024-10-31 at 13 43 20
    All others tests start from a very similar setup, yet these do not have MissingTypeInformation errors.
  • Based on AddConfigurationAnnotationIfBeansPresent, I added similar logic in my recipe. However, I am seeing the annotation being added without Prefix/space.
    Screenshot 2024-10-31 at 13 47 41
  • I have an annotation with arguments that are like @Annotation(arg1="...", arg2="..."). If I remove arg1, arg 2 keeps the space it has. I could add a visit override that looks at all arguments and formats them. But if the project is configuring @annotation( arg1="...", arg2="..." )`, removing these spaces would break "their style". I am sure core will contain one or another nifty trick to do this that I do not know (yet).
    Screenshot 2024-10-31 at 13 52 33

@Jenson3210
Copy link
Contributor Author

The spaces issues where both fixed with Prefix-workarounds
The lst information was fixed by cleaning the imports in the test case

timtebeek added a commit that referenced this issue Nov 3, 2024
* Initial draft of the ExecutionListenerToDbRiderAnnotation ScanningRecipe

fixes #624

* Added missing import

* Ran best practices

* Finishing up on the declarative recipe

* Finishing up on the declarative recipe

* Minimize tests

* Apply formatter

* Review comment refactoring

* Polish to static constructor & reduce visibility

* Final polish: fix header year & only use ridr-junit5 in src/main

---------

Co-authored-by: Jente Sondervorst <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants