2016-07-21 16:40:26 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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.mam;
|
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
2016-07-21 16:40:26 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2018-05-09 16:53:08 +02:00
|
|
|
import org.jivesoftware.smack.packet.StreamOpen;
|
|
|
|
|
2016-07-21 16:40:26 +02:00
|
|
|
import org.jivesoftware.smackx.mam.element.MamElements;
|
|
|
|
import org.jivesoftware.smackx.mam.element.MamPrefsIQ;
|
2016-07-23 15:45:45 +02:00
|
|
|
import org.jivesoftware.smackx.mam.element.MamPrefsIQ.DefaultBehavior;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jxmpp.jid.Jid;
|
|
|
|
import org.jxmpp.jid.impl.JidCreate;
|
2016-07-21 16:40:26 +02:00
|
|
|
|
2016-07-23 15:45:45 +02:00
|
|
|
public class PreferencesTest {
|
2016-07-21 16:40:26 +02:00
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private static final String retrievePrefsStanzaExample = "<iq id='sarasa' type='get'>" + "<prefs xmlns='" + MamElements.NAMESPACE
|
2016-07-23 15:45:45 +02:00
|
|
|
+ "'/>" + "</iq>";
|
2016-07-21 16:40:26 +02:00
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private static final String updatePrefsStanzaExample = "<iq id='sarasa' type='set'>" + "<prefs xmlns='" + MamElements.NAMESPACE
|
2016-07-21 16:40:26 +02:00
|
|
|
+ "' default='roster'>" + "<always>" + "<jid>romeo@montague.lit</jid>" + "<jid>other@montague.lit</jid>"
|
|
|
|
+ "</always>" + "<never>" + "<jid>montague@montague.lit</jid>" + "</never>" + "</prefs>" + "</iq>";
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void checkRetrievePrefsStanza() throws Exception {
|
2016-07-23 15:45:45 +02:00
|
|
|
MamPrefsIQ mamPrefIQ = new MamPrefsIQ();
|
2016-07-21 16:40:26 +02:00
|
|
|
mamPrefIQ.setStanzaId("sarasa");
|
2019-05-06 22:06:13 +02:00
|
|
|
assertEquals(mamPrefIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString(), retrievePrefsStanzaExample);
|
2016-07-21 16:40:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void checkUpdatePrefsStanza() throws Exception {
|
|
|
|
List<Jid> alwaysJids = new ArrayList<>();
|
|
|
|
alwaysJids.add(JidCreate.from("romeo@montague.lit"));
|
|
|
|
alwaysJids.add(JidCreate.from("other@montague.lit"));
|
|
|
|
|
|
|
|
List<Jid> neverJids = new ArrayList<>();
|
|
|
|
neverJids.add(JidCreate.from("montague@montague.lit"));
|
|
|
|
|
2016-07-23 15:45:45 +02:00
|
|
|
MamPrefsIQ mamPrefIQ = new MamPrefsIQ(alwaysJids, neverJids, DefaultBehavior.roster);
|
2016-07-21 16:40:26 +02:00
|
|
|
mamPrefIQ.setStanzaId("sarasa");
|
2019-05-06 22:06:13 +02:00
|
|
|
assertEquals(mamPrefIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString(), updatePrefsStanzaExample);
|
2016-07-21 16:40:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|