diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java index 4b405989b5..360f2da813 100644 --- a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java +++ b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java @@ -27,6 +27,7 @@ import com.mycila.xmltool.XMLDoc; import com.mycila.xmltool.XMLTag; import org.apache.commons.io.FileUtils; +import org.apache.knox.gateway.GatewayServer; import org.apache.knox.gateway.config.GatewayConfig; import org.apache.knox.gateway.config.impl.GatewayConfigImpl; import org.apache.knox.gateway.deploy.DeploymentFactory; @@ -55,6 +56,7 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.lang.reflect.Field; import java.net.URI; import java.net.URL; import java.nio.file.Files; @@ -189,7 +191,7 @@ private static void startGatewayServer() throws Exception { * Initialize the configs and components required for this test. */ private static void setupGatewayConfig(final String backend) - throws IOException { + throws Exception { services = new DefaultGatewayServices(); URL serviceUrl = ClassLoader.getSystemResource("websocket-services"); @@ -317,6 +319,8 @@ private static void setupGatewayConfig(final String backend) EasyMock.replay(gatewayConfig); + setGatewayServices(services); + try { services.init(gatewayConfig, options); } catch (ServiceLifecycleException e) { @@ -331,6 +335,17 @@ private static void setupGatewayConfig(final String backend) } + /** + * Set the static GatewayServices field to the specified value. + * + * @param gws A GatewayServices object, or null. + */ + private static void setGatewayServices(final GatewayServices gws) throws Exception { + Field gwsField = GatewayServer.class.getDeclaredField("services"); + gwsField.setAccessible(true); + gwsField.set(null, gws); + } + private static File createDir() throws IOException { return TestUtils .createTempDir(WebsocketEchoTest.class.getSimpleName() + "-"); diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTestBase.java b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTestBase.java index 5db254fd83..f3d9b6b5ba 100644 --- a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTestBase.java +++ b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTestBase.java @@ -20,6 +20,7 @@ import com.mycila.xmltool.XMLDoc; import com.mycila.xmltool.XMLTag; import org.apache.commons.io.FileUtils; +import org.apache.knox.gateway.GatewayServer; import org.apache.knox.gateway.config.GatewayConfig; import org.apache.knox.gateway.config.impl.GatewayConfigImpl; import org.apache.knox.gateway.deploy.DeploymentFactory; @@ -41,6 +42,7 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.lang.reflect.Field; import java.net.URI; import java.net.URL; import java.nio.file.Files; @@ -216,7 +218,7 @@ private static void startGatewayServer() throws Exception { * @param backend topology to use * @throws IOException exception on setting up the gateway */ - public static void setupGatewayConfig(final String backend) throws IOException { + public static void setupGatewayConfig(final String backend) throws Exception { services = new DefaultGatewayServices(); URL serviceUrl = ClassLoader.getSystemResource("websocket-services"); @@ -347,6 +349,8 @@ public static void setupGatewayConfig(final String backend) throws IOException { EasyMock.replay(gatewayConfig); + setGatewayServices(services); + try { services.init(gatewayConfig, options); } catch (ServiceLifecycleException e) { @@ -360,6 +364,17 @@ public static void setupGatewayConfig(final String backend) throws IOException { monitor.reloadTopologies(); } + /** + * Set the static GatewayServices field to the specified value. + * + * @param gws A GatewayServices object, or null. + */ + private static void setGatewayServices(final GatewayServices gws) throws Exception { + Field gwsField = GatewayServer.class.getDeclaredField("services"); + gwsField.setAccessible(true); + gwsField.set(null, gws); + } + private static File createDir() throws IOException { return TestUtils .createTempDir(WebsocketEchoTest.class.getSimpleName() + "-"); diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java index e40ec17114..edcfeff63a 100644 --- a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java +++ b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java @@ -27,6 +27,7 @@ import com.mycila.xmltool.XMLDoc; import com.mycila.xmltool.XMLTag; import org.apache.commons.io.FileUtils; +import org.apache.knox.gateway.GatewayServer; import org.apache.knox.gateway.config.GatewayConfig; import org.apache.knox.gateway.config.impl.GatewayConfigImpl; import org.apache.knox.gateway.deploy.DeploymentFactory; @@ -57,6 +58,7 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.lang.reflect.Field; import java.net.URI; import java.net.URL; import java.nio.file.Files; @@ -249,7 +251,7 @@ private static void startGatewayServer() throws Exception { * @param backend name of topology */ private static void setupGatewayConfig(final String backend) - throws IOException { + throws Exception { services = new DefaultGatewayServices(); URL serviceUrl = ClassLoader.getSystemResource("websocket-services"); @@ -380,6 +382,8 @@ private static void setupGatewayConfig(final String backend) EasyMock.replay(gatewayConfig); + setGatewayServices(services); + try { services.init(gatewayConfig, options); } catch (ServiceLifecycleException e) { @@ -393,6 +397,17 @@ private static void setupGatewayConfig(final String backend) monitor.reloadTopologies(); } + /** + * Set the static GatewayServices field to the specified value. + * + * @param gws A GatewayServices object, or null. + */ + private static void setGatewayServices(final GatewayServices gws) throws Exception { + Field gwsField = GatewayServer.class.getDeclaredField("services"); + gwsField.setAccessible(true); + gwsField.set(null, gws); + } + private static File createDir() throws IOException { return TestUtils .createTempDir(WebsocketEchoTest.class.getSimpleName() + "-");