mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-07 13:41:08 +01:00
Apply refinements and fixes to the MAM code
SMACK-625.
This commit is contained in:
parent
189cac072b
commit
aeb385a022
21 changed files with 194 additions and 236 deletions
|
|
@ -31,7 +31,7 @@ import org.jxmpp.util.XmppDateTime;
|
|||
|
||||
public class FiltersTest extends MamTest {
|
||||
|
||||
private String getMamXMemberWith(List<String> fieldsNames, List<String> fieldsValues) {
|
||||
private static String getMamXMemberWith(List<String> fieldsNames, List<String> fieldsValues) {
|
||||
String xml = "<x xmlns='jabber:x:data' type='submit'>" + "<field var='FORM_TYPE' type='hidden'>" + "<value>"
|
||||
+ MamElements.NAMESPACE + "</value>" + "</field>";
|
||||
|
||||
|
|
|
|||
|
|
@ -28,16 +28,10 @@ import org.xmlpull.v1.XmlPullParser;
|
|||
|
||||
public class MamFinProviderTest extends MamTest {
|
||||
|
||||
String exmapleMamFinXml = "<fin xmlns='urn:xmpp:mam:1' stable='true'>"
|
||||
static final String exmapleMamFinXml = "<fin xmlns='urn:xmpp:mam:1' stable='true'>"
|
||||
+ "<set xmlns='http://jabber.org/protocol/rsm'>" + "<max>10</max>" + "<after>09af3-cc343-b409f</after>"
|
||||
+ "</set>" + "</fin>";
|
||||
|
||||
private String getIQLimitedResultsExample() {
|
||||
return "<iq type='result' id='u29303'>" + "<fin xmlns='urn:xmpp:mam:1' complete='true'>"
|
||||
+ "<set xmlns='http://jabber.org/protocol/rsm'>" + "<first index='0'>23452-4534-1</first>"
|
||||
+ "<last>390-2342-22</last>" + "<count>16</count>" + "</set>" + "</fin>" + "</iq>";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkMamFinProvider() throws Exception {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(exmapleMamFinXml);
|
||||
|
|
@ -54,7 +48,18 @@ public class MamFinProviderTest extends MamTest {
|
|||
|
||||
@Test
|
||||
public void checkQueryLimitedResults() throws Exception {
|
||||
IQ iq = (IQ) PacketParserUtils.parseStanza(getIQLimitedResultsExample());
|
||||
// @formatter:off
|
||||
final String IQ_LIMITED_RESULTS_EXAMPLE = "<iq type='result' id='u29303'>"
|
||||
+ "<fin xmlns='urn:xmpp:mam:1' complete='true'>"
|
||||
+ "<set xmlns='http://jabber.org/protocol/rsm'>"
|
||||
+ "<first index='0'>23452-4534-1</first>"
|
||||
+ "<last>390-2342-22</last>" + "<count>16</count>"
|
||||
+ "</set>"
|
||||
+ "</fin>"
|
||||
+ "</iq>";
|
||||
// @formatter:on
|
||||
|
||||
IQ iq = (IQ) PacketParserUtils.parseStanza(IQ_LIMITED_RESULTS_EXAMPLE);
|
||||
|
||||
MamFinIQ mamFinIQ = (MamFinIQ) iq;
|
||||
Assert.assertEquals(mamFinIQ.getType(), Type.result);
|
||||
|
|
|
|||
|
|
@ -50,20 +50,20 @@ public class MamPrefIQProviderTest extends MamTest {
|
|||
XmlPullParser parser1 = PacketParserUtils.getParserFor(exampleMamPrefsIQ1);
|
||||
MamPrefsIQ mamPrefIQ1 = new MamPrefsIQProvider().parse(parser1);
|
||||
|
||||
Assert.assertTrue(mamPrefIQ1.isUpdate());
|
||||
Assert.assertEquals(IQ.Type.set, mamPrefIQ1.getType());
|
||||
Assert.assertEquals(mamPrefIQ1.getAlwaysJids().get(0), "romeo@montague.lit");
|
||||
Assert.assertEquals(mamPrefIQ1.getNeverJids().get(0), "montague@montague.lit");
|
||||
|
||||
XmlPullParser parser2 = PacketParserUtils.getParserFor(exampleMamPrefsIQ2);
|
||||
MamPrefsIQ mamPrefIQ2 = new MamPrefsIQProvider().parse(parser2);
|
||||
Assert.assertTrue(mamPrefIQ2.isUpdate());
|
||||
Assert.assertEquals(IQ.Type.set, mamPrefIQ2.getType());
|
||||
Assert.assertEquals(mamPrefIQ2.getAlwaysJids().get(0), "romeo@montague.lit");
|
||||
Assert.assertEquals(mamPrefIQ2.getAlwaysJids().get(1), "montague@montague.lit");
|
||||
Assert.assertTrue(mamPrefIQ2.getNeverJids().isEmpty());
|
||||
|
||||
XmlPullParser parser3 = PacketParserUtils.getParserFor(exampleMamPrefsIQ3);
|
||||
MamPrefsIQ mamPrefIQ3 = new MamPrefsIQProvider().parse(parser3);
|
||||
Assert.assertFalse(mamPrefIQ3.isUpdate());
|
||||
Assert.assertEquals(IQ.Type.set, mamPrefIQ3.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,8 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.mam;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.mam.element.MamQueryIQ;
|
||||
import org.jivesoftware.smackx.rsm.packet.RSMSet;
|
||||
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||
|
|
@ -27,25 +26,21 @@ import org.junit.Assert;
|
|||
|
||||
public class PagingTest extends MamTest {
|
||||
|
||||
String pagingStanza = "<iq id='sarasa' type='set'>" + "<query xmlns='urn:xmpp:mam:1' queryid='testid'>"
|
||||
private static final String pagingStanza = "<iq id='sarasa' type='set'>" + "<query xmlns='urn:xmpp:mam:1' queryid='testid'>"
|
||||
+ "<x xmlns='jabber:x:data' type='submit'>" + "<field var='FORM_TYPE' type='hidden'>"
|
||||
+ "<value>urn:xmpp:mam:1</value>" + "</field>" + "</x>" + "<set xmlns='http://jabber.org/protocol/rsm'>"
|
||||
+ "<max>10</max>" + "</set>" + "</query>" + "</iq>";
|
||||
|
||||
@Test
|
||||
public void checkPageQueryStanza() throws Exception {
|
||||
Method methodPreparePageQuery = MamManager.class.getDeclaredMethod("preparePageQuery", MamQueryIQ.class,
|
||||
RSMSet.class);
|
||||
methodPreparePageQuery.setAccessible(true);
|
||||
|
||||
DataForm dataForm = getNewMamForm();
|
||||
int max = 10;
|
||||
RSMSet rsmSet = new RSMSet(max);
|
||||
|
||||
MamQueryIQ mamQueryIQ = new MamQueryIQ(queryId, dataForm);
|
||||
mamQueryIQ.setStanzaId("sarasa");
|
||||
|
||||
methodPreparePageQuery.invoke(mamManager, mamQueryIQ, rsmSet);
|
||||
mamQueryIQ.setType(IQ.Type.set);
|
||||
mamQueryIQ.addExtension(rsmSet);
|
||||
|
||||
Assert.assertEquals(mamQueryIQ.getDataForm(), dataForm);
|
||||
Assert.assertEquals(mamQueryIQ.getDataForm().getFields().get(0).getValues().get(0), "urn:xmpp:mam:1");
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.mam;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -25,12 +24,13 @@ import org.jxmpp.jid.Jid;
|
|||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jivesoftware.smackx.mam.element.MamElements;
|
||||
import org.jivesoftware.smackx.mam.element.MamPrefsIQ;
|
||||
import org.jivesoftware.smackx.mam.element.MamPrefsIQ.DefaultBehavior;
|
||||
import org.junit.Assert;
|
||||
|
||||
public class PreferencesTest extends MamTest {
|
||||
public class PreferencesTest {
|
||||
|
||||
String retrievePrefsStanzaExample = "<iq id='sarasa' type='get'>" + "<prefs xmlns='" + MamElements.NAMESPACE
|
||||
+ "'></prefs>" + "</iq>";
|
||||
+ "'/>" + "</iq>";
|
||||
|
||||
String updatePrefsStanzaExample = "<iq id='sarasa' type='set'>" + "<prefs xmlns='" + MamElements.NAMESPACE
|
||||
+ "' default='roster'>" + "<always>" + "<jid>romeo@montague.lit</jid>" + "<jid>other@montague.lit</jid>"
|
||||
|
|
@ -38,21 +38,13 @@ public class PreferencesTest extends MamTest {
|
|||
|
||||
@Test
|
||||
public void checkRetrievePrefsStanza() throws Exception {
|
||||
Method prepareRetrievePreferencesStanza = MamManager.class
|
||||
.getDeclaredMethod("prepareRetrievePreferencesStanza");
|
||||
prepareRetrievePreferencesStanza.setAccessible(true);
|
||||
|
||||
MamPrefsIQ mamPrefIQ = (MamPrefsIQ) prepareRetrievePreferencesStanza.invoke(mamManager);
|
||||
MamPrefsIQ mamPrefIQ = new MamPrefsIQ();
|
||||
mamPrefIQ.setStanzaId("sarasa");
|
||||
Assert.assertEquals(mamPrefIQ.toXML().toString(), retrievePrefsStanzaExample);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkUpdatePrefsStanza() throws Exception {
|
||||
Method prepareUpdatePreferencesStanza = MamManager.class.getDeclaredMethod("prepareUpdatePreferencesStanza",
|
||||
List.class, List.class, String.class);
|
||||
prepareUpdatePreferencesStanza.setAccessible(true);
|
||||
|
||||
List<Jid> alwaysJids = new ArrayList<>();
|
||||
alwaysJids.add(JidCreate.from("romeo@montague.lit"));
|
||||
alwaysJids.add(JidCreate.from("other@montague.lit"));
|
||||
|
|
@ -60,7 +52,7 @@ public class PreferencesTest extends MamTest {
|
|||
List<Jid> neverJids = new ArrayList<>();
|
||||
neverJids.add(JidCreate.from("montague@montague.lit"));
|
||||
|
||||
MamPrefsIQ mamPrefIQ = (MamPrefsIQ) prepareUpdatePreferencesStanza.invoke(mamManager, alwaysJids, neverJids, "roster");
|
||||
MamPrefsIQ mamPrefIQ = new MamPrefsIQ(alwaysJids, neverJids, DefaultBehavior.roster);
|
||||
mamPrefIQ.setStanzaId("sarasa");
|
||||
Assert.assertEquals(mamPrefIQ.toXML().toString(), updatePrefsStanzaExample);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ import org.junit.Assert;
|
|||
|
||||
public class RetrieveFormFieldsTest extends MamTest {
|
||||
|
||||
String retrieveFormFieldStanza = "<iq id='sarasa' type='get'>" + "<query xmlns='" + MamElements.NAMESPACE
|
||||
private static final String retrieveFormFieldStanza = "<iq id='sarasa' type='get'>" + "<query xmlns='" + MamElements.NAMESPACE
|
||||
+ "' queryid='testid'></query>" + "</iq>";
|
||||
|
||||
String additionalFieldsStanza = "<x xmlns='jabber:x:data' type='submit'>" + "<field var='FORM_TYPE' type='hidden'>"
|
||||
private static final String additionalFieldsStanza = "<x xmlns='jabber:x:data' type='submit'>" + "<field var='FORM_TYPE' type='hidden'>"
|
||||
+ "<value>" + MamElements.NAMESPACE + "</value>" + "</field>"
|
||||
+ "<field var='urn:example:xmpp:free-text-search' type='text-single'>" + "<value>Hi</value>" + "</field>"
|
||||
+ "<field var='urn:example:xmpp:stanza-content' type='jid-single'>" + "<value>Hi2</value>" + "</field>"
|
||||
|
|
@ -41,10 +41,7 @@ public class RetrieveFormFieldsTest extends MamTest {
|
|||
|
||||
@Test
|
||||
public void checkRetrieveFormFieldsStanza() throws Exception {
|
||||
Method methodPrepareMamQueryIQGet = MamManager.class.getDeclaredMethod("prepareMamQueryIQGet", String.class);
|
||||
methodPrepareMamQueryIQGet.setAccessible(true);
|
||||
|
||||
MamQueryIQ mamQueryIQ = (MamQueryIQ) methodPrepareMamQueryIQGet.invoke(mamManager, queryId);
|
||||
MamQueryIQ mamQueryIQ = new MamQueryIQ(queryId);
|
||||
mamQueryIQ.setStanzaId("sarasa");
|
||||
|
||||
Assert.assertEquals(mamQueryIQ.toXML().toString(), retrieveFormFieldStanza);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue