Changes between Version 27 and Version 28 of MiddleWareConnection


Ignore:
Timestamp:
10/28/12 19:16:04 (7 years ago)
Author:
welberge
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MiddleWareConnection

    v27 v28  
    263263} 
    264264}}} 
     265 
     266=== Creating a loader for RsbToBMLRealizerAdapter === 
     267To employ a RsbToBMLRealizerAdapter within the VirtualHumanSpec, a Loader needs to be defined for it: 
     268{{{ 
     269package asap.rsbadapters.loader; 
     270 
     271import hmi.util.Clock; 
     272import hmi.xml.XMLScanException; 
     273import hmi.xml.XMLTokenizer; 
     274 
     275import java.io.IOException; 
     276 
     277import asap.bml.bridge.RealizerPort; 
     278import asap.realizerembodiments.PipeLoader; 
     279import asap.rsbadapters.RsbToBMLRealizerAdapter; 
     280 
     281/** 
     282 * Loads a RsbToBMLRealizerAdapter from XML 
     283 * @author Herwin 
     284 * 
     285 */ 
     286public class RsbToBMLRealizerAdapterLoader implements PipeLoader 
     287{ 
     288    private RealizerPort adaptedRealizerPort = null; 
     289     
     290    @Override 
     291    public void readXML(XMLTokenizer theTokenizer, String id, String vhId, String name, RealizerPort realizerPort, Clock theSchedulingClock) 
     292            throws XMLScanException, IOException 
     293    { 
     294        adaptedRealizerPort = realizerPort; 
     295        new RsbToBMLRealizerAdapter(realizerPort);          
     296        if (!theTokenizer.atETag("PipeLoader")) throw new XMLScanException("RsbToBMLRealizerAdapter should be an empty element"); 
     297    } 
     298 
     299    @Override 
     300    public RealizerPort getAdaptedRealizerPort() 
     301    { 
     302        return adaptedRealizerPort; 
     303    }     
     304} 
     305}}} 
     306 
     307A testcase can be created to validate the loader parsing and check if teh RsbToBMLRealizerAdapter is connected (as listener) to the provided RealizerPort: 
     308{{{ 
     309package asap.rsbadapters.loader; 
     310 
     311import static org.junit.Assert.assertEquals; 
     312import static org.mockito.Matchers.any; 
     313import static org.mockito.Mockito.mock; 
     314import static org.mockito.Mockito.times; 
     315import static org.mockito.Mockito.verify; 
     316import hmi.util.Clock; 
     317import hmi.xml.XMLTokenizer; 
     318 
     319import java.io.IOException; 
     320 
     321import org.junit.Test; 
     322 
     323import asap.bml.bridge.RealizerPort; 
     324import asap.bml.feedback.BMLFeedbackListener; 
     325 
     326/** 
     327 * Unit tests for the RsbToBMLRealizerAdapterLoader 
     328 * @author Herwin 
     329 * 
     330 */ 
     331public class RsbToBMLRealizerAdapterLoaderTest 
     332{ 
     333    private RealizerPort mockRealizerPort = mock(RealizerPort.class); 
     334    private Clock mockSchedulingClock = mock(Clock.class); 
     335     
     336    @Test 
     337    public void testReadFromXML() throws IOException 
     338    { 
     339        String pipeLoaderStr = "<PipeLoader id=\"id1\" loader=\"x\"/>"; 
     340        XMLTokenizer tok = new XMLTokenizer(pipeLoaderStr); 
     341        tok.takeSTag("PipeLoader"); 
     342        RsbToBMLRealizerAdapterLoader loader = new RsbToBMLRealizerAdapterLoader(); 
     343        loader.readXML(tok, "id1", "vh1", "name", mockRealizerPort, mockSchedulingClock); 
     344        verify(mockRealizerPort, times(1)).addListeners(any(BMLFeedbackListener[].class)); 
     345        assertEquals(mockRealizerPort, loader.getAdaptedRealizerPort()); 
     346    } 
     347} 
     348}}}