mil.dod.th.ose.config/test/mil/dod/th/ose/config/event/TestConfigurationAdminEventBridge.java
@SuppressWarnings("unchecked")
    @Test
    public void testConfigurationEvent()
    {
        //activate 
        activateSetup();
        
        //Mock the configuration event.
        ConfigurationEvent configEvent = mock(ConfigurationEvent.class);

        ServiceReference<ConfigurationAdmin> serviceReference = mock(ServiceReference.class);
        when(configEvent.getPid()).thenReturn("testPid");
        when(configEvent.getFactoryPid()).thenReturn("testFactoryPid");
        when(configEvent.getReference()).thenReturn(serviceReference);
        when(serviceReference.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_ID)).thenReturn("service id");
        when(serviceReference.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_PID)).
            thenReturn("service pid");
        
        //Set the type of configuration event to deleted.
        when(configEvent.getType()).thenReturn(ConfigurationEvent.CM_DELETED);
        //Post the event.
        m_ConfigListener.configurationEvent(configEvent);
        
        //Set the type of configuration event to updated.
        when(configEvent.getType()).thenReturn(ConfigurationEvent.CM_UPDATED);
        //Post the event.
        m_ConfigListener.configurationEvent(configEvent);
        
        //Set the type of configuration event to location changed.
        when(configEvent.getType()).thenReturn(ConfigurationEvent.CM_LOCATION_CHANGED);
        //Post the event.
        m_ConfigListener.configurationEvent(configEvent);
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        //Verify the event admin service was called for all three events and capture those events.
        verify(m_EventAdmin, times(3)).postEvent(eventCaptor.capture());
        
        //Verify the values of three configuration events below.
        Event event = eventCaptor.getAllValues().get(0);
        assertThat(event.getTopic(), is(ConfigurationEventConstants.TOPIC_CONFIGURATION_DELETED_EVENT));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_PID), is((Object)"testPid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID), is((Object)"testFactoryPid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_ID), is ((Object)"service id"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_PID), is((Object)"service pid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_REFERENCE), 
                is((Object)serviceReference));
        
        event = eventCaptor.getAllValues().get(1);
        assertThat(event.getTopic(), is(ConfigurationEventConstants.TOPIC_CONFIGURATION_UPDATED_EVENT));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_PID), is((Object)"testPid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID), is((Object)"testFactoryPid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_ID), is ((Object)"service id"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_PID), is((Object)"service pid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_REFERENCE), 
                is((Object)serviceReference));
        
        event = eventCaptor.getAllValues().get(2);
        assertThat(event.getTopic(), is(ConfigurationEventConstants.TOPIC_CONFIGURATION_LOCATION_EVENT));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_PID), is((Object)"testPid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID), is((Object)"testFactoryPid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_ID), is ((Object)"service id"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_PID), is((Object)"service pid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_REFERENCE), 
                is((Object)serviceReference));
        
        //Set the type to a non-existent configuration event type.
        when(configEvent.getType()).thenReturn(100);
        
        try
        {
            //Since the configuration event type does not exist an illegal argument exception should be thrown.
            m_ConfigListener.configurationEvent(configEvent);
            fail("Illegal argument exception should be thrown.");
        }
        catch (IllegalArgumentException exception)
        {
            
        }
    }
/**
     * Test method that handles converting configuration events to standard events.
     * Verify that the event is posted to the event admin and that it is converted appropriately.
     */
Test method that handles converting configuration events to standard events.
Verify that the event is posted to the event admin and that it is converted appropriately.
Test method that handles converting configuration events to standard events . Verify that the event is posted to the event admin and that it is converted appropriately .
@SuppressWarnings("unchecked")
    @Test
    public void testConfigurationEvent()
    {
        activateSetup();
        ConfigurationEvent configEvent = mock(ConfigurationEvent.class);
        ServiceReference<ConfigurationAdmin> serviceReference = mock(ServiceReference.class);
        when(configEvent.getPid()).thenReturn("testPid");
        when(configEvent.getFactoryPid()).thenReturn("testFactoryPid");
        when(configEvent.getReference()).thenReturn(serviceReference);
        when(serviceReference.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_ID)).thenReturn("service id");
        when(serviceReference.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_PID)).
            thenReturn("service pid");
        when(configEvent.getType()).thenReturn(ConfigurationEvent.CM_DELETED);
        m_ConfigListener.configurationEvent(configEvent);
        when(configEvent.getType()).thenReturn(ConfigurationEvent.CM_UPDATED);
        m_ConfigListener.configurationEvent(configEvent);
        when(configEvent.getType()).thenReturn(ConfigurationEvent.CM_LOCATION_CHANGED);
        m_ConfigListener.configurationEvent(configEvent);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(3)).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getAllValues().get(0);
        assertThat(event.getTopic(), is(ConfigurationEventConstants.TOPIC_CONFIGURATION_DELETED_EVENT));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_PID), is((Object)"testPid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID), is((Object)"testFactoryPid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_ID), is ((Object)"service id"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_PID), is((Object)"service pid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_REFERENCE), 
                is((Object)serviceReference));
        event = eventCaptor.getAllValues().get(1);
        assertThat(event.getTopic(), is(ConfigurationEventConstants.TOPIC_CONFIGURATION_UPDATED_EVENT));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_PID), is((Object)"testPid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID), is((Object)"testFactoryPid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_ID), is ((Object)"service id"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_PID), is((Object)"service pid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_REFERENCE), 
                is((Object)serviceReference));
        event = eventCaptor.getAllValues().get(2);
        assertThat(event.getTopic(), is(ConfigurationEventConstants.TOPIC_CONFIGURATION_LOCATION_EVENT));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_PID), is((Object)"testPid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID), is((Object)"testFactoryPid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_ID), is ((Object)"service id"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_PID), is((Object)"service pid"));
        assertThat(event.getProperty(ConfigurationEventConstants.EVENT_PROP_SERVICE_REFERENCE), 
                is((Object)serviceReference));
        when(configEvent.getType()).thenReturn(100);
        try
        {
            m_ConfigListener.configurationEvent(configEvent);
            fail("Illegal argument exception should be thrown.");
        }
        catch (IllegalArgumentException exception)
        {
        }
    }
