1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-07 13:41:08 +01:00

Add support Multi-User Chat Light

Fixes SMACK-740
This commit is contained in:
Fernando Ramirez 2016-11-02 12:10:56 -03:00 committed by Florian Schmaus
parent eb9242768c
commit 5372c1bcf4
39 changed files with 4053 additions and 0 deletions

View file

@ -0,0 +1,92 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.AffiliationsChangeExtension;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightAffiliationsChangeExtensionTest {
String exampleMessageStanza = "<message " + "to='coven@muclight.shakespeare.lit' id='member1' type='groupchat'>"
+ "<x xmlns='urn:xmpp:muclight:0#affiliations'>"
+ "<user affiliation='owner'>sarasa2@shakespeare.lit</user>"
+ "<user affiliation='member'>sarasa1@shakespeare.lit</user>"
+ "<user affiliation='none'>sarasa3@shakespeare.lit</user>" + "</x>" + "</message>";
String exampleMessageStanzaWithVersion = "<message "
+ "to='coven@muclight.shakespeare.lit' id='member1' type='groupchat'>"
+ "<x xmlns='urn:xmpp:muclight:0#affiliations'>" + "<version>qwerty</version>"
+ "<user affiliation='member'>sarasa1@shakespeare.lit</user>"
+ "<user affiliation='none'>sarasa3@shakespeare.lit</user>" + "</x>" + "<body></body>" + "</message>";
String exampleMessageStanzaWithPrevVersion = "<message "
+ "to='coven@muclight.shakespeare.lit' id='member1' type='groupchat'>"
+ "<x xmlns='urn:xmpp:muclight:0#affiliations'>" + "<prev-version>njiokm</prev-version>"
+ "<version>qwerty</version>" + "<user affiliation='owner'>sarasa2@shakespeare.lit</user>"
+ "<user affiliation='member'>sarasa1@shakespeare.lit</user>" + "</x>" + "<body></body>" + "</message>";
@Test
public void checkAffiliationsChangeExtension() throws Exception {
Message changeAffiliationsMessage = (Message) PacketParserUtils.parseStanza(exampleMessageStanza);
AffiliationsChangeExtension affiliationsChangeExtension = AffiliationsChangeExtension
.from(changeAffiliationsMessage);
HashMap<Jid, MUCLightAffiliation> affiliations = affiliationsChangeExtension.getAffiliations();
Assert.assertEquals(affiliations.size(), 3);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa2@shakespeare.lit")), MUCLightAffiliation.owner);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa3@shakespeare.lit")), MUCLightAffiliation.none);
}
@Test
public void checkAffiliationsChangeExtensionWithVersion() throws Exception {
Message changeAffiliationsMessage = (Message) PacketParserUtils.parseStanza(exampleMessageStanzaWithVersion);
AffiliationsChangeExtension affiliationsChangeExtension = AffiliationsChangeExtension
.from(changeAffiliationsMessage);
HashMap<Jid, MUCLightAffiliation> affiliations = affiliationsChangeExtension.getAffiliations();
Assert.assertEquals(affiliations.size(), 2);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa3@shakespeare.lit")), MUCLightAffiliation.none);
Assert.assertEquals(affiliationsChangeExtension.getVersion(), "qwerty");
}
@Test
public void checkAffiliationsChangeExtensionWithPrevVersion() throws Exception {
Message changeAffiliationsMessage = (Message) PacketParserUtils
.parseStanza(exampleMessageStanzaWithPrevVersion);
AffiliationsChangeExtension affiliationsChangeExtension = AffiliationsChangeExtension
.from(changeAffiliationsMessage);
HashMap<Jid, MUCLightAffiliation> affiliations = affiliationsChangeExtension.getAffiliations();
Assert.assertEquals(affiliations.size(), 2);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa2@shakespeare.lit")), MUCLightAffiliation.owner);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
Assert.assertEquals(affiliationsChangeExtension.getPrevVersion(), "njiokm");
Assert.assertEquals(affiliationsChangeExtension.getVersion(), "qwerty");
}
}

