jadex.bdi.testcases.misc.EndStateWorkerPlan 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.GoalFailureException;
import jadex.bdi.runtime.IMessageEvent;
import jadex.bdi.runtime.Plan;
import jadex.bdi.runtime.TimeoutException;
import jadex.bridge.fipa.SFipa;
import java.util.ArrayList;
import java.util.List;
/**
* Check correct operation of end states.
*/
public class EndStateWorkerPlan extends Plan
{
/**
* Plan body.
*/
public void body()
{
// Plan will be aborted when agent is killed.
// waitFor(IFilter.NEVER);
waitForEver();
}
/**
* Method is called when the agent terminates.
*/
public void aborted()
{
List reports = new ArrayList();
// Test abortion of agenda actions (goal and plan creation actions should have been aborted).
waitFor(20);
TestReport report = new TestReport("agenda_action", "Test if goal creation action has not been executed due to invalid precondition.");
if(getGoalbase().getGoals("testgoal").length==0)
{
report.setSucceeded(true);
}
else
{
report.setFailed("Goal was created.");
}
reports.add(report);
report = new TestReport("agenda_action2", "Test if plan creation action has not been executed due to invalid precondition.");
if(getPlanbase().getPlans("dummy_plan").length==0)
{
report.setSucceeded(true);
}
else
{
report.setFailed("Plan was created.");
}
reports.add(report);
// Test deactivation of creation/trigger conditions.
getBeliefbase().getBelief("trigger").setFact(Boolean.FALSE);
getBeliefbase().getBelief("trigger").setFact(Boolean.TRUE);
waitFor(20);
report = new TestReport("goal_condition", "Test if goal creation conditions are disabled in end state.");
if(getGoalbase().getGoals("testgoal").length==0)
{
report.setSucceeded(true);
}
else
{
report.setFailed("Goal was created.");
}
reports.add(report);
report = new TestReport("plan_condition", "Test if plan trigger conditions are disabled in end state.");
if(getPlanbase().getPlans("dummy_plan").length==0)
{
report.setSucceeded(true);
}
else
{
report.setFailed("Plan was created.");
}
reports.add(report);
// Test if manual creation of goal and activation of plan still works.
report = new TestReport("manual_goal", "Test if manual creation of goal and activation of plan still works.");
try
{
dispatchSubgoalAndWait(createGoal("testgoal"), 200);
report.setSucceeded(true);
}
catch(GoalFailureException e)
{
report.setFailed("Goal execution failed.");
}
catch(TimeoutException e)
{
report.setFailed("Timeout occurred.");
}
reports.add(report);
// Wait for testcases of end state elements.
try
{
waitForCondition("end_tests_finished", 1000);
}
catch(TimeoutException e)
{
}
TestReport[] areports = (TestReport[])getBeliefbase().getBeliefSet("reports").getFacts();
for(int i=0; i