Skip to content

Commit

Permalink
SDK-360 - Improve test coverage and fix uncovered issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
mseaton committed Nov 23, 2024
1 parent eca6700 commit d49ee7b
Show file tree
Hide file tree
Showing 21 changed files with 294 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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");
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");

Expand All @@ -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";

Expand Down Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>distro</id>
<formats>
<format>zip</format>
</formats>
<baseDirectory>${artifactId}-${version}</baseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/classes</directory>
<outputDirectory>.</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit d49ee7b

Please sign in to comment.