mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/controller/TestControllerMgrImpl.java
@Test
    public void testRemoveController()
    {
        //mocking
        SocketChannel socChannel = mock(SocketChannel.class);
        when(socChannel.getChannelType()).thenReturn(RemoteChannelTypeEnum.SOCKET);
        TransportChannel channel = mock(TransportChannel.class);
        when(channel.getChannelType()).thenReturn(RemoteChannelTypeEnum.TRANSPORT);
        
        List<RemoteChannel> channelsForCont2 = new ArrayList<RemoteChannel>();
        channelsForCont2.add(channel);
        List<RemoteChannel> channelsForCont3 = new ArrayList<RemoteChannel>();
        channelsForCont3.add(socChannel);
        when(m_ChannelLookup.getChannels(CONT_ID_2)).thenReturn(channelsForCont2);
        when(m_ChannelLookup.getChannels(CONT_ID_3)).thenReturn(channelsForCont3);
        
        //mock remote channel lookup behavior
        RemoteChannel chan = mock(RemoteChannel.class);
        List<RemoteChannel> setChanns = new ArrayList<RemoteChannel>();
        setChanns.add(chan);
        when(m_ChannelLookup.getChannels(CONT_ID_1)).thenReturn(setChanns);
        when(m_ChannelLookup.getChannels(CONT_ID_4)).thenReturn(setChanns);
        
        //sets up the map of channels by controller ID
        setUpFourChannels(setChanns);
        
        //add controllers
        m_ChannelHelper.handleEvent(createBasicChannelUpdatedEvent(mock(RemoteChannel.class), CONT_ID_1));
        m_ChannelHelper.handleEvent(createBasicChannelUpdatedEvent(mock(RemoteChannel.class), CONT_ID_2));
        m_ChannelHelper.handleEvent(createBasicChannelUpdatedEvent(mock(RemoteChannel.class), CONT_ID_3));
        m_ChannelHelper.handleEvent(createBasicChannelUpdatedEvent(mock(RemoteChannel.class), CONT_ID_4));
        
        //get all controllers, there should be the four just added
        assertThat(m_SUT.getAllControllers().size(), is(4));
        
        //remove one of the controllers
        m_SUT.removeController(CONT_ID_2);
        verify(m_ChannelLookup).removeChannel(channel);
        when(m_ChannelLookup.getChannels(CONT_ID_2)).thenReturn(new ArrayList<RemoteChannel>());
        
        //verify other three controller are still in lookup
        assertThat(m_SUT.getAllControllers().size(), is(3));
        
        //remove one of the controllers
        m_SUT.removeController(CONT_ID_3);
        verify(m_ChannelLookup).removeChannel(socChannel);
        
        //remove one of the controllers that was already removed should register a 'growl' message
        try
        {
            m_SUT.removeController(CONT_ID_3);
            fail("Expected exception! Controller was already removed.");
        }
        catch (IllegalArgumentException exception)
        {
            //expected exception
        }
        verify(m_GrowlUtil).createLocalFacesMessage(eq(FacesMessage.SEVERITY_WARN), anyString(), anyString());
    }
/**
     * Test removal of a controller from the controller manager.
     * Verify that removing a controller that doesn't exist posts a 'growl' message.
     */
Test removal of a controller from the controller manager.
Verify that removing a controller that doesn't exist posts a 'growl' message.
Test removal of a controller from the controller manager . Verify that removing a controller that doesn ' t exist posts a ' growl ' message .
@Test
    public void testRemoveController()
    {
        SocketChannel socChannel = mock(SocketChannel.class);
        when(socChannel.getChannelType()).thenReturn(RemoteChannelTypeEnum.SOCKET);
        TransportChannel channel = mock(TransportChannel.class);
        when(channel.getChannelType()).thenReturn(RemoteChannelTypeEnum.TRANSPORT);
        List<RemoteChannel> channelsForCont2 = new ArrayList<RemoteChannel>();
        channelsForCont2.add(channel);
        List<RemoteChannel> channelsForCont3 = new ArrayList<RemoteChannel>();
        channelsForCont3.add(socChannel);
        when(m_ChannelLookup.getChannels(CONT_ID_2)).thenReturn(channelsForCont2);
        when(m_ChannelLookup.getChannels(CONT_ID_3)).thenReturn(channelsForCont3);
        RemoteChannel chan = mock(RemoteChannel.class);
        List<RemoteChannel> setChanns = new ArrayList<RemoteChannel>();
        setChanns.add(chan);
        when(m_ChannelLookup.getChannels(CONT_ID_1)).thenReturn(setChanns);
        when(m_ChannelLookup.getChannels(CONT_ID_4)).thenReturn(setChanns);
        setUpFourChannels(setChanns);
        m_ChannelHelper.handleEvent(createBasicChannelUpdatedEvent(mock(RemoteChannel.class), CONT_ID_1));
        m_ChannelHelper.handleEvent(createBasicChannelUpdatedEvent(mock(RemoteChannel.class), CONT_ID_2));
        m_ChannelHelper.handleEvent(createBasicChannelUpdatedEvent(mock(RemoteChannel.class), CONT_ID_3));
        m_ChannelHelper.handleEvent(createBasicChannelUpdatedEvent(mock(RemoteChannel.class), CONT_ID_4));
        assertThat(m_SUT.getAllControllers().size(), is(4));
        m_SUT.removeController(CONT_ID_2);
        verify(m_ChannelLookup).removeChannel(channel);
        when(m_ChannelLookup.getChannels(CONT_ID_2)).thenReturn(new ArrayList<RemoteChannel>());
        assertThat(m_SUT.getAllControllers().size(), is(3));
        m_SUT.removeController(CONT_ID_3);
        verify(m_ChannelLookup).removeChannel(socChannel);
         that was already removed should register a 'growl' message
        try
        {
            m_SUT.removeController(CONT_ID_3);
            fail("Expected exception! Controller was already removed.");
        }
        catch (IllegalArgumentException exception)
        {
        }
        verify(m_GrowlUtil).createLocalFacesMessage(eq(FacesMessage.SEVERITY_WARN), anyString(), anyString());
    }
