Skip to content

Commit 620dd6d

Browse files
committed
Smoke test the administrator APIs against each database
Most smoke tests deploy a channel and send messages, and the server's tests of these controllers use mocks, so the SQL behind the administrator's other screens ran in no automated test. Add tests that drive those APIs through the client against the server and database under test: - UserAccountTest: create, update and remove a user, set and read preferences, and log in with a wrong and then a right password. - ConfigurationRoundTripTest: save and reload a channel group, a code template library and template, an alert, the global scripts and a server setting, restoring each afterwards. It also round-trips the configuration map, which by default is stored in a file rather than the database, so that part covers only the servlet. - EventBrowserTest: search audit events by name and attribute, and page through them. - MessageBrowserTest: search messages by content text, metadata column, custom metadata and attachment, page through them, reprocess one and remove some. - DataPrunerTest: run the pruner on a channel with pruning set and check the event it records. The channel's messages are too new to prune, so this covers the queries that select messages, not the deletes. - DebugUsageTest: deploy a channel with the debugger enabled and check the usage row that is reported and then deleted. updateChannelGroups replaces the whole set of groups, so the group test sends the existing groups with its own. Request bodies use mutable collections, because XStream rejects the JDK's immutable ones. Text searches use the stored case, because Oracle's are case-sensitive. The tests live in a new package, org.openintegrationengine.smoketest.admin, next to the generated .cases package, rather than among the harness classes. That makes SharedServer and OieServer public, along with the OieServer methods the tests call. OieServer also gains client(), newClient() and a deployChannel overload that takes a Channel and debug options. Deploying the same channel twice no longer records it twice for removal. Harness gains newChannel, which loads a channel fixture with a random id and a name that includes it, so tests never collide with each other or with a channel left by an earlier run. The tests wait on the server with Harness.awaitAsserted and awaitAssertedValue. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Tony Germano <tony@germano.name>
1 parent 19422a2 commit 620dd6d

10 files changed

Lines changed: 1086 additions & 17 deletions

File tree

‎smoketest/src/test/java/org/openintegrationengine/smoketest/Harness.java‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.LinkedHashMap;
1313
import java.util.List;
1414
import java.util.Map;
15+
import java.util.UUID;
1516
import java.util.concurrent.Callable;
1617

1718
import org.junit.jupiter.api.Assumptions;
@@ -21,10 +22,13 @@
2122
import com.mirth.connect.donkey.model.message.Message;
2223
import com.mirth.connect.donkey.model.message.MessageContent;
2324
import com.mirth.connect.donkey.model.message.Status;
25+
import com.mirth.connect.model.Channel;
26+
import com.mirth.connect.model.converters.ObjectXMLSerializer;
2427

2528
/**
2629
* The entry points the generated smoke tests call (see :smoketest:generateSmokeTests
27-
* and the generated smoketest/build/generated/smoketest files).
30+
* and the generated smoketest/build/generated/smoketest files), and helpers the hand-written
31+
* tests share.
2832
*/
2933
public final class Harness {
3034

@@ -111,6 +115,21 @@ public static void assumeConfiguration(String... configurations) {
111115
() -> "fixture is not enabled for configuration '" + configuration + "'");
112116
}
113117

