summaryrefslogtreecommitdiffstats
path: root/test/com
diff options
context:
space:
mode:
authorTim Robbings <tim.robbings@isode.com>2014-10-22 09:06:10 (GMT)
committerSwift Review <review@swift.im>2014-10-28 10:00:39 (GMT)
commit47cad5fd7883b8c7273ea11073643aa585b485c6 (patch)
tree1d7bc39fc1c847e0bbe88716257a9a0710ac8745 /test/com
parent244aff320257d178bbe35d87b0e09d939bd2f893 (diff)
downloadstroke-47cad5fd7883b8c7273ea11073643aa585b485c6.zip
stroke-47cad5fd7883b8c7273ea11073643aa585b485c6.tar.bz2
Stroke FormField refactoring
Changes to catch up with Swiften changes to FormField in commit 00284e5, also adds <reported/> and <item/> elements, added to Swiften in commit 83afa3d. Changes include refactoring of the FormField class, changes to Form parser and serializer classes and updates to JUnit tests. Test-information: Tested using updated JUnit tests, all tests complete successfully. Change-Id: Ic91ad4a11a335fb3d2b2a2c4a1865f836e2af70b Reviewer: Alex Clayton <alex.clayton@isode.com> Reviewer: Gurmeen Bindra <gurmeen.bindra@isode.com>
Diffstat (limited to 'test/com')
-rw-r--r--test/com/isode/stroke/elements/FormTest.java15
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/FormParserTest.java81
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/MAMQueryParserTest.java9
-rw-r--r--test/com/isode/stroke/pubsub/PubSubTools.java22
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/FormSerializerTest.java109
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializerTest.java5
6 files changed, 142 insertions, 99 deletions
diff --git a/test/com/isode/stroke/elements/FormTest.java b/test/com/isode/stroke/elements/FormTest.java
index 1d37c86..f270976 100644
--- a/test/com/isode/stroke/elements/FormTest.java
+++ b/test/com/isode/stroke/elements/FormTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012 Isode Limited, London, England.
+ * Copyright (c) 2012-2014 Isode Limited, London, England.
* All rights reserved.
*/
/*
@@ -14,8 +14,7 @@ import static org.junit.Assert.assertEquals;
import org.junit.BeforeClass;
import org.junit.Test;
-import com.isode.stroke.elements.FormField.FixedFormField;
-import com.isode.stroke.elements.FormField.HiddenFormField;
+import com.isode.stroke.elements.FormField.Type;
public class FormTest {
@BeforeClass
@@ -26,13 +25,13 @@ public class FormTest {
public void testGetFormType() {
Form form = new Form();
- form.addField(FixedFormField.create("Foo"));
+ form.addField(new FormField(Type.FIXED_TYPE, "Foo"));
- FormField field = HiddenFormField.create("jabber:bot");
+ FormField field = new FormField(Type.HIDDEN_TYPE, "jabber:bot");
field.setName("FORM_TYPE");
form.addField(field);
- form.addField(FixedFormField.create("Bar"));
+ form.addField(new FormField(Type.FIXED_TYPE, "Bar"));
assertEquals("jabber:bot", form.getFormType());
}
@@ -41,7 +40,7 @@ public class FormTest {
public void testGetFormType_InvalidFormType() {
Form form = new Form();
- FormField field = FixedFormField.create("jabber:bot");
+ FormField field = new FormField(Type.FIXED_TYPE, "jabber:bot");
field.setName("FORM_TYPE");
form.addField(field);
@@ -52,7 +51,7 @@ public class FormTest {
public void testGetFormType_NoFormType() {
Form form = new Form();
- form.addField(FixedFormField.create("Foo"));
+ form.addField(new FormField(Type.FIXED_TYPE, "Foo"));
assertEquals("", form.getFormType());
}
diff --git a/test/com/isode/stroke/parser/payloadparsers/FormParserTest.java b/test/com/isode/stroke/parser/payloadparsers/FormParserTest.java
index 5dace99..4ab8190 100644
--- a/test/com/isode/stroke/parser/payloadparsers/FormParserTest.java
+++ b/test/com/isode/stroke/parser/payloadparsers/FormParserTest.java
@@ -1,12 +1,11 @@
/*
- * Copyright (c) 2012 Isode Limited, London, England.
+ * Copyright (c) 2012-2014 Isode Limited, London, England.
* All rights reserved.
*/
/*
* Copyright (c) 2010 Remko Tronçon
* All rights reserved.
*/
-
package com.isode.stroke.parser.payloadparsers;
import static org.junit.Assert.assertEquals;
@@ -16,16 +15,8 @@ import org.junit.BeforeClass;
import org.junit.Test;
import com.isode.stroke.elements.Form;
-import com.isode.stroke.elements.Payload;
import com.isode.stroke.elements.Form.Type;
-import com.isode.stroke.elements.FormField.BooleanFormField;
-import com.isode.stroke.elements.FormField.FixedFormField;
-import com.isode.stroke.elements.FormField.HiddenFormField;
-import com.isode.stroke.elements.FormField.JIDMultiFormField;
-import com.isode.stroke.elements.FormField.ListMultiFormField;
-import com.isode.stroke.elements.FormField.ListSingleFormField;
-import com.isode.stroke.elements.FormField.TextMultiFormField;
-import com.isode.stroke.elements.FormField.TextSingleFormField;
+import com.isode.stroke.elements.Payload;
import com.isode.stroke.eventloop.DummyEventLoop;
import com.isode.stroke.jid.JID;
@@ -73,6 +64,16 @@ public class FormParserTest {
+ "<field type=\"hidden\" var=\"FORM_TYPE\">"
+ "<value>jabber:bot</value>"
+ "</field>"
+ + "<reported>"
+ + "<field var=\"field name\" label=\"description\" type=\"unknown\">"
+ + "<value>someText</value>"
+ + "</field>"
+ + "</reported>"
+ + "<item>"
+ + "<field label=\"itemField\">"
+ + "<value>itemValue</value>"
+ + "</field>"
+ + "</item>"
+ "<field type=\"fixed\"><value>Section 1: Bot Info</value></field>"
+ "<field label=\"The name of your bot\" type=\"text-single\" var=\"botname\"/>"
+ "<field label=\"Helpful description of your bot\" type=\"text-multi\" var=\"description\"><value>This is a bot.</value><value>A quite good one actually</value></field>"
@@ -103,57 +104,57 @@ public class FormParserTest {
+ "<desc>Tell all your friends about your new bot!</desc>"
+ "<value>foo@bar.com</value>" + "<value>baz@fum.org</value>"
+ "</field>" + "<field var=\"untyped\">" + "<value>foo</value>"
- + "</field>" + "</x>");
+ + "</field>"
+ + "</x>");
+
+
assertEquals(10, payload.getFields().size());
- assertEquals("jabber:bot", ((HiddenFormField) (payload.getFields()
- .get(0))).getValue());
+
+ assertEquals("jabber:bot", payload.getFields().get(0).getValues().get(0));
+
assertEquals("FORM_TYPE", payload.getFields().get(0).getName());
assertTrue(!payload.getFields().get(0).getRequired());
+
+ assertEquals("description", payload.getReportedFields().get(0).getLabel());
+ assertEquals("someText", payload.getReportedFields().get(0).getValues().get(0));
+ assertEquals("itemField", payload.getItems().get(0).getItemFields().get(0).getLabel());
+ assertEquals("itemValue", payload.getItems().get(0).getItemFields().get(0).getValues().get(0));
- assertEquals("Section 1: Bot Info", ((FixedFormField) (payload
- .getFields().get(1))).getValue());
+ assertEquals("Section 1: Bot Info", payload.getFields().get(1).getValues().get(0));
assertEquals("The name of your bot", payload.getFields().get(2)
.getLabel());
assertEquals("This is a bot.\nA quite good one actually",
- ((TextMultiFormField) (payload.getFields().get(3))).getValue());
+ payload.getFields().get(3).getTextMultiValue());
- assertEquals(Boolean.TRUE, ((BooleanFormField) (payload.getFields()
- .get(4))).getValue());
+ assertEquals(Boolean.TRUE, payload.getFields()
+ .get(4).getBoolValue());
assertTrue(payload.getFields().get(4).getRequired());
- assertEquals("1", ((BooleanFormField) (payload.getFields().get(4)))
- .getRawValues().get(0));
+ assertEquals("1", payload.getFields().get(4).getValues().get(0));
- assertEquals("news",
- ((ListMultiFormField) (payload.getFields().get(6))).getValue()
- .get(0));
- assertEquals("news", payload.getFields().get(6).getRawValues().get(0));
- assertEquals("search", ((ListMultiFormField) (payload.getFields()
- .get(6))).getValue().get(1));
- assertEquals("search", payload.getFields().get(6).getRawValues().get(1));
+ assertEquals("news", payload.getFields().get(6).getValues().get(0));
+ assertEquals("search", payload.getFields().get(6).getValues().get(1));
assertEquals(5, payload.getFields().get(6).getOptions().size());
assertEquals("Contests",
- payload.getFields().get(6).getOptions().get(0).label);
+ payload.getFields().get(6).getOptions().get(0).label_);
assertEquals("contests",
- payload.getFields().get(6).getOptions().get(0).value);
+ payload.getFields().get(6).getOptions().get(0).value_);
assertEquals("News",
- payload.getFields().get(6).getOptions().get(1).label);
+ payload.getFields().get(6).getOptions().get(1).label_);
assertEquals("news",
- payload.getFields().get(6).getOptions().get(1).value);
+ payload.getFields().get(6).getOptions().get(1).value_);
- assertEquals("20", ((ListSingleFormField) (payload.getFields().get(7)))
- .getValue());
+ assertEquals("20", payload.getFields().get(7).getValues().get(0));
- assertEquals(new JID("foo@bar.com"), ((JIDMultiFormField) (payload
- .getFields().get(8))).getValue().get(0));
- assertEquals(new JID("baz@fum.org"), ((JIDMultiFormField) (payload
- .getFields().get(8))).getValue().get(1));
+ assertEquals(new JID("foo@bar.com"), payload
+ .getFields().get(8).getJIDMultiValue(0));
+ assertEquals(new JID("baz@fum.org"), payload
+ .getFields().get(8).getJIDMultiValue(1));
assertEquals("Tell all your friends about your new bot!", payload
.getFields().get(8).getDescription());
- assertEquals("foo",
- ((TextSingleFormField) (payload.getFields().get(9))).getValue());
+ assertEquals("foo", payload.getFields().get(9).getValues().get(0));
}
} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/MAMQueryParserTest.java b/test/com/isode/stroke/parser/payloadparsers/MAMQueryParserTest.java
index c98562f..1cd09d1 100644
--- a/test/com/isode/stroke/parser/payloadparsers/MAMQueryParserTest.java
+++ b/test/com/isode/stroke/parser/payloadparsers/MAMQueryParserTest.java
@@ -45,12 +45,13 @@ public class MAMQueryParserTest {
assertEquals("id0", payload.getQueryID());
assertTrue(payload.getForm() != null);
- FormField.TextSingleFormField fieldType = (FormField.TextSingleFormField)payload.getForm().getField("FORM_TYPE");
+
+ FormField fieldType = payload.getForm().getField("FORM_TYPE");
assertTrue(fieldType != null);
- assertEquals("urn:xmpp:mam:0", fieldType.getValue());
- FormField.TextSingleFormField fieldStart = (FormField.TextSingleFormField)payload.getForm().getField("start");
+ assertEquals("urn:xmpp:mam:0", fieldType.getTextSingleValue());
+ FormField fieldStart = payload.getForm().getField("start");
assertTrue(fieldStart != null);
- assertEquals("2010-08-07T00:00:00Z", fieldStart.getValue());
+ assertEquals("2010-08-07T00:00:00Z", fieldStart.getTextSingleValue());
assertTrue(payload.getResultSet() != null);
ResultSet resultSet = payload.getResultSet();
diff --git a/test/com/isode/stroke/pubsub/PubSubTools.java b/test/com/isode/stroke/pubsub/PubSubTools.java
index 17d0896..2af92bf 100644
--- a/test/com/isode/stroke/pubsub/PubSubTools.java
+++ b/test/com/isode/stroke/pubsub/PubSubTools.java
@@ -14,8 +14,7 @@ import com.isode.stroke.elements.DiscoItems;
import com.isode.stroke.elements.ErrorPayload;
import com.isode.stroke.elements.Form;
import com.isode.stroke.elements.FormField;
-import com.isode.stroke.elements.FormField.BooleanFormField;
-import com.isode.stroke.elements.FormField.ListSingleFormField;
+import com.isode.stroke.elements.FormField.Type;
import com.isode.stroke.elements.IQ;
import com.isode.stroke.elements.Payload;
import com.isode.stroke.elements.PubSub;
@@ -35,7 +34,6 @@ import com.isode.stroke.elements.PubSubPublish;
import com.isode.stroke.elements.PubSubRetract;
import com.isode.stroke.elements.PubSubSubscribe;
import com.isode.stroke.elements.PubSubSubscriptions;
-import com.isode.stroke.elements.FormField.TextSingleFormField;
import com.isode.stroke.elements.PubSubUnsubscribe;
import com.isode.stroke.jid.JID;
import com.isode.stroke.queries.GenericRequest;
@@ -189,15 +187,15 @@ public class PubSubTools {
Form form = config.getData();
for (FormField field : form.getFields()) {
if (field.getName().equals(parameter)) {
- if (field instanceof TextSingleFormField) { /* find and update the specified parameter */
- TextSingleFormField fieldText = (TextSingleFormField)field;
- fieldText.setValue(newValue);
- } else if (field instanceof ListSingleFormField) {
- ListSingleFormField fieldList = (ListSingleFormField)field;
- fieldList.setValue(newValue);
- } else if (field instanceof BooleanFormField) {
- BooleanFormField fieldBoolean = (BooleanFormField)field;
- fieldBoolean.setValue(newValue.equals("1"));
+ if (field.getType() == Type.TEXT_SINGLE_TYPE) { /* find and update the specified parameter */
+ FormField fieldText = field;
+ fieldText.addValue(newValue);
+ } else if (field.getType() == Type.LIST_SINGLE_TYPE) {
+ FormField fieldList = field;
+ fieldList.addValue(newValue);
+ } else if (field.getType() == Type.BOOLEAN_TYPE) {
+ FormField fieldBoolean = field;
+ fieldBoolean.setBoolValue(newValue.equals("1"));
}
}
}
diff --git a/test/com/isode/stroke/serializer/payloadserializers/FormSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/FormSerializerTest.java
index 7636eb4..7b16aa4 100644
--- a/test/com/isode/stroke/serializer/payloadserializers/FormSerializerTest.java
+++ b/test/com/isode/stroke/serializer/payloadserializers/FormSerializerTest.java
@@ -1,36 +1,23 @@
/*
- * Copyright (c) 2012 Isode Limited, London, England.
+ * Copyright (c) 2012-2014 Isode Limited, London, England.
* All rights reserved.
*/
/*
* Copyright (c) 2010 Remko Tronçon
* All rights reserved.
*/
-
package com.isode.stroke.serializer.payloadserializers;
import static org.junit.Assert.assertEquals;
-import java.util.ArrayList;
-import java.util.List;
-
import org.junit.BeforeClass;
import org.junit.Test;
import com.isode.stroke.elements.Form;
-import com.isode.stroke.elements.FormField;
import com.isode.stroke.elements.Form.Type;
-import com.isode.stroke.elements.FormField.BooleanFormField;
-import com.isode.stroke.elements.FormField.FixedFormField;
-import com.isode.stroke.elements.FormField.HiddenFormField;
-import com.isode.stroke.elements.FormField.JIDMultiFormField;
-import com.isode.stroke.elements.FormField.ListMultiFormField;
-import com.isode.stroke.elements.FormField.ListSingleFormField;
+import com.isode.stroke.elements.FormField;
import com.isode.stroke.elements.FormField.Option;
-import com.isode.stroke.elements.FormField.TextMultiFormField;
-import com.isode.stroke.elements.FormField.TextPrivateFormField;
-import com.isode.stroke.elements.FormField.TextSingleFormField;
-import com.isode.stroke.jid.JID;
+import com.isode.stroke.elements.FormItem;
public class FormSerializerTest {
@BeforeClass
@@ -58,38 +45,51 @@ public class FormSerializerTest {
FormSerializer testling = new FormSerializer();
Form form = new Form(Type.FORM_TYPE);
- FormField field = HiddenFormField.create("jabber:bot");
+ FormField field = new FormField(FormField.Type.UNKNOWN_TYPE);
+ field.setName("field name");
+ field.setLabel("description");
+ field.addValue("someText");
+ form.addReportedField(field);
+
+ FormItem item = new FormItem();
+ field = new FormField(FormField.Type.UNKNOWN_TYPE);
+ field.setName("itemField");
+ field.addValue("itemValue");
+ item.addItemField(field);
+ form.addItem(item);
+
+ field = new FormField(FormField.Type.HIDDEN_TYPE, "jabber:bot");
field.setName("FORM_TYPE");
form.addField(field);
+
+ form.addField(new FormField(FormField.Type.FIXED_TYPE, "Section 1: Bot Info"));
- form.addField(FixedFormField.create("Section 1: Bot Info"));
-
- field = TextSingleFormField.create();
+ field = new FormField(FormField.Type.TEXT_SINGLE_TYPE);
field.setName("botname");
field.setLabel("The name of your bot");
form.addField(field);
- field = TextMultiFormField
- .create("This is a bot.\nA quite good one actually");
+ field = new FormField(FormField.Type.TEXT_MULTI_TYPE,
+ "This is a bot.\nA quite good one actually");
field.setName("description");
field.setLabel("Helpful description of your bot");
form.addField(field);
- field = BooleanFormField.create(true);
+ field = new FormField(FormField.Type.BOOLEAN_TYPE);
+ field.setBoolValue(true);
field.setName("public");
field.setLabel("Public bot?");
field.setRequired(true);
form.addField(field);
- field = TextPrivateFormField.create();
+ field = new FormField(FormField.Type.TEXT_PRIVATE_TYPE);
field.setName("password");
field.setLabel("Password for special access");
form.addField(field);
- List<String> values = new ArrayList<String>();
- values.add("news");
- values.add("search");
- field = ListMultiFormField.create(values);
+ field = new FormField(FormField.Type.LIST_MULTI_TYPE);
+ field.addValue("news");
+ field.addValue("search");
field.setName("features");
field.setLabel("What features will the bot support?");
field.addOption(new Option("Contests", "contests"));
@@ -99,7 +99,7 @@ public class FormSerializerTest {
field.addOption(new Option("Search", "search"));
form.addField(field);
- field = ListSingleFormField.create("20");
+ field = new FormField(FormField.Type.LIST_SINGLE_TYPE, "20");
field.setName("maxsubs");
field.setLabel("Maximum number of subscribers");
field.addOption(new Option("10", "10"));
@@ -109,11 +109,18 @@ public class FormSerializerTest {
field.addOption(new Option("100", "100"));
field.addOption(new Option("", "none"));
form.addField(field);
+
+ String jid = "user@example.com";
+ field = new FormField(FormField.Type.JID_SINGLE_TYPE);
+ field.addValue(jid);
+ field.setName("jidSingle");
+ field.setLabel("jidSingleLabel");
+ field.setDescription("jidSingleDescription");
+ form.addField(field);
- List<JID> jids = new ArrayList<JID>();
- jids.add(new JID("foo@bar.com"));
- jids.add(new JID("baz@fum.org"));
- field = JIDMultiFormField.create(jids);
+ field = new FormField(FormField.Type.JID_MULTI_TYPE);
+ field.addValue("foo@bar.com");
+ field.addValue("baz@fum.org");
field.setName("invitelist");
field.setLabel("People to invite");
field.setDescription("Tell all your friends about your new bot!");
@@ -121,6 +128,16 @@ public class FormSerializerTest {
assertEquals(
"<x type=\"form\" xmlns=\"jabber:x:data\">"
+ + "<reported>"
+ + "<field label=\"description\" type=\"unknown\" var=\"field name\">"
+ + "<value>someText</value>"
+ + "</field>"
+ + "</reported>"
+ + "<item>"
+ + "<field var=\"itemField\">"
+ + "<value>itemValue</value>"
+ + "</field>"
+ + "</item>"
+ "<field type=\"hidden\" var=\"FORM_TYPE\">"
+ "<value>jabber:bot</value>"
+ "</field>"
@@ -150,10 +167,36 @@ public class FormSerializerTest {
+ "<option label=\"100\"><value>100</value></option>"
+ "<option><value>none</value></option>"
+ "</field>"
+ + "<field label=\"jidSingleLabel\" type=\"jid-single\" var=\"jidSingle\">"
+ + "<desc>jidSingleDescription</desc>"
+ + "<value>user@example.com</value>"
+ + "</field>"
+ "<field label=\"People to invite\" type=\"jid-multi\" var=\"invitelist\">"
+ "<desc>Tell all your friends about your new bot!</desc>"
+ "<value>foo@bar.com</value>"
+ "<value>baz@fum.org</value>" + "</field>" + "</x>",
+
+ /*
+ + "<field label=\"booleanField\" type=\"boolean\"><value>0</value></field>"
+ + "<field label=\"fixedField\" type=\"fixed\"><value>Fixed></value></field>"
+ + "<field label=\"hiddenField\" type=\"hidden\"/>"
+ + "<field label=\"listSingleField\" type=\"list-single\">"
+ + "<option label=\"option1\"><value>listVal</value></option>"
+ + "<option label=\"option2\"><value>listVal</value></option>"
+ + "<option label=\"option3\"><value>listVal</value></option>"
+ + "</field>"
+ + "<field label=\"listMultiField\" type=\"list-multi\">"
+ + "<option label=\"option1\"><value>listVal</value></option>"
+ + "<option label=\"option1\"><value>listVal</value></option>"
+ + "<option label=\"option1\"><value>listVal</value></option>"
+ + "</field>"
+ + "<field label=\"textPrivateField\" type=\"text-private\"><value>textPrivateVal</value></field>"
+ + "<field label=\"textMultiField\" type=\"text-multi\">"
+ + ""
+ + ""
+ + ""
+ + "</field>"
+ */
testling.serialize(form));
}
}
diff --git a/test/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializerTest.java
index ab4a3fa..519b981 100644
--- a/test/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializerTest.java
+++ b/test/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializerTest.java
@@ -13,6 +13,7 @@ package com.isode.stroke.serializer.payloadserializers;
import org.junit.Test;
import com.isode.stroke.elements.Form;
import com.isode.stroke.elements.FormField;
+import com.isode.stroke.elements.FormField.Type;
import com.isode.stroke.elements.MAMQuery;
import com.isode.stroke.elements.ResultSet;
import static org.junit.Assert.assertEquals;
@@ -25,11 +26,11 @@ public class MAMQuerySerializerTest {
Form parameters = new Form();
- FormField.TextSingleFormField fieldType = FormField.TextSingleFormField.create("urn:xmpp:mam:0");
+ FormField fieldType = new FormField(Type.TEXT_SINGLE_TYPE, "urn:xmpp:mam:0");
fieldType.setName("FORM_TYPE");
parameters.addField(fieldType);
- FormField.TextSingleFormField fieldStart = FormField.TextSingleFormField.create("2010-08-07T00:00:00Z");
+ FormField fieldStart = new FormField(Type.TEXT_SINGLE_TYPE, "2010-08-07T00:00:00Z");
fieldStart.setName("start");
parameters.addField(fieldStart);