Browse Source

Integrate implementation of XEP-0249 with existing MUC invitation code

invitation
Paul Schaub 2 months ago
parent
commit
190f3888be
No known key found for this signature in database GPG Key ID: 62BEE9264BF17311
11 changed files with 161 additions and 278 deletions
  1. +0
    -127
      smack-extensions/src/main/java/org/jivesoftware/smackx/invitation/element/DirectMucInvitationElement.java
  2. +0
    -21
      smack-extensions/src/main/java/org/jivesoftware/smackx/invitation/element/package-info.java
  3. +0
    -21
      smack-extensions/src/main/java/org/jivesoftware/smackx/invitation/package-info.java
  4. +0
    -21
      smack-extensions/src/main/java/org/jivesoftware/smackx/invitation/provider/package-info.java
  5. +3
    -3
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DirectMucInvitationListener.java
  6. +8
    -9
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DirectMucInvitationManager.java
  7. +4
    -0
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java
  8. +125
    -50
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/GroupChatInvitation.java
  9. +12
    -11
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/GroupChatInvitationProvider.java
  10. +1
    -6
      smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers
  11. +8
    -9
      smack-extensions/src/test/java/org/jivesoftware/smackx/muc/packet/GroupChatInvitationElementTest.java

+ 0
- 127
smack-extensions/src/main/java/org/jivesoftware/smackx/invitation/element/DirectMucInvitationElement.java View File

@@ -1,127 +0,0 @@
/**
*
* Copyright 2020 Paul Schaub.
*
* 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.invitation.element;

import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.util.HashCode;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.XmlStringBuilder;

import org.jxmpp.jid.EntityBareJid;

public class DirectMucInvitationElement implements ExtensionElement {

public static final String ELEMENT = "x";
public static final String NAMESPACE = "jabber:x:conference";
public static final String ATTR_CONTINUE = "continue";
public static final String ATTR_JID = "jid";
public static final String ATTR_PASSWORD = "password";
public static final String ATTR_REASON = "reason";
public static final String ATTR_THREAD = "thread";

private final EntityBareJid jid;
private final String password;
private final String reason;
private final boolean _continue;
private final String thread;

public DirectMucInvitationElement(EntityBareJid mucJid) {
this(mucJid, null, null, false, null);
}

public DirectMucInvitationElement(EntityBareJid mucJid, String password, String reason, boolean _continue, String thread) {
this.jid = Objects.requireNonNull(mucJid);
this.password = password;
this.reason = reason;
this._continue = _continue;
this.thread = thread;
}

public EntityBareJid getJid() {
return jid;
}

public String getPassword() {
return password;
}

public String getReason() {
return reason;
}

public boolean isContinue() {
return _continue;
}

public String getThread() {
return thread;
}

@Override
public String getNamespace() {
return NAMESPACE;
}

@Override
public String getElementName() {
return ELEMENT;
}

@Override
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
return new XmlStringBuilder(this)
.optBooleanAttribute(ATTR_CONTINUE, isContinue())
.attribute(ATTR_JID, getJid())
.optAttribute(ATTR_PASSWORD, getPassword())
.optAttribute(ATTR_REASON, getReason())
.optAttribute(ATTR_THREAD, getThread())
.closeEmptyElement();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (!(obj instanceof DirectMucInvitationElement)) {
return false;
}

DirectMucInvitationElement other = (DirectMucInvitationElement) obj;

return Objects.equals(getJid(), other.getJid())
&& Objects.equals(getPassword(), other.getPassword())
&& Objects.equals(getReason(), other.getReason())
&& isContinue() == other.isContinue()
&& Objects.equals(getThread(), other.getThread());
}

@Override
public int hashCode() {
return HashCode.builder()
.append(getJid())
.append(getPassword())
.append(getReason())
.append(isContinue())
.append(getThread())
.build();
}
}

+ 0
- 21
smack-extensions/src/main/java/org/jivesoftware/smackx/invitation/element/package-info.java View File

@@ -1,21 +0,0 @@
/**
*
* Copyright 2020 Paul Schaub
*
* 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.
*/

/**
* Smack's API for XEP-0249: Direct MUC Invitations.
*/
package org.jivesoftware.smackx.invitation.element;

+ 0
- 21
smack-extensions/src/main/java/org/jivesoftware/smackx/invitation/package-info.java View File

@@ -1,21 +0,0 @@
/**
*
* Copyright 2020 Paul Schaub
*
* 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.
*/

/**
* Smack's API for XEP-0249: Direct MUC Invitations.
*/
package org.jivesoftware.smackx.invitation;

+ 0
- 21
smack-extensions/src/main/java/org/jivesoftware/smackx/invitation/provider/package-info.java View File

@@ -1,21 +0,0 @@
/**
*
* Copyright 2020 Paul Schaub
*
* 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.
*/

/**
* Smack's API for XEP-0249: Direct MUC Invitations.
*/
package org.jivesoftware.smackx.invitation.provider;

smack-extensions/src/main/java/org/jivesoftware/smackx/invitation/DirectMucInvitationListener.java → smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DirectMucInvitationListener.java View File

@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.invitation;
package org.jivesoftware.smackx.muc;

import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smackx.invitation.element.DirectMucInvitationElement;
import org.jivesoftware.smackx.muc.packet.GroupChatInvitation;

public interface DirectMucInvitationListener {

void invitationReceived(DirectMucInvitationElement invitation, Stanza stanza);
void invitationReceived(GroupChatInvitation invitation, Stanza stanza);
}

smack-extensions/src/main/java/org/jivesoftware/smackx/invitation/DirectMucInvitationManager.java → smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DirectMucInvitationManager.java View File

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.invitation;
package org.jivesoftware.smackx.muc;

import java.util.ArrayList;
import java.util.List;
@@ -30,8 +30,7 @@ import org.jivesoftware.smack.filter.StanzaExtensionFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.MessageBuilder;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.invitation.element.DirectMucInvitationElement;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.muc.packet.GroupChatInvitation;

import org.jxmpp.jid.EntityBareJid;

@@ -66,18 +65,18 @@ public final class DirectMucInvitationManager extends Manager {

private DirectMucInvitationManager(XMPPConnection connection) {
super(connection);
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(DirectMucInvitationElement.NAMESPACE);
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(GroupChatInvitation.NAMESPACE);

registerExtensionElementListener();
}

private void registerExtensionElementListener() {
connection().addAsyncStanzaListener(stanza -> {
DirectMucInvitationElement invitation = stanza.getExtension(DirectMucInvitationElement.ELEMENT, DirectMucInvitationElement.NAMESPACE);
GroupChatInvitation invitation = stanza.getExtension(GroupChatInvitation.class);
for (DirectMucInvitationListener listener : directMucInvitationListeners) {
listener.invitationReceived(invitation, stanza);
}
}, new StanzaExtensionFilter(DirectMucInvitationElement.ELEMENT, DirectMucInvitationElement.NAMESPACE));
}, new StanzaExtensionFilter(GroupChatInvitation.ELEMENT, GroupChatInvitation.NAMESPACE));
}

