mil.dod.th.ose.datastream/test/mil/dod/th/ose/datastream/TestDataStreamServiceImpl.java
@SuppressWarnings("unchecked")
    @Test
    public void testConfigurationListenerNoFactory() throws InvalidSyntaxException, IllegalArgumentException, 
        FactoryException, FactoryObjectInformationException, IOException, InterruptedException
    {
        String factoryPid = "factory.pid";
        String host = "225.1.2.3";
        int port = 5004;
        
        when(m_ServiceContext.getFactories()).thenReturn(new HashMap<String, FactoryInternal>());
        
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(DataStreamServiceConfig.CONFIG_PROP_MULTICAST_HOST, host);
        props.put(DataStreamServiceConfig.CONFIG_PROP_START_PORT, port);
        
        m_SUT.activate(Collections.unmodifiableMap(props), m_BundleContext);
        
        ArgumentCaptor<EventHandler> handlerCaptor = ArgumentCaptor.forClass(EventHandler.class);
        verify(m_BundleContext, times(2)).registerService(eq(EventHandler.class), handlerCaptor.capture(), 
                Mockito.any(Dictionary.class));
        
        ConfigurationListener configListener = (ConfigurationListener)handlerCaptor.getAllValues().get(0);
        
        Map<String, Object> topicProps = new HashMap<>();
        topicProps.put(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID, factoryPid);
        topicProps.put(ConfigurationEventConstants.EVENT_PROP_PID, "config.pid");
        Event configAddedEvent = new Event(StreamProfileConfigListener.TOPIC_STREAM_PROFILE_CONFIG_UPDATED, topicProps);
        
        configListener.handleEvent(configAddedEvent);
        
        //Sleep needed to allow thread time create the object.
        Thread.sleep(500);
        
        verify(m_Registry, never()).createNewObjectForConfig(m_StreamProfileFactory, null, "config.pid");
        verify(m_WakeLock, never()).activate();
        verify(m_WakeLock, never()).cancel();
    }
/**
     * Verify there is no attempt to create a factory object if no factory exists.
     */
Verify there is no attempt to create a factory object if no factory exists.
Verify there is no attempt to create a factory object if no factory exists .
@SuppressWarnings("unchecked")
    @Test
    public void testConfigurationListenerNoFactory() throws InvalidSyntaxException, IllegalArgumentException, 
        FactoryException, FactoryObjectInformationException, IOException, InterruptedException
    {
        String factoryPid = "factory.pid";
        String host = "225.1.2.3";
        int port = 5004;
        when(m_ServiceContext.getFactories()).thenReturn(new HashMap<String, FactoryInternal>());
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(DataStreamServiceConfig.CONFIG_PROP_MULTICAST_HOST, host);
        props.put(DataStreamServiceConfig.CONFIG_PROP_START_PORT, port);
        m_SUT.activate(Collections.unmodifiableMap(props), m_BundleContext);
        ArgumentCaptor<EventHandler> handlerCaptor = ArgumentCaptor.forClass(EventHandler.class);
        verify(m_BundleContext, times(2)).registerService(eq(EventHandler.class), handlerCaptor.capture(), 
                Mockito.any(Dictionary.class));
        ConfigurationListener configListener = (ConfigurationListener)handlerCaptor.getAllValues().get(0);
        Map<String, Object> topicProps = new HashMap<>();
        topicProps.put(ConfigurationEventConstants.EVENT_PROP_FACTORY_PID, factoryPid);
        topicProps.put(ConfigurationEventConstants.EVENT_PROP_PID, "config.pid");
        Event configAddedEvent = new Event(StreamProfileConfigListener.TOPIC_STREAM_PROFILE_CONFIG_UPDATED, topicProps);
        configListener.handleEvent(configAddedEvent);
        Thread.sleep(500);
        verify(m_Registry, never()).createNewObjectForConfig(m_StreamProfileFactory, null, "config.pid");
        verify(m_WakeLock, never()).activate();
        verify(m_WakeLock, never()).cancel();
    }
@ SuppressWarnings ( "unchecked" ) @ Test public void testConfigurationListenerNoFactory ( ) throws InvalidSyntaxException , IllegalArgumentException , FactoryException , FactoryObjectInformationException , IOException , InterruptedException { String factoryPid = "factory.pid" ; String host = "225.1.2.3" ; int port = 5004 ; when ( m_ServiceContext . getFactories ( ) ) . thenReturn ( new HashMap < String , FactoryInternal > ( ) ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( DataStreamServiceConfig . CONFIG_PROP_MULTICAST_HOST , host ) ; props . put ( DataStreamServiceConfig . CONFIG_PROP_START_PORT , port ) ; m_SUT . activate ( Collections . unmodifiableMap ( props ) , m_BundleContext ) ; ArgumentCaptor < EventHandler > handlerCaptor = ArgumentCaptor . forClass ( EventHandler . class ) ; verify ( m_BundleContext , times ( 2 ) ) . registerService ( eq ( EventHandler . class ) , handlerCaptor . capture ( ) , Mockito . any ( Dictionary . class ) ) ; ConfigurationListener configListener = ( ConfigurationListener ) handlerCaptor . getAllValues ( ) . get ( 0 ) ; Map < String , Object > topicProps = new HashMap < > ( ) ; topicProps . put ( ConfigurationEventConstants . EVENT_PROP_FACTORY_PID , factoryPid ) ; topicProps . put ( ConfigurationEventConstants . EVENT_PROP_PID , "config.pid" ) ; Event configAddedEvent = new Event ( StreamProfileConfigListener . TOPIC_STREAM_PROFILE_CONFIG_UPDATED , topicProps ) ; configListener . handleEvent ( configAddedEvent ) ; Thread . sleep ( 500 ) ; verify ( m_Registry , never ( ) ) . createNewObjectForConfig ( m_StreamProfileFactory , null , "config.pid" ) ; verify ( m_WakeLock , never ( ) ) . activate ( ) ; verify ( m_WakeLock , never ( ) ) . cancel ( ) ; }
Verify there is no attempt to create a factory object if no factory exists.
Verify there is no attempt to create a factory object if no factory exists .
//Sleep needed to allow thread time create the object.