use of org.jivesoftware.smackx.xdata.FormField in project Smack by igniterealtime.
the class DataFormTest method testValidation.
@Test
public void testValidation() throws Exception {
//Build a Form
DataForm df = new DataForm(DataForm.Type.submit);
String instruction = "InstructionTest1";
df.addInstruction(instruction);
FormField field = new FormField("testField1");
df.addField(field);
ValidateElement dv = new RangeValidateElement("xs:integer", "1111", "9999");
field.setValidateElement(dv);
assertNotNull(df.toXML());
String output = df.toXML().toString();
assertEquals(TEST_OUTPUT_3, output);
XmlPullParser parser = PacketParserUtils.getParserFor(output);
df = pr.parse(parser);
assertNotNull(df);
assertNotNull(df.getFields());
assertEquals(1, df.getFields().size());
Element element = df.getFields().get(0).getValidateElement();
assertNotNull(element);
dv = (ValidateElement) element;
assertEquals("xs:integer", dv.getDatatype());
assertNotNull(df.toXML());
output = df.toXML().toString();
assertEquals(TEST_OUTPUT_3, output);
}
use of org.jivesoftware.smackx.xdata.FormField in project Smack by igniterealtime.
the class DataValidationHelperTest method testCheckConsistencyFormFieldRegexValidateElement.
@Test
public void testCheckConsistencyFormFieldRegexValidateElement() {
FormField field = new FormField("var");
field.setType(FormField.Type.list_multi);
RegexValidateElement element = new RegexValidateElement(null, ".*");
try {
element.checkConsistency(field);
fail("No correct check on consistency");
} catch (ValidationConsistencyException e) {
assertEquals("Field type 'list-multi' is not consistent with validation method 'regex'.", e.getMessage());
}
}
use of org.jivesoftware.smackx.xdata.FormField in project Smack by igniterealtime.
the class DataValidationHelperTest method testCheckConsistencyFormFieldOpenValidateElement.
@Test
public void testCheckConsistencyFormFieldOpenValidateElement() {
FormField field = new FormField("var");
field.setType(FormField.Type.hidden);
OpenValidateElement element = new OpenValidateElement(null);
try {
element.checkConsistency(field);
fail("No correct check on consistency");
} catch (ValidationConsistencyException e) {
assertEquals("Field type 'hidden' is not consistent with validation method 'open'.", e.getMessage());
}
}
use of org.jivesoftware.smackx.xdata.FormField in project Smack by igniterealtime.
the class RoomInfoTest method validateRoomWithForm.
@Test
public void validateRoomWithForm() {
DataForm dataForm = new DataForm(DataForm.Type.result);
FormField desc = new FormField("muc#roominfo_description");
desc.addValue("The place for all good witches!");
dataForm.addField(desc);
FormField subject = new FormField("muc#roominfo_subject");
subject.addValue("Spells");
dataForm.addField(subject);
FormField occupants = new FormField("muc#roominfo_occupants");
occupants.addValue("3");
dataForm.addField(occupants);
DiscoverInfo discoInfo = new DiscoverInfo();
discoInfo.addExtension(dataForm);
RoomInfo roomInfo = new RoomInfo(discoInfo);
assertEquals("The place for all good witches!", roomInfo.getDescription());
assertEquals("Spells", roomInfo.getSubject());
assertEquals(3, roomInfo.getOccupantsCount());
}
use of org.jivesoftware.smackx.xdata.FormField in project Smack by igniterealtime.
the class EnablePushNotificationsIQ method getIQChildElementBuilder.
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.attribute("jid", jid);
xml.attribute("node", node);
xml.rightAngleBracket();
if (publishOptions != null) {
DataForm dataForm = new DataForm(DataForm.Type.form);
FormField formTypeField = new FormField("FORM_TYPE");
formTypeField.addValue(PubSub.NAMESPACE + "#publish-options");
dataForm.addField(formTypeField);
Iterator<Map.Entry<String, String>> publishOptionsIterator = publishOptions.entrySet().iterator();
while (publishOptionsIterator.hasNext()) {
Map.Entry<String, String> pairVariableValue = publishOptionsIterator.next();
FormField field = new FormField(pairVariableValue.getKey());
field.addValue(pairVariableValue.getValue());
dataForm.addField(field);
}
xml.element(dataForm);
}
return xml;
}
Aggregations