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

jadex.micro.testcases.RequiredServiceConfigurationsAgent Maven / Gradle / Ivy

Go to download

The Jadex micro applications package contains several example applications, benchmarks and testcases using micro agents.

There is a newer version: 4.0.267
Show newest version
package jadex.micro.testcases;

import jadex.base.test.TestReport;
import jadex.base.test.Testcase;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IArgumentsResultsFeature;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.component.IRequiredServicesFeature;
import jadex.commons.Boolean3;
import jadex.commons.future.IFuture;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.AgentCreated;
import jadex.micro.annotation.Binding;
import jadex.micro.annotation.Configuration;
import jadex.micro.annotation.Configurations;
import jadex.micro.annotation.RequiredService;
import jadex.micro.annotation.RequiredServices;
import jadex.micro.annotation.Result;
import jadex.micro.annotation.Results;

/**
 *  Test if binding of required service info can be overridden in configuration.
 */
@RequiredServices(@RequiredService(name="as", type=IAService.class, binding=@Binding(scope=RequiredServiceInfo.SCOPE_PLATFORM)))
@Configurations({
	@Configuration(name="a", requiredservices=@RequiredService(name="as", type=IAService.class, binding=@Binding(scope=RequiredServiceInfo.SCOPE_LOCAL))),
	@Configuration(name="b")
})
@Results(@Result(name="testresults", clazz=Testcase.class)) 
@Agent(keepalive=Boolean3.FALSE)
public class RequiredServiceConfigurationsAgent
{
	@Agent
	protected IInternalAccess agent;
	
	/**
	 *  Agent created.
	 */
	@AgentCreated
	public IFuture agentCreated()
	{
//		BasicServiceContainer con = (BasicServiceContainer)agent.getServiceContainer();
		RequiredServiceInfo rsi = agent.getComponentFeature(IRequiredServicesFeature.class).getRequiredServiceInfo("as");
//		System.out.println(rsi.getDefaultBinding().getScope());
		TestReport tr = new TestReport("#1", "Test required service overriding.");
		if(rsi.getDefaultBinding().getScope().equals(RequiredServiceInfo.SCOPE_LOCAL))
		{
			tr.setSucceeded(true);
		}
		else
		{
			tr.setFailed("Wrong service implementation: "+rsi.getDefaultBinding().getScope());
		}
		agent.getComponentFeature(IArgumentsResultsFeature.class).getResults().put("testresults", new Testcase(1, new TestReport[]{tr}));
		return IFuture.DONE;
	}	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy