Skip to content

Commit

Permalink
SDK-347 - The deploy goal should support upgrading all SDK artifacts …
Browse files Browse the repository at this point in the history
…from the distribution properties (#313)
  • Loading branch information
mseaton authored Nov 26, 2024
1 parent f79a2e3 commit 0bec29a
Show file tree
Hide file tree
Showing 29 changed files with 1,296 additions and 659 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.io.FileMatchers.anExistingFileOrDirectory;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.openmrs.maven.plugins.SdkMatchers.hasModuleVersion;
Expand Down Expand Up @@ -145,12 +146,12 @@ static synchronized int nextCounter() {
return counter++;
}

public String setupTestServer() throws Exception{
public String setupTestServer(String distro) throws Exception{
Verifier setupServer = new Verifier(testDirectory.getAbsolutePath());
String serverId = UUID.randomUUID().toString();
try {
addTaskParam(setupServer, "openMRSPath", testDirectory.getAbsolutePath());
addTaskParam(setupServer, "distro", "referenceapplication:2.2");
addTaskParam(setupServer, "distro", distro);
addTaskParam(setupServer, "debug", "1044");
addMockDbSettings(setupServer);

Expand Down Expand Up @@ -326,22 +327,28 @@ protected void assertServerInstalled(String serverId) {
assertFilePresent(serverId, SDKConstants.OPENMRS_SERVER_PROPERTIES);
}

protected void assertModulesInstalled(String serverId, String... filenames){
protected void assertModulesInstalled(String serverId, String... filenames) {
Path modulesRoot = testDirectoryPath.resolve(Paths.get(serverId, "modules"));
for(String filename : filenames){
for(String filename : filenames) {
assertPathPresent(modulesRoot.resolve(filename));
}
}

protected void assertModulesInstalled(String serverId, DistroProperties distroProperties) {
protected void assertOnlyModulesInstalled(String serverId, DistroProperties distroProperties) {
List<Artifact> modules = distroProperties.getModuleArtifacts();
String[] moduleFilenames = new String[modules.size()];

for (int i = 0; i < modules.size(); i ++) {
moduleFilenames[i] = modules.get(i).getDestFileName();
}

assertModulesInstalled(serverId, moduleFilenames);
Path modulesRoot = testDirectoryPath.resolve(Paths.get(serverId, "modules"));
File[] expectedFiles = modulesRoot.toFile().listFiles(f -> f.getName().endsWith(".omod"));
assertNotNull(expectedFiles);
assertThat(expectedFiles.length, equalTo(moduleFilenames.length));
for(String filename : moduleFilenames) {
assertPathPresent(modulesRoot.resolve(filename));
}
}

protected void addMockDbSettings() {
Expand Down Expand Up @@ -376,4 +383,18 @@ protected String getAnswers() {
answers = StringUtils.removeStart(answers, "[");
return answers;
}

protected String getLogContents() throws Exception {
File logFile = new File(testDirectory, "log.txt");
assertTrue(logFile.exists());
return FileUtils.readFileToString(logFile, "UTF-8");
}

protected void assertLogContains(String message) throws Exception {
assertTrue(getLogContents().contains(message));
}

protected void assertLogDoesNotContain(String message) throws Exception {
assertFalse(getLogContents().contains(message));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.openmrs.maven.plugins;

import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.openmrs.maven.plugins.model.DistroProperties;
import org.openmrs.maven.plugins.utility.PropertiesUtils;

import java.io.File;
import java.util.Properties;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
Expand All @@ -35,7 +33,7 @@ public void shouldAddExclusionIfNoParentDefined() throws Exception {
executeExclusionTask(distroFile, "omod.uicommons");
assertNotNull(getDistroProperties());
assertTrue(getDistroProperties().getExclusions().contains("omod.uicommons"));
assertTrue(getLogContents().contains(AddExclusion.WARNING_NO_PARENT_DISTRO));
assertLogContains(AddExclusion.WARNING_NO_PARENT_DISTRO);
}

@Test
Expand All @@ -47,8 +45,8 @@ public void shouldAddExclusionForPropertyContainedInParent() throws Exception {
executeExclusionTask(distroFile, "omod.uicommons");
assertNotNull(getDistroProperties());
assertTrue(getDistroProperties().getExclusions().contains("omod.uicommons"));
assertFalse(getLogContents().contains(AddExclusion.WARNING_NO_PARENT_DISTRO));
assertFalse(getLogContents().contains(AddExclusion.WARNING_PROPERTY_NOT_IN_PARENT));
assertLogDoesNotContain(AddExclusion.WARNING_NO_PARENT_DISTRO);
assertLogDoesNotContain(AddExclusion.WARNING_PROPERTY_NOT_IN_PARENT);
}

@Test
Expand All @@ -60,8 +58,8 @@ public void shouldAddExclusionForPropertyContainedInDistro() throws Exception {
executeExclusionTask(distroFile, "omod.uicommons");
assertNotNull(getDistroProperties());
assertTrue(getDistroProperties().getExclusions().contains("omod.uicommons"));
assertFalse(getLogContents().contains(AddExclusion.WARNING_NO_PARENT_DISTRO));
assertFalse(getLogContents().contains(AddExclusion.WARNING_PROPERTY_NOT_IN_PARENT));
assertLogDoesNotContain(AddExclusion.WARNING_NO_PARENT_DISTRO);
assertLogDoesNotContain(AddExclusion.WARNING_PROPERTY_NOT_IN_PARENT);
}

@Test
Expand All @@ -73,14 +71,8 @@ public void shouldAddExclusionForPropertyNotContainedInParent() throws Exception
executeExclusionTask(distroFile, "omod.invalidmodulename");
assertNotNull(getDistroProperties());
assertTrue(getDistroProperties().getExclusions().contains("omod.invalidmodulename"));
assertFalse(getLogContents().contains(AddExclusion.WARNING_NO_PARENT_DISTRO));
assertTrue(getLogContents().contains(AddExclusion.WARNING_PROPERTY_NOT_IN_PARENT));
}

private String getLogContents() throws Exception {
File logFile = new File(testDirectory, "log.txt");
assertTrue(logFile.exists());
return FileUtils.readFileToString(logFile, "UTF-8");
assertLogDoesNotContain(AddExclusion.WARNING_NO_PARENT_DISTRO);
assertLogContains(AddExclusion.WARNING_PROPERTY_NOT_IN_PARENT);
}

private void executeExclusionTask(File distroFile, String exclusion) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected void addTestResources() throws Exception {
@Override
public void setup() throws Exception {
super.setup();
serverId = setupTestServer();
serverId = setupTestServer("referenceapplication:2.2");
Server server = Server.loadServer(testDirectoryPath.resolve(serverId));
File firstDir = new File(testDirectory, "module1");
File secondDir = new File(testDirectory, "module2");
Expand Down
Loading

0 comments on commit 0bec29a

Please sign in to comment.