2015-03-18 09:52:33 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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 java.util.List;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.MessageListener;
|
|
|
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
|
|
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|
|
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
|
|
|
import org.jivesoftware.smack.packet.Message;
|
|
|
|
import org.jivesoftware.smack.util.StringUtils;
|
2015-04-21 19:05:22 +02:00
|
|
|
import org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
|
|
|
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
|
|
|
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
|
|
|
|
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
|
|
|
import org.igniterealtime.smack.inttest.TestNotPossibleException;
|
|
|
|
import org.igniterealtime.smack.inttest.util.ResultSyncPoint;
|
2015-03-18 09:52:33 +01:00
|
|
|
import org.jxmpp.jid.DomainBareJid;
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jxmpp.jid.EntityBareJid;
|
2015-03-18 09:52:33 +01:00
|
|
|
import org.jxmpp.jid.impl.JidCreate;
|
|
|
|
import org.jxmpp.jid.parts.Localpart;
|
|
|
|
import org.jxmpp.jid.parts.Resourcepart;
|
|
|
|
|
|
|
|
public class MultiUserChatIntegrationTest extends AbstractSmackIntegrationTest {
|
|
|
|
|
2016-01-06 14:56:49 +01:00
|
|
|
private final String randomString = StringUtils.insecureRandomString(6);
|
2015-03-18 09:52:33 +01:00
|
|
|
|
|
|
|
private final MultiUserChatManager mucManagerOne;
|
|
|
|
private final MultiUserChatManager mucManagerTwo;
|
|
|
|
private final DomainBareJid mucService;
|
|
|
|
|
|
|
|
public MultiUserChatIntegrationTest(SmackIntegrationTestEnvironment environment)
|
|
|
|
throws NoResponseException, XMPPErrorException, NotConnectedException,
|
|
|
|
InterruptedException, TestNotPossibleException {
|
|
|
|
super(environment);
|
|
|
|
mucManagerOne = MultiUserChatManager.getInstanceFor(conOne);
|
|
|
|
mucManagerTwo = MultiUserChatManager.getInstanceFor(conTwo);
|
|
|
|
|
2015-05-18 16:48:23 +02:00
|
|
|
List<DomainBareJid> services = mucManagerOne.getXMPPServiceDomains();
|
2015-03-18 09:52:33 +01:00
|
|
|
if (services.isEmpty()) {
|
|
|
|
throw new TestNotPossibleException("No MUC (XEP-45) service found");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mucService = services.get(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SmackIntegrationTest
|
2017-12-13 23:10:11 +01:00
|
|
|
public void mucTest() throws Exception {
|
2015-06-06 09:00:19 +02:00
|
|
|
EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from("smack-inttest-" + randomString), mucService.getDomain());
|
2015-03-18 09:52:33 +01:00
|
|
|
|
|
|
|
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
|
|
|
|
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
|
|
|
|
|
|
|
|
final String mucMessage = "Smack Integration Test MUC Test Message " + randomString;
|
|
|
|
final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
|
|
|
|
|
|
|
|
mucAsSeenByTwo.addMessageListener(new MessageListener() {
|
|
|
|
@Override
|
|
|
|
public void processMessage(Message message) {
|
|
|
|
String body = message.getBody();
|
|
|
|
if (mucMessage.equals(body)) {
|
|
|
|
resultSyncPoint.signal(body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-21 19:05:22 +02:00
|
|
|
MucCreateConfigFormHandle handle = mucAsSeenByOne.createOrJoin(Resourcepart.from("one-" + randomString));
|
|
|
|
if (handle != null) {
|
|
|
|
handle.makeInstant();
|
2015-03-18 09:52:33 +01:00
|
|
|
}
|
|
|
|
mucAsSeenByTwo.join(Resourcepart.from("two-" + randomString));
|
|
|
|
|
|
|
|
mucAsSeenByOne.sendMessage(mucMessage);
|
2016-12-19 14:35:09 +01:00
|
|
|
resultSyncPoint.waitForResult(timeout);
|
2015-03-18 09:52:33 +01:00
|
|
|
|
|
|
|
mucAsSeenByOne.leave();
|
|
|
|
mucAsSeenByTwo.leave();
|
|
|
|
}
|
|
|
|
}
|