mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/controller/TestControllerMgrImpl.java
@Test
    public void testModeEventHandler()
    {
        int contId = 9001;
        
        RemoteChannel channel = addChannelMockHelper(contId);//mock channel lookup
        
        Event event = createBasicChannelUpdatedEvent(channel, contId);
        
        m_ChannelHelper.handleEvent(event);
        
        //mock system info response has been received for newly added channel
        mockControllerMessage(contId, BaseMessageType.ControllerInfo);
        
        ControllerModel model = m_SUT.getController(contId);
        assertThat(model, notNullValue());
        
        /*
         * Mock system mode event - update to test mode
         */        
        mockSystemModeEvent(contId, OperationMode.TEST_MODE);
        
        assertThat(m_SUT.getController(contId).getOperatingMode(), is(OperationMode.TEST_MODE));
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(3)).postEvent(eventCaptor.capture());
        
        //one event for the addition of the controller, one for controller updated, one for event registration
        assertThat(eventCaptor.getAllValues().size(), is(3));
        
        Event controllerUpdated = eventCaptor.getValue(); //most recent value
        assertThat(controllerUpdated.getTopic(), is(ControllerMgr.TOPIC_CONTROLLER_UPDATED));
        assertThat(controllerUpdated.getPropertyNames().length, is(1)); //should only contain topic property
        
        ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
        verify(m_GrowlUtil, times(2)).createGlobalFacesMessage(eq(FacesMessage.SEVERITY_INFO), 
                anyString(), stringCaptor.capture());
        
        //assert that growl message displays newly updated mode. 
        assertThat(stringCaptor.getValue(), containsString(m_SUT.getController(contId).getOperatingModeDisplayText()));
        
        /*
         * Mock system mode event - update to operational mode
         */
        eventCaptor = ArgumentCaptor.forClass(Event.class); //reset argument captor
        mockSystemModeEvent(contId, OperationMode.OPERATIONAL_MODE);
        
        assertThat(m_SUT.getController(contId).getOperatingMode(), is(OperationMode.OPERATIONAL_MODE));
        
        stringCaptor = ArgumentCaptor.forClass(String.class); //reset string captor
        verify(m_GrowlUtil, times(3)).createGlobalFacesMessage(eq(FacesMessage.SEVERITY_INFO), 
                anyString(), stringCaptor.capture());
        
        //assert that growl message displays newly updated mode
        assertThat(stringCaptor.getValue(), containsString(m_SUT.getController(contId).getOperatingModeDisplayText()));
    }
/**
     * Verify topic controller updated when system mode event is captured.
     */
Verify topic controller updated when system mode event is captured.
Verify topic controller updated when system mode event is captured .
@Test
    public void testModeEventHandler()
    {
        int contId = 9001;
        RemoteChannel channel = addChannelMockHelper(contId);
        Event event = createBasicChannelUpdatedEvent(channel, contId);
        m_ChannelHelper.handleEvent(event);
        mockControllerMessage(contId, BaseMessageType.ControllerInfo);
        ControllerModel model = m_SUT.getController(contId);
        assertThat(model, notNullValue());
        /*
         * Mock system mode event - update to test mode
         */        
        mockSystemModeEvent(contId, OperationMode.TEST_MODE);
        assertThat(m_SUT.getController(contId).getOperatingMode(), is(OperationMode.TEST_MODE));
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(3)).postEvent(eventCaptor.capture());
        assertThat(eventCaptor.getAllValues().size(), is(3));
        Event controllerUpdated = eventCaptor.getValue(); 
        assertThat(controllerUpdated.getTopic(), is(ControllerMgr.TOPIC_CONTROLLER_UPDATED));
        assertThat(controllerUpdated.getPropertyNames().length, is(1)); 
        ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
        verify(m_GrowlUtil, times(2)).createGlobalFacesMessage(eq(FacesMessage.SEVERITY_INFO), 
                anyString(), stringCaptor.capture());
        assertThat(stringCaptor.getValue(), containsString(m_SUT.getController(contId).getOperatingModeDisplayText()));
        /*
         * Mock system mode event - update to operational mode
         */
        eventCaptor = ArgumentCaptor.forClass(Event.class); 
        mockSystemModeEvent(contId, OperationMode.OPERATIONAL_MODE);
        assertThat(m_SUT.getController(contId).getOperatingMode(), is(OperationMode.OPERATIONAL_MODE));
        stringCaptor = ArgumentCaptor.forClass(String.class); 
        verify(m_GrowlUtil, times(3)).createGlobalFacesMessage(eq(FacesMessage.SEVERITY_INFO), 
                anyString(), stringCaptor.capture());
        assertThat(stringCaptor.getValue(), containsString(m_SUT.getController(contId).getOperatingModeDisplayText()));
    }
@ Test public void testModeEventHandler ( ) { int contId = 9001 ; RemoteChannel channel = addChannelMockHelper ( contId ) ; Event event = createBasicChannelUpdatedEvent ( channel , contId ) ; m_ChannelHelper . handleEvent ( event ) ; mockControllerMessage ( contId , BaseMessageType . ControllerInfo ) ; ControllerModel model = m_SUT . getController ( contId ) ; assertThat ( model , notNullValue ( ) ) ; /*
         * Mock system mode event - update to test mode
         */ mockSystemModeEvent ( contId , OperationMode . TEST_MODE ) ; assertThat ( m_SUT . getController ( contId ) . getOperatingMode ( ) , is ( OperationMode . TEST_MODE ) ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 3 ) ) . postEvent ( eventCaptor . capture ( ) ) ; assertThat ( eventCaptor . getAllValues ( ) . size ( ) , is ( 3 ) ) ; Event controllerUpdated = eventCaptor . getValue ( ) ; assertThat ( controllerUpdated . getTopic ( ) , is ( ControllerMgr . TOPIC_CONTROLLER_UPDATED ) ) ; assertThat ( controllerUpdated . getPropertyNames ( ) . length , is ( 1 ) ) ; ArgumentCaptor < String > stringCaptor = ArgumentCaptor . forClass ( String . class ) ; verify ( m_GrowlUtil , times ( 2 ) ) . createGlobalFacesMessage ( eq ( FacesMessage . SEVERITY_INFO ) , anyString ( ) , stringCaptor . capture ( ) ) ; assertThat ( stringCaptor . getValue ( ) , containsString ( m_SUT . getController ( contId ) . getOperatingModeDisplayText ( ) ) ) ; /*
         * Mock system mode event - update to operational mode
         */ eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; mockSystemModeEvent ( contId , OperationMode . OPERATIONAL_MODE ) ; assertThat ( m_SUT . getController ( contId ) . getOperatingMode ( ) , is ( OperationMode . OPERATIONAL_MODE ) ) ; stringCaptor = ArgumentCaptor . forClass ( String . class ) ; verify ( m_GrowlUtil , times ( 3 ) ) . createGlobalFacesMessage ( eq ( FacesMessage . SEVERITY_INFO ) , anyString ( ) , stringCaptor . capture ( ) ) ; assertThat ( stringCaptor . getValue ( ) , containsString ( m_SUT . getController ( contId ) . getOperatingModeDisplayText ( ) ) ) ; }
Verify topic controller updated when system mode event is captured.
Verify topic controller updated when system mode event is captured .
//mock channel lookup //mock system info response has been received for newly added channel //one event for the addition of the controller, one for controller updated, one for event registration //most recent value //should only contain topic property //assert that growl message displays newly updated mode.  //reset argument captor //reset string captor //assert that growl message displays newly updated mode