mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/messaging/TestMessageSenderImpl.java
@Test
    public void testQueueMessageWithHandler() throws IOException
    {
        //setup and activate component
        activateSetUp();

        // construct data message to send, should reg handler
        ActivateRequestData messageData = ActivateRequestData.newBuilder().
                setUuid(UUID.newBuilder().setLeastSignificantBits(0L).setMostSignificantBits(1L).build()).build();
        AssetNamespace  nameMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.ActivateRequest).
                setData(messageData.toByteString()).build();
        TerraHarvestMessage request = 
                createMessageWithDestSource(m_LocalId, m_RemoteId, 0, Namespace.Asset, nameMessage);
        
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        m_SUT.queueMessage(100, TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload()), EncryptType.NONE, 
            m_Handler);
        
        //message as response
        nameMessage = AssetNamespace.newBuilder().
                 setType(AssetMessageType.ActivateResponse).build();
        request = createTerraHarvestMessage(0, Namespace.Asset, nameMessage, true);
        TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload());
                
        // properties for the event
        final Map<String, Object> props = new HashMap<String, Object>();
        props.put(RemoteConstants.EVENT_PROP_DATA_MESSAGE, null);
        props.put(RemoteConstants.EVENT_PROP_PAYLOAD, payLoadTest);
        props.put(RemoteConstants.EVENT_PROP_MESSAGE, request);
        props.put(RemoteConstants.EVENT_PROP_SOURCE_ID, m_RemoteId);
        props.put(RemoteConstants.EVENT_PROP_DEST_ID, 0);
        props.put(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE, nameMessage);
        props.put(RemoteConstants.EVENT_PROP_NAMESPACE, Namespace.Asset.toString());
        props.put(RemoteConstants.EVENT_PROP_MESSAGE_TYPE, 
            AssetMessageType.ActivateResponse.toString());

        Event event = new Event(RemoteConstants.TOPIC_MESSAGE_RECEIVED, props);

        m_ResponseHandler.handleEvent(event);
        verify(m_Handler).handleResponse(request,payLoadTest, nameMessage, null);
        
        //post the event again and verify the handler was not called again
        m_ResponseHandler.handleEvent(event);
        verify(m_Handler, only()).handleResponse(request, payLoadTest,nameMessage, null);
        
        m_SUT.deactivate();
        verify(m_HandlerReg).unregister();
    }
/**
     * Verify that the event handler will call the response handler {@link ResponseHandler#handleResponse} method.
     * Verify activation registers the event handler.
     * Verify that deactivation unregisters the listener.
     */
Verify that the event handler will call the response handler  ResponseHandler#handleResponse method.
Verify activation registers the event handler.
Verify that deactivation unregisters the listener.
Verify that the event handler will call the response handler ResponseHandler#handleResponse method . Verify activation registers the event handler . Verify that deactivation unregisters the listener .
@Test
    public void testQueueMessageWithHandler() throws IOException
    {
        activateSetUp();
        ActivateRequestData messageData = ActivateRequestData.newBuilder().
                setUuid(UUID.newBuilder().setLeastSignificantBits(0L).setMostSignificantBits(1L).build()).build();
        AssetNamespace  nameMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.ActivateRequest).
                setData(messageData.toByteString()).build();
        TerraHarvestMessage request = 
                createMessageWithDestSource(m_LocalId, m_RemoteId, 0, Namespace.Asset, nameMessage);
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        m_SUT.queueMessage(100, TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload()), EncryptType.NONE, 
            m_Handler);
        nameMessage = AssetNamespace.newBuilder().
                 setType(AssetMessageType.ActivateResponse).build();
        request = createTerraHarvestMessage(0, Namespace.Asset, nameMessage, true);
        TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload());
        final Map<String, Object> props = new HashMap<String, Object>();
        props.put(RemoteConstants.EVENT_PROP_DATA_MESSAGE, null);
        props.put(RemoteConstants.EVENT_PROP_PAYLOAD, payLoadTest);
        props.put(RemoteConstants.EVENT_PROP_MESSAGE, request);
        props.put(RemoteConstants.EVENT_PROP_SOURCE_ID, m_RemoteId);
        props.put(RemoteConstants.EVENT_PROP_DEST_ID, 0);
        props.put(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE, nameMessage);
        props.put(RemoteConstants.EVENT_PROP_NAMESPACE, Namespace.Asset.toString());
        props.put(RemoteConstants.EVENT_PROP_MESSAGE_TYPE, 
            AssetMessageType.ActivateResponse.toString());
        Event event = new Event(RemoteConstants.TOPIC_MESSAGE_RECEIVED, props);
        m_ResponseHandler.handleEvent(event);
        verify(m_Handler).handleResponse(request,payLoadTest, nameMessage, null);
        m_ResponseHandler.handleEvent(event);
        verify(m_Handler, only()).handleResponse(request, payLoadTest,nameMessage, null);
        m_SUT.deactivate();
        verify(m_HandlerReg).unregister();
    }
@ Test public void testQueueMessageWithHandler ( ) throws IOException { activateSetUp ( ) ; ActivateRequestData messageData = ActivateRequestData . newBuilder ( ) . setUuid ( UUID . newBuilder ( ) . setLeastSignificantBits ( 0L ) . setMostSignificantBits ( 1L ) . build ( ) ) . build ( ) ; AssetNamespace nameMessage = AssetNamespace . newBuilder ( ) . setType ( AssetMessageType . ActivateRequest ) . setData ( messageData . toByteString ( ) ) . build ( ) ; TerraHarvestMessage request = createMessageWithDestSource ( m_LocalId , m_RemoteId , 0 , Namespace . Asset , nameMessage ) ; when ( m_EncryptService . encryptMessage ( Mockito . any ( Builder . class ) , Mockito . any ( TerraHarvestPayload . class ) ) ) . thenReturn ( request ) ; m_SUT . queueMessage ( 100 , TerraHarvestPayload . parseFrom ( request . getTerraHarvestPayload ( ) ) , EncryptType . NONE , m_Handler ) ; nameMessage = AssetNamespace . newBuilder ( ) . setType ( AssetMessageType . ActivateResponse ) . build ( ) ; request = createTerraHarvestMessage ( 0 , Namespace . Asset , nameMessage , true ) ; TerraHarvestPayload payLoadTest = TerraHarvestPayload . parseFrom ( request . getTerraHarvestPayload ( ) ) ; final Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( RemoteConstants . EVENT_PROP_DATA_MESSAGE , null ) ; props . put ( RemoteConstants . EVENT_PROP_PAYLOAD , payLoadTest ) ; props . put ( RemoteConstants . EVENT_PROP_MESSAGE , request ) ; props . put ( RemoteConstants . EVENT_PROP_SOURCE_ID , m_RemoteId ) ; props . put ( RemoteConstants . EVENT_PROP_DEST_ID , 0 ) ; props . put ( RemoteConstants . EVENT_PROP_NAMESPACE_MESSAGE , nameMessage ) ; props . put ( RemoteConstants . EVENT_PROP_NAMESPACE , Namespace . Asset . toString ( ) ) ; props . put ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE , AssetMessageType . ActivateResponse . toString ( ) ) ; Event event = new Event ( RemoteConstants . TOPIC_MESSAGE_RECEIVED , props ) ; m_ResponseHandler . handleEvent ( event ) ; verify ( m_Handler ) . handleResponse ( request , payLoadTest , nameMessage , null ) ; m_ResponseHandler . handleEvent ( event ) ; verify ( m_Handler , only ( ) ) . handleResponse ( request , payLoadTest , nameMessage , null ) ; m_SUT . deactivate ( ) ; verify ( m_HandlerReg ) . unregister ( ) ; }
Verify that the event handler will call the response handler {@link ResponseHandler#handleResponse} method.
Verify that the event handler will call the response handler { @link ResponseHandler#handleResponse } method .
//setup and activate component // construct data message to send, should reg handler //message as response // properties for the event //post the event again and verify the handler was not called again