summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Clayton <alex.clayton@isode.com>2014-11-13 15:15:41 (GMT)
committerAlex Clayton <alex.clayton@isode.com>2014-11-26 09:39:53 (GMT)
commitb89bf2f3363bac56fcc5d02f5fb690c73eaaacdf (patch)
tree39893e33d2bb88f0eef3e04ae9533bb1d6139c17 /test/com/isode
parent47cad5fd7883b8c7273ea11073643aa585b485c6 (diff)
downloadstroke-b89bf2f3363bac56fcc5d02f5fb690c73eaaacdf.zip
stroke-b89bf2f3363bac56fcc5d02f5fb690c73eaaacdf.tar.bz2
Bring Stroke inline with Swiften with respect to MAM
Some patches for MAM had gone into swiften without being ported to stroke. This patch should bring stroke update to date with Swiften. The swiften patches in question are 9b762e1cf26cfe12cf601d9ea95cf91b3f95c799 -- Add node attribute to MAMQuery 8096f80861667381b777af774cfd446d6fc8cda8 -- Brining XEP-0313 (MAM) implementation in line with version 3.0. Test-information: Ran the updated JUnit tests in Eclipse they all passed ok. Ran make and make test in a stroke checkout. Everything build ok and the JUNit tests passed. Change-Id: I95bf5d598808f48fe2d7af12c0f07d852d68c115
Diffstat (limited to 'test/com/isode')
-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
6 files changed, 163 insertions, 69 deletions
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>"