AbstractSmackLowLevelIntegrationTest.java

  1. /**
  2.  *
  3.  * Copyright 2015-2023 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.igniterealtime.smack.inttest;

  18. import java.io.IOException;

  19. import org.jivesoftware.smack.AbstractXMPPConnection;
  20. import org.jivesoftware.smack.SmackException;
  21. import org.jivesoftware.smack.XMPPException;

  22. import org.jxmpp.jid.DomainBareJid;

  23. public abstract class AbstractSmackLowLevelIntegrationTest extends AbstractSmackIntTest {

  24.     public interface UnconnectedConnectionSource {
  25.         AbstractXMPPConnection getUnconnectedConnection();
  26.     }

  27.     private final SmackIntegrationTestEnvironment environment;

  28.     /**
  29.      * The configuration
  30.      */
  31.     protected final Configuration configuration;

  32.     protected final DomainBareJid service;

  33.     protected AbstractSmackLowLevelIntegrationTest(SmackIntegrationTestEnvironment environment) {
  34.         super(environment);
  35.         this.environment = environment;
  36.         this.configuration = environment.configuration;
  37.         this.service = configuration.service;
  38.     }

  39.     /**
  40.      * Get a connected connection. Note that this method will return a connection constructed via the default connection
  41.      * descriptor. It is primarily meant for integration tests to discover if the XMPP service supports a certain
  42.      * feature, that the integration test requires to run. This feature discovery is typically done in the constructor of the
  43.      * integration tests. And if the discovery fails a {@link TestNotPossibleException} should be thrown by the constructor.
  44.      *
  45.      * <p> Please ensure that you invoke {@link #recycle(AbstractXMPPConnection connection)} once you are done with this connection.
  46.      *
  47.      * @return a connected connection.
  48.      * @throws InterruptedException if the calling thread was interrupted.
  49.      * @throws SmackException if Smack detected an exceptional situation.
  50.      * @throws IOException if an I/O error occurred.
  51.      * @throws XMPPException if an XMPP protocol error was received.
  52.      */
  53.     protected AbstractXMPPConnection getConnectedConnection()
  54.                     throws InterruptedException, SmackException, IOException, XMPPException {
  55.         return environment.connectionManager.constructConnectedConnection();
  56.     }

  57.     protected void recycle(AbstractXMPPConnection connection) {
  58.         environment.connectionManager.recycle(connection);
  59.     }

  60. }