@ Test public void testRemoveController ( ) { SocketChannel socChannel = mock ( SocketChannel . class ) ; when ( socChannel . getChannelType ( ) ) . thenReturn ( RemoteChannelTypeEnum . SOCKET ) ; TransportChannel channel = mock ( TransportChannel . class ) ; when ( channel . getChannelType ( ) ) . thenReturn ( RemoteChannelTypeEnum . TRANSPORT ) ; List < RemoteChannel > channelsForCont2 = new ArrayList < RemoteChannel > ( ) ; channelsForCont2 . add ( channel ) ; List < RemoteChannel > channelsForCont3 = new ArrayList < RemoteChannel > ( ) ; channelsForCont3 . add ( socChannel ) ; when ( m_ChannelLookup . getChannels ( CONT_ID_2 ) ) . thenReturn ( channelsForCont2 ) ; when ( m_ChannelLookup . getChannels ( CONT_ID_3 ) ) . thenReturn ( channelsForCont3 ) ; RemoteChannel chan = mock ( RemoteChannel . class ) ; List < RemoteChannel > setChanns = new ArrayList < RemoteChannel > ( ) ; setChanns . add ( chan ) ; when ( m_ChannelLookup . getChannels ( CONT_ID_1 ) ) . thenReturn ( setChanns ) ; when ( m_ChannelLookup . getChannels ( CONT_ID_4 ) ) . thenReturn ( setChanns ) ; setUpFourChannels ( setChanns ) ; m_ChannelHelper . handleEvent ( createBasicChannelUpdatedEvent ( mock ( RemoteChannel . class ) , CONT_ID_1 ) ) ; m_ChannelHelper . handleEvent ( createBasicChannelUpdatedEvent ( mock ( RemoteChannel . class ) , CONT_ID_2 ) ) ; m_ChannelHelper . handleEvent ( createBasicChannelUpdatedEvent ( mock ( RemoteChannel . class ) , CONT_ID_3 ) ) ; m_ChannelHelper . handleEvent ( createBasicChannelUpdatedEvent ( mock ( RemoteChannel . class ) , CONT_ID_4 ) ) ; assertThat ( m_SUT . getAllControllers ( ) . size ( ) , is ( 4 ) ) ; m_SUT . removeController ( CONT_ID_2 ) ; verify ( m_ChannelLookup ) . removeChannel ( channel ) ; when ( m_ChannelLookup . getChannels ( CONT_ID_2 ) ) . thenReturn ( new ArrayList < RemoteChannel > ( ) ) ; assertThat ( m_SUT . getAllControllers ( ) . size ( ) , is ( 3 ) ) ; m_SUT . removeController ( CONT_ID_3 ) ; verify ( m_ChannelLookup ) . removeChannel ( socChannel ) ; try { m_SUT . removeController ( CONT_ID_3 ) ; fail ( "Expected exception! Controller was already removed." ) ; } catch ( IllegalArgumentException exception ) { } verify ( m_GrowlUtil ) . createLocalFacesMessage ( eq ( FacesMessage . SEVERITY_WARN ) , anyString ( ) , anyString ( ) ) ; }
Test removal of a controller from the controller manager.
Test removal of a controller from the controller manager .
//mocking //mock remote channel lookup behavior //sets up the map of channels by controller ID //add controllers //get all controllers, there should be the four just added //remove one of the controllers //verify other three controller are still in lookup //remove one of the controllers //remove one of the controllers that was already removed should register a 'growl' message //expected exception