mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/advanced/configuration/TestSystemConfigurationImpl.java
@Test
    public void testConfigurationEventHandler() throws SecurityException, IllegalArgumentException, 
        NoSuchFieldException, IllegalAccessException
    {
        setupConfigurations();
        
        //create configuration event where controller does not exist in config list
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(ConfigurationEventConstants.EVENT_PROP_PID, "factory config 3");
        props.put(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID, "factory PID 1");
        props.put(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID, 99);
        Event nonExistingConfigEvent = new Event(SystemConfigurationMgr.TOPIC_CONFIGURATION_UPDATED_REMOTE, props);
        
        m_ConfigEventHandler.handleEvent(nonExistingConfigEvent);
        
        ArgumentCaptor<EventRegistrationRequestData> messageNonExistingCaptor = 
                ArgumentCaptor.forClass(EventRegistrationRequestData.class);
        
        verify(m_MessageFactory).createEventAdminMessage(eq(EventAdminMessageType.EventRegistrationRequest), 
                messageNonExistingCaptor.capture());
        verify(m_MessageWrapper, times(2)).queue(eq(99), 
                Mockito.any(RegisterEventsResponseHandler.class));
        
        EventRegistrationRequestData data = messageNonExistingCaptor.getValue();
        assertThat(data.getTopicCount(), is(1));
        assertThat(data.getTopic(0), is(ConfigurationEventConstants.TOPIC_ALL_CONFIGURATION_EVENTS));
        
        //create the configuration event.
        props.put(ConfigurationEventConstants.EVENT_PROP_PID, "factory config 2");
        props.put(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID, "factory PID");
        props.put(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID, 25);
        Event configEvent = new Event(SystemConfigurationMgr.TOPIC_CONFIGURATION_UPDATED_REMOTE, props);
        
        //Replay the configuration updated event.
        m_ConfigEventHandler.handleEvent(configEvent);
        
        //Replay the configuration location changed event.
        configEvent = new Event(SystemConfigurationMgr.TOPIC_CONFIGURATION_LOCATION_REMOTE, props);
        m_ConfigEventHandler.handleEvent(configEvent);
        
        ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
        
        //Verify that the remote message sender was called two times.
        verify(m_MessageFactory, times(3)).createConfigAdminMessage(
                eq(ConfigAdminMessageType.GetConfigurationInfoRequest), messageCaptor.capture());
        verify(m_MessageWrapper, times(2)).queue(eq(25), Mockito.any(ResponseHandler.class));
        
        GetConfigurationInfoRequestData configInfoRequest = 
                (GetConfigurationInfoRequestData)messageCaptor.getAllValues().get(1);
        assertThat(configInfoRequest.getFilter(), is("(service.pid=factory config 2)"));
        
        configInfoRequest = (GetConfigurationInfoRequestData)messageCaptor.getAllValues().get(1);
        assertThat(configInfoRequest.getFilter(), is("(service.pid=factory config 2)"));
        
        //Create the config deleted event.
        configEvent = new Event(SystemConfigurationMgr.TOPIC_CONFIGURATION_DELETED_REMOTE, props);
        
        assertThat(m_SUT.getConfigurationByPidAsync(25, "factory config 2"), is(notNullValue()));
        //Replay factory configuration deleted event.
        m_ConfigEventHandler.handleEvent(configEvent);
        assertThat(m_SUT.getConfigurationByPidAsync(25, "factory config 2"), is(nullValue()));
        
        //create configuration deleted event.
        props.put(ConfigurationEventConstants.EVENT_PROP_PID, "some PID");
        props.put(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID, null);
        props.put(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID, 25);
        configEvent = new Event(SystemConfigurationMgr.TOPIC_CONFIGURATION_DELETED_REMOTE, props);
        
        assertThat(m_SUT.getConfigurationByPidAsync(25, "some PID"), is(notNullValue()));
        //Replay configuration deleted event.
        m_ConfigEventHandler.handleEvent(configEvent);
        assertThat(m_SUT.getConfigurationByPidAsync(25, "some PID"), is(nullValue()));
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getAllValues().get(0);
        assertThat(event.getTopic(), is(SystemConfigurationMgr.TOPIC_CONFIG_MODEL_UPDATED));
        assertThat(event.getProperty(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID), is((Object)25));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_PID), is((Object)"factory config 2"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID), is((Object)"factory PID"));
        
        event = eventCaptor.getAllValues().get(1);
        assertThat(event.getTopic(), is(SystemConfigurationMgr.TOPIC_CONFIG_MODEL_UPDATED));
        assertThat(event.getProperty(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID), is((Object)25));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_PID), is((Object)"some PID"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID), is(nullValue()));
    }
/**
     * Test for the configuration event handler.
     * Verify that the configuration event handler handles all events appropriately. 
     */
