All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.bdi.testcases.goals.GenerateGoalPlan Maven / Gradle / Ivy

Go to download

The Jadex BDI applications package contain several example applications, benchmarks and testcases using BDI agents.

There is a newer version: 2.4
Show 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;

/**
 *  Create a goal and wait for the result.
 */
public class GenerateGoalPlan extends Plan
{
	public void body()
	{
		TestReport	report	= new TestReport("test_goal", "Dispatch a goal and wait for the result");
		try
		{
			IGoal	agoal	= createGoal("testgoal");
			
			// If "param" is present set to "foo".
			if(agoal.hasParameter("param"))
			{
				agoal.getParameter("param").setValue("foo");
			}

			// If "params" is present set to {"foo", "bar"}.
			if(agoal.hasParameterSet("params"))
			{
				agoal.getParameterSet("params").addValue("foo");
				agoal.getParameterSet("params").addValue("bar");
			}

			dispatchSubgoalAndWait(agoal);

			// If "result" is present check for "foo".
			if(!agoal.hasParameter("result") || "foo".equals(agoal.getParameter("result").getValue()))
				report.setSucceeded(true);
			else
				report.setReason("Wrong result value: "+agoal.getParameter("result").getValue());
		}
		catch(GoalFailureException gfe)
		{
			report.setReason(gfe.toString());
		}
		getBeliefbase().getBeliefSet("reports").addFact(report);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy