-
Notifications
You must be signed in to change notification settings - Fork 84
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
SDK-358 - Add integration test framework for helper classes #308
Conversation
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> |
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 adds all of the test classes to their own library, so this library can be added to the classpath of the pom used by the Maven verifier during the integration tests, which runs outside of this project
mavenEnvironment.setArtifactFactory(artifactFactory); | ||
mavenEnvironment.setPluginManager(pluginManager); | ||
mavenEnvironment.setWizard(wizard); | ||
} |
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.
See the new MavenEnvironment
class below - basically this just allows us to encapsulate everything provided by the Maven process during plugin execution in a single object that can be passed around and depended upon.
} | ||
else { | ||
testFunction.executeTest(); | ||
} |
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.
So the general idea here, is that a particular integration test will wrap it's test functionality in this executeTest
method. When this is run, the mavenEnvironment will be null, and this will trigger the new "InvokeMethod" plugin to run it, by creating a new instance of this same test class, and executing this same method, but this time with the mavenEnvironment populated from the InvokeMethod plugin.
File expectedFile = new File(getMavenTestDirectory(), "idgen-omod-4.14.0.jar"); | ||
assertTrue(expectedFile.exists()); | ||
}); | ||
} |
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.
And so this is an example of how we would run such a test. By wrapping the code in the executeTest
block, it will cause the code in that block to be executed by a bare-bones plugin that exists only to execute the provided block.
Any new test libraries that are referenced by tests that are use this pom (eg. those that extend AbstractMavenIT) | ||
need to be added as dependencies must be added here so the plugin can load and execute the tests successfully | ||
See: https://maven.apache.org/guides/mini/guide-maven-classloading.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.
This took me the longest time to figure out, but finally was able to do so. See comment above.
/** | ||
* The purpose of this class is to handle all interactions with Maven that require retrieving artifacts from the Maven repository | ||
*/ | ||
public class ArtifactHelper { |
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.
One of my goals that led me to doing this in the first place was to start identifying functionality that we might refactor into common libraries. This is the start of that effort, and the integration test that corresponds with it is necessary to make sure it is operating as expected.
/** | ||
* Component that allows access to the Maven components set within the current execution environment | ||
*/ | ||
@Data |
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 love lombok, we should use it everywhere.
catch (Exception e) { | ||
throw new MojoExecutionException("Error executing method: " + methodName, e); | ||
} | ||
} |
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 code is admittedly ugly. I probably should have just found a library to do this all more elegantly. In any event, this plugin will instantiate the given class, set the mavenEnvironment
property on it if available, and the call the given method. This is what allows us to test functionality that requires a Maven Environment outside of individual plugins that consume that functionality (aside from this one, which is necessary).
see https://openmrs.atlassian.net/browse/SDK-358