1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-06-16 16:44:48 +02:00
Smack/smack-experimental/src/test/java/org/jivesoftware/smackx/muclight/MUCLightBlockingTest.java
Florian Schmaus 4133eb175c Replace XPP3 by XmlPullParser interface wrapping StAX and XPP3
Introducing Smack's own XmlPullParser interface which tries to stay as
compatible as possible to XPP3. The interface is used to either wrap
StAX's XMLStreamReader if Smack is used on Java SE, and XPP3's
XmlPullParser if Smack is used on on Android.

Fixes SMACK-591.

Also introduce JUnit 5 and non-strict javadoc projects.
2019-05-06 22:10:50 +02:00

127 lines
5.9 KiB
Java

/**
*
* 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 static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.StreamOpen;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ;
import org.junit.jupiter.api.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightBlockingTest {
private static final String getBlockingListIQExample = "<iq to='muclight.shakespeare.lit' id='getblock1' type='get'>"
+ "<query xmlns='urn:xmpp:muclight:0#blocking'>" + "</query>" + "</iq>";
private static final 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>";
private static final 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>";
private static final 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>";
private static final 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"));
assertEquals(getBlockingListIQExample, mucLightBlockingIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString());
}
@Test
public void checkGetBlockingListResponse() throws Exception {
IQ iqInfoResult = PacketParserUtils.parseStanza(getBlockingListIQResponse);
MUCLightBlockingIQ mucLightBlockingIQ = (MUCLightBlockingIQ) iqInfoResult;
assertEquals(2, mucLightBlockingIQ.getRooms().size());
assertEquals(1, mucLightBlockingIQ.getUsers().size());
assertEquals(false, mucLightBlockingIQ.getRooms().get(JidCreate.from("coven@muclight.shakespeare.lit")));
assertEquals(false,
mucLightBlockingIQ.getRooms().get(JidCreate.from("sarasa@muclight.shakespeare.lit")));
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");
assertEquals(blockingRoomsIQExample, mucLightBlockingIQ.toXML(StreamOpen.CLIENT_NAMESPACE).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");
assertEquals(blockingUsersIQExample, mucLightBlockingIQ.toXML(StreamOpen.CLIENT_NAMESPACE).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");
assertEquals(unblockingUsersAndRoomsExample, mucLightBlockingIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString());
}
}