-
Notifications
You must be signed in to change notification settings - Fork 63
Ref #596: adapt library 'camel-test-blueprint-junit5' to camel-karaf #651
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
base: main
Are you sure you want to change the base?
Conversation
a1238cc to
4dac01b
Compare
essobedo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for the PR, please avoid huge PR like this one next time as it too long to review. Regarding the PR, could you please remove all tests that seem to test Camel instead of camel-blueprint?
| * | ||
| * @return the name of the path for the .cfg file to load, and the persistence-id of the property placeholder. | ||
| */ | ||
| protected String[] loadConfigAdminConfigurationFile() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could create a dedicated class to hold the path of the cfg and the persistence id. Using an array of strings is too error-prone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| FileWriter writer = new FileWriter(cfg); | ||
| try { | ||
| initialConfiguration.store(writer, null); | ||
| } finally { | ||
| IOHelper.close(writer); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use try-with-resources statement instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| camelCore.stop(); | ||
| test.stop(); | ||
|
|
||
| Thread.sleep(500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid it will make this test flaky, so either we find a way to avoid this sleep or I rather prefer not having the test at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inherited from the legacy code; I assume it provides some value in terms of non-regression.
https://github.com/apache/camel-karaf/commits/camel-karaf-3.22.4/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintPropertiesTest.java
| if (mJar instanceof JarFile) { | ||
| JarFile jf = (JarFile) mJar; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be inlined using pattern matching https://docs.oracle.com/en/java/javase/17/language/pattern-matching-instanceof.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| + "It's likely that the test is misconfigured!"); | ||
| } | ||
|
|
||
| // doPostTearDown(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| if (node instanceof Element) { | ||
| Element pp = (Element) node; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be inlined using pattern matching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| String[][] configAdminPidFiles = new String[0][0]; | ||
| if (file != null) { | ||
| if (file.length % 2 != 0) { // This needs to return pairs of filename and pid | ||
| throw new IllegalArgumentException("The length of the String[] returned from loadConfigAdminConfigurationFile must divisible by 2, was " + file.length); | ||
| } | ||
| configAdminPidFiles = new String[file.length / 2][2]; | ||
|
|
||
| int pair = 0; | ||
| for (int i = 0; i < file.length; i += 2) { | ||
| String fileName = file[i]; | ||
| String pid = file[i + 1]; | ||
| if (!new File(fileName).exists()) { | ||
| throw new IllegalArgumentException("The provided file \"" + fileName + "\" from loadConfigAdminConfigurationFile doesn't exist"); | ||
| } | ||
| configAdminPidFiles[pair][0] = fileName; | ||
| configAdminPidFiles[pair][1] = pid; | ||
| pair++; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope it can be simplified or at least it should be moved to a dedicated method as it is very hard to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea — I’ve done a small refactoring and adopted your proposal.
| @Test | ||
| public void testOverrideNormal() { | ||
| final Long someValue = 60000L; | ||
| System.clearProperty(CamelBlueprintTestSupport.SPROP_CAMEL_CONTEXT_CREATION_TIMEOUT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be needed as it is already done by the cleanup method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
|
||
| @Test | ||
| public void testDefault() { | ||
| System.clearProperty(CamelBlueprintTestSupport.SPROP_CAMEL_CONTEXT_CREATION_TIMEOUT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| <artifactId>camel-blueprint-main</artifactId> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <name>Apache Camel :: Karaf :: Blueprint Main</name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <name>Apache Camel :: Karaf :: Blueprint Main</name> | |
| <name>Apache Camel :: Karaf :: Components :: Blueprint Main</name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a bundle or a component; perhaps we should consider moving these dependencies to another directory in the project, for example under tests?
| </parent> | ||
|
|
||
| <artifactId>camel-blueprint-main</artifactId> | ||
| <packaging>jar</packaging> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jar or bundle?
| <artifactId>camel-test-blueprint-junit5</artifactId> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <name>Apache Camel :: Karaf :: Test :: Blueprint :: Junit 5 </name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <name>Apache Camel :: Karaf :: Test :: Blueprint :: Junit 5 </name> | |
| <name>Apache Camel :: Karaf :: Test :: Blueprint :: JUnit 5 </name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| </parent> | ||
|
|
||
| <artifactId>camel-test-blueprint-junit5</artifactId> | ||
| <packaging>jar</packaging> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jar or bundle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my experience, this dependency is only useful when provided as a JAR. It allows unit tests to be executed without requiring a Karaf container.
…nt-junit5 from version 3.22.0-SNAPSHOT
|
Thank you very much for the code review. I have reworked the PR by splitting it into two commits: one containing the code inherited from the Karaf Camel 3.22.0 version, and a second one with the adaptations for version 4.10.8-SNAPSHOT. I hope this makes the changes easier to review. Regarding the tests, I believe they are necessary to ensure that the Camel patterns are correctly ported and behave as expected in a Blueprint context, even if they may appear to test Camel itself. |
|
camel-blueprint-main and camel-test-blueprint-junit5 are not bundles or components; perhaps we should consider moving these dependencies to another directory in the project, for example under tests? |
I agree, if they are not compoments, please move them under tests indeed 👍 |
…nt-main' to tests subdirectory
fixes #596
Here’s my first Pull Request on GitHub.
I’m open to any feedback that could help improve the code and the way we collaborate on these projects.
All the unit tests should normally be working.
I reintroduced the code and unit tests that were present in version 3.22.4 of camel-karaf, and then took inspiration from the changes made to the Spring tests in the Apache Camel project.