
jadex.bdi.testcases.goals.SubgoalHandlingPlan 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.
The newest version!
package jadex.bdi.testcases.goals;
import jadex.base.test.TestReport;
import jadex.bdi.runtime.GoalFailureException;
import jadex.bdi.runtime.IGoal;
import jadex.bdi.runtime.Plan;
import jadex.bdi.runtime.TimeoutException;
/**
* Test subgoal handling for standard plans.
*/
public class SubgoalHandlingPlan extends Plan
{
/**
* Plan body.
*/
public void body()
{
// Test success.
TestReport report = new TestReport("test_success", "Test if a subgoal succeeds.");
IGoal sg = createGoal("success_goal");
try
{
dispatchSubgoalAndWait(sg);
if(sg.isSucceeded())
report.setSucceeded(true);
else
report.setReason("Should not continue execution after failed subgoal.");
}
catch(Exception e)
{
report.setReason("Unexpected exception: "+e);
}
getBeliefbase().getBeliefSet("testcap.reports").addFact(report);
// Test failure.
report = new TestReport("test_failure", "Test if a subgoal fails.");
sg = createGoal("failure_goal");
try
{
dispatchSubgoalAndWait(sg);
if(sg.isSucceeded())
report.setReason("Subgoal unexpectedly succeeded.");
else
report.setReason("Should not continue execution after failed subgoal.");
}
catch(Exception e)
{
if(e instanceof GoalFailureException)
report.setSucceeded(true);
else
report.setReason("Wrong exception: "+e);
}
getBeliefbase().getBeliefSet("testcap.reports").addFact(report);
// Test timeout.
report = new TestReport("test_failure", "Test if a subgoal times out.");
sg = createGoal("timeout_goal");
try
{
dispatchSubgoalAndWait(sg, 100);
if(sg.isSucceeded())
report.setReason("Subgoal unexpectedly succeeded.");
else
report.setReason("Should not continue execution after failed subgoal.");
}
catch(Exception e)
{
if(e instanceof TimeoutException)
report.setSucceeded(true);
else
report.setReason("Wrong exception: "+e);
}
getBeliefbase().getBeliefSet("testcap.reports").addFact(report);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy