2020-05-14 14:35:37 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection;
|
|
|
|
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration;
|
|
|
|
import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal;
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.jxmpp.stringprep.XmppStringprepException;
|
|
|
|
|
2020-09-01 21:30:14 +02:00
|
|
|
public class XmppWebSocketTransportModuleTest {
|
2020-05-14 14:35:37 +02:00
|
|
|
@Test
|
2020-09-01 21:30:14 +02:00
|
|
|
public void createWebSocketModuleConnectionInstanceTest() throws URISyntaxException, XmppStringprepException {
|
2020-05-14 14:35:37 +02:00
|
|
|
ModularXmppClientToServerConnectionConfiguration.Builder builder = ModularXmppClientToServerConnectionConfiguration
|
|
|
|
.builder();
|
|
|
|
|
|
|
|
builder.removeAllModules();
|
2020-09-01 21:30:14 +02:00
|
|
|
builder.addModule(XmppWebSocketTransportModuleDescriptor.class);
|
2020-05-14 14:35:37 +02:00
|
|
|
builder.setXmppAddressAndPassword("user5@localhost.org", "user5");
|
|
|
|
builder.setHost("localhost.org");
|
|
|
|
|
2020-09-01 21:30:14 +02:00
|
|
|
XmppWebSocketTransportModuleDescriptor.Builder websocketBuilder = XmppWebSocketTransportModuleDescriptor.getBuilder(builder);
|
|
|
|
websocketBuilder.explicitlySetWebSocketEndpointAndDiscovery(new URI("wss://localhost.org:7443/ws/"), false);
|
2020-05-14 14:35:37 +02:00
|
|
|
|
|
|
|
ModularXmppClientToServerConnectionConfiguration config = builder.build();
|
|
|
|
ModularXmppClientToServerConnection connection = new ModularXmppClientToServerConnection(config);
|
|
|
|
assertNotNull(connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void createDescriptorTest() throws URISyntaxException, XmppStringprepException {
|
2020-09-01 21:30:14 +02:00
|
|
|
XmppWebSocketTransportModuleDescriptor websocketTransportModuleDescriptor = getWebSocketDescriptor();
|
2020-05-14 14:35:37 +02:00
|
|
|
assertNotNull(websocketTransportModuleDescriptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void lookupConnectionEndpointsTest() throws URISyntaxException {
|
2020-09-01 21:30:14 +02:00
|
|
|
XmppWebSocketTransportModuleDescriptor websocketTransportModuleDescriptor = getWebSocketDescriptor();
|
2020-05-14 14:35:37 +02:00
|
|
|
ModularXmppClientToServerConnectionInternal connectionInternal = mock(ModularXmppClientToServerConnectionInternal.class);
|
|
|
|
|
2020-09-01 21:30:14 +02:00
|
|
|
XmppWebSocketTransportModule transportModule
|
|
|
|
= new XmppWebSocketTransportModule(websocketTransportModuleDescriptor, connectionInternal);
|
2020-05-14 14:35:37 +02:00
|
|
|
|
2020-09-01 21:30:14 +02:00
|
|
|
XmppWebSocketTransportModule.XmppWebSocketTransport transport = transportModule.getTransport();
|
2020-05-14 14:35:37 +02:00
|
|
|
assertNotNull(transport.lookupConnectionEndpoints());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-01 21:30:14 +02:00
|
|
|
private static XmppWebSocketTransportModuleDescriptor getWebSocketDescriptor() throws URISyntaxException {
|
2020-05-14 14:35:37 +02:00
|
|
|
ModularXmppClientToServerConnectionConfiguration.Builder builder = ModularXmppClientToServerConnectionConfiguration
|
|
|
|
.builder();
|
|
|
|
|
2020-09-01 21:30:14 +02:00
|
|
|
XmppWebSocketTransportModuleDescriptor.Builder websocketBuilder = XmppWebSocketTransportModuleDescriptor.getBuilder(builder);
|
|
|
|
websocketBuilder.explicitlySetWebSocketEndpointAndDiscovery(new URI("wss://localhost.org:7443/ws/"), false);
|
|
|
|
return (XmppWebSocketTransportModuleDescriptor) websocketBuilder.build();
|
2020-05-14 14:35:37 +02:00
|
|
|
}
|
|
|
|
}
|