Skip to content

Commit

Permalink
SDK-359 - Upgrade commons-io and add logging to integration tests (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
mseaton authored Nov 20, 2024
1 parent 58351c8 commit e90379c
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 19 deletions.
20 changes: 20 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<properties>
<testBaseDir>${project.build.directory}/integration-test-base-dir</testBaseDir>
<testResourceDir>${testBaseDir}/test-resources</testResourceDir>
<slf4jVersion>1.7.36</slf4jVersion>
<log4jVersion>2.22.1</log4jVersion>
</properties>

<dependencies>
Expand Down Expand Up @@ -51,6 +53,24 @@
<groupId>org.semver4j</groupId>
<artifactId>semver4j</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.24.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.24.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.24.1</version>
<scope>test</scope>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.openmrs.maven.plugins.model.DistroProperties;
import org.openmrs.maven.plugins.model.Server;
import org.openmrs.maven.plugins.utility.SDKConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -45,10 +47,11 @@
import static org.openmrs.maven.plugins.SdkMatchers.hasPlatformVersion;
import static org.openmrs.maven.plugins.SdkMatchers.hasWarVersion;


@RunWith(BlockJUnit4ClassRunner.class)
public abstract class AbstractSdkIT {

public final Logger log = LoggerFactory.getLogger(getClass());

/**
* contains name of directory in project's target dir, where integration tests are conducted
*/
Expand All @@ -74,6 +77,7 @@ public abstract class AbstractSdkIT {

Path testBaseDir;
Path testResourceDir;
boolean preserveTestOutput;

public String resolveSdkArtifact() throws MojoExecutionException {
Properties sdk = new Properties();
Expand Down Expand Up @@ -116,6 +120,7 @@ public void setup() throws Exception {
testResourceDir = testBaseDir.resolve("test-resources");
testDirectoryPath = testBaseDir.resolve(getClass().getSimpleName() + "_" + nextCounter());
testDirectory = testDirectoryPath.toFile();
preserveTestOutput = Boolean.parseBoolean(System.getProperty("preserveTestOutput"));
if (!testDirectory.mkdirs()) {
throw new RuntimeException("Unable to create test directory: " + testDirectory);
}
Expand All @@ -128,7 +133,13 @@ public void setup() throws Exception {

@After
public void teardown() {
FileUtils.deleteQuietly(testDirectory);
verifier.resetStreams();
if (preserveTestOutput) {
log.debug("Test output preserved: " + testDirectory.getName());
}
else {
FileUtils.deleteQuietly(testDirectory);
}
cleanAnswers();
}

Expand All @@ -139,22 +150,26 @@ static synchronized int nextCounter() {
public String setupTestServer() throws Exception{
Verifier setupServer = new Verifier(testDirectory.getAbsolutePath());
String serverId = UUID.randomUUID().toString();

addTaskParam(setupServer, "openMRSPath", testDirectory.getAbsolutePath());
addTaskParam(setupServer, "distro", "referenceapplication:2.2");
addTaskParam(setupServer, "debug", "1044");
addMockDbSettings(setupServer);

addAnswer(serverId);
addAnswer(System.getProperty("java.home"));
addAnswer("8080");
addTaskParam(setupServer, BATCH_ANSWERS, getAnswers());
cleanAnswers();

String sdk = resolveSdkArtifact();
setupServer.executeGoal(sdk + ":setup");
assertFilePresent(serverId, "openmrs-server.properties");
new File(testDirectory, "log.txt").delete();
try {
addTaskParam(setupServer, "openMRSPath", testDirectory.getAbsolutePath());
addTaskParam(setupServer, "distro", "referenceapplication:2.2");
addTaskParam(setupServer, "debug", "1044");
addMockDbSettings(setupServer);

addAnswer(serverId);
addAnswer(System.getProperty("java.home"));
addAnswer("8080");
addTaskParam(setupServer, BATCH_ANSWERS, getAnswers());
cleanAnswers();

String sdk = resolveSdkArtifact();
setupServer.executeGoal(sdk + ":setup");
assertFilePresent(serverId, "openmrs-server.properties");
new File(testDirectory, "log.txt").delete();
}
finally {
verifier.resetStreams();
}
return serverId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@
<version>3.9.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.24.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.24.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.24.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
Expand Down
13 changes: 13 additions & 0 deletions integration-tests/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%p - %C{1}.%M(%L) |%d{ISO8601}| %m%n" />
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="CONSOLE" />
</Root>
</Loggers>
</Configuration>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
<version>2.17.0</version>
</dependency>

<!-- yaml parser -->
Expand Down

0 comments on commit e90379c

Please sign in to comment.