View file

@ -0,0 +1,122 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightBlockingTest {
String getBlockingListIQExample = "<iq to='muclight.shakespeare.lit' id='getblock1' type='get'>"
+ "<query xmlns='urn:xmpp:muclight:0#blocking'>" + "</query>" + "</iq>";
String getBlockingListIQResponse = "<iq type='result' id='getblock1' to='crone1@shakespeare.lit/desktop' from='muclight.shakespeare.lit'>"
+ "<query xmlns='urn:xmpp:muclight:0#blocking'>"
+ "<room action='deny'>coven@muclight.shakespeare.lit</room>"
+ "<room action='deny'>sarasa@muclight.shakespeare.lit</room>"
+ "<user action='deny'>hag77@shakespeare.lit</user>" + "</query>" + "</iq>";
String blockingRoomsIQExample = "<iq to='muclight.shakespeare.lit' id='block1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#blocking'>"
+ "<room action='deny'>coven@muclight.shakespeare.lit</room>"
+ "<room action='deny'>chapel@shakespeare.lit</room>" + "</query>" + "</iq>";
String blockingUsersIQExample = "<iq to='muclight.shakespeare.lit' id='block2' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#blocking'>" + "<user action='deny'>hag77@shakespeare.lit</user>"
+ "<user action='deny'>hag66@shakespeare.lit</user>" + "</query>" + "</iq>";
String unblockingUsersAndRoomsExample = "<iq to='muclight.shakespeare.lit' id='unblock1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#blocking'>"
+ "<room action='allow'>coven@muclight.shakespeare.lit</room>"
+ "<user action='allow'>hag66@shakespeare.lit</user>" + "</query>" + "</iq>";
@Test
public void checkGetBlockingListIQ() throws Exception {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, null);
mucLightBlockingIQ.setType(Type.get);
mucLightBlockingIQ.setStanzaId("getblock1");
mucLightBlockingIQ.setTo(JidCreate.from("muclight.shakespeare.lit"));
Assert.assertEquals(getBlockingListIQExample, mucLightBlockingIQ.toXML().toString());
}
@Test
public void checkGetBlockingListResponse() throws Exception {
IQ iqInfoResult = (IQ) PacketParserUtils.parseStanza(getBlockingListIQResponse);
MUCLightBlockingIQ mucLightBlockingIQ = (MUCLightBlockingIQ) iqInfoResult;
Assert.assertEquals(2, mucLightBlockingIQ.getRooms().size());
Assert.assertEquals(1, mucLightBlockingIQ.getUsers().size());
Assert.assertEquals(false, mucLightBlockingIQ.getRooms().get(JidCreate.from("coven@muclight.shakespeare.lit")));
Assert.assertEquals(false,
mucLightBlockingIQ.getRooms().get(JidCreate.from("sarasa@muclight.shakespeare.lit")));
Assert.assertEquals(false, mucLightBlockingIQ.getUsers().get(JidCreate.from("hag77@shakespeare.lit")));
}
@Test
public void checkBlockRoomsIQ() throws Exception {
HashMap<Jid, Boolean> rooms = new HashMap<>();
rooms.put(JidCreate.from("coven@muclight.shakespeare.lit"), false);
rooms.put(JidCreate.from("chapel@shakespeare.lit"), false);
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, null);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(JidCreate.from("muclight.shakespeare.lit"));
mucLightBlockingIQ.setStanzaId("block1");
Assert.assertEquals(blockingRoomsIQExample, mucLightBlockingIQ.toXML().toString());
}
@Test
public void checkBlockUsersIQ() throws Exception {
HashMap<Jid, Boolean> users = new HashMap<>();
users.put(JidCreate.from("hag77@shakespeare.lit"), false);
users.put(JidCreate.from("hag66@shakespeare.lit"), false);
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, users);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(JidCreate.from("muclight.shakespeare.lit"));
mucLightBlockingIQ.setStanzaId("block2");
Assert.assertEquals(blockingUsersIQExample, mucLightBlockingIQ.toXML().toString());
}
@Test
public void checkUnblockUsersAndRoomsIQ() throws Exception {
HashMap<Jid, Boolean> users = new HashMap<>();
users.put(JidCreate.from("hag66@shakespeare.lit"), true);
HashMap<Jid, Boolean> rooms = new HashMap<>();
rooms.put(JidCreate.from("coven@muclight.shakespeare.lit"), true);
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, users);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(JidCreate.from("muclight.shakespeare.lit"));
mucLightBlockingIQ.setStanzaId("unblock1");
Assert.assertEquals(unblockingUsersAndRoomsExample, mucLightBlockingIQ.toXML().toString());
}
}