public void inviteToMuc(MultiUserChat muc, EntityBareJid user)
@@ -87,10 +86,10 @@ public final class DirectMucInvitationManager extends Manager {

public void inviteToMuc(MultiUserChat muc, EntityBareJid user, String password, String reason, boolean _continue, String thread)
throws SmackException.NotConnectedException, InterruptedException {
inviteToMuc(user, new DirectMucInvitationElement(muc.getRoom(), password, reason, _continue, thread));
inviteToMuc(user, new GroupChatInvitation(muc.getRoom(), password, reason, _continue, thread));
}

public void inviteToMuc(EntityBareJid jid, DirectMucInvitationElement invitation) throws SmackException.NotConnectedException, InterruptedException {
public void inviteToMuc(EntityBareJid jid, GroupChatInvitation invitation) throws SmackException.NotConnectedException, InterruptedException {
Message invitationMessage = MessageBuilder.buildMessage()
.to(jid)
.addExtension(invitation)
@@ -101,7 +100,7 @@ public final class DirectMucInvitationManager extends Manager {
public boolean userSupportsInvitations(EntityBareJid jid)
throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
SmackException.NoResponseException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, DirectMucInvitationElement.NAMESPACE);
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, GroupChatInvitation.NAMESPACE);
}

public synchronized void addInvitationListener(DirectMucInvitationListener listener) {

+ 4
- 0
smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java View File

@@ -78,6 +78,10 @@ import org.jxmpp.jid.parts.Resourcepart;
* further attempts will be made for the other rooms.
* </p>
*
* Note:
* For inviting other users to a group chat or listening for such invitations, take a look at the
* {@link DirectMucInvitationManager} which provides an implementation of XEP-0249: Direct MUC Invitations.
*
* @see <a href="http://xmpp.org/extensions/xep-0045.html">XEP-0045: Multi-User Chat</a>
*/
public final class MultiUserChatManager extends Manager {


+ 125
- 50
smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/GroupChatInvitation.java View File

@@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software.
* Copyright 2003-2007 Jive Software, 2020 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,46 +17,27 @@

package org.jivesoftware.smackx.muc.packet;

import java.io.IOException;

import javax.xml.namespace.QName;

import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.HashCode;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;

import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;

/**
* A group chat invitation stanza extension, which is used to invite other
* users to a group chat room. To invite a user to a group chat room, address
* a new message to the user and set the room name appropriately, as in the
* following code example:
*
* <pre>
* Message message = new Message("user@chat.example.com");
* message.setBody("Join me for a group chat!");
* message.addExtension(new GroupChatInvitation("room@chat.example.com"););
* con.sendStanza(message);
* </pre>
*
* To listen for group chat invitations, use a StanzaExtensionFilter for the
* <code>x</code> element name and <code>jabber:x:conference</code> namespace, as in the
* following code example:
* users to a group chat room.
*
* <pre>
* PacketFilter filter = new StanzaExtensionFilter("x", "jabber:x:conference");
* // Create a stanza collector or stanza listeners using the filter...
* </pre>
*
* <b>Note</b>: this protocol is outdated now that the Multi-User Chat (MUC) XEP is available
* (<a href="http://www.xmpp.org/extensions/jep-0045.html">XEP-45</a>). However, most
* existing clients still use this older protocol. Once MUC support becomes more
* widespread, this API may be deprecated.
* This implementation now conforms to XEP-0249: Direct MUC Invitations,
* while staying backwards compatible to legacy MUC invitations.
*
* @author Matt Tucker
* @author Paul Schaub
*/
public class GroupChatInvitation implements ExtensionElement {

@@ -69,10 +50,19 @@ public class GroupChatInvitation implements ExtensionElement {
* Namespace of the stanza extension.
*/
public static final String NAMESPACE = "jabber:x:conference";

public static final QName QNAME = new QName(NAMESPACE, ELEMENT);

private final String roomAddress;
public static final String ATTR_CONTINUE = "continue";
public static final String ATTR_JID = "jid";
public static final String ATTR_PASSWORD = "password";
public static final String ATTR_REASON = "reason";
public static final String ATTR_THREAD = "thread";

private final EntityBareJid roomAddress;
private final String password;
private final String reason;
private final boolean _continue;
private final String thread;

/**
* Creates a new group chat invitation to the specified room address.
@@ -81,9 +71,23 @@ public class GroupChatInvitation implements ExtensionElement {
* <code>chat.example.com</code>.
*
* @param roomAddress the address of the group chat room.
* @deprecated use {@link #GroupChatInvitation(EntityBareJid)} instead.
*/
@Deprecated
public GroupChatInvitation(String roomAddress) {
this.roomAddress = roomAddress;
this(JidCreate.entityBareFromOrThrowUnchecked(roomAddress));
}

public GroupChatInvitation(EntityBareJid roomAddress) {
this(roomAddress, null, null, false, null);
}

public GroupChatInvitation(EntityBareJid mucJid, String password, String reason, boolean _continue, String thread) {
this.roomAddress = Objects.requireNonNull(mucJid);
this.password = password;
this.reason = reason;
this._continue = _continue;
this.thread = thread;
}

/**
@@ -91,12 +95,61 @@ public class GroupChatInvitation implements ExtensionElement {
* are in the form <code>room@service</code>, where <code>service</code> is
* the name of group chat server, such as <code>chat.example.com</code>.
*
* @deprecated use {@link #getRoomAddressJid()} instead.
* @return the address of the group chat room.
*/
@Deprecated
public String getRoomAddress() {
return roomAddress.asEntityBareJidString();
}

/**
* Returns the address of the group chat room as an {@link EntityBareJid}.
*
* @return room address
*/
public EntityBareJid getRoomAddressJid() {
return roomAddress;
}

/**
* Returns the password which is used to join the room.
* This value can be null if no password is required.
*
* @return password
*/
public String getPassword() {
return password;
}

/**
* Return the reason of invitation.
*
* @return reason
*/
public String getReason() {
return reason;
}

/**
* Returns true if the invitation represents the continuation of a one-to-one chat.
* The chat continues the thread returned by {@link #getThread()}.
*
* @return true if this is a continued one-to-one chat, false otherwise.
*/
public boolean isContinue() {
return _continue;
}

/**
* In case of a continuation, this returns the thread name of the one-to-one chat that is being continued.
*
* @return thread
*/
public String getThread() {
return thread;
}

@Override
public String getElementName() {
return ELEMENT;
@@ -108,11 +161,46 @@ public class GroupChatInvitation implements ExtensionElement {
}

@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.attribute("jid", getRoomAddress());
xml.closeEmptyElement();
return xml;
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
return new XmlStringBuilder(this)
.optBooleanAttribute(ATTR_CONTINUE, isContinue())
.attribute(ATTR_JID, getRoomAddressJid())
.optAttribute(ATTR_PASSWORD, getPassword())
.optAttribute(ATTR_REASON, getReason())
.optAttribute(ATTR_THREAD, getThread())
.closeEmptyElement();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (!(obj instanceof GroupChatInvitation)) {
return false;
}

GroupChatInvitation other = (GroupChatInvitation) obj;

return Objects.equals(getRoomAddressJid(), other.getRoomAddressJid())
&& Objects.equals(getPassword(), other.getPassword())
&& Objects.equals(getReason(), other.getReason())
&& isContinue() == other.isContinue()
&& Objects.equals(getThread(), other.getThread());
}

@Override
public int hashCode() {
return HashCode.builder()
.append(getRoomAddressJid())
.append(getPassword())
.append(getReason())
.append(isContinue())
.append(getThread())
.build();
}

/**
@@ -123,17 +211,4 @@ public class GroupChatInvitation implements ExtensionElement {
public static GroupChatInvitation from(Stanza packet) {
return packet.getExtension(GroupChatInvitation.class);
}

public static class Provider extends ExtensionElementProvider<GroupChatInvitation> {

@Override
public GroupChatInvitation parse(XmlPullParser parser,
int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException,
IOException {
String roomAddress = parser.getAttributeValue("", "jid");
// Advance to end of extension.
parser.next();
return new GroupChatInvitation(roomAddress);
}
}
}

smack-extensions/src/main/java/org/jivesoftware/smackx/invitation/provider/DirectMucInvitationElementProvider.java → smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/GroupChatInvitationProvider.java View File

@@ -14,13 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.invitation.provider;
package org.jivesoftware.smackx.muc.provider;

import static org.jivesoftware.smackx.invitation.element.DirectMucInvitationElement.ATTR_CONTINUE;
import static org.jivesoftware.smackx.invitation.element.DirectMucInvitationElement.ATTR_JID;
import static org.jivesoftware.smackx.invitation.element.DirectMucInvitationElement.ATTR_PASSWORD;
import static org.jivesoftware.smackx.invitation.element.DirectMucInvitationElement.ATTR_REASON;
import static org.jivesoftware.smackx.invitation.element.DirectMucInvitationElement.ATTR_THREAD;
import static org.jivesoftware.smackx.muc.packet.GroupChatInvitation.ATTR_CONTINUE;
import static org.jivesoftware.smackx.muc.packet.GroupChatInvitation.ATTR_JID;
import static org.jivesoftware.smackx.muc.packet.GroupChatInvitation.ATTR_PASSWORD;
import static org.jivesoftware.smackx.muc.packet.GroupChatInvitation.ATTR_REASON;
import static org.jivesoftware.smackx.muc.packet.GroupChatInvitation.ATTR_THREAD;

import java.io.IOException;

@@ -30,15 +30,16 @@ import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.invitation.element.DirectMucInvitationElement;
import org.jivesoftware.smackx.muc.packet.GroupChatInvitation;

public class DirectMucInvitationElementProvider extends ExtensionElementProvider<DirectMucInvitationElement> {
public class GroupChatInvitationProvider extends ExtensionElementProvider<GroupChatInvitation> {

public static final DirectMucInvitationElementProvider TEST_PROVIDER = new DirectMucInvitationElementProvider();
public static final GroupChatInvitationProvider TEST_PROVIDER = new GroupChatInvitationProvider();

@Override
public DirectMucInvitationElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
return new DirectMucInvitationElement(
public GroupChatInvitation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
return new GroupChatInvitation(
ParserUtils.getBareJidAttribute(parser, ATTR_JID),
parser.getAttributeValue(ATTR_PASSWORD),
parser.getAttributeValue(ATTR_REASON),

+ 1
- 6
smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers View File

@@ -510,12 +510,7 @@
<extensionProvider>
<elementName>x</elementName>
<namespace>jabber:x:conference</namespace>
<className>org.jivesoftware.smackx.muc.packet.GroupChatInvitation$Provider</className>
</extensionProvider>
<extensionProvider>
<elementName>x</elementName>
<namespace>jabber:x:conference</namespace>
<className>org.jivesoftware.smackx.invitation.provider.DirectMucInvitationElementProvider</className>
<className>org.jivesoftware.smackx.muc.provider.GroupChatInvitationProvider</className>
</extensionProvider>

<!-- XEP-0297: Stanza Forwarding -->


smack-extensions/src/test/java/org/jivesoftware/smackx/invitation/DirectMucInvitationElementTest.java → smack-extensions/src/test/java/org/jivesoftware/smackx/muc/packet/GroupChatInvitationElementTest.java View File

@@ -14,24 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.invitation;
package org.jivesoftware.smackx.muc.packet;

import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;

import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.invitation.element.DirectMucInvitationElement;
import org.jivesoftware.smackx.invitation.provider.DirectMucInvitationElementProvider;
import org.jivesoftware.smackx.muc.provider.GroupChatInvitationProvider;

import org.junit.jupiter.api.Test;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;

public class DirectMucInvitationElementTest {
public class GroupChatInvitationElementTest {

private static final EntityBareJid mucJid = JidCreate.entityBareFromOrThrowUnchecked("darkcave@macbeth.shakespeare.lit");

@@ -45,12 +44,12 @@ public class DirectMucInvitationElementTest {
" reason='Hey Hecate, this is the place for all good witches!'\n" +
" thread='e0ffe42b28561960c6b12b944a092794b9683a38'/>";

DirectMucInvitationElement invitation = new DirectMucInvitationElement(mucJid, "cauldronburn",
GroupChatInvitation invitation = new GroupChatInvitation(mucJid, "cauldronburn",
"Hey Hecate, this is the place for all good witches!", true,
"e0ffe42b28561960c6b12b944a092794b9683a38");
assertXmlSimilar(expectedXml, invitation.toXML());

DirectMucInvitationElement parsed = DirectMucInvitationElementProvider.TEST_PROVIDER.parse(TestUtils.getParser(expectedXml));
GroupChatInvitation parsed = GroupChatInvitationProvider.TEST_PROVIDER.parse(TestUtils.getParser(expectedXml));
assertEquals(invitation, parsed);
}

@@ -58,10 +57,10 @@ public class DirectMucInvitationElementTest {
public void serializeMinimalElementTest() throws XmlPullParserException, IOException, SmackParsingException {
final String expectedXml = "<x xmlns='jabber:x:conference' jid='darkcave@macbeth.shakespeare.lit'/>";

DirectMucInvitationElement invitation = new DirectMucInvitationElement(mucJid);
GroupChatInvitation invitation = new GroupChatInvitation(mucJid);
assertXmlSimilar(expectedXml, invitation.toXML());

DirectMucInvitationElement parsed = DirectMucInvitationElementProvider.TEST_PROVIDER.parse(TestUtils.getParser(expectedXml));
GroupChatInvitation parsed = GroupChatInvitationProvider.TEST_PROVIDER.parse(TestUtils.getParser(expectedXml));
assertEquals(invitation, parsed);
}
}

Loading…
Cancel
Save