mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/transport/TestTransportMessageListener.java
@Test
    public void testHandleEventLoggingDisabled() throws IOException
    {      
        //disable logging
        when(m_RemoteSettings.isLogRemoteMessagesEnabled()).thenReturn(false);
        Thread thread = new Thread(m_SUT);
        thread.start();
    
        int sourceId = 100;
        // setup the message to be received
        BaseNamespace baseMessage = BaseNamespace.newBuilder().
                setType(BaseMessageType.RequestControllerInfo).
                build();
    
        TerraHarvestMessage message = TerraHarvestMessageHelper.createTerraHarvestMessage(sourceId, 1, Namespace.Base, 
                100, baseMessage);
    
        //mimics message that would be sent through TransportChannel
        Map<String, Object> properties = new HashMap<String, Object>();
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        message.writeDelimitedTo(output);
    
        //mimics type of event that would be caught by listener
        TransportPacket packet = mock(TransportPacket.class);
        when(packet.getPayload()).thenReturn(ByteBuffer.wrap(output.toByteArray()));
        properties.put(TransportLayer.EVENT_PROP_PACKET, packet);
        Event event = new Event(TransportLayer.TOPIC_PACKET_RECEIVED, properties);
    
        EventAdminSyncer syncer = new EventAdminSyncer(m_EventAdmin, RemoteConstants.TOPIC_NEW_OR_CHANGED_CHANNEL_ID);
    
        m_SUT.handleEvent(event);
    
        // event is posted on a separate thread, wait for it
        syncer.waitFor(1, TimeUnit.SECONDS);
    
        // the listener should read in the message and parse as the same message
        verify(m_MessageRouter).handleMessage(message, m_Channel);
    
        // verify logging is disabled
        // debug logging for id should still be posted, no other debug messages should be logged (exactly 1)
        verify(m_Logging, times(1)).debug(anyString(), anyVararg());
    }
/**
     * Method verifies correct behavior of events in handleEvent method.
     * 
     * Verify new/changed id event is only sent when id changesInterruptedException
     */
Method verifies correct behavior of events in handleEvent method.

Verify new/changed id event is only sent when id changesInterruptedException
Method verifies correct behavior of events in handleEvent method . Verify new / changed id event is only sent when id changesInterruptedException
@Test
    public void testHandleEventLoggingDisabled() throws IOException
    {      
        when(m_RemoteSettings.isLogRemoteMessagesEnabled()).thenReturn(false);
        Thread thread = new Thread(m_SUT);
        thread.start();
        int sourceId = 100;
        BaseNamespace baseMessage = BaseNamespace.newBuilder().
                setType(BaseMessageType.RequestControllerInfo).
                build();
        TerraHarvestMessage message = TerraHarvestMessageHelper.createTerraHarvestMessage(sourceId, 1, Namespace.Base, 
                100, baseMessage);
        Map<String, Object> properties = new HashMap<String, Object>();
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        message.writeDelimitedTo(output);
        TransportPacket packet = mock(TransportPacket.class);
        when(packet.getPayload()).thenReturn(ByteBuffer.wrap(output.toByteArray()));
        properties.put(TransportLayer.EVENT_PROP_PACKET, packet);
        Event event = new Event(TransportLayer.TOPIC_PACKET_RECEIVED, properties);
        EventAdminSyncer syncer = new EventAdminSyncer(m_EventAdmin, RemoteConstants.TOPIC_NEW_OR_CHANGED_CHANNEL_ID);
        m_SUT.handleEvent(event);
        syncer.waitFor(1, TimeUnit.SECONDS);
        verify(m_MessageRouter).handleMessage(message, m_Channel);
        verify(m_Logging, times(1)).debug(anyString(), anyVararg());
    }
@ Test public void testHandleEventLoggingDisabled ( ) throws IOException { when ( m_RemoteSettings . isLogRemoteMessagesEnabled ( ) ) . thenReturn ( false ) ; Thread thread = new Thread ( m_SUT ) ; thread . start ( ) ; int sourceId = 100 ; BaseNamespace baseMessage = BaseNamespace . newBuilder ( ) . setType ( BaseMessageType . RequestControllerInfo ) . build ( ) ; TerraHarvestMessage message = TerraHarvestMessageHelper . createTerraHarvestMessage ( sourceId , 1 , Namespace . Base , 100 , baseMessage ) ; Map < String , Object > properties = new HashMap < String , Object > ( ) ; ByteArrayOutputStream output = new ByteArrayOutputStream ( ) ; message . writeDelimitedTo ( output ) ; TransportPacket packet = mock ( TransportPacket . class ) ; when ( packet . getPayload ( ) ) . thenReturn ( ByteBuffer . wrap ( output . toByteArray ( ) ) ) ; properties . put ( TransportLayer . EVENT_PROP_PACKET , packet ) ; Event event = new Event ( TransportLayer . TOPIC_PACKET_RECEIVED , properties ) ; EventAdminSyncer syncer = new EventAdminSyncer ( m_EventAdmin , RemoteConstants . TOPIC_NEW_OR_CHANGED_CHANNEL_ID ) ; m_SUT . handleEvent ( event ) ; syncer . waitFor ( 1 , TimeUnit . SECONDS ) ; verify ( m_MessageRouter ) . handleMessage ( message , m_Channel ) ; verify ( m_Logging , times ( 1 ) ) . debug ( anyString ( ) , anyVararg ( ) ) ; }
Method verifies correct behavior of events in handleEvent method.
Method verifies correct behavior of events in handleEvent method .
//disable logging // setup the message to be received //mimics message that would be sent through TransportChannel //mimics type of event that would be caught by listener // event is posted on a separate thread, wait for it // the listener should read in the message and parse as the same message // verify logging is disabled // debug logging for id should still be posted, no other debug messages should be logged (exactly 1)