1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

Added ability to register a local command using a factory. Improved ad-hoc command tests.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@10905 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2008-11-18 23:12:10 +00:00 committed by matt
parent ffb8cd914a
commit e6f29ee641
3 changed files with 111 additions and 24 deletions

View file

@ -53,10 +53,13 @@
package org.jivesoftware.smackx.commands;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.FormField;
/**
*
* AdHocCommand tests.
*
* @author Matt Tucker
*/
@ -70,15 +73,58 @@ public class AdHocCommandDiscoTest extends SmackTestCase {
super(arg0);
}
public void testInvitation() {
public void testAdHocCommands() {
try {
AdHocCommandManager manager1 = AdHocCommandManager.getAddHocCommandsManager(getConnection(0));
manager1.registerCommand("test", "test node", LocalCommand.class);
manager1.registerCommand("test2", "test node", new LocalCommandFactory() {
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
return new LocalCommand() {
public boolean isLastStage() {
return true;
}
public boolean hasPermission(String jid) {
return true;
}
public void execute() throws XMPPException {
Form result = new Form(Form.TYPE_RESULT);
FormField resultField = new FormField("test2");
resultField.setLabel("test node");
resultField.addValue("it worked");
result.addField(resultField);
setForm(result);
}
public void next(Form response) throws XMPPException {
//
}
public void complete(Form response) throws XMPPException {
//
}
public void prev() throws XMPPException {
//
}
public void cancel() throws XMPPException {
//
}
};
}
});
AdHocCommandManager manager2 = AdHocCommandManager.getAddHocCommandsManager(getConnection(1));
DiscoverItems items = manager2.discoverCommands(getFullJID(0));
assertTrue("Disco for command test failed", items.getItems().next().getNode().equals("test"));
RemoteCommand command = manager2.getRemoteCommand(getFullJID(0), "test2");
command.execute();
assertEquals("Disco for command test failed", command.getForm().getField("test2").getValues().next(), "it worked");
}
catch (Exception e) {
fail(e.getMessage());