View file

@ -0,0 +1,56 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.element.MUCLightChangeAffiliationsIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightChangeAffiliationsIQTest {
String stanza = "<iq " + "to='coven@muclight.shakespeare.lit' id='member1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#affiliations'>"
+ "<user affiliation='owner'>sarasa2@shakespeare.lit</user>"
+ "<user affiliation='member'>sarasa1@shakespeare.lit</user>"
+ "<user affiliation='none'>sarasa3@shakespeare.lit</user>" + "</query>" + "</iq>";
@Test
public void checkChangeAffiliationsMUCLightStanza() throws Exception {
HashMap<Jid, MUCLightAffiliation> affiliations = new HashMap<>();
affiliations.put(JidCreate.from("sarasa2@shakespeare.lit"), MUCLightAffiliation.owner);
affiliations.put(JidCreate.from("sarasa1@shakespeare.lit"), MUCLightAffiliation.member);
affiliations.put(JidCreate.from("sarasa3@shakespeare.lit"), MUCLightAffiliation.none);
MUCLightChangeAffiliationsIQ mucLightChangeAffiliationsIQ = new MUCLightChangeAffiliationsIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), affiliations);
mucLightChangeAffiliationsIQ.setStanzaId("member1");
Assert.assertEquals(mucLightChangeAffiliationsIQ.getTo(), "coven@muclight.shakespeare.lit");
Assert.assertEquals(mucLightChangeAffiliationsIQ.getType(), IQ.Type.set);
HashMap<Jid, MUCLightAffiliation> iqAffiliations = mucLightChangeAffiliationsIQ.getAffiliations();
Assert.assertEquals(iqAffiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
Assert.assertEquals(iqAffiliations.get(JidCreate.from("sarasa2@shakespeare.lit")), MUCLightAffiliation.owner);
Assert.assertEquals(iqAffiliations.get(JidCreate.from("sarasa3@shakespeare.lit")), MUCLightAffiliation.none);
}
}

View file

@ -0,0 +1,83 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationsChangeExtension;
import org.junit.Assert;
import org.junit.Test;
public class MUCLightConfigurationsChangeExtensionTest {
String messageWithSubjectChangeExample = "<message to='crone1@shakespeare.lit' from='coven@muclight.shakespeare.lit' id='newsubject' type='groupchat'>"
+ "<body></body>" + "<x xmlns='urn:xmpp:muclight:0#configuration'>"
+ "<prev-version>asdfghj000</prev-version>" + "<version>asdfghj</version>"
+ "<subject>To be or not to be?</subject>" + "</x>" + "</message>";
String messageWithRoomNameChangeExample = "<message to='crone1@shakespeare.lit' from='coven@muclight.shakespeare.lit' id='newsubject' type='groupchat'>"
+ "<body></body>" + "<x xmlns='urn:xmpp:muclight:0#configuration'>" + "<prev-version>zaqwsx</prev-version>"
+ "<version>zxcvbnm</version>" + "<roomname>A Darker Cave</roomname>" + "</x>" + "</message>";
String messageWithConfigsChangeExample = "<message to='crone1@shakespeare.lit' from='coven@muclight.shakespeare.lit' id='newsubject' type='groupchat'>"
+ "<body></body>" + "<x xmlns='urn:xmpp:muclight:0#configuration'>" + "<prev-version>zaqwsx</prev-version>"
+ "<version>zxcvbnm</version>" + "<roomname>A Darker Cave</roomname>" + "<color>blue</color>" + "</x>"
+ "</message>";
@Test
public void checkSubjectChangeExtension() throws Exception {
Message configurationsMessage = (Message) PacketParserUtils.parseStanza(messageWithSubjectChangeExample);
ConfigurationsChangeExtension configurationsChangeExtension = ConfigurationsChangeExtension
.from(configurationsMessage);
Assert.assertEquals("asdfghj000", configurationsChangeExtension.getPrevVersion());
Assert.assertEquals("asdfghj", configurationsChangeExtension.getVersion());
Assert.assertEquals("To be or not to be?", configurationsChangeExtension.getSubject());
Assert.assertNull(configurationsChangeExtension.getRoomName());
Assert.assertNull(configurationsChangeExtension.getCustomConfigs());
Assert.assertEquals(messageWithSubjectChangeExample, configurationsMessage.toXML().toString());
}
@Test
public void checkRoomNameChangeExtension() throws Exception {
Message configurationsMessage = (Message) PacketParserUtils.parseStanza(messageWithRoomNameChangeExample);
ConfigurationsChangeExtension configurationsChangeExtension = ConfigurationsChangeExtension
.from(configurationsMessage);
Assert.assertEquals("zaqwsx", configurationsChangeExtension.getPrevVersion());
Assert.assertEquals("zxcvbnm", configurationsChangeExtension.getVersion());
Assert.assertEquals("A Darker Cave", configurationsChangeExtension.getRoomName());
Assert.assertNull(configurationsChangeExtension.getSubject());
Assert.assertNull(configurationsChangeExtension.getCustomConfigs());
Assert.assertEquals(messageWithRoomNameChangeExample, configurationsMessage.toXML().toString());
}
@Test
public void checkConfigsChangeExtension() throws Exception {
Message configurationsMessage = (Message) PacketParserUtils.parseStanza(messageWithConfigsChangeExample);
ConfigurationsChangeExtension configurationsChangeExtension = ConfigurationsChangeExtension
.from(configurationsMessage);
Assert.assertEquals("zaqwsx", configurationsChangeExtension.getPrevVersion());
Assert.assertEquals("zxcvbnm", configurationsChangeExtension.getVersion());
Assert.assertEquals("A Darker Cave", configurationsChangeExtension.getRoomName());
Assert.assertNull(configurationsChangeExtension.getSubject());
Assert.assertEquals("blue", configurationsChangeExtension.getCustomConfigs().get("color"));
Assert.assertEquals(messageWithConfigsChangeExample, configurationsMessage.toXML().toString());
}
}

View file

@ -0,0 +1,55 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.jivesoftware.smackx.muclight.element.MUCLightCreateIQ;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.junit.Assert;
public class MUCLightCreateIQTest {
String stanza = "<iq to='ef498f55-5f79-4238-a5ae-4efe19cbe617@muclight.test.com' id='1c72W-50' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#create'>" + "<configuration>" + "<roomname>test</roomname>"
+ "</configuration>" + "<occupants>" + "<user affiliation='member'>charlie@test.com</user>"
+ "<user affiliation='member'>pep@test.com</user>" + "</occupants>" + "</query>" + "</iq>";
@Test
public void checkCreateMUCLightStanza() throws Exception {
List<Jid> occupants = new ArrayList<>();
occupants.add(JidCreate.from("charlie@test.com"));
occupants.add(JidCreate.from("pep@test.com"));
MUCLightCreateIQ mucLightCreateIQ = new MUCLightCreateIQ(
JidCreate.from("ef498f55-5f79-4238-a5ae-4efe19cbe617@muclight.test.com").asEntityJidIfPossible(),
"test", occupants);
mucLightCreateIQ.setStanzaId("1c72W-50");
Assert.assertEquals(mucLightCreateIQ.getConfiguration().getRoomName(), "test");
HashMap<Jid, MUCLightAffiliation> iqOccupants = mucLightCreateIQ.getOccupants();
Assert.assertEquals(iqOccupants.get(JidCreate.from("charlie@test.com")), MUCLightAffiliation.member);
Assert.assertEquals(iqOccupants.get(JidCreate.from("pep@test.com")), MUCLightAffiliation.member);
}
}

