From 310a48f1615cb24fe0341d4e7142fe7e9d47749e Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 2 Mar 2020 17:04:04 +0100 Subject: [PATCH] Add Mix Providers and tests --- .../smackx/mix/core/MixCoreConstants.java | 16 +++ .../smackx/mix/core/MixManager.java | 16 +++ .../smackx/mix/core/MixNodes.java | 16 +++ ...AbstractSubscriptionsModifyingElement.java | 16 +++ .../core/element/CreateChannelElement.java | 16 +++ .../core/element/DestroyChannelElement.java | 16 +++ .../smackx/mix/core/element/JidElement.java | 16 +++ .../smackx/mix/core/element/JoinElement.java | 16 +++ .../smackx/mix/core/element/LeaveElement.java | 16 +++ .../smackx/mix/core/element/MixElement.java | 24 +++++ .../smackx/mix/core/element/NickElement.java | 16 +++ .../mix/core/element/ParticipantElement.java | 16 +++ .../mix/core/element/SetNickElement.java | 16 +++ .../mix/core/element/SubscribeElement.java | 37 +++++++ .../element/UpdateSubscriptionElement.java | 16 +++ .../CreateChannelElementProvider.java | 39 ++++++++ .../DestroyChannelElementProvider.java | 39 ++++++++ .../core/provider/JoinElementProvider.java | 64 ++++++++++++ .../core/provider/LeaveElementProvider.java | 22 ++++- .../mix/core/provider/MixElementProvider.java | 59 +++++++++++ .../provider/ParticipantElementProvider.java | 59 +++++++++++ .../core/provider/SetNickElementProvider.java | 52 ++++++++++ .../UpdateSubscriptionElementProvider.java | 59 +++++++++++ .../smackx/mix/pam/MixPamConstants.java | 16 +++ .../mix/pam/element/ClientJoinElement.java | 16 +++ .../provider/ClientJoinElementProvider.java | 59 +++++++++++ .../element/CreateChannelElementTest.java | 16 +++ .../element/DestroyChannelElementTest.java | 16 +++ .../mix/core/element/JidElementTest.java | 16 +++ .../mix/core/element/JoinElementTest.java | 16 +++ .../mix/core/element/LeaveElementTest.java | 16 +++ .../mix/core/element/MixElementTest.java | 16 +++ .../mix/core/element/NickElementTest.java | 16 +++ .../core/element/ParticipantElementTest.java | 16 +++ .../mix/core/element/SetNickElementTest.java | 16 +++ .../UpdateSubscriptionElementTest.java | 16 +++ .../CreateChannelElementProviderTest.java | 54 +++++++++++ .../DestroyChannelElementProviderTest.java | 46 +++++++++ .../provider/JoinElementProviderTest.java | 97 +++++++++++++++++++ .../provider/LeaveElementProviderTest.java | 45 +++++++++ .../core/provider/MixElementProviderTest.java | 54 +++++++++++ .../ParticipantElementProviderTest.java | 54 +++++++++++ .../provider/SetNickElementProviderTest.java | 49 ++++++++++ ...UpdateSubscriptionElementProviderTest.java | 70 +++++++++++++ .../pam/element/ClientJoinElementTest.java | 16 +++ .../ClientJoinElementProviderTest.java | 65 +++++++++++++ 46 files changed, 1460 insertions(+), 3 deletions(-) create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/CreateChannelElementProvider.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/DestroyChannelElementProvider.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/JoinElementProvider.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/MixElementProvider.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/ParticipantElementProvider.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/SetNickElementProvider.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/UpdateSubscriptionElementProvider.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/mix/pam/provider/ClientJoinElementProvider.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/CreateChannelElementProviderTest.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/DestroyChannelElementProviderTest.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/JoinElementProviderTest.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/LeaveElementProviderTest.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/MixElementProviderTest.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/ParticipantElementProviderTest.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/SetNickElementProviderTest.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/UpdateSubscriptionElementProviderTest.java create mode 100644 smack-experimental/src/test/java/org/jivesoftware/smackx/mix/pam/provider/ClientJoinElementProviderTest.java diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixCoreConstants.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixCoreConstants.java index 0df94fc17..762122851 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixCoreConstants.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixCoreConstants.java @@ -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 { diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixManager.java index b55750a27..569ef4a9a 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixManager.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixNodes.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixNodes.java index 628b5846a..30c5819da 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixNodes.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixNodes.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/AbstractSubscriptionsModifyingElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/AbstractSubscriptionsModifyingElement.java index b4b8c6664..5c78e7bf1 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/AbstractSubscriptionsModifyingElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/AbstractSubscriptionsModifyingElement.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/CreateChannelElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/CreateChannelElement.java index 6ba6ff4f2..1c7110e2d 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/CreateChannelElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/CreateChannelElement.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/DestroyChannelElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/DestroyChannelElement.java index 7cb603443..c0424439f 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/DestroyChannelElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/DestroyChannelElement.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/JidElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/JidElement.java index fa9a01ee0..54fa7b3b9 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/JidElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/JidElement.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/JoinElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/JoinElement.java index 51532ee10..9ac3a65ed 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/JoinElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/JoinElement.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/LeaveElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/LeaveElement.java index e70cb897e..47455011c 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/LeaveElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/LeaveElement.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/MixElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/MixElement.java index e81d043f0..ceac22a5b 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/MixElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/MixElement.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/NickElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/NickElement.java index 28c2e7b38..e3723c87e 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/NickElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/NickElement.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/ParticipantElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/ParticipantElement.java index 235f4d198..1d1c5b594 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/ParticipantElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/ParticipantElement.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/SetNickElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/SetNickElement.java index 5a49eac3e..549db5244 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/SetNickElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/SetNickElement.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/SubscribeElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/SubscribeElement.java index a61d48440..7e642742c 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/SubscribeElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/SubscribeElement.java @@ -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()); + } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/UpdateSubscriptionElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/UpdateSubscriptionElement.java index 5f3862e06..f34cf67f9 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/UpdateSubscriptionElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/element/UpdateSubscriptionElement.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/CreateChannelElementProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/CreateChannelElementProvider.java new file mode 100644 index 000000000..afe3f3baa --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/CreateChannelElementProvider.java @@ -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 extends ExtensionElementProvider { + + public static class V1 extends CreateChannelElementProvider { + + @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); + } + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/DestroyChannelElementProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/DestroyChannelElementProvider.java new file mode 100644 index 000000000..9cb62a065 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/DestroyChannelElementProvider.java @@ -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 extends ExtensionElementProvider { + + public static class V1 extends DestroyChannelElementProvider { + + @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); + } + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/JoinElementProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/JoinElementProvider.java new file mode 100644 index 000000000..d9f199250 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/JoinElementProvider.java @@ -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 extends ExtensionElementProvider { + + public static class V1 extends JoinElementProvider { + + @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 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); + } + } + } + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/LeaveElementProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/LeaveElementProvider.java index 31e280bac..4a19ac51b 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/LeaveElementProvider.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/LeaveElementProvider.java @@ -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 { +public abstract class LeaveElementProvider extends ExtensionElementProvider { - public static class V1 extends LeaveElementProvider { + public static class V1 extends LeaveElementProvider { @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(); } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/MixElementProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/MixElementProvider.java new file mode 100644 index 000000000..8d4bd957d --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/MixElementProvider.java @@ -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 extends ExtensionElementProvider { + + public static class V1 extends MixElementProvider { + + @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); + } + } + } + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/ParticipantElementProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/ParticipantElementProvider.java new file mode 100644 index 000000000..2819db6f3 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/ParticipantElementProvider.java @@ -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 extends ExtensionElementProvider { + + public static class V1 extends ParticipantElementProvider { + + @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); + } + } + } + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/SetNickElementProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/SetNickElementProvider.java new file mode 100644 index 000000000..7592ac0da --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/SetNickElementProvider.java @@ -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 extends ExtensionElementProvider { + + public static class V1 extends SetNickElementProvider { + + @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); + } + } + } + } + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/UpdateSubscriptionElementProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/UpdateSubscriptionElementProvider.java new file mode 100644 index 000000000..25b935889 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/provider/UpdateSubscriptionElementProvider.java @@ -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 extends ExtensionElementProvider { + + public static class V1 extends UpdateSubscriptionElementProvider { + + @Override + public UpdateSubscriptionElement.V1 parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) + throws XmlPullParserException, IOException, SmackParsingException { + EntityBareJid jid = ParserUtils.getBareJidAttribute(parser, UpdateSubscriptionElement.ATTR_JID); + List 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); + } + } + } + } + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/pam/MixPamConstants.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/pam/MixPamConstants.java index ada6852d4..62d9f19a1 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/pam/MixPamConstants.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/pam/MixPamConstants.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/pam/element/ClientJoinElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/pam/element/ClientJoinElement.java index 64047b85a..4fd690809 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/pam/element/ClientJoinElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/pam/element/ClientJoinElement.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/pam/provider/ClientJoinElementProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/pam/provider/ClientJoinElementProvider.java new file mode 100644 index 000000000..ae735df76 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/pam/provider/ClientJoinElementProvider.java @@ -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 extends ExtensionElementProvider { + + public static class V2 extends ClientJoinElementProvider { + 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); + } + } + } + } + } +} diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/CreateChannelElementTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/CreateChannelElementTest.java index 5548bc635..e5131326b 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/CreateChannelElementTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/CreateChannelElementTest.java @@ -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; diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/DestroyChannelElementTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/DestroyChannelElementTest.java index ee53ce134..11d0e2c0f 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/DestroyChannelElementTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/DestroyChannelElementTest.java @@ -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; diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/JidElementTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/JidElementTest.java index 6ee5e65d3..144425778 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/JidElementTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/JidElementTest.java @@ -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; diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/JoinElementTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/JoinElementTest.java index 3138c6d78..8ec69901b 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/JoinElementTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/JoinElementTest.java @@ -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; diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/LeaveElementTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/LeaveElementTest.java index 6c6a997e3..222a79d4a 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/LeaveElementTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/LeaveElementTest.java @@ -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; diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/MixElementTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/MixElementTest.java index f5505abca..afe566ec1 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/MixElementTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/MixElementTest.java @@ -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; diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/NickElementTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/NickElementTest.java index 7d07d3475..b9febd9fa 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/NickElementTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/NickElementTest.java @@ -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; diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/ParticipantElementTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/ParticipantElementTest.java index aaa115f7a..06dd96092 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/ParticipantElementTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/ParticipantElementTest.java @@ -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; diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/SetNickElementTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/SetNickElementTest.java index 62a5c72c2..d3bc0a0f9 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/SetNickElementTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/SetNickElementTest.java @@ -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; diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/UpdateSubscriptionElementTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/UpdateSubscriptionElementTest.java index 02b186556..8271c86c0 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/UpdateSubscriptionElementTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/element/UpdateSubscriptionElementTest.java @@ -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; diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/CreateChannelElementProviderTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/CreateChannelElementProviderTest.java new file mode 100644 index 000000000..cdce12a5a --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/CreateChannelElementProviderTest.java @@ -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 = ""; + 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 = ""; + String channel = "coven"; + CreateChannelElementProvider.V1 provider = new CreateChannelElementProvider.V1(); + XmlPullParser parser = TestUtils.getParser(xml); + + CreateChannelElement.V1 element = provider.parse(parser); + assertEquals(channel, element.getChannel()); + } +} diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/DestroyChannelElementProviderTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/DestroyChannelElementProviderTest.java new file mode 100644 index 000000000..a792ae195 --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/DestroyChannelElementProviderTest.java @@ -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 = ""; + 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()); + } +} diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/JoinElementProviderTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/JoinElementProviderTest.java new file mode 100644 index 000000000..c5af756c2 --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/JoinElementProviderTest.java @@ -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 = "" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " third witch\n" + + ""; + 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 = "" + + "\n" + + " \n" + + " \n" + + " third witch\n" + + ""; + 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 = "" + + "\n" + + " \n" + + " third witch\n" + + ""; + 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()); + } +} diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/LeaveElementProviderTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/LeaveElementProviderTest.java new file mode 100644 index 000000000..24c2dcd27 --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/LeaveElementProviderTest.java @@ -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 = ""; + LeaveElementProvider.V1 provider = new LeaveElementProvider.V1(); + XmlPullParser parser = TestUtils.getParser(xml); + + LeaveElement element = provider.parse(parser); + + assertNotNull(element); + assertTrue(element instanceof LeaveElement.V1); + } +} diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/MixElementProviderTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/MixElementProviderTest.java new file mode 100644 index 000000000..212435587 --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/MixElementProviderTest.java @@ -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 = "" + + "\n" + + " thirdwitch\n" + + " hag66@shakespeare.example\n" + + ""; + 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()); + } +} diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/ParticipantElementProviderTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/ParticipantElementProviderTest.java new file mode 100644 index 000000000..44575872b --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/ParticipantElementProviderTest.java @@ -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 = "" + + "\n" + + " thirdwitch\n" + + " hag66@shakespeare.example\n" + + ""; + 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()); + } +} diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/SetNickElementProviderTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/SetNickElementProviderTest.java new file mode 100644 index 000000000..99eab5308 --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/SetNickElementProviderTest.java @@ -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 = "" + + "\n" + + " thirdwitch\n" + + ""; + 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()); + } +} diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/UpdateSubscriptionElementProviderTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/UpdateSubscriptionElementProviderTest.java new file mode 100644 index 000000000..75217b729 --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/core/provider/UpdateSubscriptionElementProviderTest.java @@ -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 = "" + + "\n" + + " \n" + + ""; + 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 = "\n" + + " \n" + + " \n" + + ""; + 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()); + } +} diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/pam/element/ClientJoinElementTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/pam/element/ClientJoinElementTest.java index 65290d85e..4c0df6059 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/pam/element/ClientJoinElementTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/pam/element/ClientJoinElementTest.java @@ -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; diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/pam/provider/ClientJoinElementProviderTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/pam/provider/ClientJoinElementProviderTest.java new file mode 100644 index 000000000..d9d9525e3 --- /dev/null +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/mix/pam/provider/ClientJoinElementProviderTest.java @@ -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 = "" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + EntityBareJid channel = JidCreate.entityBareFromOrThrowUnchecked("coven@mix.shakespeare.example"); + List 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()); + } +}