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

es.upm.dit.gsi.beast.mock.jadex.common.MockAgentPlan Maven / Gradle / Ivy

Go to download

BEhavioural Agents Simple Testing Tool - BEAST Tool The aim of this project is the development of a system which allows Behavior Driven Development (BDD) in Multi-Agent Systems (MAS), to make testing practices more accessible and intuitive to everybody. In one hand, in order to let tests be writable by newcomers and experts alike, system must allow the redaction of tests in plain text, because client does not need to have knowledge of our code. This plain text will be traduced to software later. The definition of test will be realized with the terminology Given-When-Then, which allows trace an easy guide of the behavior of a given scenario when something happened. In the other hand, due to the complexity of MAS, making unit testing of an agent that needs the interaction with others is almost impossible until the whole system is finished. This implies to leave testing issues to the end of the project, generating big troubles in case of malfunction. Consequently, its necessary to carry out a tool to allow the creation of mock agents and to perform tests during the whole development process. Therefore another objective of our systems is to include a mocking tool which permits testing continuously. Definitively, our tool allows the testing of any MAS in the development process, increasing its modularity and decreasing its elaboration and testing cost. These tests will be written in plain text so that anyone would be able to understand them. For further reading, a paper published in ITMAS2012 workshop can be found in: http://scholar.google.es/citations?view_op=view_citation&hl=es&user=mT3KgXUAAAAJ&citation_for_view=mT3KgXUAAAAJ:Tyk-4Ss8FVUC

The newest version!
package es.upm.dit.gsi.beast.mock.jadex.common;

import jadex.base.fipa.IDF;
import jadex.base.fipa.IDFComponentDescription;
import jadex.base.fipa.IDFServiceDescription;
import jadex.base.fipa.SFipa;
import jadex.bdi.runtime.IGoal;
import jadex.bdi.runtime.IMessageEvent;
import jadex.bdi.runtime.Plan;
import jadex.bridge.ISearchConstraints;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.SServiceProvider;

import java.util.logging.Logger;

/**
 * Project: beast
 * File: es.upm.dit.gsi.beast.mock.jadex.common.MockAgentPlan.java
 * 
 * MockAgentPlan is the class all Agents-plan must extend from.
 * 
 * Grupo de Sistemas Inteligentes
 * Departamento de Ingeniería de Sistemas Telemáticos
 * Universidad Politécnica de Madrid (UPM)
 * 
 * @author Jorge Solitario
 * @version 0.1
 * 
 */
public abstract class MockAgentPlan extends Plan {
    // -------- attributes --------

    /** Serial version UID of the serializable class MockAgentPlan. */
    private static final long serialVersionUID = 5211108972962782274L;

    private static final int LEASE_TIME = 60000;

    Logger logger = Logger.getLogger(this.getClass().toString());

    // -------- methods --------

    /**
     * Method to send Request messages to a specific df_service
     * 
     * @param df_service
     *            The name of the df_service
     * @param msgContent
     *            The content of the message to be sent
     * @return Message sent to + the name of the df_service
     */
    protected String sendRequestToDF(String df_service, Object msgContent) {

        IDFComponentDescription[] receivers = getReceivers(df_service);
        if (receivers.length > 0) {
            IMessageEvent mevent = createMessageEvent("send_request");
            mevent.getParameter(SFipa.CONTENT).setValue(msgContent);
            for (int i = 0; i < receivers.length; i++) {
                mevent.getParameterSet(SFipa.RECEIVERS).addValue(
                        receivers[i].getName());
                logger.info("The receiver is " + receivers[i].getName());
            }
            sendMessage(mevent);
        }
        logger.info("Message sended to " + df_service + " to "
                + receivers.length + " receivers");
        return ("Message sended to " + df_service);
    }

    /**
     * Method to send Inform messages to a specific df_service
     * 
     * @param df_service
     *            The name of the df_service
     * @param msgContent
     *            The content of the message to be sent
     * @return Message sent to + the name of the df_service
     */
    protected String sendInformToDF(String df_service, Object msgContent) {

        IDFComponentDescription[] receivers = getReceivers(df_service);
        if (receivers.length > 0) {
            IMessageEvent mevent = createMessageEvent("send_inform");
            mevent.getParameter(SFipa.CONTENT).setValue(msgContent);
            for (int i = 0; i < receivers.length; i++) {
                mevent.getParameterSet(SFipa.RECEIVERS).addValue(
                        receivers[i].getName());
                logger.info("The receiver is " + receivers[i].getName());
            }
            sendMessage(mevent);
        }
        logger.info("Message sended to " + df_service + " to "
                + receivers.length + " receivers");
        return ("Message sended to " + df_service);
    }

    /**
     * This method will be used to know the IDFComponentDescription of all the
     * agents that own a df_service. Given the IDFComponentDescription, the name
     * of the agent is known using getName()
     * 
     * @param target_service
     *            The name of the df_service
     * @return Its agent IDFComponentDescription
     */
    protected IDFComponentDescription[] getReceivers(String target_service) {
        // Search for X_Service
        // Create a service description to search for.
        IDF df = (IDF) SServiceProvider.getService(getServiceContainer(),
                IDF.class, RequiredServiceInfo.SCOPE_PLATFORM).get(this);
        IDFServiceDescription sd = df.createDFServiceDescription(
                target_service, null, null);
        IDFComponentDescription dfadesc = df.createDFComponentDescription(null,
                sd);

        ISearchConstraints constraints = df.createSearchConstraints(-1, 0);

        // Use a subgoal to search
        IGoal ft = createGoal("dfcap.df_search");
        ft.getParameter("description").setValue(dfadesc);
        ft.getParameter("constraints").setValue(constraints);
        ft.getParameter("leasetime").setValue(new Long(LEASE_TIME));

        dispatchSubgoalAndWait(ft);

        return (IDFComponentDescription[]) ft.getParameterSet("result")
                .getValues();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy