2008-11-13 22:52:35 +01:00
|
|
|
/**
|
|
|
|
*
|
2013-02-07 15:19:47 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2013-02-07 15:19:47 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2008-11-13 22:52:35 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.jivesoftware.smackx.commands;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.test.SmackTestCase;
|
2008-11-19 00:12:10 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException;
|
2008-11-13 22:52:35 +01:00
|
|
|
import org.jivesoftware.smackx.packet.DiscoverItems;
|
2008-11-19 00:12:10 +01:00
|
|
|
import org.jivesoftware.smackx.Form;
|
|
|
|
import org.jivesoftware.smackx.FormField;
|
2008-11-13 22:52:35 +01:00
|
|
|
|
|
|
|
/**
|
2008-11-19 00:12:10 +01:00
|
|
|
* AdHocCommand tests.
|
2008-11-13 22:52:35 +01:00
|
|
|
*
|
|
|
|
* @author Matt Tucker
|
|
|
|
*/
|
|
|
|
public class AdHocCommandDiscoTest extends SmackTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for test.
|
2008-11-13 22:53:18 +01:00
|
|
|
* @param arg0 argument.
|
2008-11-13 22:52:35 +01:00
|
|
|
*/
|
|
|
|
public AdHocCommandDiscoTest(String arg0) {
|
|
|
|
super(arg0);
|
|
|
|
}
|
|
|
|
|
2008-11-19 00:12:10 +01:00
|
|
|
public void testAdHocCommands() {
|
2008-11-13 22:52:35 +01:00
|
|
|
try {
|
|
|
|
AdHocCommandManager manager1 = AdHocCommandManager.getAddHocCommandsManager(getConnection(0));
|
|
|
|
manager1.registerCommand("test", "test node", LocalCommand.class);
|
2008-11-19 00:12:10 +01:00
|
|
|
|
|
|
|
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 {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
2008-11-13 22:52:35 +01:00
|
|
|
|
|
|
|
AdHocCommandManager manager2 = AdHocCommandManager.getAddHocCommandsManager(getConnection(1));
|
2008-11-14 01:59:48 +01:00
|
|
|
DiscoverItems items = manager2.discoverCommands(getFullJID(0));
|
2008-11-13 22:52:35 +01:00
|
|
|
|
2008-11-14 01:59:48 +01:00
|
|
|
assertTrue("Disco for command test failed", items.getItems().next().getNode().equals("test"));
|
2008-11-19 00:12:10 +01:00
|
|
|
|
|
|
|
RemoteCommand command = manager2.getRemoteCommand(getFullJID(0), "test2");
|
|
|
|
command.execute();
|
|
|
|
assertEquals("Disco for command test failed", command.getForm().getField("test2").getValues().next(), "it worked");
|
2008-11-13 22:52:35 +01:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
super.setUp();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void tearDown() throws Exception {
|
|
|
|
super.tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int getMaxConnections() {
|
|
|
|
return 2;
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|