Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,60 @@ jobs:
path: |
ci/test-results/**/*.xml

windows:
runs-on: windows-latest
timeout-minutes: 30

defaults:
run:
shell: pwsh

steps:
# Fixtures are compared byte-for-byte; keep the repository's line endings
# instead of the runner's default core.autocrlf=true.
- run: git config --global core.autocrlf false

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

# Same JDK as .sdkmanrc; the client needs JavaFX.
- uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: zulu
java-version: '17.0.17'
java-package: jdk+fx
cache: gradle

- name: Build and run unit tests
run: .\gradlew.bat build -PdisableSigning=true

# The server runs from server\setup, so don't let Gradle re-stage it.
- name: Run smoke tests
run: |
Add-Content server\setup\conf\mirth.properties 'server.initialadminpassword = ci-smoke-admin'
$server = server\setup\oieserver.ps1 &
.\gradlew.bat :smoketest:test -x :server:createSetup -PdisableSigning=true "-Doie.baseUrl=https://localhost:8443" "-Doie.password=ci-smoke-admin" "-Doie.configuration=windows-zulu17-derby"
$testExit = $LASTEXITCODE
Stop-Job $server
"::group::Server output"
Receive-Job $server -ErrorAction Continue 2>&1 | Out-String
"::endgroup::"
exit $testExit

- name: Upload Test Results
if: (!cancelled())
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: Test Results (windows)
path: |
**/build/test-results/**/*.xml

# The daemon holds locks in the Gradle cache, which setup-java then cannot save.
- name: Stop Gradle
if: always()
run: .\gradlew.bat --stop

test-results:
needs: [build, integration-test]
needs: [build, integration-test, windows]
if: (!cancelled())
runs-on: ubuntu-latest

Expand Down
5 changes: 4 additions & 1 deletion ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The rest are optional assertions against the message the channel produced:

`NN` is the destination connector's metadata ID: `dest01` is the first
destination, `dest02` the second, and so on. Metadata files are YAML mappings; list
only the keys that matter to the test. Content assertions are byte-for-byte, except
only the keys that matter to the test. Content assertions are line-by-line, except
that `((ANY))` matches variable content such as generated IDs or timestamps.

