jadex.bdi.testcases.plans.WaitForBeliefPlan 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.plans;
import jadex.base.test.TestReport;
import jadex.bdi.runtime.Plan;
/**
* Wait endlessly for belief changes.
*/
public class WaitForBeliefPlan extends Plan
{
//-------- attributes --------
/** The test report. */
protected TestReport tr;
//-------- constructors --------
/**
* The body method is called on the
* instatiated plan instance from the scheduler.
*/
public void body()
{
for(int i=0; i<3; i++)
{
tr = new TestReport("#"+i, "Tests if a beliefchange is detected.");
getLogger().info("Now waiting for a change of belief 'some_number': ");
waitForFactChanged("some_number", 3000);
tr.setSucceeded(true);
getLogger().info("Belief changed: "+getBeliefbase().getBelief("some_number").getFact());
getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);
}
}
/**
* Called on plan failure.
*/
public void failed()
{
getLogger().info("No belief update detected. Plan failed.");
if(tr==null)
tr = new TestReport("", "Plan failure occurred before test was created.");
tr.setReason("No belief update detected");
getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);
}
}