jadex.micro.testcases.NoServiceAgent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-micro Show documentation
Show all versions of jadex-applications-micro Show documentation
The Jadex micro applications package contains several example applications, benchmarks and testcases using micro agents.
package jadex.micro.testcases;
import java.util.Collection;
import jadex.base.test.TestReport;
import jadex.base.test.Testcase;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IArgumentsResultsFeature;
import jadex.bridge.service.IService;
import jadex.bridge.service.component.IRequiredServicesFeature;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IResultListener;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.AgentBody;
import jadex.micro.annotation.Description;
import jadex.micro.annotation.Result;
import jadex.micro.annotation.Results;
/**
* Test searching for services that don't exist.
*/
@Description("Test searching for services that don't exist.")
@Results(@Result(name="testresults", clazz=Testcase.class))
@Agent
public class NoServiceAgent
{
@Agent
protected IInternalAccess agent;
@AgentBody
public IFuture executeBody()
{
final Future ret = new Future();
final TestReport tr = new TestReport("#1", "Searching for services.");
agent.getComponentFeature(IRequiredServicesFeature.class).searchServices(INoService.class).addResultListener(new IResultListener>()
{
public void resultAvailable(Collection result)
{
if(result.isEmpty())
{
tr.setSucceeded(true);
}
else
{
tr.setFailed("Expected empty collection but was: "+result);
}
agent.getComponentFeature(IArgumentsResultsFeature.class).getResults().put("testresults", new Testcase(1, new TestReport[]{tr}));
ret.setResult(null);
}
public void exceptionOccurred(Exception exception)
{
tr.setFailed("Exception during test: "+exception);
agent.getComponentFeature(IArgumentsResultsFeature.class).getResults().put("testresults", new Testcase(1, new TestReport[]{tr}));
ret.setResult(null);
}
});
return ret;
}
/** Test service interface. */
public static interface INoService extends IService {}
}