Test for the configuration event handler.
Verify that the configuration event handler handles all events appropriately.
Test for the configuration event handler . Verify that the configuration event handler handles all events appropriately .
@Test
    public void testConfigurationEventHandler() throws SecurityException, IllegalArgumentException, 
        NoSuchFieldException, IllegalAccessException
    {
        setupConfigurations();
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(ConfigurationEventConstants.EVENT_PROP_PID, "factory config 3");
        props.put(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID, "factory PID 1");
        props.put(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID, 99);
        Event nonExistingConfigEvent = new Event(SystemConfigurationMgr.TOPIC_CONFIGURATION_UPDATED_REMOTE, props);
        m_ConfigEventHandler.handleEvent(nonExistingConfigEvent);
        ArgumentCaptor<EventRegistrationRequestData> messageNonExistingCaptor = 
                ArgumentCaptor.forClass(EventRegistrationRequestData.class);
        verify(m_MessageFactory).createEventAdminMessage(eq(EventAdminMessageType.EventRegistrationRequest), 
                messageNonExistingCaptor.capture());
        verify(m_MessageWrapper, times(2)).queue(eq(99), 
                Mockito.any(RegisterEventsResponseHandler.class));
        EventRegistrationRequestData data = messageNonExistingCaptor.getValue();
        assertThat(data.getTopicCount(), is(1));
        assertThat(data.getTopic(0), is(ConfigurationEventConstants.TOPIC_ALL_CONFIGURATION_EVENTS));
        props.put(ConfigurationEventConstants.EVENT_PROP_PID, "factory config 2");
        props.put(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID, "factory PID");
        props.put(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID, 25);
        Event configEvent = new Event(SystemConfigurationMgr.TOPIC_CONFIGURATION_UPDATED_REMOTE, props);
        m_ConfigEventHandler.handleEvent(configEvent);
        configEvent = new Event(SystemConfigurationMgr.TOPIC_CONFIGURATION_LOCATION_REMOTE, props);
        m_ConfigEventHandler.handleEvent(configEvent);
        ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
        verify(m_MessageFactory, times(3)).createConfigAdminMessage(
                eq(ConfigAdminMessageType.GetConfigurationInfoRequest), messageCaptor.capture());
        verify(m_MessageWrapper, times(2)).queue(eq(25), Mockito.any(ResponseHandler.class));
        GetConfigurationInfoRequestData configInfoRequest = 
                (GetConfigurationInfoRequestData)messageCaptor.getAllValues().get(1);
        assertThat(configInfoRequest.getFilter(), is("(service.pid=factory config 2)"));
        configInfoRequest = (GetConfigurationInfoRequestData)messageCaptor.getAllValues().get(1);
        assertThat(configInfoRequest.getFilter(), is("(service.pid=factory config 2)"));
        configEvent = new Event(SystemConfigurationMgr.TOPIC_CONFIGURATION_DELETED_REMOTE, props);
        assertThat(m_SUT.getConfigurationByPidAsync(25, "factory config 2"), is(notNullValue()));
        m_ConfigEventHandler.handleEvent(configEvent);
        assertThat(m_SUT.getConfigurationByPidAsync(25, "factory config 2"), is(nullValue()));
        props.put(ConfigurationEventConstants.EVENT_PROP_PID, "some PID");
        props.put(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID, null);
        props.put(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID, 25);
        configEvent = new Event(SystemConfigurationMgr.TOPIC_CONFIGURATION_DELETED_REMOTE, props);
        assertThat(m_SUT.getConfigurationByPidAsync(25, "some PID"), is(notNullValue()));
        m_ConfigEventHandler.handleEvent(configEvent);
        assertThat(m_SUT.getConfigurationByPidAsync(25, "some PID"), is(nullValue()));
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getAllValues().get(0);
        assertThat(event.getTopic(), is(SystemConfigurationMgr.TOPIC_CONFIG_MODEL_UPDATED));
        assertThat(event.getProperty(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID), is((Object)25));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_PID), is((Object)"factory config 2"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID), is((Object)"factory PID"));
        event = eventCaptor.getAllValues().get(1);
        assertThat(event.getTopic(), is(SystemConfigurationMgr.TOPIC_CONFIG_MODEL_UPDATED));
        assertThat(event.getProperty(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID), is((Object)25));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_PID), is((Object)"some PID"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID), is(nullValue()));
    }
