@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;
}
}));
}