mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/observation/TestRemoteObservationListener.java
@SuppressWarnings("unchecked")
    @Test
    public void testHandleRegistration()
    {
        //prop map simulating the enabled property is updated to false
        Map<String, Object> props = new HashMap<String, Object>();
        props.put("enabled", false);
        m_SUT.modified(props);

        //verify
        verify(m_HandlerReg, times(2)).unregister();

        //reactivate
        props.put("enabled", true);
        m_SUT.modified(props);

        //verify, handlers registered again.
        @SuppressWarnings("rawtypes")
        ArgumentCaptor<Dictionary> dictCaptor = ArgumentCaptor.forClass(Dictionary.class);
        verify(m_Context, times(4)).registerService(eq(EventHandler.class), Mockito.any(EventHandler.class), 
            dictCaptor.capture());

        //map for filter and the topic value, not topic and then filter, because two of the registrations have the same
        //topic but different filters. 
        Map<Object, Object> topicFilters = new HashMap<Object, Object>();
        for (@SuppressWarnings("rawtypes") Dictionary dictionary : dictCaptor.getAllValues())
        {
            topicFilters.put(dictionary.get(EventConstants.EVENT_FILTER), 
                dictionary.get(EventConstants.EVENT_TOPIC));
        }
        
        assertThat(topicFilters, hasEntry((Object)String.format("(&(%s=%s)(|(%s=%s)(%s=%s)))", 
                RemoteConstants.EVENT_PROP_NAMESPACE, Namespace.ObservationStore.toString(),
                RemoteConstants.EVENT_PROP_MESSAGE_TYPE, 
                ObservationStoreMessageType.FindObservationByUUIDResponse.toString(),
                RemoteConstants.EVENT_PROP_MESSAGE_TYPE, 
                ObservationStoreMessageType.GetObservationResponse.toString()),
                (Object)RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat(topicFilters, hasEntry((Object)null, (Object)(new
             String[] {ObservationStore.TOPIC_OBSERVATION_MERGED_WITH_OBS + RemoteConstants.REMOTE_TOPIC_SUFFIX,
            ObservationStore.TOPIC_OBSERVATION_PERSISTED_WITH_OBS + RemoteConstants.REMOTE_TOPIC_SUFFIX})));
    }
/**
     * Test the handler registrations. 
     * Verify correct topic, and filters are being used.
     */
Test the handler registrations.
Verify correct topic, and filters are being used.
Test the handler registrations . Verify correct topic and filters are being used .
@SuppressWarnings("unchecked")
    @Test
    public void testHandleRegistration()
    {
        Map<String, Object> props = new HashMap<String, Object>();
        props.put("enabled", false);
        m_SUT.modified(props);
        verify(m_HandlerReg, times(2)).unregister();
        props.put("enabled", true);
        m_SUT.modified(props);
        , handlers registered again.
        @SuppressWarnings("rawtypes")
        ArgumentCaptor<Dictionary> dictCaptor = ArgumentCaptor.forClass(Dictionary.class);
        verify(m_Context, times(4)).registerService(eq(EventHandler.class), Mockito.any(EventHandler.class), 
            dictCaptor.capture());
        Map<Object, Object> topicFilters = new HashMap<Object, Object>();
        for (@SuppressWarnings("rawtypes") Dictionary dictionary : dictCaptor.getAllValues())
        {
            topicFilters.put(dictionary.get(EventConstants.EVENT_FILTER), 
                dictionary.get(EventConstants.EVENT_TOPIC));
        }
        assertThat(topicFilters, hasEntry((Object)String.format("(&(%s=%s)(|(%s=%s)(%s=%s)))", 
                RemoteConstants.EVENT_PROP_NAMESPACE, Namespace.ObservationStore.toString(),
                RemoteConstants.EVENT_PROP_MESSAGE_TYPE, 
                ObservationStoreMessageType.FindObservationByUUIDResponse.toString(),
                RemoteConstants.EVENT_PROP_MESSAGE_TYPE, 
                ObservationStoreMessageType.GetObservationResponse.toString()),
                (Object)RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat(topicFilters, hasEntry((Object)null, (Object)(new
             String[] {ObservationStore.TOPIC_OBSERVATION_MERGED_WITH_OBS + RemoteConstants.REMOTE_TOPIC_SUFFIX,
            ObservationStore.TOPIC_OBSERVATION_PERSISTED_WITH_OBS + RemoteConstants.REMOTE_TOPIC_SUFFIX})));
    }
@ SuppressWarnings ( "unchecked" ) @ Test public void testHandleRegistration ( ) { Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( "enabled" , false ) ; m_SUT . modified ( props ) ; verify ( m_HandlerReg , times ( 2 ) ) . unregister ( ) ; props . put ( "enabled" , true ) ; m_SUT . modified ( props ) ; @ SuppressWarnings ( "rawtypes" ) ArgumentCaptor < Dictionary > dictCaptor = ArgumentCaptor . forClass ( Dictionary . class ) ; verify ( m_Context , times ( 4 ) ) . registerService ( eq ( EventHandler . class ) , Mockito . any ( EventHandler . class ) , dictCaptor . capture ( ) ) ; Map < Object , Object > topicFilters = new HashMap < Object , Object > ( ) ; for ( @ SuppressWarnings ( "rawtypes" ) Dictionary dictionary : dictCaptor . getAllValues ( ) ) { topicFilters . put ( dictionary . get ( EventConstants . EVENT_FILTER ) , dictionary . get ( EventConstants . EVENT_TOPIC ) ) ; } assertThat ( topicFilters , hasEntry ( ( Object ) String . format ( "(&(%s=%s)(|(%s=%s)(%s=%s)))" , RemoteConstants . EVENT_PROP_NAMESPACE , Namespace . ObservationStore . toString ( ) , RemoteConstants . EVENT_PROP_MESSAGE_TYPE , ObservationStoreMessageType . FindObservationByUUIDResponse . toString ( ) , RemoteConstants . EVENT_PROP_MESSAGE_TYPE , ObservationStoreMessageType . GetObservationResponse . toString ( ) ) , ( Object ) RemoteConstants . TOPIC_MESSAGE_RECEIVED ) ) ; assertThat ( topicFilters , hasEntry ( ( Object ) null , ( Object ) ( new String [ ] { ObservationStore . TOPIC_OBSERVATION_MERGED_WITH_OBS + RemoteConstants . REMOTE_TOPIC_SUFFIX , ObservationStore . TOPIC_OBSERVATION_PERSISTED_WITH_OBS + RemoteConstants . REMOTE_TOPIC_SUFFIX } ) ) ) ; }
Test the handler registrations.
Test the handler registrations .
//prop map simulating the enabled property is updated to false //verify //reactivate //verify, handlers registered again. //map for filter and the topic value, not topic and then filter, because two of the registrations have the same //topic but different filters. 