A fixture case runs in every configuration by default. To limit it, add a
Expand All @@ -74,6 +74,9 @@ alpine-temurin21-postgres
ubuntu-temurin21-postgres
```

The `windows` CI job also runs the smoke tests, as `windows-zulu17-derby`, against
a server outside of a container.

### Parse Batch

If you are using "Parse Batch" mode, put each expected message's assertion
Expand Down
45 changes: 13 additions & 32 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -488,39 +488,20 @@ def createServerExtensions = tasks.register('createServerExtensions') {
// Javadocs (user API), part of the distributed docs
// ---------------------------------------------------------------------

// Invokes the javadoc tool directly: the multiline -bottom argument
// (whitespace from the old build.xml CDATA block) cannot pass through
// Gradle's javadoc options file, and the generated HTML should be
// identical to the Ant build's.
def userApiJavadoc = tasks.register('userApiJavadoc') {
def userApiJavadoc = tasks.register('userApiJavadoc', Javadoc) {
description = 'Generates the user API javadocs into docs/javadocs/user-api.'
def outDir = file('docs/javadocs/user-api')
inputs.files(fileTree('src/main/java') {
include 'com/mirth/connect/server/userutil/**'
include 'com/mirth/connect/userutil/**'
include 'com/mirth/connect/plugins/httpauth/userutil/**'
})
outputs.dir outDir
dependsOn syncDonkeyLibs
doLast {
outDir.mkdirs()
def cmd = [new File(System.getProperty('java.home'), 'bin/javadoc').absolutePath,
'-d', outDir.absolutePath,
'-notimestamp',
'-classpath', (configurations.compileClasspath + fileTree(dir: 'lib', include: '**/*.jar')).asPath,
'-sourcepath', file('src/main/java').absolutePath,
'-link', 'https://docs.oracle.com/en/java/javase/17/docs/api/',
'-bottom', '\n\t\t\t\tLicensed under the <a href="https://www.mozilla.org/MPL/2.0/">Mozilla Public License 2.0</a>.\n\t\t\t',
'--add-modules=java.sql.rowset',
'--add-exports=java.sql.rowset/com.sun.rowset=ALL-UNNAMED',
'com.mirth.connect.server.userutil',
'com.mirth.connect.userutil',
'com.mirth.connect.plugins.httpauth.userutil']
def proc = new ProcessBuilder(cmd).redirectErrorStream(true).start()
def out = proc.inputStream.text
if (proc.waitFor() != 0) {
throw new GradleException("javadoc failed:\n${out}")
}
source = fileTree('src/main/java') {
include 'com/mirth/connect/server/userutil/*.java'
include 'com/mirth/connect/userutil/*.java'
include 'com/mirth/connect/plugins/httpauth/userutil/*.java'
}
classpath = sourceSets.main.output + sourceSets.main.compileClasspath
destinationDir = file('docs/javadocs/user-api')
title = null
options {
noTimestamp = true
links 'https://docs.oracle.com/en/java/javase/17/docs/api/'
bottom = 'Licensed under the <a href="https://www.mozilla.org/MPL/2.0/">Mozilla Public License 2.0</a>.'
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/conf/mirth.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ server.api.accesscontrolmaxage =

# Password for the admin user, only applied when the database is first created.
# If blank, a random password is generated and written to the log once on first startup.
server.initialadminpassword =
# server.initialadminpassword =

# Determines whether or not channels are deployed on server startup.
server.startupdeploy = true
Expand Down
9 changes: 7 additions & 2 deletions smoketest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ apply plugin: 'distribution'

apply from: 'generate-smoke-tests.gradle'

// The harness runs with the server's whole staged distribution
// The harness runs with the server's whole staged distribution, the engine's own jars
// first (see ci/run-harness.sh)
def stagedServer = files([
project(':server').fileTree('setup/server-lib') { include '**/*.jar' },
project(':server').fileTree('setup/server-lib') { include 'mirth-*.jar' },
project(':server').fileTree('setup/server-lib') { include '**/*.jar'; exclude 'mirth-*.jar' },
project(':server').fileTree('setup/extensions') { include '**/*.jar' }]) {
builtBy ':server:createSetup'
}
Expand All @@ -35,6 +37,9 @@ tasks.named('test') {
// Only run our tests if a live server URL is provided
// `./gradlew :smoketest:test -Doie.baseUrl=https://localhost:8443`
onlyIf { System.getProperty('oie.baseUrl') != null }
classpath = stagedServer + sourceSets.test.runtimeClasspath
jvmArgs "@${project(':server').file('setup/conf/default_modules.vmoptions')}"
systemProperty 'oie.cliHome', project(':server').file('setup').path
systemProperties System.getProperties().findAll { it.key.toString().startsWith('oie.') }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ private CommandLineClient() {

/** Runs the CLI against the server under test, feeding it {@code statements} as a script. */
static Result runScript(String... statements) throws Exception {
return runScriptAgainst(HarnessConfig.BASE_URL, HarnessConfig.USERNAME, HarnessConfig.PASSWORD,
statements);
OieServer server = SharedServer.get();
return runScriptAgainst(server.baseUrl(), server.username(), server.password(), statements);
}

/** As {@link #runScript}, against an address and credentials of the caller's choosing. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ void printsUsageForHelp() throws Exception {
void logsInAndReportsServerVersion() throws Exception {
// Read over the API, so a match proves the CLI reached this server rather than
// echoing back the address it was given.
String version = SharedServer.get().version();
OieServer server = SharedServer.get();
String version = server.version();

CommandLineClient.Result result = CommandLineClient.runScript("status");

assertEquals(0, result.exitCode(), () -> "the CLI did not exit cleanly: " + result);
assertTrue(result.output().contains("Server @ " + HarnessConfig.BASE_URL + " (" + version + ")"),
() -> "the CLI did not report a connection to " + HarnessConfig.BASE_URL
assertTrue(result.output().contains("Server @ " + server.baseUrl() + " (" + version + ")"),
() -> "the CLI did not report a connection to " + server.baseUrl()
+ " running " + version + ": " + result);
// A failed logout prints "Error: ..." and then "Disconnected from server." anyway.
assertFalse(result.output().contains("Error:"),
Expand All @@ -63,7 +64,7 @@ void exitsWhenServerIsUnreachable() throws Exception {
// The client's connection monitor is a non-daemon thread: a CLI that leaves it
// running never exits, and this fails on the timeout rather than an assertion.
CommandLineClient.Result result = CommandLineClient.runScriptAgainst(
"https://127.0.0.1:1", HarnessConfig.USERNAME, HarnessConfig.PASSWORD, "status");
"https://127.0.0.1:1", "admin", "unused", "status");

assertFalse(result.output().contains("Server @ "),
() -> "the CLI reported a connection it could not have made: " + result);
Expand All @@ -75,11 +76,12 @@ void exitsWhenServerIsUnreachable() throws Exception {
@Test
@DisplayName("runs read-only commands against the live server")
void runsReadOnlyCommands() throws Exception {
OieServer server = SharedServer.get();
CommandLineClient.Result result =
CommandLineClient.runScript("status", "channel list", "user list");

assertEquals(0, result.exitCode(), () -> "the CLI did not exit cleanly: " + result);
assertTrue(result.output().contains("Server @ " + HarnessConfig.BASE_URL),
assertTrue(result.output().contains("Server @ " + server.baseUrl()),
() -> "the CLI never reported a connection: " + result);

assertTrue(result.output().contains("Status\t\tName"),
Expand All @@ -88,8 +90,8 @@ void runsReadOnlyCommands() throws Exception {
() -> "no channel listing: " + result);
assertTrue(result.output().contains("User Name"),
() -> "no user listing: " + result);
assertTrue(result.output().contains(HarnessConfig.USERNAME),
() -> "user listing omits " + HarnessConfig.USERNAME + ": " + result);
assertTrue(result.output().contains(server.username()),
() -> "user listing omits " + server.username() + ": " + result);

// A failed statement prints "Error: ..." or a stack trace, and does not change the exit code.
assertFalse(result.output().contains("Error:"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,21 @@ private static void assertMatches(String label, String expected, String actual)
if (actual == null) {
throw new AssertionError("Expected " + label + " content but the server stored none");
}
if (!toPattern(expected).matcher(actual).matches()) {
if (!toPattern(normalizeLineEndings(expected)).matcher(normalizeLineEndings(actual)).matches()) {
throw new AssertionError("Content mismatch for " + label
+ "\n expected: " + describe(expected)
+ "\n actual: " + describe(actual));
}
}

/**
* The server's XML serializers break lines with the platform's separator, so CRLF matches
* LF. A lone CR stays significant: it separates HL7 segments.
*/
private static String normalizeLineEndings(String content) {
return content.replace("\r\n", "\n");
}

/** Quotes the fixture text, leaving {@value #ANY_WILDCARD} as a lazy match-anything. */
private static Pattern toPattern(String expected) {
StringBuilder regex = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.mirth.connect.model.LoginStatus;
import com.mirth.connect.model.converters.ObjectXMLSerializer;
import com.mirth.connect.model.filters.MessageFilter;
import com.mirth.connect.server.controllers.ConfigurationController;
import com.mirth.connect.util.MirthSSLUtil;

/**
Expand Down Expand Up @@ -46,6 +47,7 @@ static OieServer connect() {
Client client = newClient();

try {
awaitHealthy(client);
LoginStatus status = client.login(HarnessConfig.USERNAME, HarnessConfig.PASSWORD);
if (status == null || !status.isSuccess()) {
throw new IllegalStateException("Login as " + HarnessConfig.USERNAME + " failed: "
Expand All @@ -63,6 +65,39 @@ static OieServer connect() {
return new OieServer(client);
}

/**
* Waits for the server's unauthenticated status endpoint to report it has started, so the
* harness can be launched alongside the server.
*/
private static void awaitHealthy(Client client) throws Exception {
Harness.awaitAsserted(() -> {
int status;
try {
status = client.getStatus();
} catch (ClientException e) {
throw new AssertionError("Could not reach " + HarnessConfig.BASE_URL, e);
}
if (status != ConfigurationController.STATUS_OK) {
throw new AssertionError("Server at " + HarnessConfig.BASE_URL + " has status " + status);
}
});
}

/** The base URL of the server this is connected to. */
public String baseUrl() {
return HarnessConfig.BASE_URL;
}

/** The user this is logged in as. */
public String username() {
return HarnessConfig.USERNAME;
}

/** The password of {@link #username()}, for a client that needs its own session. */
public String password() {
return HarnessConfig.PASSWORD;
}

/**
* Creates a client for the server under test that has not logged in, for tests that need a
* session other than the shared one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static void undeploy() {
@Test
@DisplayName("accepts a SOAP request")
void acceptsSoapRequest() throws Exception {
URI endpoint = new URI("http", null, URI.create(HarnessConfig.BASE_URL).getHost(), PORT,
URI endpoint = new URI("http", null, URI.create(SharedServer.get().baseUrl()).getHost(), PORT,
"/services/" + SERVICE, null, null);

HttpRequest request = HttpRequest.newBuilder(endpoint)
Expand Down
Loading