@ SuppressWarnings ( "unchecked" ) @ Test public void testConfigurationEvent ( ) { activateSetup ( ) ; ConfigurationEvent configEvent = mock ( ConfigurationEvent . class ) ; ServiceReference < ConfigurationAdmin > serviceReference = mock ( ServiceReference . class ) ; when ( configEvent . getPid ( ) ) . thenReturn ( "testPid" ) ; when ( configEvent . getFactoryPid ( ) ) . thenReturn ( "testFactoryPid" ) ; when ( configEvent . getReference ( ) ) . thenReturn ( serviceReference ) ; when ( serviceReference . getProperty ( ConfigurationEventConstants . EVENT_PROP_SERVICE_ID ) ) . thenReturn ( "service id" ) ; when ( serviceReference . getProperty ( ConfigurationEventConstants . EVENT_PROP_SERVICE_PID ) ) . thenReturn ( "service pid" ) ; when ( configEvent . getType ( ) ) . thenReturn ( ConfigurationEvent . CM_DELETED ) ; m_ConfigListener . configurationEvent ( configEvent ) ; when ( configEvent . getType ( ) ) . thenReturn ( ConfigurationEvent . CM_UPDATED ) ; m_ConfigListener . configurationEvent ( configEvent ) ; when ( configEvent . getType ( ) ) . thenReturn ( ConfigurationEvent . CM_LOCATION_CHANGED ) ; m_ConfigListener . configurationEvent ( configEvent ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 3 ) ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getAllValues ( ) . get ( 0 ) ; assertThat ( event . getTopic ( ) , is ( ConfigurationEventConstants . TOPIC_CONFIGURATION_DELETED_EVENT ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_PID ) , is ( ( Object ) "testPid" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_FACTORY_PID ) , is ( ( Object ) "testFactoryPid" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_SERVICE_ID ) , is ( ( Object ) "service id" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_SERVICE_PID ) , is ( ( Object ) "service pid" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_SERVICE_REFERENCE ) , is ( ( Object ) serviceReference ) ) ; event = eventCaptor . getAllValues ( ) . get ( 1 ) ; assertThat ( event . getTopic ( ) , is ( ConfigurationEventConstants . TOPIC_CONFIGURATION_UPDATED_EVENT ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_PID ) , is ( ( Object ) "testPid" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_FACTORY_PID ) , is ( ( Object ) "testFactoryPid" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_SERVICE_ID ) , is ( ( Object ) "service id" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_SERVICE_PID ) , is ( ( Object ) "service pid" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_SERVICE_REFERENCE ) , is ( ( Object ) serviceReference ) ) ; event = eventCaptor . getAllValues ( ) . get ( 2 ) ; assertThat ( event . getTopic ( ) , is ( ConfigurationEventConstants . TOPIC_CONFIGURATION_LOCATION_EVENT ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_PID ) , is ( ( Object ) "testPid" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_FACTORY_PID ) , is ( ( Object ) "testFactoryPid" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_SERVICE_ID ) , is ( ( Object ) "service id" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_SERVICE_PID ) , is ( ( Object ) "service pid" ) ) ; assertThat ( event . getProperty ( ConfigurationEventConstants . EVENT_PROP_SERVICE_REFERENCE ) , is ( ( Object ) serviceReference ) ) ; when ( configEvent . getType ( ) ) . thenReturn ( 100 ) ; try { m_ConfigListener . configurationEvent ( configEvent ) ; fail ( "Illegal argument exception should be thrown." ) ; } catch ( IllegalArgumentException exception ) { } }
Test method that handles converting configuration events to standard events.
Test method that handles converting configuration events to standard events .
//activate  //Mock the configuration event. //Set the type of configuration event to deleted. //Post the event. //Set the type of configuration event to updated. //Post the event. //Set the type of configuration event to location changed. //Post the event. //Verify the event admin service was called for all three events and capture those events. //Verify the values of three configuration events below. //Set the type to a non-existent configuration event type. //Since the configuration event type does not exist an illegal argument exception should be thrown.