118+
/**
119+
* Loads the channel exported at {@code channelResource} as a new channel: it gets a random id,
120+
* and a name made of {@code name} and the start of that id, so it never collides with another
121+
* test's channel or one left by an earlier run. Nothing is created on the server.
122+
*/
123+
public static Channel newChannel(String channelResource, String name) {
124+
// Deserializing needs ObjectXMLSerializer, which the shared login initialises.
125+
server();
126+
Channel channel = ObjectXMLSerializer.getInstance().deserialize(resource(channelResource), Channel.class);
127+
String id = UUID.randomUUID().toString();
128+
channel.setId(id);
129+
channel.setName(name + " " + id.substring(0, 8));
130+
return channel;
131+
}
132+
114133
/** Deploys the channel exported at {@code channelResource} and returns its id. */
115134
public static String deploy(String channelResource) throws Exception {
116135
return server().deployChannel(resource(channelResource), channelResource);

‎smoketest/src/test/java/org/openintegrationengine/smoketest/OieServer.java‎

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* {@code X-Requested-With} header, keeps the session cookie, and serialises the OIE model
3131
* classes. Assertions therefore run against typed objects rather than scraped XML.
3232
*/
33-
final class OieServer implements AutoCloseable {
33+
public final class OieServer implements AutoCloseable {
3434

3535
private static boolean serializerInitialized;
3636

@@ -43,13 +43,7 @@ private OieServer(Client client) {
4343
}
4444

4545
static OieServer connect() {
46-
Client client;
47-
try {
48-
client = new Client(HarnessConfig.BASE_URL, HarnessConfig.REQUEST_TIMEOUT_MILLIS,
49-
MirthSSLUtil.DEFAULT_HTTPS_CLIENT_PROTOCOLS, MirthSSLUtil.DEFAULT_HTTPS_CIPHER_SUITES);
50-
} catch (Exception e) {
51-
throw new IllegalStateException("Could not create a client for " + HarnessConfig.BASE_URL, e);
52-
}
46+
Client client = newClient();
5347

5448
try {
5549
LoginStatus status = client.login(HarnessConfig.USERNAME, HarnessConfig.PASSWORD);
@@ -69,6 +63,19 @@ static OieServer connect() {
6963
return new OieServer(client);
7064
}
7165

66+
/**
67+
* Creates a client for the server under test that has not logged in, for tests that need a
68+
* session other than the shared one.
69+
*/
70+
public static Client newClient() {
71+
try {
72+
return new Client(HarnessConfig.BASE_URL, HarnessConfig.REQUEST_TIMEOUT_MILLIS,
73+
MirthSSLUtil.DEFAULT_HTTPS_CLIENT_PROTOCOLS, MirthSSLUtil.DEFAULT_HTTPS_CIPHER_SUITES);
74+
} catch (Exception e) {
75+
throw new IllegalStateException("Could not create a client for " + HarnessConfig.BASE_URL, e);
76+
}
77+
}
78+
7279
/**
7380
* {@code ObjectXMLSerializer.init} throws if called twice, and the singleton outlives
7481
* any one connection, so initialise it at most once per JVM.
@@ -80,11 +87,19 @@ private static synchronized void initSerializer(String serverVersion) throws Exc
8087
}
8188
}
8289

90+
/**
91+
* The underlying client, for the administrator operations this class has no helper for.
92+
* It shares this server's session, so a test must restore anything it changes.
93+
*/
94+
public Client client() {
95+
return client;
96+
}
97+
8398
/**
8499
* Returns a typed client for one of the server's servlet interfaces, for the APIs the
85100
* administrator uses that have no {@link Client} convenience method.
86101
*/
87-
<T> T servlet(Class<T> servletInterface) {
102+
public <T> T servlet(Class<T> servletInterface) {
88103
return client.getServlet(servletInterface);
89104
}
90105

@@ -96,7 +111,19 @@ <T> T servlet(Class<T> servletInterface) {
96111
* @return the deployed channel's id
97112
*/
98113
String deployChannel(String xml, String label) throws Exception {
99-
Channel channel = ObjectXMLSerializer.getInstance().deserialize(xml, Channel.class);
114+
return deployChannel(ObjectXMLSerializer.getInstance().deserialize(xml, Channel.class), label, "");
115+
}
116+
117+
/**
118+
* Deploys a channel and waits for it to reach {@link DeployedState#STARTED}.
119+
*
120+
* @param channel the channel to create, or to update if it already exists
121+
* @param label a human-readable name for the channel, used only in error messages
122+
* @param debug the debug options, in the comma-separated form the engine servlet takes
123+
* (empty for none)
124+
* @return the deployed channel's id
125+
*/
126+
public String deployChannel(Channel channel, String label, String debug) throws Exception {
100127
String channelId = channel.getId();
101128
if (channelId == null || channelId.isBlank()) {
102129
throw new IllegalArgumentException("Channel fixture has no id: " + label);
@@ -106,11 +133,13 @@ String deployChannel(String xml, String label) throws Exception {
106133
if (!client.createChannel(channel)) {
107134
client.updateChannel(channel, true, null);
108135
}
109-
deployedChannelIds.push(channelId);
136+
if (!deployedChannelIds.contains(channelId)) {
137+
deployedChannelIds.push(channelId);
138+
}
110139

111140
// returnErrors=true so a deploy failure surfaces here instead of only as a status
112141
// that never reaches STARTED. The String overload avoids DebuggerUtil parsing.
113-
client.deployChannel(channelId, true, "");
142+
client.deployChannel(channelId, true, debug);
114143
awaitStarted(channelId, label);
115144
return channelId;
116145
}
@@ -132,7 +161,7 @@ String version() throws ClientException {
132161
}
133162

134163
/** Submits a source payload and returns the id of every message it produced, in dispatch order. */
135-
List<Long> submitMessage(String channelId, String rawData, Map<String, Object> sourceMap) throws ClientException {
164+
public List<Long> submitMessage(String channelId, String rawData, Map<String, Object> sourceMap) throws ClientException {
136165
RawMessage rawMessage = new RawMessage(rawData, null, sourceMap);
137166
List<Long> messageIds = client.processBatchMessage(channelId, rawMessage);
138167
if (messageIds == null) {

‎smoketest/src/test/java/org/openintegrationengine/smoketest/SharedServer.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
package org.openintegrationengine.smoketest;
55

66
/**
7-
* The one server connection shared by every generated test class in a JVM. The JUnit
7+
* The one server connection shared by every test class in a JVM. The JUnit
88
* launcher runs one configuration per JVM and then exits, so a single login is reused
99
* for the whole run and closed by a shutdown hook rather than per test class.
1010
*/
11-
final class SharedServer {
11+
public final class SharedServer {
1212

1313
private static OieServer instance;
1414

1515
private SharedServer() {
1616
}
1717

18-
static synchronized OieServer get() {
18+
public static synchronized OieServer get() {
1919
if (instance == null) {
2020
OieServer server = OieServer.connect();
2121
Runtime.getRuntime().addShutdownHook(new Thread(server::close, "oie-smoketest-logout"));
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: 2026 Tony Germano
3+
4+
package org.openintegrationengine.smoketest.admin;
5+
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertNotNull;
8+
import static org.junit.jupiter.api.Assertions.assertNull;
9+
import static org.junit.jupiter.api.Assertions.assertThrows;
10+
import static org.junit.jupiter.api.Assertions.assertTrue;
11+
12+
import java.util.ArrayList;
13+
import java.util.HashMap;
14+
import java.util.HashSet;
15+
import java.util.List;
16+
import java.util.Map;
17+
import java.util.Set;
18+
import java.util.UUID;
19+
20+
import org.junit.jupiter.api.DisplayName;
21+
import org.junit.jupiter.api.Test;
22+
import org.openintegrationengine.smoketest.Harness;
23+
import org.openintegrationengine.smoketest.SharedServer;
24+
25+
import com.mirth.connect.client.core.Client;
26+
import com.mirth.connect.client.core.ClientException;
27+
import com.mirth.connect.model.Channel;
28+
import com.mirth.connect.model.ChannelGroup;
29+
import com.mirth.connect.model.ServerSettings;
30+
import com.mirth.connect.model.alert.AlertActionGroup;
31+
import com.mirth.connect.model.alert.AlertModel;
32+
import com.mirth.connect.model.alert.DefaultTrigger;
33+
import com.mirth.connect.model.codetemplates.CodeTemplate;
34+
import com.mirth.connect.model.codetemplates.CodeTemplateLibrary;
35+
import com.mirth.connect.util.ConfigurationProperty;
36+
37+
/**
38+
* Saves each kind of server configuration the administrator edits, reads it back, and removes
39+
* or restores it. Every test leaves the server as it found it.
40+
*/
41+
@DisplayName("Configuration round trips")
42+
class ConfigurationRoundTripTest {
43+
44+
/**
45+
* The update replaces the server's whole set of groups and deletes any group it leaves out,
46+
* so every request sends the existing groups along with the test's own.
47+
*/
48+
@Test
49+
@DisplayName("saves, reads and removes a channel group")
50+
void channelGroup() throws Exception {
51+
Channel channel = Harness.newChannel("admin/channel.xml", "Smoke group member");
52+
assertTrue(admin().createChannel(channel), "createChannel");
53+
ChannelGroup group = new ChannelGroup("Smoke group " + suffix(), "created by the smoke tests");
54+
group.setChannels(new ArrayList<>(List.of(new Channel(channel.getId()))));
55+
try {
56+
Set<ChannelGroup> groups = new HashSet<>(admin().getAllChannelGroups());
57+
groups.add(group);
58+
assertTrue(admin().updateChannelGroups(groups, new HashSet<>(), false), "updateChannelGroups");
59+
60+
ChannelGroup saved = findGroup(group.getId());
61+
assertNotNull(saved, "group " + group.getId());
62+
assertEquals(group.getName(), saved.getName());
63+
assertEquals(channel.getId(), saved.getChannels().get(0).getId(), "member channel");
64+
} finally {
65+
try {
66+
Set<ChannelGroup> others = new HashSet<>();
67+
for (ChannelGroup existing : admin().getAllChannelGroups()) {
68+
if (!existing.getId().equals(group.getId())) {
69+
others.add(existing);
70+
}
71+
}
72+
admin().updateChannelGroups(others, ids(group.getId()), false);
73+
} finally {
74+
admin().removeChannel(channel.getId());
75+
}
76+
}
77+
78+
assertNull(findGroup(group.getId()), "group after removal");
79+
}
80+
81+
/** Lists every group, because a lookup by id logs an error for an id that doesn't exist. */
82+
private static ChannelGroup findGroup(String id) throws Exception {
83+
return admin().getAllChannelGroups().stream().filter(g -> g.getId().equals(id)).findFirst().orElse(null);
84+
}
85+
86+
@Test
87+
@DisplayName("saves, reads and removes a code template library")
88+
void codeTemplateLibrary() throws Exception {
89+
List<CodeTemplateLibrary> original = admin().getCodeTemplateLibraries(null, false);
90+
91+
CodeTemplate template = CodeTemplate.getDefaultCodeTemplate("smokeTemplate" + suffix());
92+
CodeTemplateLibrary library = new CodeTemplateLibrary();
93+
library.setName("Smoke library " + suffix());
94+
library.setCodeTemplates(new ArrayList<>(List.of(new CodeTemplate(template.getId()))));
95+
96+
List<CodeTemplateLibrary> withNew = new ArrayList<>(original);
97+
withNew.add(library);
98+
try {
99+
assertTrue(admin().updateCodeTemplate(template, false), "updateCodeTemplate");
100+
assertTrue(admin().updateCodeTemplateLibraries(withNew, false), "updateCodeTemplateLibraries");
101+
102+
CodeTemplateLibrary saved = admin().getCodeTemplateLibrary(library.getId(), true);
103+
assertNotNull(saved, "library " + library.getId());
104+
assertEquals(library.getName(), saved.getName());
105+
assertEquals(1, saved.getCodeTemplates().size(), "templates in the library");
106+
assertEquals(template.getCode(), saved.getCodeTemplates().get(0).getCode(), "template code");
107+
} finally {
108+
try {
109+
admin().updateCodeTemplateLibraries(original, true);
110+
} finally {
111+
admin().removeCodeTemplate(template.getId());
112+
}
113+
}
114+
115+
assertTrue(admin().getCodeTemplates(null).stream().noneMatch(t -> t.getId().equals(template.getId())), "template after removal");
116+
}
117+
118+
@Test
119+
@DisplayName("creates, updates, reads and removes an alert")
120+
void alert() throws Exception {
121+
AlertModel alert = new AlertModel(new DefaultTrigger(), new AlertActionGroup());
122+
alert.setName("Smoke alert " + suffix());
123+
admin().createAlert(alert);
124+
try {
125+
assertEquals(alert.getName(), admin().getAlert(alert.getId()).getName(), "alert after create");
126+
127+
alert.setName(alert.getName() + " renamed");
128+
admin().updateAlert(alert);
129+
assertEquals(alert.getName(), admin().getAlert(alert.getId()).getName(), "alert after update");
130+
131+
assertTrue(admin().getAlerts(null).stream().anyMatch(a -> a.getId().equals(alert.getId())),
132+
"alert listed among all alerts");
133+
} finally {
134+
admin().removeAlert(alert.getId());
135+
}
136+
137+
ClientException missing = assertThrows(ClientException.class, () -> admin().getAlert(alert.getId()), "alert after removal");
138+
assertTrue(missing.getMessage().contains("404"), () -> "error for the removed alert: " + missing.getMessage());
139+
}
140+
141+
@Test
142+
@DisplayName("saves and restores the global scripts")
143+
void globalScripts() throws Exception {
144+
Map<String, String> original = admin().getGlobalScripts();
145+
Map<String, String> changed = new HashMap<>(original);
146+
String script = "// smoke test " + suffix() + "\nreturn;";
147+
changed.put("Deploy", script);
148+
try {
149+
admin().setGlobalScripts(changed);
150+
assertEquals(script, admin().getGlobalScripts().get("Deploy"));
151+
} finally {
152+
admin().setGlobalScripts(original);
153+
}
154+
155+
assertEquals(original, admin().getGlobalScripts(), "global scripts after restoring");
156+
}
157+
158+
@Test
159+
@DisplayName("saves and restores the server settings")
160+
void serverSettings() throws Exception {
161+
ServerSettings settings = admin().getServerSettings();
162+
String original = settings.getSmtpTimeout();
163+
try {
164+
settings.setSmtpTimeout("54321");
165+
admin().setServerSettings(settings);
166+
assertEquals("54321", admin().getServerSettings().getSmtpTimeout());
167+
} finally {
168+
settings.setSmtpTimeout(original);
169+
admin().setServerSettings(settings);
170+
}
171+
172+
assertEquals(original, admin().getServerSettings().getSmtpTimeout(), "SMTP timeout after restoring");
173+
}
174+
175+
@Test
176+
@DisplayName("saves and restores the configuration map")
177+
void configurationMap() throws Exception {
178+
Map<String, ConfigurationProperty> original = admin().getConfigurationMap();
179+
Map<String, ConfigurationProperty> changed = new HashMap<>(original);
180+
String key = "smoke." + suffix();
181+
changed.put(key, new ConfigurationProperty("value", "added by the smoke tests"));
182+
try {
183+
admin().setConfigurationMap(changed);
184+
ConfigurationProperty saved = admin().getConfigurationMap().get(key);
185+
assertNotNull(saved, key + " in the configuration map");
186+
assertEquals("value", saved.getValue());
187+
assertEquals("added by the smoke tests", saved.getComment());
188+
} finally {
189+
admin().setConfigurationMap(original);
190+
}
191+
192+
assertNull(admin().getConfigurationMap().get(key), key + " after restoring");
193+
}
194+
195+
/**
196+
* Request bodies are serialized by XStream, which rejects the JDK's immutable collections, so
197+
* the sets and lists sent to the server have to be mutable ones.
198+
*/
199+
private static Set<String> ids(String... ids) {
200+
return new HashSet<>(List.of(ids));
201+
}
202+
203+
private static String suffix() {
204+
return UUID.randomUUID().toString().substring(0, 8);
205+
}
206+
207+
private static Client admin() {
208+
return SharedServer.get().client();
209+
}
210+
}

0 commit comments

Comments
 (0)