Skip to content

Commit ad96c4f

Browse files
committed
SDK-347 - Follow-up with improved logging and test coverage
1 parent f881029 commit ad96c4f

File tree

5 files changed

+112
-53
lines changed

5 files changed

+112
-53
lines changed

integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIT.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public abstract class AbstractSdkIT {
7777
protected File distroFile;
7878
protected Path testBaseDir;
7979
protected Path testResourceDir;
80-
protected boolean preserveTestOutput;
80+
protected boolean deleteTestArtifacts = false;
8181

8282
public String resolveSdkArtifact() throws MojoExecutionException {
8383
Properties sdk = new Properties();
@@ -119,7 +119,7 @@ public void setup() throws Exception {
119119
testResourceDir = testBaseDir.resolve("test-resources");
120120
testDirectoryPath = testBaseDir.resolve(getClass().getSimpleName() + "_" + nextCounter());
121121
testDirectory = testDirectoryPath.toFile();
122-
preserveTestOutput = Boolean.parseBoolean(System.getProperty("preserveTestOutput"));
122+
FileUtils.deleteQuietly(testDirectory);
123123
if (!testDirectory.mkdirs()) {
124124
throw new RuntimeException("Unable to create test directory: " + testDirectory);
125125
}
@@ -128,15 +128,14 @@ public void setup() throws Exception {
128128
verifier.setAutoclean(false);
129129
addTaskParam("openMRSPath", testDirectory.getAbsolutePath());
130130
distroFile = new File(testDirectory, DistroProperties.DISTRO_FILE_NAME);
131+
deleteTestArtifacts = Boolean.parseBoolean(System.getProperty("deleteTestArtifacts"));
131132
}
132133

133134
@After
134135
public void teardown() {
135136
verifier.resetStreams();
136-
if (preserveTestOutput) {
137-
log.debug("Test output preserved: " + testDirectory.getName());
138-
}
139-
else {
137+
if (deleteTestArtifacts) {
138+
log.debug("Removing test artifacts: " + testDirectory);
140139
FileUtils.deleteQuietly(testDirectory);
141140
}
142141
cleanAnswers();

integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIT.java

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
import java.util.Properties;
1414

1515
import static org.hamcrest.MatcherAssert.assertThat;
16+
import static org.hamcrest.Matchers.equalTo;
1617
import static org.hamcrest.Matchers.hasItemInArray;
1718
import static org.junit.Assert.assertFalse;
19+
import static org.junit.Assert.assertNotNull;
1820
import static org.openmrs.maven.plugins.SdkMatchers.hasNameStartingWith;
1921
import static org.openmrs.maven.plugins.SdkMatchers.hasUserOwa;
2022
import static org.openmrs.maven.plugins.SdkMatchers.serverHasVersion;
@@ -148,8 +150,8 @@ public void deploy_shouldUpgradeDistroTo3_0_0() throws Exception {
148150
Server server = Server.loadServer(testServerId);
149151
assertThat(server, serverHasVersion("3.0.0"));
150152

151-
assertLogContains("+ Adds frontend spa");
152-
assertLogContains("+ Adds frontend configuration");
153+
assertLogContains("+ Assembles and builds new frontend spa");
154+
assertLogContains("+ Adds config package distro-emr-configuration 3.0.0");
153155
}
154156

155157
@Test
@@ -165,7 +167,7 @@ public void deploy_shouldUpgradeDistroWithConfigPackage() throws Exception {
165167
assertFilePresent(testServerId, "configuration", "addresshierarchy", "addresshierarchy-core_demo.csv");
166168
assertFilePresent(testServerId, "configuration", "conceptclasses", "conceptclasses-core_data.csv");
167169
assertFilePresent(testServerId, "configuration", "encountertypes", "encountertypes_core-demo.csv");
168-
assertLogContains("+ Adds frontend configuration");
170+
assertLogContains("+ Adds config package distro-emr-configuration 3.0.0");
169171
}
170172

171173
@Test
@@ -180,7 +182,7 @@ public void deploy_shouldUpgradeDistroWithContentPackage() throws Exception {
180182
assertFilePresent(testServerId, "configuration", "conceptclasses", "hiv", "conceptclasses.csv");
181183
assertFilePresent(testServerId, "configuration", "conceptsources", "hiv", "conceptsources.csv");
182184
assertFilePresent(testServerId, "configuration", "encountertypes", "hiv", "encountertypes.csv");
183-
assertLogContains("+ Adds frontend configuration");
185+
assertLogContains("+ Adds content package hiv 1.0.0");
184186
}
185187

186188
@Test
@@ -197,7 +199,13 @@ public void deploy_shouldReplaceConfigurationAndContentIfChanged() throws Except
197199
assertFilePresent(testServerId, "configuration", "addresshierarchy", "addresshierarchy-core_demo.csv");
198200
assertFilePresent(testServerId, "configuration", "conceptclasses", "conceptclasses-core_data.csv");
199201
assertFilePresent(testServerId, "configuration", "encountertypes", "encountertypes_core-demo.csv");
200-
assertLogContains("+ Adds frontend configuration");
202+
assertLogContains("+ Adds config package distro-emr-configuration 3.0.0");
203+
204+
Server server = Server.loadServer(testDirectoryPath.resolve(testServerId));
205+
assertNotNull(server);
206+
assertThat(server.getConfigArtifacts().size(), equalTo(1));
207+
assertThat(server.getConfigArtifacts().get(0).getArtifactId(), equalTo("distro-emr-configuration"));
208+
assertThat(server.getContentArtifacts().size(), equalTo(0));
201209

202210
includeDistroPropertiesFile("openmrs-distro-content-package.properties");
203211
addAnswer(testServerId);
@@ -212,7 +220,14 @@ public void deploy_shouldReplaceConfigurationAndContentIfChanged() throws Except
212220
assertFilePresent(testServerId, "configuration", "conceptclasses", "hiv", "conceptclasses.csv");
213221
assertFilePresent(testServerId, "configuration", "conceptsources", "hiv", "conceptsources.csv");
214222
assertFilePresent(testServerId, "configuration", "encountertypes", "hiv", "encountertypes.csv");
215-
assertLogContains("^ Updates frontend configuration");
223+
assertLogContains("- Removes existing configuration");
224+
assertLogContains("+ Adds content package hiv 1.0.0");
225+
226+
server = Server.loadServer(testDirectoryPath.resolve(testServerId));
227+
assertNotNull(server);
228+
assertThat(server.getConfigArtifacts().size(), equalTo(0));
229+
assertThat(server.getContentArtifacts().size(), equalTo(1));
230+
assertThat(server.getContentArtifacts().get(0).getArtifactId(), equalTo("hiv"));
216231
}
217232

218233
@Test
@@ -279,4 +294,43 @@ public void deploy_shouldInstallOwaAndOwaModule() throws Exception {
279294
Server server = Server.loadServer(testServerId);
280295
assertThat(server, hasUserOwa(new OwaId("conceptdictionary","1.0.0")));
281296
}
297+
298+
@Test
299+
public void deploy_shouldDeployOwas() throws Exception {
300+
testServerId = setupTestServer("referenceapplication:2.2");
301+
includeDistroPropertiesFile("openmrs-distro-owa1.properties");
302+
addAnswer(testServerId);
303+
addAnswer("y");
304+
addAnswer("y");
305+
executeTask("deploy");
306+
assertSuccess();
307+
assertFilePresent(testServerId, "owa");
308+
assertFilePresent(testServerId, "owa", "addonmanager.owa");
309+
assertFilePresent(testServerId, "owa", "SystemAdministration.owa");
310+
assertFilePresent(testServerId, "owa", "orderentry.owa");
311+
assertLogContains("+ Adds owa addonmanager 1.0.0");
312+
assertLogContains("+ Adds owa sysadmin 1.2.0");
313+
assertLogContains("+ Adds owa orderentry 1.2.4");
314+
315+
Server server = Server.loadServer(testDirectoryPath.resolve(testServerId));
316+
assertNotNull(server);
317+
assertThat(server.getOwaArtifacts().size(), equalTo(3));
318+
319+
// Re-deploy with a distro properties that includes additions, upgrades, downgrades, and removals
320+
includeDistroPropertiesFile("openmrs-distro-owa2.properties");
321+
executeTask("deploy");
322+
assertSuccess();
323+
assertFilePresent(testServerId, "owa");
324+
assertFilePresent(testServerId, "owa", "addonmanager.owa");
325+
assertFilePresent(testServerId, "owa", "SystemAdministration.owa");
326+
assertFileNotPresent(testServerId, "owa", "orderentry.owa");
327+
assertFilePresent(testServerId, "owa", "conceptdictionary.owa");
328+
assertLogContains("^ Updates owa addonmanager 1.0.0 to 1.1.0");
329+
assertLogContains("v Downgrades owa sysadmin 1.2.0 to 1.1.0");
330+
assertLogContains("+ Adds owa conceptdictionary 1.0.0");
331+
assertLogContains("- Deletes owa orderentry 1.2.4");
332+
333+
server = Server.loadServer(testDirectoryPath.resolve(testServerId));
334+
assertThat(server.getOwaArtifacts().size(), equalTo(3));
335+
}
282336
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name=Content Package Example
2+
version=1.0.0
3+
war.openmrs=2.6.9
4+
owa.addonmanager=1.0.0
5+
owa.sysadmin=1.2.0
6+
owa.orderentry=1.2.4
7+
db.h2.supported=true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name=Content Package Example
2+
version=1.0.0
3+
war.openmrs=2.6.9
4+
owa.addonmanager=1.1.0
5+
owa.conceptdictionary=1.0.0
6+
owa.sysadmin=1.1.0
7+
db.h2.supported=true

sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ public class DefaultWizard implements Wizard {
9191

9292
static final String UPGRADE_CONFIRM_TMPL = "\nThe %s %s introduces the following changes:";
9393

94-
static final String UPDATE_ARTIFACT_TMPL = "^ Updates %s %s to %s";
94+
static final String UPDATE_ARTIFACT_TMPL = "^ Updates %s %s %s to %s";
9595

96-
static final String DOWNGRADE_ARTIFACT_TMPL = "v Downgrades %s %s to %s";
96+
static final String DOWNGRADE_ARTIFACT_TMPL = "v Downgrades %s %s %s to %s";
9797

98-
static final String ADD_ARTIFACT_TMPL = "+ Adds %s %s";
98+
static final String ADD_ARTIFACT_TMPL = "+ Adds %s %s %s";
9999

100-
static final String DELETE_ARTIFACT_TMPL = "- Deletes %s %s";
100+
static final String DELETE_ARTIFACT_TMPL = "- Deletes %s %s %s";
101101

102102
static final String NO_DIFFERENTIAL = "\nNo distribution changes found";
103103

@@ -1037,31 +1037,38 @@ public boolean promptForConfirmDistroUpgrade(UpgradeDifferential upgradeDifferen
10371037
writer.printf((UPGRADE_CONFIRM_TMPL) + "%n", distribution.getName(), distribution.getVersion());
10381038

10391039
if (warChanges.hasChanges()) {
1040-
writer.printf(
1041-
(warChanges.getDowngradedArtifacts().isEmpty() ? UPDATE_ARTIFACT_TMPL : DOWNGRADE_ARTIFACT_TMPL) + "%n",
1042-
warChanges.getNewArtifacts().get(0).getArtifactId(),
1043-
upgradeDifferential.getServer().getPlatformVersion(),
1044-
warChanges.getNewArtifacts().get(0).getVersion());
1040+
String template = (warChanges.getDowngradedArtifacts().isEmpty() ? UPDATE_ARTIFACT_TMPL : DOWNGRADE_ARTIFACT_TMPL) + "%n";
1041+
Artifact oldWar = warChanges.getOldArtifacts().get(0);
1042+
Artifact newWar = warChanges.getNewArtifacts().get(0);
1043+
writer.printf(template, "OpenMRS", "Core", oldWar.getVersion(), newWar.getVersion());
10451044
}
10461045

1047-
promptForArtifactChangesIfNecessary(moduleChanges);
1048-
promptForArtifactChangesIfNecessary(owaChanges);
1046+
promptForArtifactChangesIfNecessary("module", moduleChanges);
1047+
promptForArtifactChangesIfNecessary("owa", owaChanges);
10491048

10501049
if (spaArtifactChanges.hasChanges() || spaBuildChanges.hasChanges()) {
10511050
if (hasExistingFilesInDirectory(server, SDKConstants.OPENMRS_SERVER_FRONTEND)) {
1052-
writer.print("^ Updates frontend spa%n");
1051+
writer.println("- Removes existing spa");
10531052
}
1054-
else {
1055-
writer.print("+ Adds frontend spa%n");
1053+
if (spaBuildChanges.hasChanges()) {
1054+
writer.println("+ Assembles and builds new frontend spa");
1055+
}
1056+
if (spaArtifactChanges.hasChanges()) {
1057+
for (Artifact a : spaArtifactChanges.getNewArtifacts()) {
1058+
writer.printf(ADD_ARTIFACT_TMPL + "%n", "spa", a.getArtifactId(), a.getVersion());
1059+
}
10561060
}
10571061
}
10581062

10591063
if (configChanges.hasChanges() || contentChanges.hasChanges()) {
10601064
if (hasExistingFilesInDirectory(server, SDKConstants.OPENMRS_SERVER_CONFIGURATION)) {
1061-
writer.print("^ Updates frontend configuration%n");
1065+
writer.println("- Removes existing configuration");
10621066
}
1063-
else {
1064-
writer.print("+ Adds frontend configuration%n");
1067+
for (Artifact a : configChanges.getArtifactsToAdd()) {
1068+
writer.printf(ADD_ARTIFACT_TMPL + "%n", "config package", a.getArtifactId(), a.getVersion());
1069+
}
1070+
for (Artifact a : contentChanges.getArtifactsToAdd()) {
1071+
writer.printf(ADD_ARTIFACT_TMPL + "%n", "content package", a.getArtifactId(), a.getVersion());
10651072
}
10661073
}
10671074

@@ -1077,34 +1084,19 @@ protected boolean hasExistingFilesInDirectory(Server server, String directory) {
10771084
return false;
10781085
}
10791086

1080-
protected void promptForArtifactChangesIfNecessary(UpgradeDifferential.ArtifactChanges artifactChanges) {
1087+
protected void promptForArtifactChangesIfNecessary(String type, UpgradeDifferential.ArtifactChanges artifactChanges) {
10811088
if (artifactChanges.hasChanges()) {
1082-
for (Entry<Artifact, Artifact> updateEntry : artifactChanges.getUpgradedArtifacts().entrySet()) {
1083-
if (!updateEntry.getKey().getVersion().equals(updateEntry.getValue().getVersion())) {
1084-
writer.printf((UPDATE_ARTIFACT_TMPL) + "%n",
1085-
updateEntry.getKey().getArtifactId(),
1086-
updateEntry.getKey().getVersion(),
1087-
updateEntry.getValue().getVersion());
1088-
}
1089+
for (Entry<Artifact, Artifact> e : artifactChanges.getUpgradedArtifacts().entrySet()) {
1090+
writer.printf(UPDATE_ARTIFACT_TMPL + "%n", type, e.getKey().getArtifactId(), e.getKey().getVersion(), e.getValue().getVersion());
10891091
}
1090-
for (Entry<Artifact, Artifact> downgradeEntry : artifactChanges.getDowngradedArtifacts().entrySet()) {
1091-
if (!downgradeEntry.getKey().getVersion().equals(downgradeEntry.getValue().getVersion())) {
1092-
writer.printf((DOWNGRADE_ARTIFACT_TMPL) + "%n",
1093-
downgradeEntry.getKey().getArtifactId(),
1094-
downgradeEntry.getKey().getVersion(),
1095-
downgradeEntry.getValue().getVersion());
1096-
}
1092+
for (Entry<Artifact, Artifact> e : artifactChanges.getDowngradedArtifacts().entrySet()) {
1093+
writer.printf(DOWNGRADE_ARTIFACT_TMPL + "%n", type, e.getKey().getArtifactId(), e.getKey().getVersion(), e.getValue().getVersion());
10971094
}
1098-
for (Artifact addArtifact : artifactChanges.getAddedArtifacts()) {
1099-
writer.printf((ADD_ARTIFACT_TMPL) + "%n",
1100-
addArtifact.getArtifactId(),
1101-
addArtifact.getVersion());
1095+
for (Artifact a : artifactChanges.getAddedArtifacts()) {
1096+
writer.printf(ADD_ARTIFACT_TMPL + "%n", type, a.getArtifactId(), a.getVersion());
11021097
}
1103-
1104-
for (Artifact deleteArtifact : artifactChanges.getRemovedArtifacts()) {
1105-
writer.printf((DELETE_ARTIFACT_TMPL) + "%n",
1106-
deleteArtifact.getArtifactId(),
1107-
deleteArtifact.getVersion());
1098+
for (Artifact a : artifactChanges.getRemovedArtifacts()) {
1099+
writer.printf(DELETE_ARTIFACT_TMPL + "%n", type, a.getArtifactId(), a.getVersion());
11081100
}
11091101
}
11101102
}

0 commit comments

Comments
 (0)