diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index cc3954b35..071aade2f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 diff --git a/ci/README.md b/ci/README.md index 1fd3f24e9..8c6e795f8 100644 --- a/ci/README.md +++ b/ci/README.md @@ -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 @@ -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 diff --git a/server/build.gradle b/server/build.gradle index 1356c2301..8acd64015 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -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 Mozilla Public License 2.0.\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 Mozilla Public License 2.0.' } } diff --git a/server/conf/mirth.properties b/server/conf/mirth.properties index 4c9894277..28bd664b0 100644 --- a/server/conf/mirth.properties +++ b/server/conf/mirth.properties @@ -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 diff --git a/smoketest/build.gradle b/smoketest/build.gradle index c71faf3d6..91306ef6a 100644 --- a/smoketest/build.gradle +++ b/smoketest/build.gradle @@ -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' } @@ -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.') } } diff --git a/smoketest/src/test/java/org/openintegrationengine/smoketest/CommandLineClient.java b/smoketest/src/test/java/org/openintegrationengine/smoketest/CommandLineClient.java index a0e6c85be..0e39d4612 100644 --- a/smoketest/src/test/java/org/openintegrationengine/smoketest/CommandLineClient.java +++ b/smoketest/src/test/java/org/openintegrationengine/smoketest/CommandLineClient.java @@ -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. */ diff --git a/smoketest/src/test/java/org/openintegrationengine/smoketest/CommandLineInterfaceTest.java b/smoketest/src/test/java/org/openintegrationengine/smoketest/CommandLineInterfaceTest.java index 0f77909b2..ef1078718 100644 --- a/smoketest/src/test/java/org/openintegrationengine/smoketest/CommandLineInterfaceTest.java +++ b/smoketest/src/test/java/org/openintegrationengine/smoketest/CommandLineInterfaceTest.java @@ -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:"), @@ -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); @@ -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"), @@ -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:"), diff --git a/smoketest/src/test/java/org/openintegrationengine/smoketest/MessageAssertions.java b/smoketest/src/test/java/org/openintegrationengine/smoketest/MessageAssertions.java index b99ca9a28..e087a979d 100644 --- a/smoketest/src/test/java/org/openintegrationengine/smoketest/MessageAssertions.java +++ b/smoketest/src/test/java/org/openintegrationengine/smoketest/MessageAssertions.java @@ -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(); diff --git a/smoketest/src/test/java/org/openintegrationengine/smoketest/OieServer.java b/smoketest/src/test/java/org/openintegrationengine/smoketest/OieServer.java index 962eabba0..2a9700994 100644 --- a/smoketest/src/test/java/org/openintegrationengine/smoketest/OieServer.java +++ b/smoketest/src/test/java/org/openintegrationengine/smoketest/OieServer.java @@ -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; /** @@ -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: " @@ -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. diff --git a/smoketest/src/test/java/org/openintegrationengine/smoketest/WebServiceListenerTest.java b/smoketest/src/test/java/org/openintegrationengine/smoketest/WebServiceListenerTest.java index 63de56155..9f6fffa60 100644 --- a/smoketest/src/test/java/org/openintegrationengine/smoketest/WebServiceListenerTest.java +++ b/smoketest/src/test/java/org/openintegrationengine/smoketest/WebServiceListenerTest.java @@ -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)