View file

@ -0,0 +1,36 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import org.jivesoftware.smackx.muclight.element.MUCLightDestroyIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightDestroyTest {
String stanza = "<iq to='coven@muclight.shakespeare.lit' id='destroy1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#destroy'/>" + "</iq>";
@Test
public void checkDestroyMUCLightStanza() throws Exception{
MUCLightDestroyIQ mucLightDestroyIQ = new MUCLightDestroyIQ(JidCreate.from("coven@muclight.shakespeare.lit"));
mucLightDestroyIQ.setStanzaId("destroy1");
Assert.assertEquals(mucLightDestroyIQ.toXML().toString(), stanza);
}
}

View file

@ -0,0 +1,63 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightAffiliationsIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightGetAffiliationsIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightGetAffiliationsTest {
String getAffiliationsIQExample = "<iq to='coven@muclight.shakespeare.lit' id='getmembers' type='get'>"
+ "<query xmlns='urn:xmpp:muclight:0#affiliations'>" + "<version>abcdefg</version>" + "</query>" + "</iq>";
String getAffiliationsResponseExample = "<iq from='coven@muclight.shakespeare.lit' id='getmembers' to='crone1@shakespeare.lit/desktop' type='result'>"
+ "<query xmlns='urn:xmpp:muclight:0#affiliations'>" + "<version>123456</version>"
+ "<user affiliation='owner'>user1@shakespeare.lit</user>"
+ "<user affiliation='member'>user2@shakespeare.lit</user>"
+ "<user affiliation='member'>user3@shakespeare.lit</user>" + "</query>" + "</iq>";
@Test
public void checkGetAffiliationsIQ() throws Exception {
MUCLightGetAffiliationsIQ mucLightGetAffiliationsIQ = new MUCLightGetAffiliationsIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), "abcdefg");
mucLightGetAffiliationsIQ.setStanzaId("getmembers");
Assert.assertEquals(getAffiliationsIQExample, mucLightGetAffiliationsIQ.toXML().toString());
}
@Test
public void checkGetAffiliationsResponse() throws Exception {
IQ iqInfoResult = (IQ) PacketParserUtils.parseStanza(getAffiliationsResponseExample);
MUCLightAffiliationsIQ mucLightAffiliationsIQ = (MUCLightAffiliationsIQ) iqInfoResult;
Assert.assertEquals("123456", mucLightAffiliationsIQ.getVersion());
HashMap<Jid, MUCLightAffiliation> affiliations = mucLightAffiliationsIQ.getAffiliations();
Assert.assertEquals(3, affiliations.size());
Assert.assertEquals(MUCLightAffiliation.owner, affiliations.get(JidCreate.from("user1@shakespeare.lit")));
Assert.assertEquals(MUCLightAffiliation.member, affiliations.get(JidCreate.from("user2@shakespeare.lit")));
Assert.assertEquals(MUCLightAffiliation.member, affiliations.get(JidCreate.from("user3@shakespeare.lit")));
}
}

View file

