mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestServerSocketChannel.java
@Test
    public void testQueueMessage() throws IOException
    {
        // mock the socket that will be used to send the message
        Socket socket = mock(Socket.class);
        SocketAddress socketAddress = mock(SocketAddress.class);
        when(socketAddress.toString()).thenReturn(REMOTE_SOCKET_ADDR);
        when(socket.getRemoteSocketAddress()).thenReturn(socketAddress);
        
        // activate method expects a connected socket to be passed in
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(ServerSocketChannel.SOCKET_PROP_KEY, socket);
        m_SUT.activate(props);
        
        TerraHarvestMessage message = createBaseMessage();
        
        when(m_MessageSender.queue(message)).thenReturn(false);
        
        // replay
        boolean result = m_SUT.queueMessage(message);
        
        // verify message is passed down to queue and result returned by queue is returned
        verify(m_MessageSender).queue(message);
        assertThat("message reorted the same as returned by sender", result, is(false));
        
        // mock to return true instead, verify result is passed correctly
        when(m_MessageSender.queue(message)).thenReturn(true);
        
        // replay
        result = m_SUT.queueMessage(message);
        
        // verify message is passed down 2nd time to queue and result returned by queue is returned
        verify(m_MessageSender, times(2)).queue(message);
        assertThat("message reported the same as returned by sender", result, is(true));   
    }
/**
     * Verify the message is sent using the given socket in binary form if no error sending message.
     */
Verify the message is sent using the given socket in binary form if no error sending message.
Verify the message is sent using the given socket in binary form if no error sending message .
@Test
    public void testQueueMessage() throws IOException
    {
        Socket socket = mock(Socket.class);
        SocketAddress socketAddress = mock(SocketAddress.class);
        when(socketAddress.toString()).thenReturn(REMOTE_SOCKET_ADDR);
        when(socket.getRemoteSocketAddress()).thenReturn(socketAddress);
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(ServerSocketChannel.SOCKET_PROP_KEY, socket);
        m_SUT.activate(props);
        TerraHarvestMessage message = createBaseMessage();
        when(m_MessageSender.queue(message)).thenReturn(false);
        boolean result = m_SUT.queueMessage(message);
        verify(m_MessageSender).queue(message);
        assertThat("message reorted the same as returned by sender", result, is(false));
        when(m_MessageSender.queue(message)).thenReturn(true);
        result = m_SUT.queueMessage(message);
        verify(m_MessageSender, times(2)).queue(message);
        assertThat("message reported the same as returned by sender", result, is(true));   
    }
@ Test public void testQueueMessage ( ) throws IOException { Socket socket = mock ( Socket . class ) ; SocketAddress socketAddress = mock ( SocketAddress . class ) ; when ( socketAddress . toString ( ) ) . thenReturn ( REMOTE_SOCKET_ADDR ) ; when ( socket . getRemoteSocketAddress ( ) ) . thenReturn ( socketAddress ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( ServerSocketChannel . SOCKET_PROP_KEY , socket ) ; m_SUT . activate ( props ) ; TerraHarvestMessage message = createBaseMessage ( ) ; when ( m_MessageSender . queue ( message ) ) . thenReturn ( false ) ; boolean result = m_SUT . queueMessage ( message ) ; verify ( m_MessageSender ) . queue ( message ) ; assertThat ( "message reorted the same as returned by sender" , result , is ( false ) ) ; when ( m_MessageSender . queue ( message ) ) . thenReturn ( true ) ; result = m_SUT . queueMessage ( message ) ; verify ( m_MessageSender , times ( 2 ) ) . queue ( message ) ; assertThat ( "message reported the same as returned by sender" , result , is ( true ) ) ; }
Verify the message is sent using the given socket in binary form if no error sending message.
Verify the message is sent using the given socket in binary form if no error sending message .
// mock the socket that will be used to send the message // activate method expects a connected socket to be passed in // replay // verify message is passed down to queue and result returned by queue is returned // mock to return true instead, verify result is passed correctly // replay // verify message is passed down 2nd time to queue and result returned by queue is returned