jadex.bdi.testcases.misc.EndStatePlan Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-bdi Show documentation
Show all versions of jadex-applications-bdi Show documentation
The Jadex BDI applications package contain
several example applications, benchmarks and
testcases using BDI agents.
package jadex.bdi.testcases.misc;
import jadex.base.test.TestReport;
import jadex.bdi.runtime.IGoal;
import jadex.bdi.runtime.IMessageEvent;
import jadex.bdi.runtime.Plan;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.fipa.SFipa;
import jadex.bridge.service.search.SServiceProvider;
import jadex.bridge.service.types.cms.CMSComponentDescription;
import jadex.bridge.service.types.cms.IComponentManagementService;
import jadex.bridge.service.types.df.IDF;
import jadex.bridge.service.types.df.IDFComponentDescription;
import jadex.bridge.service.types.df.IDFServiceDescription;
import jadex.commons.collection.SCollection;
import java.util.List;
import java.util.Map;
/**
* Check correct operation of end states.
*/
public class EndStatePlan extends Plan
{
/**
* Plan body.
*/
public void body()
{
// Store report message from worker agent.
getWaitqueue().addMessageEvent("inform_reports");
// Create worker agent.
IGoal create = createGoal("cmscap.cms_create_component");
create.getParameter("type").setValue("/jadex/bdi/testcases/misc/EndStateWorker.agent.xml");
Map args = SCollection.createHashMap();
args.put("testagent", getComponentIdentifier());
create.getParameter("arguments").setValue(args);
create.getParameter("rid").setValue(getComponentDescription().getResourceIdentifier());
dispatchSubgoalAndWait(create);
IComponentIdentifier worker = (IComponentIdentifier)create.getParameter("componentidentifier").getValue();
// Wait for reports from worker agent.
IMessageEvent msg = waitForMessageEvent("inform_reports");
getWaitqueue().removeMessageEvent("inform_reports");
List reports = (List)msg.getParameter(SFipa.CONTENT).getValue();
// Check if worker agent has been correctly removed.
waitFor(1000); // Hack!!! how to ensure that agent has time to remove itself?
IGoal search = createGoal("cmscap.cms_search_components");
// IComponentManagementService cms = (IComponentManagementService)SServiceProvider.getServiceUpwards(
// getServiceContainer(), IComponentManagementService.class).get(this);
// search.getParameter("description").setValue(cms.createComponentDescription(worker, null, null, null, null, null));
search.getParameter("description").setValue(new CMSComponentDescription(worker, null, null, null, null, null, null, null, -1, null));
dispatchSubgoalAndWait(search);
TestReport report = new TestReport("termination", "Test if the worker agent has been terminated");
if(search.getParameterSet("result").getValues().length==0)
{
report.setSucceeded(true);
}
else
{
report.setFailed("Worker agent still alive.");
}
getBeliefbase().getBeliefSet("testcap.reports").addFact(report);
// Add test results from worker.
for(int i=0; i