2015-03-18 09:52:33 +01:00
|
|
|
/**
|
|
|
|
*
|
2017-03-09 21:35:29 +01:00
|
|
|
* Copyright 2015-2017 Florian Schmaus
|
2015-03-18 09:52:33 +01:00
|
|
|
*
|
|
|
|
* 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.igniterealtime.smack.inttest;
|
|
|
|
|
|
|
|
import java.security.KeyManagementException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
|
|
|
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-03-18 09:52:33 +01:00
|
|
|
import org.jxmpp.jid.DomainBareJid;
|
|
|
|
|
|
|
|
public abstract class AbstractSmackLowLevelIntegrationTest extends AbstractSmackIntTest {
|
|
|
|
|
2016-12-19 18:10:04 +01:00
|
|
|
private final SmackIntegrationTestEnvironment environment;
|
|
|
|
|
2015-03-18 09:52:33 +01:00
|
|
|
/**
|
|
|
|
* The configuration
|
|
|
|
*/
|
|
|
|
protected final Configuration configuration;
|
|
|
|
|
|
|
|
protected final DomainBareJid service;
|
|
|
|
|
2016-12-19 18:10:04 +01:00
|
|
|
public AbstractSmackLowLevelIntegrationTest(SmackIntegrationTestEnvironment environment) {
|
2017-03-09 21:35:29 +01:00
|
|
|
super(environment.testRunId, environment.configuration);
|
2016-12-19 18:10:04 +01:00
|
|
|
this.environment = environment;
|
|
|
|
this.configuration = environment.configuration;
|
2015-03-18 09:52:33 +01:00
|
|
|
this.service = configuration.service;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final XMPPTCPConnectionConfiguration.Builder getConnectionConfiguration() throws KeyManagementException, NoSuchAlgorithmException {
|
|
|
|
XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
|
2017-03-09 21:35:29 +01:00
|
|
|
if (configuration.tlsContext != null) {
|
|
|
|
builder.setCustomSSLContext(configuration.tlsContext);
|
2015-03-18 09:52:33 +01:00
|
|
|
}
|
|
|
|
builder.setSecurityMode(configuration.securityMode);
|
2015-06-08 14:39:05 +02:00
|
|
|
builder.setXmppDomain(service);
|
2015-03-18 09:52:33 +01:00
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void performCheck(ConnectionCallback callback) throws Exception {
|
2016-12-19 18:10:04 +01:00
|
|
|
XMPPTCPConnection connection = SmackIntegrationTestFramework.getConnectedConnection(environment, -1);
|
2015-03-18 09:52:33 +01:00
|
|
|
try {
|
|
|
|
callback.connectionCallback(connection);
|
|
|
|
} finally {
|
2016-11-27 21:14:44 +01:00
|
|
|
IntTestUtil.disconnectAndMaybeDelete(connection, configuration);
|
2015-03-18 09:52:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface ConnectionCallback {
|
2018-03-28 14:02:21 +02:00
|
|
|
void connectionCallback(XMPPTCPConnection connection) throws Exception;
|
2015-03-18 09:52:33 +01:00
|
|
|
}
|
|
|
|
}
|