2015-04-21 19:05:22 +02:00
|
|
|
/**
|
|
|
|
*
|
2020-04-04 13:03:31 +02:00
|
|
|
* Copyright 2015-2020 Florian Schmaus
|
2015-04-21 19:05:22 +02: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.jivesoftware.smackx.muc;
|
|
|
|
|
2020-04-12 21:54:18 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
2015-04-21 19:05:22 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2019-02-04 08:59:39 +01:00
|
|
|
import org.jivesoftware.smack.AbstractXMPPConnection;
|
2015-04-21 19:05:22 +02:00
|
|
|
import org.jivesoftware.smack.SmackException;
|
|
|
|
import org.jivesoftware.smack.XMPPException;
|
|
|
|
import org.jivesoftware.smack.util.StringUtils;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-04-21 19:05:22 +02:00
|
|
|
import org.jivesoftware.smackx.bookmarks.BookmarkManager;
|
|
|
|
import org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle;
|
|
|
|
import org.jivesoftware.smackx.muc.bookmarkautojoin.MucBookmarkAutojoinManager;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
|
|
|
import org.igniterealtime.smack.inttest.AbstractSmackLowLevelIntegrationTest;
|
|
|
|
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
|
|
|
import org.igniterealtime.smack.inttest.TestNotPossibleException;
|
2020-04-12 21:54:18 +02:00
|
|
|
import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest;
|
2015-04-21 19:05:22 +02:00
|
|
|
import org.jxmpp.jid.DomainBareJid;
|
|
|
|
import org.jxmpp.jid.impl.JidCreate;
|
|
|
|
import org.jxmpp.jid.parts.Localpart;
|
|
|
|
import org.jxmpp.jid.parts.Resourcepart;
|
|
|
|
|
|
|
|
public class MultiUserChatLowLevelIntegrationTest extends AbstractSmackLowLevelIntegrationTest {
|
|
|
|
|
2020-04-04 13:03:31 +02:00
|
|
|
public MultiUserChatLowLevelIntegrationTest(SmackIntegrationTestEnvironment environment) throws Exception {
|
2016-12-19 18:10:04 +01:00
|
|
|
super(environment);
|
2019-02-04 08:59:39 +01:00
|
|
|
AbstractXMPPConnection connection = getConnectedConnection();
|
|
|
|
try {
|
|
|
|
if (MultiUserChatManager.getInstanceFor(connection).getMucServiceDomains().isEmpty()) {
|
|
|
|
throw new TestNotPossibleException("MUC component not offered by service");
|
2015-04-21 19:05:22 +02:00
|
|
|
}
|
2019-02-04 08:59:39 +01:00
|
|
|
} finally {
|
|
|
|
recycle(connection);
|
|
|
|
}
|
2015-04-21 19:05:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SmackIntegrationTest
|
2019-02-04 08:59:39 +01:00
|
|
|
public void testMucBookmarksAutojoin(AbstractXMPPConnection connection) throws InterruptedException,
|
2015-04-21 19:05:22 +02:00
|
|
|
TestNotPossibleException, XMPPException, SmackException, IOException {
|
|
|
|
final BookmarkManager bookmarkManager = BookmarkManager.getBookmarkManager(connection);
|
|
|
|
if (!bookmarkManager.isSupported()) {
|
|
|
|
throw new TestNotPossibleException("Private data storage not supported");
|
|
|
|
}
|
|
|
|
final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);
|
|
|
|
final Resourcepart mucNickname = Resourcepart.from("Nick-" + StringUtils.randomString(6));
|
|
|
|
final String randomMucName = StringUtils.randomString(6);
|
2018-04-18 09:11:04 +02:00
|
|
|
final DomainBareJid mucComponent = multiUserChatManager.getMucServiceDomains().get(0);
|
2015-06-06 09:00:19 +02:00
|
|
|
final MultiUserChat muc = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom(
|
2015-04-21 19:05:22 +02:00
|
|
|
Localpart.from(randomMucName), mucComponent));
|
|
|
|
|
|
|
|
MucCreateConfigFormHandle handle = muc.createOrJoin(mucNickname);
|
|
|
|
if (handle != null) {
|
|
|
|
handle.makeInstant();
|
|
|
|
}
|
|
|
|
muc.leave();
|
|
|
|
|
|
|
|
bookmarkManager.addBookmarkedConference("Smack Inttest: " + testRunId, muc.getRoom(), true,
|
|
|
|
mucNickname, null);
|
|
|
|
|
|
|
|
connection.disconnect();
|
|
|
|
connection.connect().login();
|
|
|
|
|
|
|
|
// MucBookmarkAutojoinManager is also able to do its task automatically
|
2017-12-13 23:10:11 +01:00
|
|
|
// after every login, it's not deterministic when this will be finished.
|
2015-04-21 19:05:22 +02:00
|
|
|
// So we trigger it manually here.
|
|
|
|
MucBookmarkAutojoinManager.getInstanceFor(connection).autojoinBookmarkedConferences();
|
|
|
|
|
|
|
|
assertTrue(muc.isJoined());
|
|
|
|
|
|
|
|
// If the test went well, leave the MUC
|
|
|
|
muc.leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|