mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestEventAdminMessageService.java
@Test
    public void testActivateDatastorePull()
    {
        //persistent reg messages.
        List<PersistentData> datas = new ArrayList<PersistentData>();
        PersistentEventRegistrationMessage message1 = createPersistedRegMessage();
        PersistentEventRegistrationMessage message2 = createPersistedRegMessage();
        
        //mock persistent data
        PersistentData data1 = mock(PersistentData.class);
        when(data1.getEntity()).thenReturn(message1.toByteArray());
        when(data1.getDescription()).thenReturn("1");
        PersistentData data2 = mock(PersistentData.class);
        when(data2.getEntity()).thenReturn(message2.toByteArray());
        when(data2.getDescription()).thenReturn("2");
        
        //add the mocks to the collection
        datas.add(data1);
        datas.add(data2);
        Collection<PersistentData> perData = datas;
        when(m_DataStore.query(EventAdminMessageService.class)).thenReturn(perData);
        
        //when the message are pulled the events will be re registered for
        ServiceRegistration<EventHandler> handler1 = mock(ServiceRegistration.class);
        ServiceRegistration<EventHandler> handler2 = mock(ServiceRegistration.class);
        
        //service registreation mocks
        when(m_Context.registerService(eq(EventHandler.class), Mockito.any(EventHandler.class), 
                Mockito.any(Dictionary.class))).thenReturn(handler1, handler2);
        
        //activate
        m_SUT.activate(m_Context);
        
        verify(m_DataStore, times(2)).query(EventAdminMessageService.class);
        
        m_SUT.deactivate();
        
        verify(handler1).unregister();
        verify(handler2).unregister();
    }
/**
     * Verify persisted event registrations are pulled out of the datastore.
     */
Verify persisted event registrations are pulled out of the datastore.
Verify persisted event registrations are pulled out of the datastore .
@Test
    public void testActivateDatastorePull()
    {
        List<PersistentData> datas = new ArrayList<PersistentData>();
        PersistentEventRegistrationMessage message1 = createPersistedRegMessage();
        PersistentEventRegistrationMessage message2 = createPersistedRegMessage();
        PersistentData data1 = mock(PersistentData.class);
        when(data1.getEntity()).thenReturn(message1.toByteArray());
        when(data1.getDescription()).thenReturn("1");
        PersistentData data2 = mock(PersistentData.class);
        when(data2.getEntity()).thenReturn(message2.toByteArray());
        when(data2.getDescription()).thenReturn("2");
        datas.add(data1);
        datas.add(data2);
        Collection<PersistentData> perData = datas;
        when(m_DataStore.query(EventAdminMessageService.class)).thenReturn(perData);
        ServiceRegistration<EventHandler> handler1 = mock(ServiceRegistration.class);
        ServiceRegistration<EventHandler> handler2 = mock(ServiceRegistration.class);
        when(m_Context.registerService(eq(EventHandler.class), Mockito.any(EventHandler.class), 
                Mockito.any(Dictionary.class))).thenReturn(handler1, handler2);
        m_SUT.activate(m_Context);
        verify(m_DataStore, times(2)).query(EventAdminMessageService.class);
        m_SUT.deactivate();
        verify(handler1).unregister();
        verify(handler2).unregister();
    }
@ Test public void testActivateDatastorePull ( ) { List < PersistentData > datas = new ArrayList < PersistentData > ( ) ; PersistentEventRegistrationMessage message1 = createPersistedRegMessage ( ) ; PersistentEventRegistrationMessage message2 = createPersistedRegMessage ( ) ; PersistentData data1 = mock ( PersistentData . class ) ; when ( data1 . getEntity ( ) ) . thenReturn ( message1 . toByteArray ( ) ) ; when ( data1 . getDescription ( ) ) . thenReturn ( "1" ) ; PersistentData data2 = mock ( PersistentData . class ) ; when ( data2 . getEntity ( ) ) . thenReturn ( message2 . toByteArray ( ) ) ; when ( data2 . getDescription ( ) ) . thenReturn ( "2" ) ; datas . add ( data1 ) ; datas . add ( data2 ) ; Collection < PersistentData > perData = datas ; when ( m_DataStore . query ( EventAdminMessageService . class ) ) . thenReturn ( perData ) ; ServiceRegistration < EventHandler > handler1 = mock ( ServiceRegistration . class ) ; ServiceRegistration < EventHandler > handler2 = mock ( ServiceRegistration . class ) ; when ( m_Context . registerService ( eq ( EventHandler . class ) , Mockito . any ( EventHandler . class ) , Mockito . any ( Dictionary . class ) ) ) . thenReturn ( handler1 , handler2 ) ; m_SUT . activate ( m_Context ) ; verify ( m_DataStore , times ( 2 ) ) . query ( EventAdminMessageService . class ) ; m_SUT . deactivate ( ) ; verify ( handler1 ) . unregister ( ) ; verify ( handler2 ) . unregister ( ) ; }
Verify persisted event registrations are pulled out of the datastore.
Verify persisted event registrations are pulled out of the datastore .
//persistent reg messages. //mock persistent data //add the mocks to the collection //when the message are pulled the events will be re registered for //service registreation mocks //activate