1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-27 06:22:07 +01:00

Add Mix Providers and tests

This commit is contained in:
Paul Schaub 2020-03-02 17:04:04 +01:00
parent d38f1c7726
commit 310a48f161
46 changed files with 1460 additions and 3 deletions

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core;
public class MixCoreConstants {

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core;
import java.util.Map;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core;
import org.jivesoftware.smackx.mix.core.element.SubscribeElement;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import java.util.Collections;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import org.jivesoftware.smack.packet.ExtensionElement;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import org.jivesoftware.smack.packet.ExtensionElement;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import org.jivesoftware.smack.packet.NamedElement;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import java.util.List;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import org.jivesoftware.smack.packet.ExtensionElement;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import org.jivesoftware.smack.packet.ExtensionElement;
@ -21,6 +37,14 @@ public abstract class MixElement implements ExtensionElement {
this.jid = jid;
}
public NickElement getNick() {
return nick;
}
public JidElement getJid() {
return jid;
}
@Override
public String getElementName() {
return ELEMENT;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import org.jivesoftware.smack.packet.NamedElement;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import org.jivesoftware.smack.packet.ExtensionElement;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import org.jivesoftware.smack.packet.ExtensionElement;

View file

@ -1,7 +1,24 @@
/**
*
* 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.mix.core.element;
import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.mix.core.MixCoreConstants;
@ -32,4 +49,24 @@ public class SubscribeElement implements NamedElement {
.closeEmptyElement();
}
@Override
public int hashCode() {
return getValue().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
if (!(obj instanceof SubscribeElement)) {
return false;
}
SubscribeElement other = (SubscribeElement) obj;
return Objects.equals(getValue(), other.getValue());
}
}

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import java.util.List;

View file

@ -0,0 +1,39 @@
/**
*
* 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.mix.core.provider;
import java.io.IOException;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.CreateChannelElement;
public abstract class CreateChannelElementProvider<E extends CreateChannelElement> extends ExtensionElementProvider<E> {
public static class V1 extends CreateChannelElementProvider<CreateChannelElement.V1> {
@Override
public CreateChannelElement.V1 parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
String channel = parser.getAttributeValue("", CreateChannelElement.ATTR_CHANNEL);
return new CreateChannelElement.V1(channel);
}
}
}

View file

@ -0,0 +1,39 @@
/**
*
* 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.mix.core.provider;
import java.io.IOException;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.DestroyChannelElement;
public abstract class DestroyChannelElementProvider<E extends DestroyChannelElement> extends ExtensionElementProvider<E> {
public static class V1 extends DestroyChannelElementProvider<DestroyChannelElement.V1> {
@Override
public DestroyChannelElement.V1 parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
String channel = parser.getAttributeValue("", DestroyChannelElement.ATTR_CHANNEL);
return new DestroyChannelElement.V1(channel);
}
}
}

View file

@ -0,0 +1,64 @@
/**
*
* 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.mix.core.provider;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.JoinElement;
import org.jivesoftware.smackx.mix.core.element.NickElement;
import org.jivesoftware.smackx.mix.core.element.SubscribeElement;
public abstract class JoinElementProvider<E extends JoinElement> extends ExtensionElementProvider<E> {
public static class V1 extends JoinElementProvider<JoinElement.V1> {
@Override
public JoinElement.V1 parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
String id = parser.getAttributeValue("", JoinElement.ATTR_ID);
NickElement nickElement = null;
List<SubscribeElement> subscribeElements = new ArrayList<>();
while (true) {
XmlPullParser.TagEvent tag = parser.nextTag();
String elementName = parser.getName();
if (tag == XmlPullParser.TagEvent.START_ELEMENT) {
switch (elementName) {
case SubscribeElement.ELEMENT:
String node = parser.getAttributeValue("", SubscribeElement.ATTR_NODE);
subscribeElements.add(new SubscribeElement(node));
break;
case NickElement.ELEMENT:
String nick = parser.nextText();
nickElement = new NickElement(nick);
break;
}
} else if (JoinElement.ELEMENT.equals(elementName)) {
return new JoinElement.V1(id, subscribeElements, nickElement);
}
}
}
}
}

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.provider;
import java.io.IOException;
@ -9,12 +25,12 @@ import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.LeaveElement;
public abstract class LeaveElementProvider extends ExtensionElementProvider<LeaveElement> {
public abstract class LeaveElementProvider<E extends LeaveElement> extends ExtensionElementProvider<E> {
public static class V1 extends LeaveElementProvider {
public static class V1 extends LeaveElementProvider<LeaveElement.V1> {
@Override
public LeaveElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
public LeaveElement.V1 parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
return new LeaveElement.V1();
}

View file

@ -0,0 +1,59 @@
/**
*
* 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.mix.core.provider;
import java.io.IOException;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.JidElement;
import org.jivesoftware.smackx.mix.core.element.MixElement;
import org.jivesoftware.smackx.mix.core.element.NickElement;
import org.jxmpp.jid.impl.JidCreate;
public abstract class MixElementProvider<E extends MixElement> extends ExtensionElementProvider<E> {
public static class V1 extends MixElementProvider<MixElement.V1> {
@Override
public MixElement.V1 parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
NickElement nickElement = null;
JidElement jidElement = null;
while (true) {
XmlPullParser.TagEvent tag = parser.nextTag();
String name = parser.getName();
if (tag == XmlPullParser.TagEvent.START_ELEMENT) {
switch (name) {
case NickElement.ELEMENT:
nickElement = new NickElement(parser.nextText());
break;
case JidElement.ELEMENT:
jidElement = new JidElement(JidCreate.entityBareFrom(parser.nextText()));
break;
}
} else if (MixElement.ELEMENT.equals(name)) {
return new MixElement.V1(nickElement, jidElement);
}
}
}
}
}

View file

@ -0,0 +1,59 @@
/**
*
* 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.mix.core.provider;
import java.io.IOException;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.JidElement;
import org.jivesoftware.smackx.mix.core.element.NickElement;
import org.jivesoftware.smackx.mix.core.element.ParticipantElement;
import org.jxmpp.jid.impl.JidCreate;
public abstract class ParticipantElementProvider<E extends ParticipantElement> extends ExtensionElementProvider<E> {
public static class V1 extends ParticipantElementProvider<ParticipantElement.V1> {
@Override
public ParticipantElement.V1 parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
NickElement nickElement = null;
JidElement jidElement = null;
while (true) {
XmlPullParser.TagEvent tag = parser.nextTag();
String name = parser.getName();
if (tag == XmlPullParser.TagEvent.START_ELEMENT) {
switch (name) {
case NickElement.ELEMENT:
nickElement = new NickElement(parser.nextText());
break;
case JidElement.ELEMENT:
jidElement = new JidElement(JidCreate.entityBareFrom(parser.nextText()));
break;
}
} else if (ParticipantElement.ELEMENT.equals(name)) {
return new ParticipantElement.V1(nickElement, jidElement);
}
}
}
}
}

View file

@ -0,0 +1,52 @@
/**
*
* 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.mix.core.provider;
import java.io.IOException;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.NickElement;
import org.jivesoftware.smackx.mix.core.element.SetNickElement;
public abstract class SetNickElementProvider<E extends SetNickElement> extends ExtensionElementProvider<E> {
public static class V1 extends SetNickElementProvider<SetNickElement.V1> {
@Override
public SetNickElement.V1 parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
NickElement nickElement = null;
while (true) {
XmlPullParser.TagEvent tagEvent = parser.nextTag();
String name = parser.getName();
if (tagEvent == XmlPullParser.TagEvent.START_ELEMENT) {
if (NickElement.ELEMENT.equals(name)) {
nickElement = new NickElement(parser.nextText());
}
} else if (tagEvent == XmlPullParser.TagEvent.END_ELEMENT) {
if (SetNickElement.ELEMENT.equals(name)) {
return new SetNickElement.V1(nickElement);
}
}
}
}
}
}

View file

@ -0,0 +1,59 @@
/**
*
* 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.mix.core.provider;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
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.mix.core.element.SubscribeElement;
import org.jivesoftware.smackx.mix.core.element.UpdateSubscriptionElement;
import org.jxmpp.jid.EntityBareJid;
public abstract class UpdateSubscriptionElementProvider<E extends UpdateSubscriptionElement> extends ExtensionElementProvider<E> {
public static class V1 extends UpdateSubscriptionElementProvider<UpdateSubscriptionElement.V1> {
@Override
public UpdateSubscriptionElement.V1 parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
EntityBareJid jid = ParserUtils.getBareJidAttribute(parser, UpdateSubscriptionElement.ATTR_JID);
List<SubscribeElement> subscribeElementList = new ArrayList<>();
while(true) {
XmlPullParser.TagEvent tag = parser.nextTag();
String name = parser.getName();
if (tag == XmlPullParser.TagEvent.START_ELEMENT) {
if (name.equals(SubscribeElement.ELEMENT)) {
subscribeElementList.add(new SubscribeElement(parser.getAttributeValue("", SubscribeElement.ATTR_NODE)));
}
} else if (tag == XmlPullParser.TagEvent.END_ELEMENT) {
if (name.equals(UpdateSubscriptionElement.ELEMENT)) {
return new UpdateSubscriptionElement.V1(subscribeElementList, jid);
}
}
}
}
}
}

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.pam;
import static org.jivesoftware.smackx.mix.core.MixCoreConstants.URN_XMPP_MIX;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.pam.element;
import org.jivesoftware.smack.packet.ExtensionElement;

View file

@ -0,0 +1,59 @@
/**
*
* 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.mix.pam.provider;
import java.io.IOException;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
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.mix.core.element.JoinElement;
import org.jivesoftware.smackx.mix.core.provider.JoinElementProvider;
import org.jivesoftware.smackx.mix.pam.element.ClientJoinElement;
import org.jxmpp.jid.EntityBareJid;
public abstract class ClientJoinElementProvider<E extends ClientJoinElement> extends ExtensionElementProvider<E> {
public static class V2 extends ClientJoinElementProvider<ClientJoinElement.V2> {
JoinElementProvider.V1 joinElementProvider = new JoinElementProvider.V1();
@Override
public ClientJoinElement.V2 parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
EntityBareJid channel = ParserUtils.getBareJidAttribute(parser, ClientJoinElement.ATTR_CHANNEL);
JoinElement.V1 joinElement = null;
while (true) {
XmlPullParser.TagEvent tagEvent = parser.nextTag();
String name = parser.getName();
if (tagEvent == XmlPullParser.TagEvent.START_ELEMENT) {
if (name.equals(JoinElement.ELEMENT)) {
joinElement = joinElementProvider.parse(parser);
}
} else if (tagEvent == XmlPullParser.TagEvent.END_ELEMENT) {
if (name.equals(ClientJoinElement.ELEMENT)) {
return new ClientJoinElement.V2(channel, joinElement);
}
}
}
}
}
}

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.core.element;
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;

View file

@ -0,0 +1,54 @@
/**
*
* 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.mix.core.provider;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.IOException;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.CreateChannelElement;
import org.junit.jupiter.api.Test;
public class CreateChannelElementProviderTest {
@Test
public void v1ProviderEmptyElementTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "<create xmlns='urn:xmpp:mix:core:1'/>";
CreateChannelElementProvider.V1 provider = new CreateChannelElementProvider.V1();
XmlPullParser parser = TestUtils.getParser(xml);
CreateChannelElement.V1 element = provider.parse(parser);
assertNull(element.getChannel());
}
@Test
public void v1ProviderWithChannelTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "<create channel='coven' xmlns='urn:xmpp:mix:core:1'/>";
String channel = "coven";
CreateChannelElementProvider.V1 provider = new CreateChannelElementProvider.V1();
XmlPullParser parser = TestUtils.getParser(xml);
CreateChannelElement.V1 element = provider.parse(parser);
assertEquals(channel, element.getChannel());
}
}

View file

@ -0,0 +1,46 @@
/**
*
* 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.mix.core.provider;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.DestroyChannelElement;
import org.junit.jupiter.api.Test;
public class DestroyChannelElementProviderTest {
@Test
public void v1ProviderTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "<destroy channel='coven' xmlns='urn:xmpp:mix:core:1'/>";
String channel = "coven";
DestroyChannelElementProvider.V1 provider = new DestroyChannelElementProvider.V1();
XmlPullParser parser = TestUtils.getParser(xml);
DestroyChannelElement.V1 element = provider.parse(parser);
assertNotNull(element);
assertEquals(channel, element.getChannel());
}
}

View file

@ -0,0 +1,97 @@
/**
*
* 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.mix.core.provider;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.MixNodes;
import org.jivesoftware.smackx.mix.core.element.JoinElement;
import org.junit.jupiter.api.Test;
public class JoinElementProviderTest {
@Test
public void v1ProviderTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "" +
"<join xmlns='urn:xmpp:mix:core:1'\n" +
" id='123456'>\n" +
" <subscribe node='urn:xmpp:mix:nodes:messages'/>\n" +
" <subscribe node='urn:xmpp:mix:nodes:presence'/>\n" +
" <subscribe node='urn:xmpp:mix:nodes:participants'/>\n" +
" <subscribe node='urn:xmpp:mix:nodes:info'/>\n" +
" <nick>third witch</nick>\n" +
"</join>";
JoinElementProvider.V1 provider = new JoinElementProvider.V1();
XmlPullParser parser = TestUtils.getParser(xml);
JoinElement.V1 element = provider.parse(parser);
assertEquals("123456", element.getId());
assertNotNull(element.getNick());
assertEquals("third witch", element.getNick().getValue());
assertEquals(4, element.getNodeSubscriptions().size());
assertEquals(MixNodes.NODE_MESSAGES, element.getNodeSubscriptions().get(0));
assertEquals(MixNodes.NODE_PRESENCE, element.getNodeSubscriptions().get(1));
assertEquals(MixNodes.NODE_PARTICIPANTS, element.getNodeSubscriptions().get(2));
assertEquals(MixNodes.NODE_INFO, element.getNodeSubscriptions().get(3));
}
@Test
public void ignoreUnknownElementsTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "" +
"<join xmlns='urn:xmpp:mix:core:1'\n" +
" id='123456'>\n" +
" <subscribe node='urn:xmpp:mix:nodes:messages'/>\n" +
" <ignore me='please'/>\n" +
" <nick>third witch</nick>\n" +
"</join>";
JoinElementProvider.V1 provider = new JoinElementProvider.V1();
XmlPullParser parser = TestUtils.getParser(xml);
JoinElement.V1 element = provider.parse(parser);
assertEquals("123456", element.getId());
assertEquals(1, element.getNodeSubscriptions().size());
assertEquals("third witch", element.getNick().getValue());
}
@Test
public void ignoreUnknownAttributeTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "" +
"<join xmlns='urn:xmpp:mix:core:1'\n" +
" id='123456' ignore='me'>\n" +
" <subscribe node='urn:xmpp:mix:nodes:messages'/>\n" +
" <nick>third witch</nick>\n" +
"</join>";
JoinElementProvider.V1 provider = new JoinElementProvider.V1();
XmlPullParser parser = TestUtils.getParser(xml);
JoinElement.V1 element = provider.parse(parser);
assertEquals("123456", element.getId());
assertEquals(1, element.getNodeSubscriptions().size());
assertEquals("third witch", element.getNick().getValue());
}
}

View file

@ -0,0 +1,45 @@
/**
*
* 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.mix.core.provider;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.LeaveElement;
import org.junit.jupiter.api.Test;
public class LeaveElementProviderTest {
@Test
public void v1ProviderTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "<leave xmlns='urn:xmpp:mix:core:1'/>";
LeaveElementProvider.V1 provider = new LeaveElementProvider.V1();
XmlPullParser parser = TestUtils.getParser(xml);
LeaveElement element = provider.parse(parser);
assertNotNull(element);
assertTrue(element instanceof LeaveElement.V1);
}
}

View file

@ -0,0 +1,54 @@
/**
*
* 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.mix.core.provider;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.MixElement;
import org.junit.jupiter.api.Test;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;
public class MixElementProviderTest {
@Test
public void v1ProviderTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "" +
"<mix xmlns='urn:xmpp:mix:core:1'>\n" +
" <nick>thirdwitch</nick>\n" +
" <jid>hag66@shakespeare.example</jid>\n" +
"</mix>";
String nick = "thirdwitch";
EntityBareJid jid = JidCreate.entityBareFromOrThrowUnchecked("hag66@shakespeare.example");
MixElementProvider.V1 provider = new MixElementProvider.V1();
XmlPullParser parser = TestUtils.getParser(xml);
MixElement.V1 element = provider.parse(parser);
assertNotNull(element);
assertEquals(nick, element.getNick().getValue());
assertEquals(jid, element.getJid().getValue());
}
}

View file

@ -0,0 +1,54 @@
/**
*
* 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.mix.core.provider;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.ParticipantElement;
import org.junit.jupiter.api.Test;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;
public class ParticipantElementProviderTest {
@Test
public void v1ProviderTest() throws XmlPullParserException, IOException, SmackParsingException {
final String xml = "" +
"<participant xmlns='urn:xmpp:mix:core:1'>\n" +
" <nick>thirdwitch</nick>\n" +
" <jid>hag66@shakespeare.example</jid>\n" +
"</participant>";
EntityBareJid jid = JidCreate.entityBareFromOrThrowUnchecked("hag66@shakespeare.example");
String nick = "thirdwitch";
ParticipantElementProvider.V1 provider = new ParticipantElementProvider.V1();
XmlPullParser parser = TestUtils.getParser(xml);
ParticipantElement.V1 element = provider.parse(parser);
assertNotNull(element);
assertEquals(jid, element.getJid().getValue());
assertEquals(nick, element.getNick().getValue());
}
}

View file

@ -0,0 +1,49 @@
/**
*
* 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.mix.core.provider;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.element.SetNickElement;
import org.junit.jupiter.api.Test;
public class SetNickElementProviderTest {
@Test
public void v1ProviderTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "" +
"<setnick xmlns='urn:xmpp:mix:core:1'>\n" +
" <nick>thirdwitch</nick>\n" +
"</setnick>";
String nick = "thirdwitch";
SetNickElementProvider.V1 provider = new SetNickElementProvider.V1();
XmlPullParser parser = TestUtils.getParser(xml);
SetNickElement.V1 element = provider.parse(parser);
assertNotNull(element);
assertEquals(nick, element.getNick().getValue());
}
}

View file

@ -0,0 +1,70 @@
/**
*
* 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.mix.core.provider;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.MixNodes;
import org.jivesoftware.smackx.mix.core.element.UpdateSubscriptionElement;
import org.junit.jupiter.api.Test;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;
public class UpdateSubscriptionElementProviderTest {
@Test
public void v1ProviderWithoutJidTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "" +
"<update-subscription xmlns='urn:xmpp:mix:core:1'>\n" +
" <subscribe node='urn:xmpp:mix:nodes:messages'/>\n" +
"</update-subscription>";
UpdateSubscriptionElementProvider.V1 provider = new UpdateSubscriptionElementProvider.V1();
XmlPullParser parser = TestUtils.getParser(xml);
UpdateSubscriptionElement.V1 element = provider.parse(parser);
assertNotNull(element);
assertEquals(1, element.getNodeSubscriptions().size());
assertEquals(MixNodes.NODE_MESSAGES, element.getNodeSubscriptions().get(0));
}
@Test
public void v1ProviderWithJidTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "<update-subscription xmlns='urn:xmpp:mix:core:1'\n" +
" jid='hag66@shakespeare.example'>\n" +
" <subscribe node='urn:xmpp:mix:nodes:messages'/>\n" +
" <subscribe node='urn:xmpp:mix:nodes:presence'/>\n" +
"</update-subscription>";
EntityBareJid jid = JidCreate.entityBareFromOrThrowUnchecked("hag66@shakespeare.example");
UpdateSubscriptionElementProvider.V1 provider = new UpdateSubscriptionElementProvider.V1();
XmlPullParser parser = TestUtils.getParser(xml);
UpdateSubscriptionElement.V1 element = provider.parse(parser);
assertNotNull(element);
assertEquals(2, element.getNodeSubscriptions().size());
assertEquals(jid, element.getJid());
}
}

View file

@ -1,3 +1,19 @@
/**
*
* 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.mix.pam.element;
import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar;

View file

@ -0,0 +1,65 @@
/**
*
* 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.mix.pam.provider;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.mix.core.MixNodes;
import org.jivesoftware.smackx.mix.core.element.SubscribeElement;
import org.jivesoftware.smackx.mix.pam.element.ClientJoinElement;
import org.junit.jupiter.api.Test;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;
public class ClientJoinElementProviderTest {
@Test
public void v2ProviderTest() throws XmlPullParserException, IOException, SmackParsingException {
String xml = "" +
"<client-join xmlns='urn:xmpp:mix:pam:2' channel='coven@mix.shakespeare.example'>\n" +
" <join xmlns='urn:xmpp:mix:core:1'>\n" +
" <subscribe node='urn:xmpp:mix:nodes:messages'/>\n" +
" <subscribe node='urn:xmpp:mix:nodes:presence'/>\n" +
" <subscribe node='urn:xmpp:mix:nodes:participants'/>\n" +
" <subscribe node='urn:xmpp:mix:nodes:info'/>\n" +
" </join>\n" +
"</client-join>";
EntityBareJid channel = JidCreate.entityBareFromOrThrowUnchecked("coven@mix.shakespeare.example");
List<SubscribeElement> subscribeElements = Arrays.asList(
MixNodes.NODE_MESSAGES, MixNodes.NODE_PRESENCE, MixNodes.NODE_PARTICIPANTS, MixNodes.NODE_INFO);
ClientJoinElementProvider.V2 provider = new ClientJoinElementProvider.V2();
XmlPullParser parser = TestUtils.getParser(xml);
ClientJoinElement.V2 element = provider.parse(parser);
assertEquals(channel, element.getChannel());
assertEquals(4, element.getJoin().getNodeSubscriptions().size());
assertNull(element.getJoin().getId());
assertNull(element.getJoin().getNick());
assertEquals(subscribeElements, element.getJoin().getNodeSubscriptions());
}
}