diff --git a/settings.gradle b/settings.gradle index 460e5e403..73a52263a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -31,6 +31,7 @@ include 'smack-core', 'smack-repl', 'smack-openpgp', 'smack-websocket', + 'smack-websocket-okhttp', 'smack-xmlparser', 'smack-xmlparser-stax', 'smack-xmlparser-xpp3' diff --git a/smack-websocket-okhttp/build.gradle b/smack-websocket-okhttp/build.gradle new file mode 100644 index 000000000..6f83f2c83 --- /dev/null +++ b/smack-websocket-okhttp/build.gradle @@ -0,0 +1,10 @@ +description = """\ +Smack for XMPP connections over WebSocket (RFC 7395) using OkHttp.""" + +dependencies { + api project(':smack-websocket') + + testFixturesApi(testFixtures(project(':smack-websocket'))) + + implementation("com.squareup.okhttp3:okhttp:4.6.0") +} diff --git a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/okhttp/LoggingInterceptor.java b/smack-websocket-okhttp/src/main/java/org/jivesoftware/smack/websocket/okhttp/LoggingInterceptor.java similarity index 98% rename from smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/okhttp/LoggingInterceptor.java rename to smack-websocket-okhttp/src/main/java/org/jivesoftware/smack/websocket/okhttp/LoggingInterceptor.java index c76684b98..e6e14e0e0 100644 --- a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/okhttp/LoggingInterceptor.java +++ b/smack-websocket-okhttp/src/main/java/org/jivesoftware/smack/websocket/okhttp/LoggingInterceptor.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.websocket.implementations.okhttp; +package org.jivesoftware.smack.websocket.okhttp; import java.io.IOException; import java.nio.charset.Charset; diff --git a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/okhttp/OkHttpWebsocket.java b/smack-websocket-okhttp/src/main/java/org/jivesoftware/smack/websocket/okhttp/OkHttpWebsocket.java similarity index 94% rename from smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/okhttp/OkHttpWebsocket.java rename to smack-websocket-okhttp/src/main/java/org/jivesoftware/smack/websocket/okhttp/OkHttpWebsocket.java index 0d898d849..3e7640699 100644 --- a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/okhttp/OkHttpWebsocket.java +++ b/smack-websocket-okhttp/src/main/java/org/jivesoftware/smack/websocket/okhttp/OkHttpWebsocket.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.websocket.implementations.okhttp; +package org.jivesoftware.smack.websocket.okhttp; import java.io.IOException; import java.util.logging.Level; @@ -28,9 +28,8 @@ import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionIn import org.jivesoftware.smack.packet.TopLevelStreamElement; import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.websocket.WebsocketException; -import org.jivesoftware.smack.websocket.XmppWebsocketTransportModule.XmppWebsocketTransport.DiscoveredWebsocketEndpoints; import org.jivesoftware.smack.websocket.elements.WebsocketOpenElement; -import org.jivesoftware.smack.websocket.implementations.AbstractWebsocket; +import org.jivesoftware.smack.websocket.impl.AbstractWebsocket; import org.jivesoftware.smack.websocket.rce.WebsocketRemoteConnectionEndpoint; import org.jivesoftware.smack.xml.XmlPullParserException; @@ -54,8 +53,7 @@ public final class OkHttpWebsocket extends AbstractWebsocket { private WebsocketConnectionPhase phase; private WebsocketRemoteConnectionEndpoint connectedEndpoint; - public OkHttpWebsocket(ModularXmppClientToServerConnectionInternal connectionInternal, - DiscoveredWebsocketEndpoints discoveredWebsocketEndpoints) { + public OkHttpWebsocket(ModularXmppClientToServerConnectionInternal connectionInternal) { this.connectionInternal = connectionInternal; if (okHttpClient == null) { diff --git a/smack-websocket-okhttp/src/main/java/org/jivesoftware/smack/websocket/okhttp/OkHttpWebsocketFactory.java b/smack-websocket-okhttp/src/main/java/org/jivesoftware/smack/websocket/okhttp/OkHttpWebsocketFactory.java new file mode 100644 index 000000000..48b42e815 --- /dev/null +++ b/smack-websocket-okhttp/src/main/java/org/jivesoftware/smack/websocket/okhttp/OkHttpWebsocketFactory.java @@ -0,0 +1,30 @@ +/** + * + * Copyright 2020 Florian Schmaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smack.websocket.okhttp; + +import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal; +import org.jivesoftware.smack.websocket.impl.AbstractWebsocket; +import org.jivesoftware.smack.websocket.impl.WebsocketFactory; + +public class OkHttpWebsocketFactory implements WebsocketFactory { + + @Override + public AbstractWebsocket create(ModularXmppClientToServerConnectionInternal connectionInternal) { + return new OkHttpWebsocket(connectionInternal); + } + +} diff --git a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/okhttp/package-info.java b/smack-websocket-okhttp/src/main/java/org/jivesoftware/smack/websocket/okhttp/package-info.java similarity index 90% rename from smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/okhttp/package-info.java rename to smack-websocket-okhttp/src/main/java/org/jivesoftware/smack/websocket/okhttp/package-info.java index c077b1214..e4b3d388c 100644 --- a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/okhttp/package-info.java +++ b/smack-websocket-okhttp/src/main/java/org/jivesoftware/smack/websocket/okhttp/package-info.java @@ -14,4 +14,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.websocket.implementations.okhttp; +package org.jivesoftware.smack.websocket.okhttp; diff --git a/smack-websocket-okhttp/src/main/resources/META-INF/services/org.jivesoftware.smack.websocket.impl.WebsocketFactory b/smack-websocket-okhttp/src/main/resources/META-INF/services/org.jivesoftware.smack.websocket.impl.WebsocketFactory new file mode 100644 index 000000000..75257214f --- /dev/null +++ b/smack-websocket-okhttp/src/main/resources/META-INF/services/org.jivesoftware.smack.websocket.impl.WebsocketFactory @@ -0,0 +1 @@ +org.jivesoftware.smack.websocket.okhttp.OkHttpWebsocketFactory \ No newline at end of file diff --git a/smack-websocket-okhttp/src/test/java/org/jivesoftware/smack/websocket/okhttp/OkHttpWebsocketFactoryServiceTest.java b/smack-websocket-okhttp/src/test/java/org/jivesoftware/smack/websocket/okhttp/OkHttpWebsocketFactoryServiceTest.java new file mode 100644 index 000000000..d4fca586f --- /dev/null +++ b/smack-websocket-okhttp/src/test/java/org/jivesoftware/smack/websocket/okhttp/OkHttpWebsocketFactoryServiceTest.java @@ -0,0 +1,30 @@ +/** + * + * Copyright 2020 Florian Schmaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smack.websocket.okhttp; + +import org.jivesoftware.smack.websocket.test.WebsocketFactoryServiceTestUtil; + +import org.junit.jupiter.api.Test; + +public class OkHttpWebsocketFactoryServiceTest { + + @Test + public void createWebsocketTest() { + WebsocketFactoryServiceTestUtil.createWebsocketTest(OkHttpWebsocket.class); + } + +} diff --git a/smack-websocket/build.gradle b/smack-websocket/build.gradle index 43d205f36..1ef60c233 100644 --- a/smack-websocket/build.gradle +++ b/smack-websocket/build.gradle @@ -1,10 +1,8 @@ description = """\ -Smack for standard XMPP connections over Websockets.""" +Smack for XMPP connections over WebSocket (RFC 7395).""" dependencies { - compile project(':smack-core') + api project(':smack-core') - testFixturesApi(testFixtures(project(":smack-core"))) - - implementation("com.squareup.okhttp3:okhttp:4.6.0") + testFixturesApi(testFixtures(project(':smack-core'))) } diff --git a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/WebsocketConnectionAttemptState.java b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/WebsocketConnectionAttemptState.java index ba683fc75..60639d5b5 100644 --- a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/WebsocketConnectionAttemptState.java +++ b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/WebsocketConnectionAttemptState.java @@ -1,6 +1,6 @@ /** * - * Copyright 2020 Aditya Borikar + * Copyright 2020 Aditya Borikar, Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,13 @@ */ package org.jivesoftware.smack.websocket; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal; import org.jivesoftware.smack.websocket.XmppWebsocketTransportModule.EstablishingWebsocketConnectionState; -import org.jivesoftware.smack.websocket.implementations.AbstractWebsocket; -import org.jivesoftware.smack.websocket.implementations.WebsocketImplProvider; -import org.jivesoftware.smack.websocket.implementations.okhttp.OkHttpWebsocket; +import org.jivesoftware.smack.websocket.impl.AbstractWebsocket; +import org.jivesoftware.smack.websocket.impl.WebsocketFactoryService; import org.jivesoftware.smack.websocket.rce.WebsocketRemoteConnectionEndpoint; public final class WebsocketConnectionAttemptState { @@ -56,15 +54,7 @@ public final class WebsocketConnectionAttemptState { } List connectionFailureList = new ArrayList<>(); - AbstractWebsocket websocket; - - try { - // Obtain desired websocket implementation by using WebsocketImplProvider - websocket = WebsocketImplProvider.getWebsocketImpl(OkHttpWebsocket.class, connectionInternal, discoveredEndpoints); - } catch (NoSuchMethodException | SecurityException | InstantiationException | - IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { - throw new WebsocketException(exception); - } + AbstractWebsocket websocket = WebsocketFactoryService.createWebsocket(connectionInternal); // Keep iterating over available endpoints until a connection is establised or all endpoints are tried to create a connection with. for (WebsocketRemoteConnectionEndpoint endpoint : endpoints) { diff --git a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/XmppWebsocketTransportModule.java b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/XmppWebsocketTransportModule.java index 77f16f27c..d3f5d9773 100644 --- a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/XmppWebsocketTransportModule.java +++ b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/XmppWebsocketTransportModule.java @@ -53,7 +53,7 @@ import org.jivesoftware.smack.util.rce.RemoteConnectionEndpointLookupFailure; import org.jivesoftware.smack.websocket.XmppWebsocketTransportModule.XmppWebsocketTransport.DiscoveredWebsocketEndpoints; import org.jivesoftware.smack.websocket.elements.WebsocketCloseElement; import org.jivesoftware.smack.websocket.elements.WebsocketOpenElement; -import org.jivesoftware.smack.websocket.implementations.AbstractWebsocket; +import org.jivesoftware.smack.websocket.impl.AbstractWebsocket; import org.jivesoftware.smack.websocket.rce.WebsocketRemoteConnectionEndpoint; import org.jivesoftware.smack.websocket.rce.WebsocketRemoteConnectionEndpointLookup; import org.jivesoftware.smack.websocket.rce.WebsocketRemoteConnectionEndpointLookup.Result; diff --git a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/AbstractWebsocket.java b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/AbstractWebsocket.java similarity index 97% rename from smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/AbstractWebsocket.java rename to smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/AbstractWebsocket.java index 8341c2f1b..293208006 100644 --- a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/AbstractWebsocket.java +++ b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/AbstractWebsocket.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.websocket.implementations; +package org.jivesoftware.smack.websocket.impl; import javax.net.ssl.SSLSession; diff --git a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/WebsocketFactory.java b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/WebsocketFactory.java new file mode 100644 index 000000000..345db0d86 --- /dev/null +++ b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/WebsocketFactory.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2020 Florian Schmaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smack.websocket.impl; + +import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal; + +public interface WebsocketFactory { + + AbstractWebsocket create(ModularXmppClientToServerConnectionInternal connectionInternal); + +} diff --git a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/WebsocketFactoryService.java b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/WebsocketFactoryService.java new file mode 100644 index 000000000..a852c897b --- /dev/null +++ b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/WebsocketFactoryService.java @@ -0,0 +1,40 @@ +/** + * + * Copyright 2020 Florian Schmaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smack.websocket.impl; + +import java.util.Iterator; +import java.util.ServiceLoader; + +import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal; + +public final class WebsocketFactoryService { + + private static final ServiceLoader SERVICE_LOADER = ServiceLoader.load(WebsocketFactory.class); + + public static AbstractWebsocket createWebsocket(ModularXmppClientToServerConnectionInternal connectionInternal) { + assert connectionInternal != null; + + Iterator websocketFactories = SERVICE_LOADER.iterator(); + if (!websocketFactories.hasNext()) { + throw new IllegalStateException("No smack websocket service configured"); + } + + WebsocketFactory websocketFactory = websocketFactories.next(); + return websocketFactory.create(connectionInternal); + } + +} diff --git a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/package-info.java b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/package-info.java similarity index 92% rename from smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/package-info.java rename to smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/package-info.java index 4260faaaf..3f2620e7b 100644 --- a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/package-info.java +++ b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/package-info.java @@ -17,4 +17,4 @@ /** * This package contains websocket implementations to be plugged inside websocket transport. */ -package org.jivesoftware.smack.websocket.implementations; +package org.jivesoftware.smack.websocket.impl; diff --git a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/WebsocketImplProvider.java b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/WebsocketImplProvider.java deleted file mode 100644 index b67ac236d..000000000 --- a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/implementations/WebsocketImplProvider.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * - * Copyright 2020 Aditya Borikar. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jivesoftware.smack.websocket.implementations; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal; -import org.jivesoftware.smack.util.Objects; -import org.jivesoftware.smack.websocket.XmppWebsocketTransportModule.XmppWebsocketTransport.DiscoveredWebsocketEndpoints; - -public final class WebsocketImplProvider { - - public static AbstractWebsocket getWebsocketImpl(Class websocketImpl, ModularXmppClientToServerConnectionInternal connectionInternal, DiscoveredWebsocketEndpoints discoveredWebsocketEndpoints) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - Objects.requireNonNull(connectionInternal, "ConnectionInternal cannot be null"); - - // Creates an instance of the constructor for the desired websocket implementation. - Constructor constructor = websocketImpl.getConstructor(ModularXmppClientToServerConnectionInternal.class, DiscoveredWebsocketEndpoints.class); - return (AbstractWebsocket) constructor.newInstance(connectionInternal, discoveredWebsocketEndpoints); - } -} diff --git a/smack-websocket/src/test/java/org/jivesoftware/smack/websocket/implementations/AbstractWebsocketTest.java b/smack-websocket/src/test/java/org/jivesoftware/smack/websocket/impl/AbstractWebsocketTest.java similarity index 97% rename from smack-websocket/src/test/java/org/jivesoftware/smack/websocket/implementations/AbstractWebsocketTest.java rename to smack-websocket/src/test/java/org/jivesoftware/smack/websocket/impl/AbstractWebsocketTest.java index 3c71dadfa..c1e11e6df 100644 --- a/smack-websocket/src/test/java/org/jivesoftware/smack/websocket/implementations/AbstractWebsocketTest.java +++ b/smack-websocket/src/test/java/org/jivesoftware/smack/websocket/impl/AbstractWebsocketTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.websocket.implementations; +package org.jivesoftware.smack.websocket.impl; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/smack-websocket/src/test/java/org/jivesoftware/smack/websocket/implementations/ProviderTest.java b/smack-websocket/src/test/java/org/jivesoftware/smack/websocket/implementations/ProviderTest.java deleted file mode 100644 index 842a3fe0e..000000000 --- a/smack-websocket/src/test/java/org/jivesoftware/smack/websocket/implementations/ProviderTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * - * Copyright 2020 Aditya Borikar. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jivesoftware.smack.websocket.implementations; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.lang.reflect.InvocationTargetException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; - -import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal; -import org.jivesoftware.smack.websocket.XmppWebsocketTransportModule.XmppWebsocketTransport.DiscoveredWebsocketEndpoints; - -import org.jivesoftware.smack.websocket.implementations.okhttp.OkHttpWebsocket; -import org.jivesoftware.smack.websocket.rce.WebsocketRemoteConnectionEndpoint; -import org.jivesoftware.smack.websocket.rce.WebsocketRemoteConnectionEndpointLookup.Result; - -import org.junit.jupiter.api.Test; - -public class ProviderTest { - @Test - public void providerTest() { - assertThrows(IllegalArgumentException.class, () -> WebsocketImplProvider.getWebsocketImpl(OkHttpWebsocket.class, null, null)); - } - - @Test - public void getImplTest() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, URISyntaxException { - WebsocketRemoteConnectionEndpoint endpoint = new WebsocketRemoteConnectionEndpoint("wss://localhost.org:7443/ws/"); - - List discoveredRemoteConnectionEndpoints = new ArrayList<>(); - discoveredRemoteConnectionEndpoints.add(endpoint); - - Result result = new Result(discoveredRemoteConnectionEndpoints, null); - - DiscoveredWebsocketEndpoints discoveredWebsocketEndpoints = mock(DiscoveredWebsocketEndpoints.class); - when(discoveredWebsocketEndpoints.getResult()).thenReturn(result); - - ModularXmppClientToServerConnectionInternal connectionInternal = mock(ModularXmppClientToServerConnectionInternal.class); - - assertNotNull(WebsocketImplProvider.getWebsocketImpl(OkHttpWebsocket.class, connectionInternal, discoveredWebsocketEndpoints)); - } -} diff --git a/smack-websocket/src/testFixtures/java/org/jivesoftware/smack/websocket/test/WebsocketFactoryServiceTestUtil.java b/smack-websocket/src/testFixtures/java/org/jivesoftware/smack/websocket/test/WebsocketFactoryServiceTestUtil.java new file mode 100644 index 000000000..1f4a29e60 --- /dev/null +++ b/smack-websocket/src/testFixtures/java/org/jivesoftware/smack/websocket/test/WebsocketFactoryServiceTestUtil.java @@ -0,0 +1,36 @@ +/** + * + * Copyright 2020 Florian Schmaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smack.websocket.test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import static org.mockito.Mockito.mock; + +import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal; +import org.jivesoftware.smack.websocket.impl.AbstractWebsocket; +import org.jivesoftware.smack.websocket.impl.WebsocketFactoryService; + +public class WebsocketFactoryServiceTestUtil { + + public static void createWebsocketTest(Class expected) { + ModularXmppClientToServerConnectionInternal connectionInternal = mock(ModularXmppClientToServerConnectionInternal.class); + + AbstractWebsocket websocket = WebsocketFactoryService.createWebsocket(connectionInternal); + assertEquals(expected, websocket.getClass()); + } + +}