Search in sources :

Example 31 with FormField

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);
}
Also used : RangeValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RangeValidateElement) ValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement) RangeValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RangeValidateElement) Element(org.jivesoftware.smack.packet.Element) ValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement) RangeValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RangeValidateElement) XmlPullParser(org.xmlpull.v1.XmlPullParser) FormField(org.jivesoftware.smackx.xdata.FormField) Test(org.junit.Test)

Example 32 with FormField

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());
    }
}
Also used : RegexValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RegexValidateElement) FormField(org.jivesoftware.smackx.xdata.FormField) Test(org.junit.Test)

Example 33 with FormField

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());
    }
}
Also used : OpenValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.OpenValidateElement) FormField(org.jivesoftware.smackx.xdata.FormField) Test(org.junit.Test)

Example 34 with FormField

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());
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField) Test(org.junit.Test)

Example 35 with FormField

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;
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

FormField (org.jivesoftware.smackx.xdata.FormField)46 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)18 Test (org.junit.Test)10 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)6 ArrayList (java.util.ArrayList)4 TreeSet (java.util.TreeSet)3 Element (org.jivesoftware.smack.packet.Element)3 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)3 Form (org.jivesoftware.smackx.xdata.Form)3 RangeValidateElement (org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RangeValidateElement)3 XmlPullParser (org.xmlpull.v1.XmlPullParser)3 LinkedList (java.util.LinkedList)2 IQ (org.jivesoftware.smack.packet.IQ)2 RemoteCommand (org.jivesoftware.smackx.commands.RemoteCommand)2 StreamInitiation (org.jivesoftware.smackx.si.packet.StreamInitiation)2 ValidateElement (org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Method (java.lang.reflect.Method)1 MessageDigest (java.security.MessageDigest)1 HashMap (java.util.HashMap)1