From d49ee7ba9d732c2c299ce5f8f64346f363e0a3c1 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Sat, 23 Nov 2024 00:18:24 -0500 Subject: [PATCH] SDK-360 - Improve test coverage and fix uncovered issues. --- .../openmrs/maven/plugins/AbstractSdkIT.java | 18 +++-- .../maven/plugins/AddDependencyIT.java | 7 ++ .../openmrs/maven/plugins/AddExclusionIT.java | 6 ++ .../openmrs/maven/plugins/BuildDistroIT.java | 78 ++++++++++++++++++- .../org/openmrs/maven/plugins/DeployIT.java | 8 +- .../maven/plugins/RemoveDependencyIT.java | 2 + .../org/openmrs/maven/plugins/SetupIT.java | 13 ++-- .../utility/DistributionBuilderIT.java | 7 +- .../buildDistroIT/assembly.xml | 18 +++++ .../buildDistroIT/openmrs-distro.properties | 16 ++++ .../integration-test/buildDistroIT/pom.xml | 63 +++++++++++++++ .../integration-test/buildIT/pom.xml | 6 +- .../deployIT/pom-owa-module.xml | 21 +++++ .../integration-test/invokeIT/pom.xml | 6 +- .../test/resources/integration-test/pom.xml | 6 +- .../openmrs/maven/plugins/BuildDistro.java | 2 +- .../org/openmrs/maven/plugins/Deploy.java | 1 + .../openmrs/maven/plugins/model/Version.java | 12 ++- .../plugins/utility/DistributionBuilder.java | 15 +++- .../maven/plugins/utility/DistroHelper.java | 17 ++-- .../plugins/utility/DistroHelperTest.java | 10 ++- 21 files changed, 294 insertions(+), 38 deletions(-) create mode 100644 integration-tests/src/test/resources/integration-test/buildDistroIT/assembly.xml create mode 100644 integration-tests/src/test/resources/integration-test/buildDistroIT/openmrs-distro.properties create mode 100644 integration-tests/src/test/resources/integration-test/buildDistroIT/pom.xml create mode 100644 integration-tests/src/test/resources/integration-test/deployIT/pom-owa-module.xml diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIT.java index 192d2a40d..522da5ac9 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIT.java @@ -39,9 +39,11 @@ import java.util.zip.ZipFile; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.not; import static org.hamcrest.io.FileMatchers.anExistingFileOrDirectory; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.openmrs.maven.plugins.SdkMatchers.hasModuleVersion; import static org.openmrs.maven.plugins.SdkMatchers.hasModuleVersionInDisstro; import static org.openmrs.maven.plugins.SdkMatchers.hasPlatformVersion; @@ -70,14 +72,11 @@ public abstract class AbstractSdkIT { * test directory, contains mock files and files created during tests */ protected File testDirectory; - protected Path testDirectoryPath; - protected File distroFile; - protected Path testBaseDir; protected Path testResourceDir; - boolean preserveTestOutput; + protected boolean preserveTestOutput; public String resolveSdkArtifact() throws MojoExecutionException { Properties sdk = new Properties(); @@ -110,7 +109,6 @@ protected void includePomFile(String... paths) throws Exception { protected void addTestResources() throws Exception { includePomFile("pom.xml"); - includeDistroPropertiesFile(DistroProperties.DISTRO_FILE_NAME); } @Before @@ -244,6 +242,16 @@ public File getTestFile(Path path) { return testDirectoryPath.resolve(path).toFile(); } + /** + * asserts that file with given path is present in test directory + */ + public void assertNumFilesPresent(int numExpected, String path, String extension) { + File dir = testDirectoryPath.resolve(path).toFile(); + assertTrue(dir.exists()); + File[] files = dir.listFiles((dir1, name) -> extension == null || name.endsWith(extension)); + assertThat(files.length, equalTo(numExpected)); + } + /** * asserts that file with given path is present in test directory */ diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/AddDependencyIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/AddDependencyIT.java index c86e29620..221d3c78b 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/AddDependencyIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/AddDependencyIT.java @@ -1,6 +1,7 @@ package org.openmrs.maven.plugins; import org.junit.Test; +import org.openmrs.maven.plugins.model.DistroProperties; import org.openmrs.maven.plugins.utility.PropertiesUtils; import java.util.Properties; @@ -11,6 +12,12 @@ public class AddDependencyIT extends AbstractSdkIT { + @Override + protected void addTestResources() throws Exception { + super.addTestResources(); + includeDistroPropertiesFile(DistroProperties.DISTRO_FILE_NAME); + } + @Test public void shouldAddOmodDependency() throws Exception { addTaskParam("distro", distroFile.getAbsolutePath()); diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/AddExclusionIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/AddExclusionIT.java index 55dd85edc..e2dce834b 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/AddExclusionIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/AddExclusionIT.java @@ -15,6 +15,12 @@ public class AddExclusionIT extends AbstractSdkIT { + @Override + protected void addTestResources() throws Exception { + super.addTestResources(); + includeDistroPropertiesFile(DistroProperties.DISTRO_FILE_NAME); + } + public DistroProperties getDistroProperties() throws Exception { Properties properties = PropertiesUtils.loadPropertiesFromFile(distroFile); return new DistroProperties(properties); diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/BuildDistroIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/BuildDistroIT.java index 56d2f8de4..62c5d2801 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/BuildDistroIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/BuildDistroIT.java @@ -1,11 +1,16 @@ package org.openmrs.maven.plugins; +import org.apache.commons.io.FileUtils; import org.junit.Test; +import org.openmrs.maven.plugins.model.DistroProperties; + +import java.nio.file.Path; public class BuildDistroIT extends AbstractSdkIT { @Test - public void testBuildDistroFromDistroFile() throws Exception { + public void buildDistro_shouldBuildFromDistroPropertiesInCurrentDirectory() throws Exception { + includeDistroPropertiesFile(DistroProperties.DISTRO_FILE_NAME); addTaskParam("dir", "target"); addTaskParam("ignorePeerDependencies", "false"); executeTask("build-distro"); @@ -19,14 +24,34 @@ public void testBuildDistroFromDistroFile() throws Exception { assertFilePresent("target/web/startup.sh"); assertFilePresent("target/web/wait-for-it.sh"); assertFilePresent("target/web/modules"); + assertFilePresent("target/web/modules/uiframework-3.6.omod"); + assertFilePresent("target/web/modules/uicommons-1.7.omod"); + assertFilePresent("target/web/modules/owa-1.4.omod"); assertFilePresent("target/web/owa"); assertFilePresent("target/web/openmrs.war"); assertFilePresent("target/web/openmrs-distro.properties"); + assertFileContains("war.openmrs=1.11.5", "target", "web", "openmrs-distro.properties"); + assertSuccess(); + } + + @Test + public void buildDistro_shouldBuildFromDistroPropertiesInCurrentProject() throws Exception { + Path sourcePath = testResourceDir.resolve(TEST_DIRECTORY).resolve("buildDistroIT"); + FileUtils.copyDirectory(sourcePath.toFile(), testDirectory); + + addTaskParam("dir", "distro"); + addTaskParam("ignorePeerDependencies", "false"); + executeTask("build-distro"); + assertFileContains("war.openmrs=2.6.9", "distro", "web", "openmrs-distro.properties"); + assertFilePresent("distro/web/openmrs-distro.properties"); + assertFilePresent("distro/web/openmrs_core/openmrs.war"); + assertFilePresent("distro/web/openmrs_modules"); + assertNumFilesPresent(12, "distro/web/openmrs_modules", ".omod"); assertSuccess(); } @Test - public void testBuildDistroRefApp23() throws Exception { + public void buildDistro_shouldBuildFromRefapp23Artifact() throws Exception { addTaskParam("distro", "referenceapplication:2.3.1"); addTaskParam("dir", "referenceapplication"); addTaskParam("ignorePeerDependencies", "false"); @@ -43,6 +68,55 @@ public void testBuildDistroRefApp23() throws Exception { assertFilePresent("referenceapplication/web/modules"); assertFilePresent("referenceapplication/web/openmrs.war"); assertFilePresent("referenceapplication/web/openmrs-distro.properties"); + assertNumFilesPresent(36, "referenceapplication/web/modules", ".omod"); + assertFileContains("war.openmrs=1.11.5", "referenceapplication", "web", "openmrs-distro.properties"); + assertSuccess(); + } + + @Test + public void buildDistro_shouldBuildFromRefapp2xArtifact() throws Exception { + addTaskParam("distro", "referenceapplication:2.13.0"); + addTaskParam("dir", "referenceapplication"); + addTaskParam("ignorePeerDependencies", "false"); + executeTask("build-distro"); + + assertFilePresent("referenceapplication/docker-compose.yml"); + assertFilePresent("referenceapplication/docker-compose.override.yml"); + assertFilePresent("referenceapplication/docker-compose.prod.yml"); + assertFilePresent("referenceapplication/.env"); + assertFilePresent("referenceapplication/web/Dockerfile"); + assertFilePresent("referenceapplication/web/openmrs-distro.properties"); + assertFilePresent("referenceapplication/web/openmrs_core/openmrs.war"); + assertFileContains("war.openmrs=2.5.9", "referenceapplication", "web", "openmrs-distro.properties"); + assertFilePresent("referenceapplication/web/openmrs_modules"); + assertNumFilesPresent(42, "referenceapplication/web/openmrs_modules", ".omod"); + assertFilePresent("referenceapplication/web/openmrs_owas"); + assertFilePresent("referenceapplication/web/openmrs_owas/SystemAdministration.owa"); + + assertSuccess(); + } + + @Test + public void buildDistro_shouldBuildFromRefapp3xArtifact() throws Exception { + addTaskParam("distro", "referenceapplication:3.0.0"); + addTaskParam("dir", "referenceapplication"); + addTaskParam("ignorePeerDependencies", "false"); + executeTask("build-distro"); + + assertFilePresent("referenceapplication/docker-compose.yml"); + assertFilePresent("referenceapplication/docker-compose.override.yml"); + assertFilePresent("referenceapplication/docker-compose.prod.yml"); + assertFilePresent("referenceapplication/.env"); + assertFilePresent("referenceapplication/web/Dockerfile"); + assertFilePresent("referenceapplication/web/openmrs-distro.properties"); + assertFilePresent("referenceapplication/web/openmrs_core/openmrs.war"); + assertFileContains("war.openmrs=2.6.7", "referenceapplication", "web", "openmrs-distro.properties"); + assertFilePresent("referenceapplication/web/openmrs_modules"); + assertNumFilesPresent(24, "referenceapplication/web/openmrs_modules", null); + assertFileContains("omod.spa", "referenceapplication", "web", "openmrs-distro.properties"); + assertFilePresent("referenceapplication/web/openmrs_owas"); + assertNumFilesPresent(0, "referenceapplication/web/openmrs_owas", null); + assertSuccess(); } diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIT.java index 6eb9fa65e..512ec0f76 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIT.java @@ -60,8 +60,6 @@ public void deploy_shouldReplaceDistroPlatform() throws Exception{ public void deploy_shouldUpgradeDistroTo2_3_1() throws Exception { addAnswer(testServerId); - addAnswer("n"); - addAnswer("n"); addAnswer("Distribution"); addAnswer("referenceapplication:2.3.1"); addAnswer("y"); @@ -84,8 +82,6 @@ public void deploy_shouldUpgradeDistroTo2_3_1() throws Exception { public void deploy_shouldDowngradeDistroTo2_1() throws Exception { addAnswer(testServerId); - addAnswer("n"); - addAnswer("n"); addAnswer("Distribution"); addAnswer("referenceapplication:2.1"); addAnswer("y"); @@ -106,6 +102,7 @@ public void deploy_shouldDowngradeDistroTo2_1() throws Exception { @Test public void deploy_shouldUpgradeDistroFromDistroProperties() throws Exception { + includeDistroPropertiesFile(DistroProperties.DISTRO_FILE_NAME); addAnswer(testServerId); addAnswer("y"); addAnswer("y"); @@ -139,9 +136,8 @@ public void deploy_shouldInstallModule() throws Exception { @Test public void deploy_shouldInstallModuleFromPomInDir() throws Exception { - + includePomFile("deployIT", "pom-owa-module.xml"); addAnswer(testServerId); - addAnswer("n"); addAnswer("y"); executeTask("deploy"); diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/RemoveDependencyIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/RemoveDependencyIT.java index acb0d480f..819ab7167 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/RemoveDependencyIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/RemoveDependencyIT.java @@ -1,6 +1,7 @@ package org.openmrs.maven.plugins; import org.junit.Test; +import org.openmrs.maven.plugins.model.DistroProperties; import org.openmrs.maven.plugins.utility.PropertiesUtils; import java.util.Properties; @@ -13,6 +14,7 @@ public class RemoveDependencyIT extends AbstractSdkIT { @Test public void shouldRemoveExistingDependency() throws Exception { + includeDistroPropertiesFile(DistroProperties.DISTRO_FILE_NAME); Properties distroProperties = PropertiesUtils.loadPropertiesFromFile(distroFile); assertNotNull(distroProperties); diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIT.java index 9313ee1df..4b556933a 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIT.java @@ -117,6 +117,7 @@ public void setup_shouldInstallDistroPlatform2_0_2() throws Exception{ @Test public void setup_shouldInstallServerFromGivenDistroProperties() throws Exception{ String serverId = UUID.randomUUID().toString(); + includeDistroPropertiesFile(DistroProperties.DISTRO_FILE_NAME); addTaskParam("distro", testDirectory.getAbsolutePath() + File.separator + "openmrs-distro.properties"); addTaskParam("debug", "1044"); @@ -147,6 +148,8 @@ public void setup_shouldInstallServerFromGivenDistroProperties() throws Exceptio @Test public void setup_shouldInstallServerFromDistroPropertiesDir() throws Exception{ String serverId = UUID.randomUUID().toString(); + includeDistroPropertiesFile(DistroProperties.DISTRO_FILE_NAME); + addTaskParam("serverId", serverId); addTaskParam("debug", "1044"); addTaskParam("ignorePeerDependencies", "false"); @@ -182,8 +185,8 @@ public void setup_shouldInstallServerWithDefaultJavaHome() throws Exception{ addMockDbSettings(); addAnswer(serverId); - addAnswer("Distribution"); - addAnswer("referenceapplication:2.2"); + addAnswer("Platform"); + addAnswer("2.6.1"); addAnswer(System.getProperty("java.home")); addAnswer("8080"); @@ -198,7 +201,7 @@ public void setup_shouldInstallServerWithDefaultJavaHome() throws Exception{ assertThat(javaHomeServerProperty, is(nullValue())); } - @Test + @Test public void setup_shouldInstallServerWithSpecifiedLatestSnapshotDistroVersionByUsingKeywordInBatchMode() throws Exception { String keyword = "LATEST-SNAPSHOT"; @@ -324,8 +327,8 @@ public void setup_shouldInstallServerWithGivenJavaHomeAndAddJavaHomeToSdkPropert addTaskParam("ignorePeerDependencies", "false"); addAnswer(serverId); - addAnswer("Distribution"); - addAnswer("referenceapplication:2.2"); + addAnswer("Platform"); + addAnswer("2.6.1"); addAnswer("8080"); addAnswer("1044"); diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/utility/DistributionBuilderIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/utility/DistributionBuilderIT.java index f8c4c6f99..2efc24b9b 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/utility/DistributionBuilderIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/utility/DistributionBuilderIT.java @@ -71,7 +71,12 @@ public void build_shouldBuildRefapp_2_13_0() throws Exception { Properties expected = getExpectedPropertiesFromResource(artifact); assertThat(allProperties.size(), equalTo(expected.size())); for (String p : expected.stringPropertyNames()) { - assertThat(allProperties.getProperty(p), equalTo(expected.getProperty(p))); + if (p.equals("omod.atlas")) { + assertThat(allProperties.getProperty(p), equalTo("2.2.7")); + } + else { + assertThat(allProperties.getProperty(p), equalTo(expected.getProperty(p))); + } } }); } diff --git a/integration-tests/src/test/resources/integration-test/buildDistroIT/assembly.xml b/integration-tests/src/test/resources/integration-test/buildDistroIT/assembly.xml new file mode 100644 index 000000000..7e9ff54b7 --- /dev/null +++ b/integration-tests/src/test/resources/integration-test/buildDistroIT/assembly.xml @@ -0,0 +1,18 @@ + + distro + + zip + + ${artifactId}-${version} + + + ${project.build.directory}/classes + . + + **/* + + + + \ No newline at end of file diff --git a/integration-tests/src/test/resources/integration-test/buildDistroIT/openmrs-distro.properties b/integration-tests/src/test/resources/integration-test/buildDistroIT/openmrs-distro.properties new file mode 100644 index 000000000..691403e0c --- /dev/null +++ b/integration-tests/src/test/resources/integration-test/buildDistroIT/openmrs-distro.properties @@ -0,0 +1,16 @@ +name=TEST EMR +version=2.0.0 +war.openmrs=2.6.9 +omod.addresshierarchy=2.19.0 +omod.calculation=1.3.0 +omod.fhir2=2.2.0 +omod.htmlformentry=5.3.0 +omod.idgen=4.14.0 +omod.initializer=2.7.0 +omod.legacyui=1.18.0 +omod.metadatamapping=1.6.0 +omod.namephonetics=1.19.0 +omod.owa=1.15.0 +omod.spa=2.0.0 +omod.webservices.rest=2.45.0 +db.h2.supported=false \ No newline at end of file diff --git a/integration-tests/src/test/resources/integration-test/buildDistroIT/pom.xml b/integration-tests/src/test/resources/integration-test/buildDistroIT/pom.xml new file mode 100644 index 000000000..ea810b8e3 --- /dev/null +++ b/integration-tests/src/test/resources/integration-test/buildDistroIT/pom.xml @@ -0,0 +1,63 @@ + + 4.0.0 + + org.openmrs.maven + openmrs-sdk-integration-test-example + 1.0.0 + pom + + + + + maven-resources-plugin + 3.2.0 + + UTF-8 + + + ${basedir} + true + + openmrs-distro.properties + + + + ${project.build.directory}/distro + + + + maven-assembly-plugin + 3.3.0 + + false + + ${basedir}/assembly.xml + + + + + make-assembly + package + + single + + + + + + + + + + + openmrs-repo + OpenMRS repository + https://mavenrepo.openmrs.org/nexus/content/repositories/public + + + + diff --git a/integration-tests/src/test/resources/integration-test/buildIT/pom.xml b/integration-tests/src/test/resources/integration-test/buildIT/pom.xml index ec30ea1a7..9910ff794 100644 --- a/integration-tests/src/test/resources/integration-test/buildIT/pom.xml +++ b/integration-tests/src/test/resources/integration-test/buildIT/pom.xml @@ -5,9 +5,9 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.openmrs.module - owa - 1.4 + org.openmrs.maven + openmrs-sdk-integration-test-example + 1.0.0 pom diff --git a/integration-tests/src/test/resources/integration-test/deployIT/pom-owa-module.xml b/integration-tests/src/test/resources/integration-test/deployIT/pom-owa-module.xml new file mode 100644 index 000000000..d881c105d --- /dev/null +++ b/integration-tests/src/test/resources/integration-test/deployIT/pom-owa-module.xml @@ -0,0 +1,21 @@ + + 4.0.0 + + org.openmrs.module + owa + 1.4 + pom + + + + openmrs-repo + OpenMRS repository + https://mavenrepo.openmrs.org/nexus/content/repositories/public + + + + \ No newline at end of file diff --git a/integration-tests/src/test/resources/integration-test/invokeIT/pom.xml b/integration-tests/src/test/resources/integration-test/invokeIT/pom.xml index c054fd3a7..bec1eb0a2 100644 --- a/integration-tests/src/test/resources/integration-test/invokeIT/pom.xml +++ b/integration-tests/src/test/resources/integration-test/invokeIT/pom.xml @@ -5,9 +5,9 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.openmrs - openmrs-sdk-integration-test-project - 1.0 + org.openmrs.maven + openmrs-sdk-integration-test-example + 1.0.0 pom