mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
Add MucBookmarkAutojoinManager
Also add MucConfigFormManager and improve the MUC API (SMACK-648). Bump to jxmpp 0.5.0-alpha3. Improve and extend PrivateDataManager and BookmarkManager.
This commit is contained in:
parent
265e5c69d5
commit
f274581c27
15 changed files with 690 additions and 102 deletions
|
@ -30,8 +30,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.xdata.Form;
|
||||
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||
import org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.DomainBareJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
@ -82,9 +81,9 @@ public class MultiUserChatIntegrationTest extends AbstractSmackIntegrationTest {
|
|||
}
|
||||
});
|
||||
|
||||
boolean newlyCreated = mucAsSeenByOne.createOrJoin(Resourcepart.from("one-" + randomString));
|
||||
if (newlyCreated) {
|
||||
mucAsSeenByOne.sendConfigurationForm(new Form(DataForm.Type.submit));
|
||||
MucCreateConfigFormHandle handle = mucAsSeenByOne.createOrJoin(Resourcepart.from("one-" + randomString));
|
||||
if (handle != null) {
|
||||
handle.makeInstant();
|
||||
}
|
||||
mucAsSeenByTwo.join(Resourcepart.from("two-" + randomString));
|
||||
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015 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.smackx.muc;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.igniterealtime.smack.inttest.AbstractSmackLowLevelIntegrationTest;
|
||||
import org.igniterealtime.smack.inttest.Configuration;
|
||||
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
|
||||
import org.igniterealtime.smack.inttest.TestNotPossibleException;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.bookmarks.BookmarkManager;
|
||||
import org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle;
|
||||
import org.jivesoftware.smackx.muc.bookmarkautojoin.MucBookmarkAutojoinManager;
|
||||
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 {
|
||||
|
||||
public MultiUserChatLowLevelIntegrationTest(Configuration configuration, String testRunId) throws Exception {
|
||||
super(configuration, testRunId);
|
||||
performCheck(new ConnectionCallback() {
|
||||
@Override
|
||||
public void connectionCallback(XMPPTCPConnection connection) throws Exception {
|
||||
if (MultiUserChatManager.getInstanceFor(connection).getServiceNames().isEmpty()) {
|
||||
throw new TestNotPossibleException("MUC component not offered by service");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SmackIntegrationTest
|
||||
public void testMucBookmarksAutojoin(XMPPTCPConnection connection) throws InterruptedException,
|
||||
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);
|
||||
final DomainBareJid mucComponent = multiUserChatManager.getServiceNames().get(0);
|
||||
final MultiUserChat muc = multiUserChatManager.getMultiUserChat(JidCreate.bareFrom(
|
||||
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
|
||||
// after every login, it's not determinstic when this will be finished.
|
||||
// So we trigger it manually here.
|
||||
MucBookmarkAutojoinManager.getInstanceFor(connection).autojoinBookmarkedConferences();
|
||||
|
||||
assertTrue(muc.isJoined());
|
||||
|
||||
// If the test went well, leave the MUC
|
||||
muc.leave();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue