-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK-358 - Add integration test framework for helper classes
- Loading branch information
Showing
13 changed files
with
547 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractMavenIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.openmrs.maven.plugins; | ||
|
||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.junit.Before; | ||
import org.openmrs.maven.plugins.utility.MavenEnvironment; | ||
|
||
import java.io.File; | ||
|
||
@Getter @Setter | ||
public abstract class AbstractMavenIT extends AbstractSdkIT { | ||
|
||
MavenEnvironment mavenEnvironment = null; | ||
|
||
@Override | ||
@Before | ||
public void setup() throws Exception { | ||
super.setup(); | ||
mavenEnvironment = null; | ||
} | ||
|
||
@Override | ||
void addTestResources() throws Exception { | ||
includePomFile("invokeIT", "pom.xml"); | ||
} | ||
|
||
protected void executeTest(MavenTestFunction testFunction) throws Exception { | ||
StackTraceElement invoker = Thread.currentThread().getStackTrace()[2]; | ||
String className = invoker.getClassName(); | ||
String testMethod = invoker.getMethodName(); | ||
if (mavenEnvironment == null) { | ||
addTaskParam("className", className); | ||
addTaskParam("methodName", testMethod); | ||
addTaskParam(BATCH_ANSWERS, getAnswers()); | ||
addTaskParam("testMode", "true"); | ||
String plugin = resolveSdkArtifact(); | ||
verifier.executeGoal(plugin + ":" + InvokeMethod.NAME); | ||
} | ||
else { | ||
testFunction.executeTest(); | ||
} | ||
} | ||
|
||
protected File getMavenTestDirectory() { | ||
return new File(mavenEnvironment.getMavenProject().getBuild().getDirectory()); | ||
} | ||
|
||
/** | ||
* Simple interface that encapsulates a test that should be evaluated by tests that use this Mojo | ||
*/ | ||
public interface MavenTestFunction { | ||
void executeTest() throws Exception; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
integration-tests/src/test/java/org/openmrs/maven/plugins/BuildIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
integration-tests/src/test/java/org/openmrs/maven/plugins/utility/ArtifactHelperIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.openmrs.maven.plugins.utility; | ||
|
||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.apache.maven.it.VerificationException; | ||
import org.junit.Test; | ||
import org.openmrs.maven.plugins.AbstractMavenIT; | ||
import org.openmrs.maven.plugins.model.Artifact; | ||
|
||
import java.io.File; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
@Getter @Setter | ||
public class ArtifactHelperIT extends AbstractMavenIT { | ||
|
||
@Test | ||
public void test_downloadModuleWithDefaultName() throws Exception { | ||
executeTest(() -> { | ||
ArtifactHelper artifactHelper = new ArtifactHelper(getMavenEnvironment()); | ||
Artifact artifact = new Artifact("idgen-omod", "4.14.0", "org.openmrs.module", "jar"); | ||
artifactHelper.downloadArtifact(artifact, getMavenTestDirectory(), null); | ||
File expectedFile = new File(getMavenTestDirectory(), "idgen-omod-4.14.0.jar"); | ||
assertTrue(expectedFile.exists()); | ||
}); | ||
} | ||
|
||
@Test | ||
public void downloadModuleWithSpecificName() throws Exception { | ||
executeTest(() -> { | ||
ArtifactHelper artifactHelper = new ArtifactHelper(getMavenEnvironment()); | ||
Artifact artifact = new Artifact("idgen-omod", "4.14.0", "org.openmrs.module", "jar"); | ||
artifactHelper.downloadArtifact(artifact, getMavenTestDirectory(), "idgen.omod"); | ||
File expectedFile = new File(getMavenTestDirectory(), "idgen.omod"); | ||
assertTrue(expectedFile.exists()); | ||
}); | ||
} | ||
|
||
@Test(expected = VerificationException.class) | ||
public void downloadModuleThatDoesNotExist() throws Exception { | ||
executeTest(() -> { | ||
ArtifactHelper artifactHelper = new ArtifactHelper(getMavenEnvironment()); | ||
Artifact artifact = new Artifact("idgen-omod", "4.0.0", "org.openmrs.module", "jar"); | ||
artifactHelper.downloadArtifact(artifact, getMavenTestDirectory(), "idgen.omod"); | ||
}); | ||
} | ||
} |
Oops, something went wrong.