Project: engagement_generation License: BSD Dependencies:
Used by:
None |
engagement_generation/test/edu/wpi/hri/gen/policy/TurnPositionPolicyTest.javaGo to the documentation of this file.00001 package edu.wpi.hri.gen.policy; 00002 00003 import junit.framework.TestCase; 00004 00005 import org.junit.Test; 00006 00007 import ros.NodeHandle; 00008 import ros.Ros; 00009 import ros.RosException; 00010 import ros.pkg.engagement_msgs.msg.APAction; 00011 import edu.wpi.hri.bml.XMLInterface; 00012 import edu.wpi.hri.gen.Generation; 00013 import edu.wpi.hri.gen.comm.BMLEmitListener; 00014 import edu.wpi.hri.gen.ebml.EBMLList; 00015 import edu.wpi.hri.gen.policy.TurnPositionPolicy.APWaiter; 00016 import edu.wpi.hri.log.Logger; 00017 00018 public class TurnPositionPolicyTest extends TestCase { 00019 00020 @Test 00021 public void testPolicy() throws RosException { 00022 String actor = "actor-test"; 00023 NodeHandle handle = Ros.getInstance().createNodeHandle(); 00024 Logger logger = Logger.createDefault(); 00025 BMLEmitListener emit = new BMLEmitListener(handle, logger); 00026 TurnPositionPolicy policy = new TurnPositionPolicy(handle, logger, 00027 emit, true); 00028 XMLInterface xml = Generation.createXML(logger); 00029 00030 try { 00031 // beginning of first turn 00032 EBMLList list = new EBMLList(logger, xml, "list-id"); 00033 assertNull(policy.apply(list, "BEGINNING", actor, true, false, "")); 00034 assertEquals(2, list.size()); 00035 00036 // beginning of response 00037 list = new EBMLList(logger, xml, "list-id"); 00038 assertNull(policy.apply(list, "BEGINNING", actor, false, false, "")); 00039 assertEquals(2, list.size()); 00040 00041 // middle, turn doesn't matter 00042 list = new EBMLList(logger, xml, "list-id"); 00043 assertNull(policy.apply(list, "MIDDLE", actor, false, false, "")); 00044 assertEquals(2, list.size()); 00045 00046 // end, turn doesn't matter 00047 list = new EBMLList(logger, xml, "list-id"); 00048 assertNotNull(policy.apply(list, "END", actor, false, false, "")); 00049 assertNotSame(2, list.size()); 00050 00051 // full of first turn 00052 list = new EBMLList(logger, xml, "list-id"); 00053 APWaiter waiter = policy.apply(list, "FULL", actor, false, false, 00054 ""); 00055 assertNotNull(waiter); 00056 assertNotSame(2, list.size()); 00057 assertEquals(APAction.NO_ACTION, waiter.getResponse()); 00058 00059 // full of response 00060 list = new EBMLList(logger, xml, "list-id"); 00061 APWaiter second = policy 00062 .apply(list, "FULL", actor, true, false, ""); 00063 assertNotNull(second); 00064 assertNotSame(waiter, second); 00065 assertNotSame(2, list.size()); 00066 00067 // backchannel, add nothing 00068 list = new EBMLList(logger, xml, "list-id"); 00069 assertNull(policy.apply(list, "BACKCHANNEL", actor, false, false, 00070 "")); 00071 assertEquals(2, list.size()); 00072 00073 // Beginning, delay should add stuff 00074 list = new EBMLList(logger, xml, "list-id"); 00075 assertNull(policy.apply(list, "BEGINNING", actor, false, true, "")); 00076 assertNotSame(2, list.size()); 00077 00078 // middle, delay should add stuff 00079 list = new EBMLList(logger, xml, "list-id"); 00080 assertNull(policy.apply(list, "MIDDLE", actor, false, true, "")); 00081 assertNotSame(2, list.size()); 00082 } catch (Exception e) { 00083 fail("none should fail: " + e.getMessage()); 00084 } 00085 00086 try { 00087 // end and delay should not be allowed 00088 EBMLList list = new EBMLList(logger, xml, "list-id"); 00089 policy.apply(list, "END", actor, false, true, ""); 00090 fail("End and delay should throw exception"); 00091 } catch (Exception e) { 00092 } 00093 00094 try { 00095 // end and delay should not be allowed 00096 EBMLList list = new EBMLList(logger, xml, "list-id"); 00097 policy.apply(list, "FULL", actor, false, true, ""); 00098 fail("Full and delay should throw exception"); 00099 } catch (Exception e) { 00100 } 00101 00102 try { 00103 // end and delay should not be allowed 00104 EBMLList list = new EBMLList(logger, xml, "list-id"); 00105 policy.apply(list, "BACKCHANNEL", actor, false, true, ""); 00106 fail("Backchannel and delay should throw exception"); 00107 } catch (Exception e) { 00108 } 00109 00110 policy.shutdown(); 00111 emit.shutdown(); 00112 handle.shutdown(); 00113 } 00114 } |