mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 00:02:06 +01:00
Re-activate FormTest integration test
This commit is contained in:
parent
ddf90abb85
commit
50a8ff08e3
2 changed files with 38 additions and 31 deletions
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2004 Jive Software.
|
||||
* Copyright 2004 Jive Software, 2017 Florian Schmaus.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -15,39 +15,51 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
package org.jivesoftware.smackx.xdata;
|
||||
|
||||
import org.jivesoftware.smack.Chat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
||||
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
|
||||
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.StanzaCollector;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.chat.Chat;
|
||||
import org.jivesoftware.smack.chat.ChatManager;
|
||||
import org.jivesoftware.smack.filter.ThreadFilter;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||
|
||||
/**
|
||||
* Tests the DataForms extensions.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class FormTest extends SmackTestCase {
|
||||
public class FormTest extends AbstractSmackIntegrationTest {
|
||||
|
||||
public FormTest(String arg0) {
|
||||
super(arg0);
|
||||
public FormTest(SmackIntegrationTestEnvironment environment) {
|
||||
super(environment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Create a form to fill out and send it to the other user
|
||||
* 2. Retrieve the form to fill out, complete it and return it to the requestor
|
||||
* 3. Retrieve the completed form and check that everything is OK
|
||||
*
|
||||
* @throws InterruptedException
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
public void testFilloutForm() {
|
||||
Form formToSend = new Form(Form.TYPE_FORM);
|
||||
@SmackIntegrationTest
|
||||
public void testFilloutForm() throws NotConnectedException, InterruptedException {
|
||||
Form formToSend = new Form(DataForm.Type.form);
|
||||
formToSend.setInstructions(
|
||||
"Fill out this form to report your case.\nThe case will be created automatically.");
|
||||
formToSend.setTitle("Case configurations");
|
||||
// Add a hidden variable
|
||||
FormField field = new FormField("hidden_var");
|
||||
field.setType(FormField.TYPE_HIDDEN);
|
||||
field.setType(FormField.Type.hidden);
|
||||
field.addValue("Some value for the hidden variable");
|
||||
formToSend.addField(field);
|
||||
// Add a fixed variable
|
||||
|
@ -57,29 +69,29 @@ public class FormTest extends SmackTestCase {
|
|||
// Add a text-single variable
|
||||
field = new FormField("name");
|
||||
field.setLabel("Enter a name for the case");
|
||||
field.setType(FormField.TYPE_TEXT_SINGLE);
|
||||
field.setType(FormField.Type.text_single);
|
||||
formToSend.addField(field);
|
||||
// Add a text-multi variable
|
||||
field = new FormField("description");
|
||||
field.setLabel("Enter a description");
|
||||
field.setType(FormField.TYPE_TEXT_MULTI);
|
||||
field.setType(FormField.Type.text_multi);
|
||||
formToSend.addField(field);
|
||||
// Add a boolean variable
|
||||
field = new FormField("time");
|
||||
field.setLabel("Is this your first case?");
|
||||
field.setType(FormField.TYPE_BOOLEAN);
|
||||
field.setType(FormField.Type.bool);
|
||||
formToSend.addField(field);
|
||||
// Add a text variable where an int value is expected
|
||||
field = new FormField("age");
|
||||
field.setLabel("How old are you?");
|
||||
field.setType(FormField.TYPE_TEXT_SINGLE);
|
||||
field.setType(FormField.Type.text_single);
|
||||
formToSend.addField(field);
|
||||
|
||||
// Create the chats between the two participants
|
||||
Chat chat = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
StanzaCollector collector = getConnection(0).createStanzaCollector(
|
||||
Chat chat = ChatManager.getInstanceFor(conOne).createChat(conTwo.getUser(), null);
|
||||
StanzaCollector collector = conOne.createStanzaCollector(
|
||||
new ThreadFilter(chat.getThreadID()));
|
||||
StanzaCollector collector2 = getConnection(1).createStanzaCollector(
|
||||
StanzaCollector collector2 = conTwo.createStanzaCollector(
|
||||
new ThreadFilter(chat.getThreadID()));
|
||||
|
||||
Message msg = new Message();
|
||||
|
@ -91,7 +103,7 @@ public class FormTest extends SmackTestCase {
|
|||
chat.sendMessage(msg);
|
||||
|
||||
// Get the message with the form to fill out
|
||||
Message msg2 = (Message)collector2.nextResult(2000);
|
||||
Message msg2 = (Message)collector2.nextResult();
|
||||
assertNotNull("Messge not found", msg2);
|
||||
// Retrieve the form to fill out
|
||||
Form formToRespond = Form.getFormFrom(msg2);
|
||||
|
@ -107,6 +119,7 @@ public class FormTest extends SmackTestCase {
|
|||
fail("A boolean value was set to a field of type String");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// This exception is expected.
|
||||
}
|
||||
completedForm.setAnswer("name", "Credit card number invalid");
|
||||
completedForm.setAnswer(
|
||||
|
@ -116,17 +129,17 @@ public class FormTest extends SmackTestCase {
|
|||
completedForm.setAnswer("age", 20);
|
||||
// Create a new message to send with the completed form
|
||||
msg2 = new Message();
|
||||
msg2.setTo(msg.getFrom());
|
||||
msg2.setTo(conOne.getUser().asBareJid());
|
||||
msg2.setThread(msg.getThread());
|
||||
msg2.setType(Message.Type.chat);
|
||||
msg2.setBody("To enter a case please fill out this form and send it back to me");
|
||||
// Add the completed form to the message
|
||||
msg2.addExtension(completedForm.getDataFormToSend());
|
||||
// Send the message with the completed form
|
||||
getConnection(1).sendStanza(msg2);
|
||||
conTwo.sendStanza(msg2);
|
||||
|
||||
// Get the message with the completed form
|
||||
Message msg3 = (Message) collector.nextResult(2000);
|
||||
Message msg3 = (Message) collector.nextResult();
|
||||
assertNotNull("Messge not found", msg3);
|
||||
// Retrieve the completed form
|
||||
completedForm = Form.getFormFrom(msg3);
|
||||
|
@ -134,24 +147,17 @@ public class FormTest extends SmackTestCase {
|
|||
assertNotNull(completedForm.getField("name"));
|
||||
assertNotNull(completedForm.getField("description"));
|
||||
assertEquals(
|
||||
completedForm.getField("name").getValues().next(),
|
||||
completedForm.getField("name").getValues().get(0),
|
||||
"Credit card number invalid");
|
||||
assertNotNull(completedForm.getField("time"));
|
||||
assertNotNull(completedForm.getField("age"));
|
||||
assertEquals("The age is bad", "20", completedForm.getField("age").getValues().next());
|
||||
assertEquals("The age is bad", "20", completedForm.getField("age").getValues().get(0));
|
||||
|
||||
}
|
||||
catch (XMPPException ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
finally {
|
||||
collector.cancel();
|
||||
collector2.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../../smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/package-info.java
|
Loading…
Reference in a new issue