@ -0,0 +1,77 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightConfigurationIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightGetConfigsIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightGetConfigsTest {
String getConfigsIQExample = "<iq to='coven@muclight.shakespeare.lit' id='config0' type='get'>"
+ "<query xmlns='urn:xmpp:muclight:0#configuration'>" + "<version>abcdefg</version>" + "</query>" + "</iq>";
String getConfigsResponseExample = "<iq from='coven@muclight.shakespeare.lit' id='getconfig1' "
+ "to='crone1@shakespeare.lit/desktop' type='result'>" + "<query xmlns='urn:xmpp:muclight:0#configuration'>"
+ "<version>123456</version>" + "<roomname>A Dark Cave</roomname>" + "<subject>A subject</subject>"
+ "</query>" + "</iq>";
String getConfigsResponseExampleWithCustomConfigs = "<iq from='coven@muclight.shakespeare.lit' id='getconfig2' "
+ "to='crone1@shakespeare.lit/desktop' type='result'>" + "<query xmlns='urn:xmpp:muclight:0#configuration'>"
+ "<version>123456</version>" + "<roomname>A Dark Cave</roomname>" + "<color>blue</color>"
+ "<size>20</size>" + "</query>" + "</iq>";
@Test
public void checkGetConfigsIQ() throws Exception {
MUCLightGetConfigsIQ mucLightGetConfigsIQ = new MUCLightGetConfigsIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), "abcdefg");
mucLightGetConfigsIQ.setStanzaId("config0");
Assert.assertEquals(getConfigsIQExample, mucLightGetConfigsIQ.toXML().toString());
}
@Test
public void checkGetConfigsResponse() throws Exception {
IQ iqInfoResult = (IQ) PacketParserUtils.parseStanza(getConfigsResponseExample);
MUCLightConfigurationIQ mucLightConfigurationIQ = (MUCLightConfigurationIQ) iqInfoResult;
Assert.assertEquals("123456", mucLightConfigurationIQ.getVersion());
Assert.assertEquals("A Dark Cave", mucLightConfigurationIQ.getConfiguration().getRoomName());
Assert.assertEquals("A subject", mucLightConfigurationIQ.getConfiguration().getSubject());
Assert.assertNull(mucLightConfigurationIQ.getConfiguration().getCustomConfigs());
}
@Test
public void checkGetConfigsResponseWithCustomConfigs() throws Exception {
IQ iqInfoResult = (IQ) PacketParserUtils.parseStanza(getConfigsResponseExampleWithCustomConfigs);
MUCLightConfigurationIQ mucLightConfigurationIQ = (MUCLightConfigurationIQ) iqInfoResult;
Assert.assertEquals("123456", mucLightConfigurationIQ.getVersion());
Assert.assertEquals("A Dark Cave", mucLightConfigurationIQ.getConfiguration().getRoomName());
Assert.assertNull(mucLightConfigurationIQ.getConfiguration().getSubject());
HashMap<String, String> customConfigs = mucLightConfigurationIQ.getConfiguration().getCustomConfigs();
Assert.assertEquals("blue", customConfigs.get("color"));
Assert.assertEquals("20", customConfigs.get("size"));
}
}

View file