@ Test public void testConfigurationEventHandler ( ) throws SecurityException , IllegalArgumentException , NoSuchFieldException , IllegalAccessException { setupConfigurations ( ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( ConfigurationEventConstants . EVENT_PROP_PID , "factory config 3" ) ; props . put ( ConfigurationEventConstants . EVENT_PROP_FACTORY_PID , "factory PID 1" ) ; props . put ( SharedPropertyConstants . EVENT_PROP_CONTROLLER_ID , 99 ) ; Event nonExistingConfigEvent = new Event ( SystemConfigurationMgr . TOPIC_CONFIGURATION_UPDATED_REMOTE , props ) ; m_ConfigEventHandler . handleEvent ( nonExistingConfigEvent ) ; ArgumentCaptor < EventRegistrationRequestData > messageNonExistingCaptor = ArgumentCaptor . forClass ( EventRegistrationRequestData . class ) ; verify ( m_MessageFactory ) . createEventAdminMessage ( eq ( EventAdminMessageType . EventRegistrationRequest ) , messageNonExistingCaptor . capture ( ) ) ; verify ( m_MessageWrapper , times ( 2 ) ) . queue ( eq ( 99 ) , Mockito . any ( RegisterEventsResponseHandler . class ) ) ; EventRegistrationRequestData data = messageNonExistingCaptor . getValue ( ) ; assertThat ( data . getTopicCount ( ) , is ( 1 ) ) ; assertThat ( data . getTopic ( 0 ) , is ( ConfigurationEventConstants . TOPIC_ALL_CONFIGURATION_EVENTS ) ) ; props . put ( ConfigurationEventConstants . EVENT_PROP_PID , "factory config 2" ) ; props . put ( ConfigurationEventConstants . EVENT_PROP_FACTORY_PID , "factory PID" ) ; props . put ( SharedPropertyConstants . EVENT_PROP_CONTROLLER_ID , 25 ) ; Event configEvent = new Event ( SystemConfigurationMgr . TOPIC_CONFIGURATION_UPDATED_REMOTE , props ) ; m_ConfigEventHandler . handleEvent ( configEvent ) ; configEvent = new Event ( SystemConfigurationMgr . TOPIC_CONFIGURATION_LOCATION_REMOTE , props ) ; m_ConfigEventHandler . handleEvent ( configEvent ) ; ArgumentCaptor < Message > messageCaptor = ArgumentCaptor . forClass ( Message . class ) ; verify ( m_MessageFactory , times ( 3 ) ) . createConfigAdminMessage ( eq ( ConfigAdminMessageType . GetConfigurationInfoRequest ) , messageCaptor . capture ( ) ) ; verify ( m_MessageWrapper , times ( 2 ) ) . queue ( eq ( 25 ) , Mockito . any ( ResponseHandler . class ) ) ; GetConfigurationInfoRequestData configInfoRequest = ( GetConfigurationInfoRequestData ) messageCaptor . getAllValues ( ) . get ( 1 ) ; assertThat ( configInfoRequest . getFilter ( ) , is ( "(service.pid=factory config 2)" ) ) ; configInfoRequest = ( GetConfigurationInfoRequestData ) messageCaptor . getAllValues ( ) . get ( 1 ) ; assertThat ( configInfoRequest . getFilter ( ) , is ( "(service.pid=factory config 2)" ) ) ; configEvent = new Event ( SystemConfigurationMgr . TOPIC_CONFIGURATION_DELETED_REMOTE , props ) ; assertThat ( m_SUT . getConfigurationByPidAsync ( 25 , "factory config 2" ) , is ( notNullValue ( ) ) ) ; m_ConfigEventHandler . handleEvent ( configEvent ) ; assertThat ( m_SUT . getConfigurationByPidAsync ( 25 , "factory config 2" ) , is ( nullValue ( ) ) ) ; props . put ( ConfigurationEventConstants . EVENT_PROP_PID , "some PID" ) ; props . put ( ConfigurationEventConstants . EVENT_PROP_FACTORY_PID , null ) ; props . put ( SharedPropertyConstants . EVENT_PROP_CONTROLLER_ID , 25 ) ; configEvent = new Event ( SystemConfigurationMgr . TOPIC_CONFIGURATION_DELETED_REMOTE , props ) ; assertThat ( m_SUT . getConfigurationByPidAsync ( 25 , "some PID" ) , is ( notNullValue ( ) ) ) ; m_ConfigEventHandler . handleEvent ( configEvent ) ; assertThat ( m_SUT . getConfigurationByPidAsync ( 25 , "some PID" ) , is ( nullValue ( ) ) ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getAllValues ( ) . get ( 0 ) ; assertThat ( event . getTopic ( ) , is ( SystemConfigurationMgr . TOPIC_CONFIG_MODEL_UPDATED ) ) ; assertThat ( event . getProperty ( SharedPropertyConstants . EVENT_PROP_CONTROLLER_ID ) , is ( ( Object ) 25 ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_PID ) , is ( ( Object ) "factory config 2" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_FACTORY_PID ) , is ( ( Object ) "factory PID" ) ) ; event = eventCaptor . getAllValues ( ) . get ( 1 ) ; assertThat ( event . getTopic ( ) , is ( SystemConfigurationMgr . TOPIC_CONFIG_MODEL_UPDATED ) ) ; assertThat ( event . getProperty ( SharedPropertyConstants . EVENT_PROP_CONTROLLER_ID ) , is ( ( Object ) 25 ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_PID ) , is ( ( Object ) "some PID" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_FACTORY_PID ) , is ( nullValue ( ) ) ) ; }
Test for the configuration event handler.
Test for the configuration event handler .
//create configuration event where controller does not exist in config list //create the configuration event. //Replay the configuration updated event. //Replay the configuration location changed event. //Verify that the remote message sender was called two times. //Create the config deleted event. //Replay factory configuration deleted event. //create configuration deleted event. //Replay configuration deleted event.