jadex.micro.testcases.LoggerAgent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-micro Show documentation
Show all versions of jadex-applications-micro Show documentation
The Jadex micro applications package contains several example applications, benchmarks and testcases using micro agents.
package jadex.micro.testcases;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import jadex.base.test.TestReport;
import jadex.base.test.Testcase;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IArgumentsResultsFeature;
import jadex.bridge.nonfunctional.annotation.NameValue;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.component.IRequiredServicesFeature;
import jadex.bridge.service.types.clock.IClock;
import jadex.bridge.service.types.clock.IClockService;
import jadex.commons.SUtil;
import jadex.commons.future.ExceptionDelegationResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.AgentBody;
import jadex.micro.annotation.Binding;
import jadex.micro.annotation.Description;
import jadex.micro.annotation.Imports;
import jadex.micro.annotation.Properties;
import jadex.micro.annotation.RequiredService;
import jadex.micro.annotation.RequiredServices;
import jadex.micro.annotation.Result;
import jadex.micro.annotation.Results;
import jadex.micro.testcases.LoggerAgent.TestLogHandler;
/**
* A minimal test case agent serving as a demonstrator.
*/
@Imports({"java.util.logging.*"})
@Description("Tests the logger.")
@Results(@Result(name="testresults", description= "The test results.", clazz=Testcase.class))
@RequiredServices({@RequiredService(name="clockservice", type=IClockService.class,
binding=@Binding(scope=RequiredServiceInfo.SCOPE_PLATFORM))})
@Properties({
@NameValue(name="logging.level", value="Level.FINEST"),
// @NameValue(name="logging.useParentHandlers", value="true"),
// @NameValue(name="logging.addConsoleHandler", value="true"),
// @NameValue(name="logging.file", value="log.txt"),
@NameValue(name="logging.handlers", clazz=TestLogHandler.class)
// @NameValue(name="logging.handlers", value="new LoggerAgent$TestLogHandler()")
})
@Agent
public class LoggerAgent
{
@Agent
protected IInternalAccess agent;
/**
* Just finish the test by setting the result and killing the agent.
*/
@AgentBody
public IFuture executeBody()
{
final Future ret = new Future();
agent.getComponentFeature(IRequiredServicesFeature.class).getRequiredService("clockservice").addResultListener(new ExceptionDelegationResultListener