mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/transport/TestTransportMessageListener.java
@Test
    public void testHandleEventLargeMsg() throws IOException
    {
        // attempt to send message that is over the max limit
        // setup the message to be received
        byte[] tooBig = new byte[1025]; // a byte array that is just 1 byte too big
        for (int i = 0; i < tooBig.length; i++)
        {
            tooBig[i] = 0x01;
        }
        
        BaseNamespace bigMessage = BaseNamespace.newBuilder().
                setType(BaseMessageType.RequestControllerInfo).
                setData(ByteString.copyFrom(tooBig)).
                build();

        final int sourceId = 100;

        TerraHarvestMessage message = TerraHarvestMessageHelper.
                createTerraHarvestMessage(sourceId, 1, Namespace.Base, 100, bigMessage);        
        
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        message.writeDelimitedTo(output);
        TransportPacket packet = mock(TransportPacket.class);
        when(packet.getPayload()).thenReturn(ByteBuffer.wrap(output.toByteArray()));
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(TransportLayer.EVENT_PROP_PACKET, packet);
        Event event = new Event(TransportLayer.TOPIC_PACKET_RECEIVED, properties);
        
        // wait for the event again
        EventAdminSyncer syncer = new EventAdminSyncer(m_EventAdmin, RemoteConstants.TOPIC_REMOVE_CHANNEL);
        
        m_SUT.handleEvent(event);
        
        // wait again for separate thread
        syncer.waitFor(1, TimeUnit.SECONDS);

        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(1)).postEvent(eventCaptor.capture());
        List<Event> postedEvents = EventAdminVerifier.assertEventByTopicOnly(eventCaptor, 
                RemoteConstants.TOPIC_REMOVE_CHANNEL, 1);
        assertThat((TransportChannel)postedEvents.get(0).getProperty(RemoteConstants.EVENT_PROP_CHANNEL), 
                    is(m_Channel));
    }
/**
     * Test with a message that exceeds the max allowed size.
     * @throws IOException on error writing output to TerraHarvestMessage
     */
Test with a message that exceeds the max allowed size.
@throws IOException on error writing output to TerraHarvestMessage
Test with a message that exceeds the max allowed size . @throws IOException on error writing output to TerraHarvestMessage
@Test
    public void testHandleEventLargeMsg() throws IOException
    {
        byte[] tooBig = new byte[1025]; 
        for (int i = 0; i < tooBig.length; i++)
        {
            tooBig[i] = 0x01;
        }
        BaseNamespace bigMessage = BaseNamespace.newBuilder().
                setType(BaseMessageType.RequestControllerInfo).
                setData(ByteString.copyFrom(tooBig)).
                build();
        final int sourceId = 100;
        TerraHarvestMessage message = TerraHarvestMessageHelper.
                createTerraHarvestMessage(sourceId, 1, Namespace.Base, 100, bigMessage);        
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        message.writeDelimitedTo(output);
        TransportPacket packet = mock(TransportPacket.class);
        when(packet.getPayload()).thenReturn(ByteBuffer.wrap(output.toByteArray()));
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(TransportLayer.EVENT_PROP_PACKET, packet);
        Event event = new Event(TransportLayer.TOPIC_PACKET_RECEIVED, properties);
        EventAdminSyncer syncer = new EventAdminSyncer(m_EventAdmin, RemoteConstants.TOPIC_REMOVE_CHANNEL);
        m_SUT.handleEvent(event);
        syncer.waitFor(1, TimeUnit.SECONDS);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(1)).postEvent(eventCaptor.capture());
        List<Event> postedEvents = EventAdminVerifier.assertEventByTopicOnly(eventCaptor, 
                RemoteConstants.TOPIC_REMOVE_CHANNEL, 1);
        assertThat((TransportChannel)postedEvents.get(0).getProperty(RemoteConstants.EVENT_PROP_CHANNEL), 
                    is(m_Channel));
    }
@ Test public void testHandleEventLargeMsg ( ) throws IOException { byte [ ] tooBig = new byte [ 1025 ] ; for ( int i = 0 ; i < tooBig . length ; i ++ ) { tooBig [ i ] = 0x01 ; } BaseNamespace bigMessage = BaseNamespace . newBuilder ( ) . setType ( BaseMessageType . RequestControllerInfo ) . setData ( ByteString . copyFrom ( tooBig ) ) . build ( ) ; final int sourceId = 100 ; TerraHarvestMessage message = TerraHarvestMessageHelper . createTerraHarvestMessage ( sourceId , 1 , Namespace . Base , 100 , bigMessage ) ; ByteArrayOutputStream output = new ByteArrayOutputStream ( ) ; message . writeDelimitedTo ( output ) ; TransportPacket packet = mock ( TransportPacket . class ) ; when ( packet . getPayload ( ) ) . thenReturn ( ByteBuffer . wrap ( output . toByteArray ( ) ) ) ; Map < String , Object > properties = new HashMap < String , Object > ( ) ; properties . put ( TransportLayer . EVENT_PROP_PACKET , packet ) ; Event event = new Event ( TransportLayer . TOPIC_PACKET_RECEIVED , properties ) ; EventAdminSyncer syncer = new EventAdminSyncer ( m_EventAdmin , RemoteConstants . TOPIC_REMOVE_CHANNEL ) ; m_SUT . handleEvent ( event ) ; syncer . waitFor ( 1 , TimeUnit . SECONDS ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 1 ) ) . postEvent ( eventCaptor . capture ( ) ) ; List < Event > postedEvents = EventAdminVerifier . assertEventByTopicOnly ( eventCaptor , RemoteConstants . TOPIC_REMOVE_CHANNEL , 1 ) ; assertThat ( ( TransportChannel ) postedEvents . get ( 0 ) . getProperty ( RemoteConstants . EVENT_PROP_CHANNEL ) , is ( m_Channel ) ) ; }
Test with a message that exceeds the max allowed size.
Test with a message that exceeds the max allowed size .
// attempt to send message that is over the max limit // setup the message to be received // a byte array that is just 1 byte too big // wait for the event again // wait again for separate thread