Package com.calclab.emite.xep.dataforms

Examples of com.calclab.emite.xep.dataforms.Form


        }

        // This is not a extended search. Try to create a form
        // with returned fields
        final SearchFields fieldResults = processFieldsResults(session.getCurrentUserURI(), iq.getQuery(XmppNamespaces.SEARCH));
        final Form form = new Form(Form.Type.form);
        form.addInstruction(fieldResults.getInstructions());
        for (final String fieldName : fieldResults.getFieldNames()) {
          final Field field = new Field();
          field.setType(Field.Type.TEXT_SINGLE);
          field.setVar(fieldName);
          form.addField(field);
        }
        listener.onSuccess(form);
      }

      @Override
View Full Code Here


        final XmppURI userUri = XmppURI.uri(item.getAttribute("jid"));
        setOccupantPresence(userUri, occupantURI, affiliation, role, presence.getShow(), presence.getStatus());
        if (hasStatus(xmuc, 201)) {
          final IQ iq = new IQ(IQ.Type.set);
          iq.setTo(roomUri.getJID());
          iq.addQuery(XmppNamespaces.MUC_OWNER).addChild(new Form(Form.Type.submit));

          session.sendIQ("rooms", iq, new IQCallback() {
            @Override
            public void onIQSuccess(final IQ iq) {
              status = RoomStatus.ready;
View Full Code Here

    session.answerSuccess(new IQ(XMLBuilder.fromXML(XEP_0055_3_SAMPLE_7)));
    Mockito.verify(result, Mockito.never()).onFailure(Matchers.anyString());
    Mockito.verify(result).onSuccess(Matchers.argThat(new ArgumentMatcher<Form>() {
      @Override
      public boolean matches(final Object arg0) {
        final Form response = (Form) arg0;
        assertEquals("User Directory Search", response.getTitle());
        assertEquals("Please provide the following information to search for Shakespearean characters.", response.getInstructions().get(0));
        return true;
      }
    }));
  }
View Full Code Here

  private XmppSessionTester session;

  @Test
  public void parseFieldsInIQ() {
    final Form result = parse(XEP_0004_5_1_SAMPLE_2);
    final List<Field> fields = result.getFields();
    assertEquals(12, fields.size());
    assertEquals("hidden", fields.get(0).getType());
    assertEquals("FORM_TYPE", fields.get(0).getVar());
    assertEquals("jabber:bot", fields.get(0).getValues().get(0));
    assertEquals("Tell all your friends about your new bot!", fields.get(11).getDesc());
View Full Code Here

    session.answerSuccess(new IQ(XMLBuilder.fromXML(XEP_0055_2_1_SAMPLE_2)));
    Mockito.verify(result, Mockito.never()).onFailure(Matchers.anyString());
    Mockito.verify(result).onSuccess(Matchers.argThat(new ArgumentMatcher<Form>() {
      @Override
      public boolean matches(final Object arg0) {
        final Form response = (Form) arg0;
        assertEquals(4, response.getFields().size());
        assertEquals("Fill in one or more fields to search for any matching Jabber users.", response.getInstructions().get(0));
        return true;
      }
    }));
  }
View Full Code Here

    assertEquals("Tell all your friends about your new bot!", fields.get(11).getDesc());
  }

  @Test
  public void parseFieldsInMessage() {
    final Form result = parse(XEP_0154_5_3_SAMPLE_13);
    final List<Field> fields = result.getFields();
    assertEquals(1, fields.size());
    assertEquals(null, fields.get(0).getType());
    assertEquals("weblog", fields.get(0).getVar());
    assertEquals("http://www.denmark.lit/blogs/princely_musings", fields.get(0).getValues().get(0));
  }
View Full Code Here

  @Test
  /**
   * Example 8 and 9 of XEP-0055
   */
  public void testSearchUsingForms() {
    final Form form = new Form(Form.Type.submit);
    form.addField(new Field(FieldType.HIDDEN).Var("FORM_TYPE").Value("jabber:iq:search"));
    form.addField(new Field().Var("x-gender").Value("male"));
    final ResultListener<Form> result = Mockito.mock(ResultListener.class);
    manager.search(form, result);

    session.verifyIQSent("<iq type='set' from='romeo@montague.net/home' to='search.service' xml:lang='en'>"
        + "<query xmlns='jabber:iq:search'><x xmlns='jabber:x:data' type='submit'>"
        + "<field type='hidden' var='FORM_TYPE'><value>jabber:iq:search</value>"
        + "</field><field var='x-gender'><value>male</value></field></x></query></iq>");
    session.answerSuccess(new IQ(XMLBuilder.fromXML("<iq type='result'     from='characters.shakespeare.lit'    to='juliet@capulet.com/balcony'    id='search4'    xml:lang='en'>  <query xmlns='jabber:iq:search'>    <x xmlns='jabber:x:data' type='result'>      <field type='hidden' var='FORM_TYPE'>        <value>jabber:iq:search</value>      </field>      <reported>        <field var='first' label='Given Name' type='text-single'/>        <field var='last' label='Family Name' type='text-single'/>        <field var='jid' label='Jabber ID' type='jid-single'/>        <field var='x-gender' label='Gender' type='list-single'/>      </reported>      <item>        <field var='first'><value>Benvolio</value></field>        <field var='last'><value>Montague</value></field>        <field var='jid'><value>benvolio@montague.net</value></field>        <field var='x-gender'><value>male</value></field>      </item>      <item>        <field var='first'><value>Romeo</value></field>        <field var='last'><value>Montague</value></field>        <field var='jid'><value>romeo@montague.net</value></field>        <field var='x-gender'><value>male</value></field>      </item>    </x>  </query></iq>")));
    Mockito.verify(result, Mockito.never()).onFailure(Matchers.anyString());
    Mockito.verify(result).onSuccess(Matchers.argThat(new ArgumentMatcher<Form>() {
      @Override
      public boolean matches(final Object arg0) {
        final Form response = (Form) arg0;
        assertEquals(2, response.getItems().size());
        assertEquals(4, response.getReported().getFields().size());
        return true;
      }
    }));
  }
View Full Code Here

    assertEquals("http://www.denmark.lit/blogs/princely_musings", fields.get(0).getValues().get(0));
  }

  @Test
  public void parseInstructions() {
    final Form result1 = parse(XEP_0004_5_1_SAMPLE_2);
    final Form result2 = parse(XEP_0004_5_1_SAMPLE_3);
    final Form result4 = parse(XEP_0004_5_2_SAMPLE_6);
    assertEquals("Fill out this form to configure your new bot!", result1.getInstructions().get(0));
    assertEquals(0, result2.getInstructions().size());
    assertEquals("Fill out this form to search for information!", result4.getInstructions().get(0));
  }
View Full Code Here

    assertEquals("Fill out this form to search for information!", result4.getInstructions().get(0));
  }

  @Test
  public void parseReported() {
    final Form result = parse(XEP_0004_5_2_SAMPLE_8);
    final Reported reported = result.getReported();
    final List<Field> fields = reported.getFields();
    assertEquals(2, fields.size());
    assertEquals("name", fields.get(0).getVar());
    assertEquals("url", fields.get(1).getVar());
  }
View Full Code Here

    assertEquals("url", fields.get(1).getVar());
  }

  @Test
  public void parseSearchResults() {
    final Form result = parse(XEP_0004_5_2_SAMPLE_8);
    final List<Item> items = result.getItems();
    assertEquals(5, items.size());
    final List<Field> fields1 = items.get(0).getFields();
    assertEquals(2, fields1.size());
    assertEquals("name", fields1.get(0).getVar());
    assertEquals("url", fields1.get(1).getVar());
View Full Code Here

TOP

Related Classes of com.calclab.emite.xep.dataforms.Form

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.