summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/isode/stroke/elements/MAMArchived.java34
-rw-r--r--src/com/isode/stroke/elements/MAMFin.java60
-rw-r--r--src/com/isode/stroke/elements/MAMQuery.java10
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java2
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/MAMArchivedParser.java46
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/MAMFinParser.java94
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/MAMQueryParser.java11
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java1
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/MAMArchivedSerializer.java33
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/MAMFinSerializer.java44
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializer.java4
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/MAMArchivedParserTest.java34
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/MAMFinParserTest.java52
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/MAMQueryParserTest.java59
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/MAMArchivedSerilaizerTest.java33
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/MAMFinSerializerTest.java51
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializerTest.java3
17 files changed, 384 insertions, 187 deletions
diff --git a/src/com/isode/stroke/elements/MAMArchived.java b/src/com/isode/stroke/elements/MAMArchived.java
deleted file mode 100644
index c8ab2d9..0000000
--- a/src/com/isode/stroke/elements/MAMArchived.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
-* Copyright (c) 2014 Kevin Smith and Remko Tronçon
-* All rights reserved.
-*/
-
-/*
-* Copyright (c) 2014, Isode Limited, London, England.
-* All rights reserved.
-*/
-
-package com.isode.stroke.elements;
-
-import com.isode.stroke.jid.JID;
-
-public class MAMArchived extends Payload {
- public void setBy(JID by) {
- by_ = by;
- }
-
- public JID getBy() {
- return by_;
- }
-
- public void setID(String id) {
- id_ = id;
- }
-
- public String getID() {
- return id_;
- }
-
- private JID by_;
- private String id_;
-}
diff --git a/src/com/isode/stroke/elements/MAMFin.java b/src/com/isode/stroke/elements/MAMFin.java
new file mode 100644
index 0000000..ebc39e8
--- /dev/null
+++ b/src/com/isode/stroke/elements/MAMFin.java
@@ -0,0 +1,60 @@
+/*
+* Copyright (c) 2014 Kevin Smith and Remko Tronçon
+* All rights reserved.
+*/
+
+/*
+* Copyright (c) 2014, Isode Limited, London, England.
+* All rights reserved.
+*/
+
+package com.isode.stroke.elements;
+
+public class MAMFin extends Payload {
+
+ private boolean isComplete_;
+
+ private boolean isStable_;
+
+ private ResultSet resultSet_;
+
+ private String queryID_;
+
+ public MAMFin() {
+ isComplete_ = false;
+ isStable_ = true;
+ }
+
+ public boolean isComplete() {
+ return isComplete_;
+ }
+
+ public void setComplete(boolean isComplete) {
+ this.isComplete_ = isComplete;
+ }
+
+ public boolean isStable() {
+ return isStable_;
+ }
+
+ public void setStable(boolean isStable) {
+ this.isStable_ = isStable;
+ }
+
+ public ResultSet getResultSet() {
+ return resultSet_;
+ }
+
+ public void setResultSet(ResultSet resultSet) {
+ this.resultSet_ = resultSet;
+ }
+
+ public String getQueryID() {
+ return queryID_;
+ }
+
+ public void setQueryID(String queryID) {
+ this.queryID_ = queryID;
+ }
+
+}
diff --git a/src/com/isode/stroke/elements/MAMQuery.java b/src/com/isode/stroke/elements/MAMQuery.java
index 6da30b5..b889a8e 100644
--- a/src/com/isode/stroke/elements/MAMQuery.java
+++ b/src/com/isode/stroke/elements/MAMQuery.java
@@ -11,6 +11,7 @@
package com.isode.stroke.elements;
public class MAMQuery extends Payload {
+
public void setQueryID(String queryID) {
queryID_ = queryID;
}
@@ -19,6 +20,14 @@ public class MAMQuery extends Payload {
return queryID_;
}
+ public void setNode(String node) {
+ node_ = node;
+ }
+
+ public String getNode() {
+ return node_;
+ }
+
public void setForm(Form form) {
form_ = form;
}
@@ -36,6 +45,7 @@ public class MAMQuery extends Payload {
}
private String queryID_;
+ private String node_;
private Form form_;
private ResultSet resultSet_;
}
diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
index 41f44f5..4eeb741 100644
--- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
+++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
@@ -69,7 +69,7 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl
addFactory(new GenericPayloadParserFactory2<ForwardedParser>("forwarded", "urn:xmpp:forward:0", this, ForwardedParser.class));
addFactory(new GenericPayloadParserFactory2<MAMResultParser>("result", "urn:xmpp:mam:0", this, MAMResultParser.class));
addFactory(new GenericPayloadParserFactory<MAMQueryParser>("query", "urn:xmpp:mam:0", MAMQueryParser.class));
- addFactory(new GenericPayloadParserFactory<MAMArchivedParser>("archived", "urn:xmpp:mam:0", MAMArchivedParser.class));
+ addFactory(new GenericPayloadParserFactory<MAMFinParser>("fin", "urn:xmpp:mam:0", MAMFinParser.class));
//addFactory(new NicknameParserFactory());
diff --git a/src/com/isode/stroke/parser/payloadparsers/MAMArchivedParser.java b/src/com/isode/stroke/parser/payloadparsers/MAMArchivedParser.java
deleted file mode 100644
index 5547a87..0000000
--- a/src/com/isode/stroke/parser/payloadparsers/MAMArchivedParser.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
-* Copyright (c) 2014 Kevin Smith and Remko Tronçon
-* All rights reserved.
-*/
-
-/*
-* Copyright (c) 2014, Isode Limited, London, England.
-* All rights reserved.
-*/
-
-package com.isode.stroke.parser.payloadparsers;
-
-import com.isode.stroke.elements.MAMArchived;
-import com.isode.stroke.jid.JID;
-import com.isode.stroke.parser.AttributeMap;
-import com.isode.stroke.parser.GenericPayloadParser;
-
-public class MAMArchivedParser extends GenericPayloadParser<MAMArchived> {
- public MAMArchivedParser() {
- super(new MAMArchived());
- }
-
- public void handleStartElement(String element, String ns, AttributeMap attributes) {
- if (level_ == 0) {
- String attributeValue = attributes.getAttributeValue("by");
- if (attributeValue != null) {
- getPayloadInternal().setBy(JID.fromString(attributeValue));
- }
- attributeValue = attributes.getAttributeValue("id");
- if (attributeValue != null) {
- getPayloadInternal().setID(attributeValue);
- }
- }
-
- ++level_;
- }
-
- public void handleEndElement(String element, String ns) {
- --level_;
- }
-
- public void handleCharacterData(String data) {
- }
-
- private int level_;
-}
diff --git a/src/com/isode/stroke/parser/payloadparsers/MAMFinParser.java b/src/com/isode/stroke/parser/payloadparsers/MAMFinParser.java
new file mode 100644
index 0000000..f5ebdec
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/MAMFinParser.java
@@ -0,0 +1,94 @@
+/*
+* Copyright (c) 2014 Kevin Smith and Remko Tronçon
+* All rights reserved.
+*/
+
+/*
+* Copyright (c) 2014, Isode Limited, London, England.
+* All rights reserved.
+*/
+
+package com.isode.stroke.parser.payloadparsers;
+
+import com.isode.stroke.elements.MAMFin;
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.elements.ResultSet;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.GenericPayloadParser;
+
+public class MAMFinParser extends GenericPayloadParser<MAMFin> {
+
+ private static final String QUERYID_ATTRIBUTE = "queryid";
+
+ private static final String STABLE_ATTRIBUTE = "stable";
+
+ private static final String COMPLETE_ATTRIBUTE = "complete";
+
+ private static final String SET_ELEMENT = "set";
+
+ private static final String SET_NS = "http://jabber.org/protocol/rsm";
+
+ private static final int TOP_LEVEL = 0;
+
+ private static final int PAYLOAD_LEVEL = 1;
+
+ private ResultSetParser resultSetParser_ = null;
+
+ private int level_ = 0;
+
+ public MAMFinParser() {
+ super(new MAMFin());
+ }
+
+ @Override
+ public void handleStartElement(String element, String ns,
+ AttributeMap attributes) {
+ if (level_ == TOP_LEVEL) {
+ MAMFin internalPayload = getPayloadInternal();
+ internalPayload.setComplete(attributes.getBoolAttribute(COMPLETE_ATTRIBUTE, false));
+ internalPayload.setStable(attributes.getBoolAttribute(STABLE_ATTRIBUTE, true));
+ String idAttributeValue = attributes.getAttributeValue(QUERYID_ATTRIBUTE);
+ if (idAttributeValue != null) {
+ internalPayload.setQueryID(idAttributeValue);
+ }
+ }
+ else if (level_ == PAYLOAD_LEVEL) {
+ if (element == SET_ELEMENT && ns == SET_NS) {
+ resultSetParser_ = new ResultSetParser();
+ }
+ }
+
+ if (resultSetParser_ != null) {
+ // Parsing a nested result set
+ resultSetParser_.handleStartElement(element, ns, attributes);
+ }
+
+ ++level_;
+ }
+
+ @Override
+ public void handleEndElement(String element, String ns) {
+ --level_;
+
+ if (resultSetParser_ != null && level_ >= PAYLOAD_LEVEL) {
+ resultSetParser_.handleEndElement(element, ns);
+ }
+
+ if (resultSetParser_ != null && level_ == PAYLOAD_LEVEL) {
+ MAMFin internalPayload = getPayloadInternal();
+ Payload resultSetParserPayload = resultSetParser_.getPayload();
+ if (resultSetParserPayload instanceof ResultSet) {
+ internalPayload.setResultSet((ResultSet) resultSetParser_.getPayload());
+ }
+ resultSetParser_ = null;
+ }
+ }
+
+ @Override
+ public void handleCharacterData(String data) {
+ if (resultSetParser_ != null) {
+ resultSetParser_.handleCharacterData(data);
+ }
+ }
+
+}
diff --git a/src/com/isode/stroke/parser/payloadparsers/MAMQueryParser.java b/src/com/isode/stroke/parser/payloadparsers/MAMQueryParser.java
index fcfd5e4..2543a68 100644
--- a/src/com/isode/stroke/parser/payloadparsers/MAMQueryParser.java
+++ b/src/com/isode/stroke/parser/payloadparsers/MAMQueryParser.java
@@ -24,9 +24,14 @@ public class MAMQueryParser extends GenericPayloadParser<MAMQuery> {
public void handleStartElement(String element, String ns, AttributeMap attributes) {
if (level_ == 0) {
- String attributeValue = attributes.getAttributeValue("queryid");
- if (attributeValue != null) {
- getPayloadInternal().setQueryID(attributeValue);
+ MAMQuery payloadInternal = getPayloadInternal();
+ String queryIDValue = attributes.getAttributeValue("queryid");
+ if (queryIDValue != null) {
+ payloadInternal.setQueryID(queryIDValue);
+ }
+ String nodeValue = attributes.getAttributeValue("node");
+ if (nodeValue != null) {
+ payloadInternal.setNode(nodeValue);
}
} else if (level_ == 1) {
if (element == "x" && ns == "jabber:x:data") {
diff --git a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
index ee8ad05..5da22b8 100644
--- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
+++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
@@ -66,7 +66,6 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection
addSerializer(new ForwardedSerializer(this));
addSerializer(new MAMResultSerializer(this));
addSerializer(new MAMQuerySerializer());
- addSerializer(new MAMArchivedSerializer());
}
}
diff --git a/src/com/isode/stroke/serializer/payloadserializers/MAMArchivedSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/MAMArchivedSerializer.java
deleted file mode 100644
index 0a5f1f4..0000000
--- a/src/com/isode/stroke/serializer/payloadserializers/MAMArchivedSerializer.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-* Copyright (c) 2014 Kevin Smith and Remko Tronçon
-* All rights reserved.
-*/
-
-/*
-* Copyright (c) 2014, Isode Limited, London, England.
-* All rights reserved.
-*/
-
-package com.isode.stroke.serializer.payloadserializers;
-
-import com.isode.stroke.elements.MAMArchived;
-import com.isode.stroke.serializer.GenericPayloadSerializer;
-import com.isode.stroke.serializer.xml.XMLElement;
-
-public class MAMArchivedSerializer extends GenericPayloadSerializer<MAMArchived> {
- public MAMArchivedSerializer() {
- super(MAMArchived.class);
- }
-
- protected String serializePayload(MAMArchived payload) {
- if (payload == null) {
- return "";
- }
-
- XMLElement element = new XMLElement("archived", "urn:xmpp:mam:0");
- element.setAttribute("by", payload.getBy().toString());
- element.setAttribute("id", payload.getID());
-
- return element.serialize();
- }
-}
diff --git a/src/com/isode/stroke/serializer/payloadserializers/MAMFinSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/MAMFinSerializer.java
new file mode 100644
index 0000000..3fcbc1d
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/MAMFinSerializer.java
@@ -0,0 +1,44 @@
+package com.isode.stroke.serializer.payloadserializers;
+
+import com.isode.stroke.elements.MAMFin;
+import com.isode.stroke.elements.ResultSet;
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.serializer.xml.XMLRawTextNode;
+
+public class MAMFinSerializer extends GenericPayloadSerializer<MAMFin> {
+
+ public MAMFinSerializer() {
+ super(MAMFin.class);
+ }
+
+ @Override
+ protected String serializePayload(MAMFin payload) {
+ if (payload == null) {
+ return "";
+ }
+
+ XMLElement element = new XMLElement("fin","urn:xmpp:mam:0");
+
+ if (payload.isComplete()) {
+ element.setAttribute("complete", "true");
+ }
+ if (!payload.isStable()) {
+ element.setAttribute("stable", "false");
+ }
+ String queryIDValue = payload.getQueryID();
+ if (queryIDValue != null) {
+ element.setAttribute("queryid", queryIDValue);
+ }
+ ResultSet resultSet = payload.getResultSet();
+ if (resultSet != null) {
+ ResultSetSerializer resultSetSerialized = new ResultSetSerializer();
+ String serializedResultSet = resultSetSerialized.serialize(resultSet);
+ XMLRawTextNode rawTextNode = new XMLRawTextNode(serializedResultSet);
+ element.addNode(rawTextNode);
+ }
+
+ return element.serialize();
+ }
+
+}
diff --git a/src/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializer.java b/src/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializer.java
index 46cc42c..b027f7c 100644
--- a/src/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializer.java
+++ b/src/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializer.java
@@ -21,6 +21,10 @@ public class MAMQuerySerializer extends GenericPayloadSerializer<MAMQuery> {
if (payload.getQueryID() != null) {
element.setAttribute("queryid", payload.getQueryID());
}
+
+ if (payload.getNode() != null) {
+ element.setAttribute("node", payload.getNode());
+ }
if (payload.getForm() != null) {
element.addNode(new XMLRawTextNode((new FormSerializer()).serialize(payload.getForm())));
diff --git a/test/com/isode/stroke/parser/payloadparsers/MAMArchivedParserTest.java b/test/com/isode/stroke/parser/payloadparsers/MAMArchivedParserTest.java
deleted file mode 100644
index 9a657b7..0000000
--- a/test/com/isode/stroke/parser/payloadparsers/MAMArchivedParserTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
-* Copyright (c) 2014 Kevin Smith and Remko Tronçon
-* All rights reserved.
-*/
-
-/*
-* Copyright (c) 2014, Isode Limited, London, England.
-* All rights reserved.
-*/
-
-package com.isode.stroke.parser.payloadparsers;
-
-import org.junit.Test;
-import com.isode.stroke.elements.MAMArchived;
-import com.isode.stroke.eventloop.DummyEventLoop;
-import com.isode.stroke.jid.JID;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-public class MAMArchivedParserTest {
-
- @Test
- public void testParse() {
- DummyEventLoop eventLoop = new DummyEventLoop();
- PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
- assertTrue(parser.parse(
- "<archived by=\"juliet@capulet.lit\" id=\"28482-98726-73623\" xmlns=\"urn:xmpp:mam:0\"/>"));
-
- MAMArchived payload = (MAMArchived)parser.getPayload();
- assertTrue(payload != null);
- assertEquals(JID.fromString("juliet@capulet.lit"), payload.getBy());
- assertEquals("28482-98726-73623", payload.getID());
- }
-}
diff --git a/test/com/isode/stroke/parser/payloadparsers/MAMFinParserTest.java b/test/com/isode/stroke/parser/payloadparsers/MAMFinParserTest.java
new file mode 100644
index 0000000..d6b1c47
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/MAMFinParserTest.java
@@ -0,0 +1,52 @@
+package com.isode.stroke.parser.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.isode.stroke.elements.MAMFin;
+import com.isode.stroke.eventloop.DummyEventLoop;
+
+public class MAMFinParserTest {
+
+ // From swiften test 'testParse_XEP0313_Exmaple1'
+ @Test
+ public void testParse_XEP0313_Example1() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertTrue(parser.parse("<fin xmlns='urn:xmpp:mam:0' queryid='f27' />"));
+
+ MAMFin payload = (MAMFin)parser.getPayload();
+ assertTrue(payload != null);
+ assertEquals(false,payload.isComplete());
+ assertEquals(true,payload.isStable());
+
+ String queryID = payload.getQueryID();
+ assertTrue(queryID != null);
+ assertEquals("f27",queryID);
+ }
+
+ // From swiften test 'testParse_XEP0313_Exmaple9'
+ @Test
+ public void testParse_XEP0313_Example9() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertTrue(parser.parse(
+ "<fin xmlns='urn:xmpp:mam:0' 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>"));
+
+ MAMFin payload = (MAMFin)parser.getPayload();
+ assertTrue(payload != null);
+ assertEquals(true,payload.isComplete());
+ assertEquals(true,payload.isStable());
+
+ assertTrue(payload.getResultSet() != null);
+ }
+
+}
diff --git a/test/com/isode/stroke/parser/payloadparsers/MAMQueryParserTest.java b/test/com/isode/stroke/parser/payloadparsers/MAMQueryParserTest.java
index 1cd09d1..454843e 100644
--- a/test/com/isode/stroke/parser/payloadparsers/MAMQueryParserTest.java
+++ b/test/com/isode/stroke/parser/payloadparsers/MAMQueryParserTest.java
@@ -25,7 +25,7 @@ public class MAMQueryParserTest {
DummyEventLoop eventLoop = new DummyEventLoop();
PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
assertTrue(parser.parse(
- "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">"
+ "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\" node=\"node1\">"
+ "<x type=\"form\" xmlns=\"jabber:x:data\">"
+ "<field type=\"text-single\" var=\"FORM_TYPE\">"
+ "<value>urn:xmpp:mam:0</value>"
@@ -43,6 +43,8 @@ public class MAMQueryParserTest {
assertTrue(payload != null);
assertTrue(payload.getQueryID() != null);
assertEquals("id0", payload.getQueryID());
+ assertTrue(payload.getNode() != null);
+ assertEquals("node1",payload.getNode());
assertTrue(payload.getForm() != null);
@@ -58,6 +60,61 @@ public class MAMQueryParserTest {
assertTrue(resultSet.getMaxItems() != null);
assertEquals(resultSet.getMaxItems(), new Long(10));
}
+
+ @Test
+ public void testParse_XEP0313_Example3() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertTrue(parser.parse(
+ "<query xmlns='urn:xmpp:mam:0'>"
+ +"<x xmlns='jabber:x:data'>"
+ +"<field var='FORM_TYPE'>"
+ +"<value>urn:xmpp:mam:0</value>"
+ +"</field>"
+ +"<field var='with'>"
+ +"<value>juliet@capulet.lit</value>"
+ +"</field>"
+ +"</x>"
+ +"</query>"));
+
+ MAMQuery payload = (MAMQuery) parser.getPayload();
+ assertTrue(payload != null);
+ assertTrue(payload.getForm() != null);
+ assertTrue(payload.getForm().getField("FORM_TYPE") != null);
+ assertTrue(payload.getForm().getField("with") != null);
+ assertEquals("urn:xmpp:mam:0",payload.getForm().getField("FORM_TYPE").getTextSingleValue());
+ assertEquals("juliet@capulet.lit",payload.getForm().getField("with").getTextSingleValue());
+ }
+
+ @Test
+ public void testParse_XEP0313_Example4() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertTrue(parser.parse(
+ "<query xmlns='urn:xmpp:mam:0'>"
+ +"<x xmlns='jabber:x:data'>"
+ +"<field var='FORM_TYPE'>"
+ +"<value>urn:xmpp:mam:0</value>"
+ +"</field>"
+ +"<field var='start'>"
+ +"<value>2010-06-07T00:00:00Z</value>"
+ +"</field>"
+ +"<field var='end'>"
+ +"<value>2010-07-07T13:23:54Z</value>"
+ +"</field>"
+ +"</x>"
+ +"</query>"));
+
+ MAMQuery payload = (MAMQuery) parser.getPayload();
+ assertTrue(payload != null);
+ assertTrue(payload.getForm() != null);
+ assertTrue(payload.getForm().getField("FORM_TYPE") != null);
+ assertTrue(payload.getForm().getField("start") != null);
+ assertTrue(payload.getForm().getField("end") != null);
+ assertEquals("urn:xmpp:mam:0",payload.getForm().getField("FORM_TYPE").getTextSingleValue());
+ assertEquals("2010-06-07T00:00:00Z",payload.getForm().getField("start").getTextSingleValue());
+ assertEquals("2010-07-07T13:23:54Z",payload.getForm().getField("end").getTextSingleValue());
+ }
@Test
public void testParseEmpty() {
diff --git a/test/com/isode/stroke/serializer/payloadserializers/MAMArchivedSerilaizerTest.java b/test/com/isode/stroke/serializer/payloadserializers/MAMArchivedSerilaizerTest.java
deleted file mode 100644
index 865ad0c..0000000
--- a/test/com/isode/stroke/serializer/payloadserializers/MAMArchivedSerilaizerTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-* Copyright (c) 2014 Kevin Smith and Remko Tronçon
-* All rights reserved.
-*/
-
-/*
-* Copyright (c) 2014, Isode Limited, London, England.
-* All rights reserved.
-*/
-
-package com.isode.stroke.serializer.payloadserializers;
-
-import org.junit.Test;
-import com.isode.stroke.elements.MAMArchived;
-import com.isode.stroke.jid.JID;
-import static org.junit.Assert.assertEquals;
-
-public class MAMArchivedSerilaizerTest {
-
- @Test
- public void testSerialize() {
- MAMArchivedSerializer serializer = new MAMArchivedSerializer();
-
- MAMArchived archived = new MAMArchived();
- archived.setBy(JID.fromString("juliet@capulet.lit"));
- archived.setID("28482-98726-73623");
-
- String expectedResult =
- "<archived by=\"juliet@capulet.lit\" id=\"28482-98726-73623\" xmlns=\"urn:xmpp:mam:0\"/>";
-
- assertEquals(expectedResult, serializer.serialize(archived));
- }
-}
diff --git a/test/com/isode/stroke/serializer/payloadserializers/MAMFinSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/MAMFinSerializerTest.java
new file mode 100644
index 0000000..111ba17
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/MAMFinSerializerTest.java
@@ -0,0 +1,51 @@
+package com.isode.stroke.serializer.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.isode.stroke.elements.MAMFin;
+import com.isode.stroke.elements.ResultSet;
+
+public class MAMFinSerializerTest {
+
+ // From swiften test testSerialize_XEP0313_Exmaple1
+ @Test
+ public void testSerialize_XEP0313_Example1() {
+ MAMFinSerializer serializer = new MAMFinSerializer();
+
+ MAMFin fin = new MAMFin();
+ fin.setQueryID("f27");
+
+ String expectedResult = "<fin queryid=\"f27\" xmlns=\"urn:xmpp:mam:0\"/>";
+ assertEquals(expectedResult,serializer.serialize(fin));
+ }
+
+ // From swiften test testSerialize_XEP0313_Exmaple9
+ @Test
+ public void testSerialize_XEP0313_Example9() {
+ MAMFinSerializer serializer = new MAMFinSerializer();
+
+ MAMFin fin = new MAMFin();
+ fin.setComplete(true);
+
+ ResultSet resultSet = new ResultSet();
+ resultSet.setFirstID("23452-4534-1");
+ resultSet.setFirstIDIndex(Long.valueOf(0));
+ resultSet.setLastID("390-2342-22");
+ resultSet.setCount(Long.valueOf(16));
+
+ fin.setResultSet(resultSet);
+ String expectedResult =
+ "<fin complete=\"true\" xmlns=\"urn:xmpp:mam:0\">"
+ +"<set xmlns=\"http://jabber.org/protocol/rsm\">"
+ +"<count>16</count>"
+ +"<first index=\"0\">23452-4534-1</first>"
+ +"<last>390-2342-22</last>"
+ +"</set>"
+ +"</fin>";
+ assertEquals(expectedResult, serializer.serialize(fin));
+ }
+
+
+}
diff --git a/test/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializerTest.java
index 519b981..82083cc 100644
--- a/test/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializerTest.java
+++ b/test/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializerTest.java
@@ -39,11 +39,12 @@ public class MAMQuerySerializerTest {
MAMQuery query = new MAMQuery();
query.setQueryID("id0");
+ query.setNode("node1");
query.setForm(parameters);
query.setResultSet(set);
String expectedResult =
- "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">"
+ "<query node=\"node1\" queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">"
+ "<x type=\"form\" xmlns=\"jabber:x:data\">"
+ "<field type=\"text-single\" var=\"FORM_TYPE\">"
+ "<value>urn:xmpp:mam:0</value>"