Package it.unito.di.test

Source Code of it.unito.di.test.TestInteractionState

package it.unito.di.test;

import jade.core.AID;

import java.awt.Rectangle;

import it.unito.di.artifact.Role;
import it.unito.di.logic.commit.Commitment;
import it.unito.di.logic.commit.SocialState;
import it.unito.di.logic.commit.lifecycle.LifeCycleState;
import it.unito.di.logic.exception.CommitmentAlreadyAddedException;
import it.unito.di.logic.exception.LogicalExpressionAlreadyAddedException;
import it.unito.di.logic.exception.MissingOperandException;
import it.unito.di.logic.exception.WrongOperandsNumberException;
import it.unito.di.logic.expression.CompositeExpression;
import it.unito.di.logic.expression.Fact;
import it.unito.di.logic.expression.LogicalOperatorType;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import cartago.CartagoException;
import cartago.CartagoService;

public class TestInteractionState {

  private static Logger logger = LogManager.getLogger(TestInteractionState.class);
 
  private static SocialState state = new SocialState(null);
 
  public TestInteractionState() {
   
  }
 
  public static void main(String[] args) {
    logger.debug("Starting test on Interaction State");
    logger.debug("Interaction state created, status: "+state);
    testFact();
  }
 
  private static void testFact() {
    logger.debug("Initializing test on Logical Expression management, status: "+state);
    Fact f = null;
    Fact fOneStringPredicate = null;
    Fact fMultiStringPredicate = null;
    Fact fOneStringOneObject = null;
    Fact fMultiObjectPredicate = null;
    try {
      f = new Fact("factOne");
      fOneStringPredicate = new Fact("factOneStringPredicate", "stringPredicate");
      fMultiStringPredicate = new Fact("factMultiStringPredicate", "stringPredOne", "stringPredTwo", "stringPredThree");
      fOneStringOneObject = new Fact("factOneStringOneObject", "stringPred", new Rectangle(15, 20));
      fMultiObjectPredicate = new Fact("factMultiObjectPredicate", new Rectangle(10, 10), 15, new String[]{"one","two","three"});
    } catch (MissingOperandException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      logger.error("Error in creating fact factOne");
   
   
   
//    logger.debug("Facts added to state, status: "+state);
//    logger.debug("Test facts equal with facts themselves");
//    logger.debug(f.equals(f));
//    logger.debug(fOneStringPredicate.equals(fOneStringPredicate));
//    logger.debug(fMultiStringPredicate.equals(fMultiStringPredicate));
//    logger.debug(fOneStringOneObject.equals(fOneStringOneObject));
//    logger.debug(fMultiObjectPredicate.equals(fMultiObjectPredicate));
   
    // now testing commitments
    // building fake roles
   
   
   
   
//    Commitment c0 = new Commitment(r2, r2, f);
//    logger.debug("Commitment detached: "+c0);
//    Commitment c1 = new Commitment(r1, r2, f, f);
//    Commitment c2 = new Commitment(r1, r1, f, f);
//    Commitment c3 = new Commitment(r2, r1, fMultiObjectPredicate, f);
//    Commitment c4 = new Commitment(r1, r2, f, fOneStringPredicate);
//    logger.debug("Commitments created"); 
//    logger.debug("Testing equality between c1 and c2");
//    logger.debug(c1.equals(c2));
//    logger.debug("Testing equality between c1 and itself");
//    logger.debug(c1.equals(c1));
//    logger.debug("Testing equality between c1 and a fact");
//    logger.debug(c1.equals(fMultiObjectPredicate));
//    logger.debug("Testing equality between c1 and c3, same with roles exchanged");
//    logger.debug(c1.equals(c3));
//    logger.debug("Testing equality between c1 and c4, same roles, different fact");
//    logger.debug(c1.equals(c4));
//    logger.debug("Now adding commitments to interaction state");
//    try {
////      state.createCommitment(c0);
////      state.createCommitment(c1);
////      state.createCommitment(c2);
////      state.createCommitment(c3);
////      state.createCommitment(c4);
//    } catch (CommitmentAlreadyAddedException e) {
//      // TODO Auto-generated catch block
//      e.printStackTrace();
//    }
   
    logger.debug("Commitments added to state, status: "+state);
   
    try {
      state.assertFact(f);
      state.assertFact(fOneStringPredicate);
      state.assertFact(fMultiStringPredicate);
      state.assertFact(fOneStringOneObject);
      state.assertFact(fMultiObjectPredicate);
     
     
    } catch (LogicalExpressionAlreadyAddedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
    logger.debug("Facts added to state, status: "+state);
   
    logger.debug("Test retrieving commitments by status...");
    logger.debug(state.retrieveCommitmentsByLifecycleStatus(LifeCycleState.CONDITIONAL));
   
    logger.debug("Test cancel operation.");
   
    CompositeExpression ce, ce1;
    try {
      ce = new CompositeExpression(LogicalOperatorType.OR, new Fact("done"), new Fact("failure"));
      ce1 = new CompositeExpression(LogicalOperatorType.OR, new Fact("done"), new Fact("failure"));
      logger.debug("Adding...");
      logger.debug(ce);
      state.assertFact(ce);
      logger.debug(state);
      logger.debug("Testing equality: "+ce.equals(ce1));
     
    } catch (MissingOperandException | WrongOperandsNumberException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (LogicalExpressionAlreadyAddedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
   
   
    try {
//      logger.debug("Canceling commitment "+c1);
//      state.cancelCommitment(c1);
//      logger.debug("Canceling commitment "+c2);
//      state.cancelCommitment(c2);
    }
    catch (Exception e) {
      logger.error("Error in canceling commitment");
      e.printStackTrace();
    }
   
   
   
   
  }

}
TOP

Related Classes of it.unito.di.test.TestInteractionState

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.