Create an action command for asserting that a value is not null. Useable from a test like this:
<action name="VerifyNoNull" command="java:com.mystuff.MyAssertNotNullValidator">
<param>##{MyValue}</param>
</action>
package com.mystuff;
import java.util.List;
import org.mactor.framework.ConfigException;
import org.mactor.framework.MactorException;
import org.mactor.framework.TestContext;
import org.mactor.framework.extensioninterface.ActionCommand;
public class MyAssertNotNullValidator implements ActionCommand {
public void perform(TestContext context, List<String> params) throws MactorException {
if (params.size() != 1)
throw new ConfigException("Invalid testspec. One parameter requiered: [<the value to validate>]>");
if (params.get(0) == null)
throw new MactorException("Assertions failed. The value was null");
}
}
(NOTE: mactor.jar must be in the classpath to compile this code. Include the compiled class in the classpath by editing the MActor start script - testrunner-gui.cmd/testrunner-gui.sh)
Create a value command that will generate a random number. Useable from a test like this:
<value name="ANumber" command="java:com.mystuff.MyRandomNumberGenerator"/>
package com.mystuff;
import java.util.List;
import org.mactor.framework.ConfigException;
import org.mactor.framework.MactorException;
import org.mactor.framework.TestContext;
import org.mactor.framework.extensioninterface.ValueCommand;
public class MyRandomNumberGenerator implements ValueCommand {
java.util.Random r = new java.util.Random();
public String extractValue(TestContext context, List<String> params) throws MactorException {
return r.nextInt() + "";
}
}
(NOTE: mactor.jar must be in the classpath to compile this code. Include the compiled class in the classpath by editing the MActor start script - testrunner-gui.cmd/testrunner-gui.sh)
Create a message selector command that will accept any message containing the word 'blue'. Useable from a test like this:
<message_subscribe name="SubscribeForMessage" channel="Incomingmessage">
<message_selector command="java:com.mystuff.BlueMessageSelector"/>
</message_subscribe>
package com.mystuff;
import java.util.List;
import org.mactor.framework.MactorException;
import org.mactor.framework.Message;
import org.mactor.framework.extensioninterface.MessageSelectorCommand;
public class BlueMessageSelector implements MessageSelectorCommand {
public void setParams(List<String> params) throws MactorException {}
public boolean isAcceptableMessage(Message message) {
return message.getContent().indexOf("blue")>=0;
}
}
(NOTE: mactor.jar must be in the classpath to compile this code. Include the compiled class in the classpath by editing the MActor start script - testrunner-gui.cmd/testrunner-gui.sh)
Create a message builder command that will build a message with a randomly named element. Useable from a test like this:
<message_publish name="PublishRandomMessage" channel="OutgoingMessage">
<message_builder command="java:com.mystuff.RandomMessageBuilder"/>
</message_publish>
package com.mystuff;
import java.util.List;
import org.mactor.framework.ConfigException;
import org.mactor.framework.MactorException;
import org.mactor.framework.Message;
import org.mactor.framework.TestContext;
import org.mactor.framework.extensioninterface.MessageBuilderCommand;
public class RandomMessageBuilder implements MessageBuilderCommand {
java.util.Random r = new java.util.Random();
public Message buildMessage(TestContext context, String templatePath, List<String> params) throws MactorException {
String nodeName = "a" + r.nextInt() + "b";
return message.createMessage("<" + nodeName + ">this is the content of the random element " + "</" + nodeName + ">");
}
}
(NOTE: mactor.jar must be in the classpath to compile this code. Include the compiled class in the classpath by editing the MActor start script - testrunner-gui.cmd/testrunner-gui.sh)