@ -0,0 +1,72 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightGetInfoIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightInfoIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightInfoTest {
String exampleWithVersion = "<iq to='coven@muclight.shakespeare.lit' id='getinfo1' type='get'>"
+ "<query xmlns='urn:xmpp:muclight:0#info'>" + "<version>abcdefg</version>" + "</query>" + "</iq>";
String exampleWithoutVersion = "<iq to='coven@muclight.shakespeare.lit' id='getinfo1' type='get'>"
+ "<query xmlns='urn:xmpp:muclight:0#info'>" + "</query>" + "</iq>";
String exampleInfoResult = "<iq from='coven@muclight.shakespeare.lit' to='cronel@shakespeare.lit/desktop' id='getinfo1' type='result'>"
+ "<query xmlns='urn:xmpp:muclight:0#info'>" + "<version>123456</version>" + "<configuration>"
+ "<roomname>test</roomname>" + "</configuration>" + "<occupants>"
+ "<user affiliation='owner'>john@test.com</user>" + "<user affiliation='member'>charlie@test.com</user>"
+ "<user affiliation='member'>pep@test.com</user>" + "</occupants>" + "</query>" + "</iq>";
@Test
public void checkMUCLightGetInfoIQStanzaWithVersion() throws Exception {
MUCLightGetInfoIQ mucLightGetInfoIQWithVersion = new MUCLightGetInfoIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), "abcdefg");
mucLightGetInfoIQWithVersion.setStanzaId("getinfo1");
Assert.assertEquals(mucLightGetInfoIQWithVersion.toXML().toString(), exampleWithVersion);
}
@Test
public void checkMUCLightGetInfoIQStanzaWithoutVersion() throws Exception {
MUCLightGetInfoIQ mucLightGetInfoIQWithoutVersion = new MUCLightGetInfoIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), null);
mucLightGetInfoIQWithoutVersion.setStanzaId("getinfo1");
Assert.assertEquals(mucLightGetInfoIQWithoutVersion.toXML().toString(), exampleWithoutVersion);
}
@Test
public void checkMUCLightInfoResult() throws Exception {
IQ iqInfoResult = (IQ) PacketParserUtils.parseStanza(exampleInfoResult);
MUCLightInfoIQ mucLightInfoResponseIQ = (MUCLightInfoIQ) iqInfoResult;
Assert.assertEquals(mucLightInfoResponseIQ.getVersion(), "123456");
Assert.assertEquals(mucLightInfoResponseIQ.getConfiguration().getRoomName(), "test");
Assert.assertEquals(mucLightInfoResponseIQ.getOccupants().size(), 3);
Assert.assertEquals(mucLightInfoResponseIQ.getOccupants().get(JidCreate.from("john@test.com")),
MUCLightAffiliation.owner);
Assert.assertEquals(mucLightInfoResponseIQ.getOccupants().get(JidCreate.from("charlie@test.com")),
MUCLightAffiliation.member);
Assert.assertEquals(mucLightInfoResponseIQ.getOccupants().get(JidCreate.from("pep@test.com")),
MUCLightAffiliation.member);
}
}

View file

@ -0,0 +1,70 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jivesoftware.smackx.muclight.element.MUCLightSetConfigsIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightSetConfigsIQTest {
String setConfigsIQExample = "<iq to='coven@muclight.shakespeare.lit' id='conf1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#configuration'>" + "<roomname>A Darker Cave</roomname>"
+ "<color>blue</color>" + "</query>" + "</iq>";
String changeRoomNameIQExample = "<iq to='coven@muclight.shakespeare.lit' id='roomName1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#configuration'>" + "<roomname>A Darker Cave</roomname>" + "</query>"
+ "</iq>";
String changeSubjectIQExample = "<iq to='coven@muclight.shakespeare.lit' id='subject1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#configuration'>" + "<subject>To be or not to be?</subject>"
+ "</query>" + "</iq>";
@Test
public void checkSetConfigsStanza() throws Exception {
HashMap<String, String> customConfigs = new HashMap<>();
customConfigs.put("color", "blue");
MUCLightSetConfigsIQ mucLightSetConfigsIQ = new MUCLightSetConfigsIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), "A Darker Cave", customConfigs);
mucLightSetConfigsIQ.setStanzaId("conf1");
Assert.assertEquals(setConfigsIQExample, mucLightSetConfigsIQ.toXML().toString());
}
@Test
public void checkChangeRoomNameStanza() throws Exception {
MUCLightSetConfigsIQ mucLightChangeRoomNameIQ = new MUCLightSetConfigsIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), "A Darker Cave", null);
mucLightChangeRoomNameIQ.setStanzaId("roomName1");
Assert.assertEquals(changeRoomNameIQExample, mucLightChangeRoomNameIQ.toXML().toString());
}
@Test
public void checkChangeSubjectStanza() throws Exception {
MUCLightSetConfigsIQ mucLightChangeSubjectIQ = new MUCLightSetConfigsIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), null, "To be or not to be?", null);
mucLightChangeSubjectIQ.setStanzaId("subject1");
Assert.assertEquals(changeSubjectIQExample, mucLightChangeSubjectIQ.toXML().toString());
}
}