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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.google.inject.Inject;
import com.google.common.annotations.VisibleForTesting;
import com.mirth.connect.donkey.model.DatabaseConstants;
import com.mirth.connect.donkey.server.channel.Channel;
import com.mirth.connect.donkey.server.controllers.ChannelController;
Expand All @@ -39,7 +39,6 @@
import com.mirth.connect.donkey.util.xstream.XStreamSerializer;

public class Donkey {
@Inject
private static Donkey instance;

public static Donkey getInstance() {
Expand All @@ -52,6 +51,26 @@ public static Donkey getInstance() {
}
}

/** Replaces the instance {@link #getInstance()} hands out until the returned handle is closed. */
@VisibleForTesting
public static AutoCloseable setInstanceForTesting(Donkey newInstance) {
synchronized (Donkey.class) {
Donkey previous = instance;
instance = newInstance;

return () -> {
synchronized (Donkey.class) {
if (instance != newInstance) {
throw new IllegalStateException("The Donkey instance was replaced by " + instance
+ " while " + newInstance + " was installed for testing.");
}

instance = previous;
}
};
}
}

public Donkey() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@

import org.apache.commons.lang3.StringUtils;

import com.google.inject.Inject;
import com.google.common.annotations.VisibleForTesting;
import com.mirth.connect.donkey.model.DatabaseConstants;
import com.mirth.connect.donkey.server.data.jdbc.ConnectionPool;
import com.mirth.connect.donkey.server.data.jdbc.DBCPConnectionPool;
import com.mirth.connect.donkey.server.data.jdbc.HikariConnectionPool;

public class DonkeyConnectionPools {

@Inject
private static volatile DonkeyConnectionPools instance = null;

private ConnectionPool connectionPool;
Expand All @@ -42,6 +41,26 @@ public static DonkeyConnectionPools getInstance() {
return connectionPools;
}

/** Replaces the instance {@link #getInstance()} hands out until the returned handle is closed. */
@VisibleForTesting
public static AutoCloseable setInstanceForTesting(DonkeyConnectionPools newInstance) {
synchronized (DonkeyConnectionPools.class) {
DonkeyConnectionPools previous = instance;
instance = newInstance;

return () -> {
synchronized (DonkeyConnectionPools.class) {
if (instance != newInstance) {
throw new IllegalStateException("The DonkeyConnectionPools instance was replaced by " + instance
+ " while " + newInstance + " was installed for testing.");
}

instance = previous;
}
};
}
}

DonkeyConnectionPools() {}

public ConnectionPool getConnectionPool() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.apache.commons.lang3.StringUtils;

import com.google.inject.Inject;
import com.google.common.annotations.VisibleForTesting;
import com.mirth.connect.donkey.model.channel.Ports;
import com.mirth.connect.donkey.model.message.Status;
import com.mirth.connect.donkey.server.Donkey;
Expand All @@ -27,7 +27,6 @@
import com.mirth.connect.donkey.server.data.DonkeyDaoFactory;

public class ChannelController {
@Inject
private static ChannelController instance;

public static ChannelController getInstance() {
Expand All @@ -40,6 +39,26 @@ public static ChannelController getInstance() {
}
}

/** Replaces the instance {@link #getInstance()} hands out until the returned handle is closed. */
@VisibleForTesting
public static AutoCloseable setInstanceForTesting(ChannelController newInstance) {
synchronized (ChannelController.class) {
ChannelController previous = instance;
instance = newInstance;

return () -> {
synchronized (ChannelController.class) {
if (instance != newInstance) {
throw new IllegalStateException("The ChannelController instance was replaced by " + instance
+ " while " + newInstance + " was installed for testing.");
}

instance = previous;
}
};
}
}

private Statistics currentStats;
private Statistics totalStats;
private Donkey donkey = Donkey.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;

import com.google.inject.Inject;
import com.mirth.connect.donkey.model.message.ConnectorMessage;
import com.mirth.connect.donkey.model.message.Message;
import com.mirth.connect.donkey.model.message.Status;
Expand All @@ -30,7 +29,6 @@
import com.mirth.connect.donkey.util.StringUtil;

public class MessageController {
@Inject
private static MessageController instance;

public static MessageController getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.mirth.connect.donkey.model.channel.ConnectorProperties;
import com.mirth.connect.donkey.model.channel.SourceConnectorProperties;
import com.mirth.connect.donkey.model.channel.SourceConnectorPropertiesInterface;
Expand All @@ -48,24 +46,24 @@

public class ChannelTest {

private static AutoCloseable donkeyOverride;

@BeforeClass
public static void setupControllers() throws Exception {
Donkey donkey = mock(Donkey.class);
when(donkey.getEventDispatcher()).thenReturn(mock(EventDispatcher.class));

Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
requestStaticInjection(Donkey.class);
bind(Donkey.class).toInstance(donkey);
}
});
injector.getInstance(Donkey.class);
donkeyOverride = Donkey.setInstanceForTesting(donkey);

// Make sure injection succeeded
assertTrue(donkey == Donkey.getInstance());
}

@AfterClass
public static void restoreDonkey() throws Exception {
donkeyOverride.close();
}

@Test
public void testRawMessageWithAttachments() throws Exception {
Channel channel = createChannel();
Expand Down
3 changes: 0 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ glassfish-ha-api = { module = "org.glassfish.ha:ha-api", version = "3.1.9" }
glassfish-management-api = { module = "org.glassfish.external:management-api", version = "3.2.1-b001" }
gmbal-api-only = { module = "org.glassfish.gmbal:gmbal-api-only", version = "3.1.0-b001" }
guava = { module = "com.google.guava:guava", version = "32.0.1-jre" }
guice = { module = "com.google.inject:guice", version = "4.1.0" }
hamcrest = { module = "org.hamcrest:hamcrest", version = "2.2" }
hapi-structures-v27 = { module = "ca.uhn.hapi:hapi-structures-v27", version.ref = "hapi" }
hapi-structures-v28 = { module = "ca.uhn.hapi:hapi-structures-v28", version.ref = "hapi" }
Expand Down Expand Up @@ -407,7 +406,6 @@ donkey-main = [
"error-prone-annotations",
"failureaccess",
"guava",
"guice",
"hikaricp",
"j2objc-annotations",
"javassist",
Expand Down Expand Up @@ -522,7 +520,6 @@ server-main = [
"glassfish-ha-api",
"glassfish-management-api",
"gmbal-api-only",
"guice",
"hapi-structures-v27",
"hapi-structures-v28",
"hapi-structures-v281",
Expand Down
2 changes: 0 additions & 2 deletions gradle/vendored-layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
"com.google.guava:failureaccess": "guava",
"com.google.guava:guava": "guava",
"com.google.guava:listenablefuture": "guava",
"com.google.inject:guice": "",
"com.google.j2objc:j2objc-annotations": "guava",
"com.microsoft.sqlserver:mssql-jdbc": "database",
"com.mysql:mysql-connector-j": "database",
Expand Down Expand Up @@ -183,7 +182,6 @@
"com.github.mwiede:jsch": "",
"com.github.oshi:oshi-core": "",
"com.github.zafarkhaja:java-semver": "",
"com.google.inject:guice": "",
"com.microsoft.sqlserver:mssql-jdbc": "database",
"com.mysql:mysql-connector-j": "database",
"com.oracle.database.jdbc:ojdbc8": "database",
Expand Down
13 changes: 0 additions & 13 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -410,19 +410,6 @@
<sha256 value="18d4b1db26153d4e55079ce1f76bb1fe05cdb862ef9954a88cbcc4ff38b8679b" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.inject" name="guice" version="4.1.0">
<artifact name="guice-4.1.0.jar">
<sha256 value="9b9df27a5b8c7864112b4137fd92b36c3f1395bfe57be42fedf2f520ead1a93e" origin="Generated by Gradle"/>
</artifact>
<artifact name="guice-4.1.0.pom">
<sha256 value="0fa847b77ecf18b17007bf3853f44bf7f0b6170f2f944a05b1990dc59c441695" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.inject" name="guice-parent" version="4.1.0">
<artifact name="guice-parent-4.1.0.pom">
<sha256 value="1ecea87b2c44d210e60f0f2ecc241538de227006bd2b2d1e75349ee4164b77dc" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.j2objc" name="j2objc-annotations" version="1.3">
<artifact name="j2objc-annotations-1.3.jar">
<sha256 value="21af30c92267bd6122c0e0b4d20cccb6641a37eaf956c6540ec471d584e64a7b" origin="Generated by Gradle"/>
Expand Down
1 change: 0 additions & 1 deletion server/docs/thirdparty/THIRD-PARTY-README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ The following are distributed under the terms of the Apache License version 2.0
Google Code libphonenumber (https://github.com/google/libphonenumber)
Google Code Prettify (https://github.com/google/code-prettify)
Guava 32.0.1 [incl. CLI] (https://github.com/google/guava)
Guice 4.1 (https://github.com/google/guice)
HikariCP 2.5.1
J2ObjC Annotations 1.3 (https://github.com/google/j2objc/)
Jackson Project [incl. CLI] (https://github.com/FasterXML/jackson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.google.inject.Inject;
import com.mirth.connect.client.core.PropertiesConfigurationUtil;
import com.mirth.connect.model.ConnectorMetaData;
import com.mirth.connect.model.MetaData;
Expand All @@ -43,7 +42,6 @@
import com.mirth.connect.server.util.ResourceUtil;

public class ExtensionLoader {
@Inject
private static ExtensionLoader instance = new ExtensionLoader();

public static ExtensionLoader getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

package com.mirth.connect.server.controllers;

import com.google.inject.Inject;
import com.google.common.annotations.VisibleForTesting;

public abstract class ControllerFactory {
@Inject
private static ControllerFactory factory;

public static ControllerFactory getFactory() {
Expand All @@ -25,6 +24,26 @@ public static ControllerFactory getFactory() {
}
}

/** Replaces the factory {@link #getFactory()} hands out until the returned handle is closed. */
@VisibleForTesting
public static AutoCloseable setFactoryForTesting(ControllerFactory newFactory) {
synchronized (ControllerFactory.class) {
ControllerFactory previous = factory;
factory = newFactory;

return () -> {
synchronized (ControllerFactory.class) {
if (factory != newFactory) {
throw new IllegalStateException("The ControllerFactory was replaced by " + factory
+ " while " + newFactory + " was installed for testing.");
}

factory = previous;
}
};
}
}

public abstract AuthorizationController createAuthorizationController();

public abstract AlertController createAlertController();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.w3c.dom.Element;
import org.xml.sax.InputSource;

import com.google.inject.Inject;
import com.google.common.annotations.VisibleForTesting;
import com.mirth.connect.donkey.model.DatabaseConstants;
import com.mirth.connect.donkey.util.DonkeyElement;
import com.mirth.connect.model.DatabaseSettings;
Expand All @@ -40,7 +40,6 @@

public class SqlConfig {

@Inject
private static volatile SqlConfig instance = null;

private boolean splitReadWrite = false;
Expand All @@ -67,6 +66,26 @@ public static SqlConfig getInstance() {
return sqlConfig;
}

/** Replaces the instance {@link #getInstance()} hands out until the returned handle is closed. */
@VisibleForTesting
public static AutoCloseable setInstanceForTesting(SqlConfig newInstance) {
synchronized (SqlConfig.class) {
SqlConfig previous = instance;
instance = newInstance;

return () -> {
synchronized (SqlConfig.class) {
if (instance != newInstance) {
throw new IllegalStateException("The SqlConfig instance was replaced by " + instance
+ " while " + newInstance + " was installed for testing.");
}

instance = previous;
}
};
}
}

public SqlConfig() {
init();
}
Expand Down
Loading
Loading