mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestEventAdminMessageService.java
@Test
    public void testGetEventRegistrations() throws UnmarshalException, IOException, ObjectConverterException
    {
        int systemId = 200;
        
        //construct message
        EventRegistrationRequestData.Builder requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic("test-topic");
        // add required fields
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
        EventAdminNamespace eventAdminMessage = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.EventRegistrationRequest)
                .setData(requestMessage.build().toByteString())
                .build();
        
        TerraHarvestMessage message = createEventAdminMessage(eventAdminMessage);
        TerraHarvestPayload payload = createPayload(eventAdminMessage);

      //construct message
        EventRegistrationRequestData.Builder requestMessage2 = EventRegistrationRequestData.newBuilder()
                .addTopic("test-topic2");
        // add required fields
        requestMessage2 = RemoteUtils.appendRequiredFields(requestMessage2, true);
        EventAdminNamespace eventAdminMessage2 = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.EventRegistrationRequest)
                .setData(requestMessage2.build().toByteString())
                .build();
        
        TerraHarvestMessage message2 = createEventAdminMessage(eventAdminMessage2);
        TerraHarvestPayload payload2 = createPayload(eventAdminMessage2);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        //mocks
        ServiceRegistration<EventHandler> handler1 = mock(ServiceRegistration.class);
        ServiceRegistration<EventHandler> handler2 = mock(ServiceRegistration.class);
        
        //service registration mocks
        when(m_Context.registerService(eq(EventHandler.class), Mockito.any(EventHandler.class), 
                Mockito.any(Dictionary.class))).thenReturn(handler1, handler2);
        
        //handle messages
        m_SUT.handleMessage(message, payload, channel);
        m_SUT.handleMessage(message2, payload2, channel);

        Map<Integer, RemoteEventRegistration> regsMap = m_SUT.getRemoteEventRegistrations();
        assertThat(regsMap.size(), is(2));
        for (Integer regId : regsMap.keySet())
        {
            RemoteEventRegistration reg = regsMap.get(regId);

            assertThat(reg.getSystemId(), is(systemId));
            if(reg.getServiceRegistration().equals(handler1))
            {
                assertThat(reg.getEventRegistrationRequestData(), is(requestMessage.build()));
            }
            else
            {
                assertThat(reg.getEventRegistrationRequestData(), is(requestMessage2.build()));
            }

            assertThat(m_SUT.getRemoteEventExpirationHours(regId), is(167L));
        }
    }
/**
     * Verify the ability to get the registrations known for a particular system Id.
     */
Verify the ability to get the registrations known for a particular system Id.
Verify the ability to get the registrations known for a particular system Id .
@Test
    public void testGetEventRegistrations() throws UnmarshalException, IOException, ObjectConverterException
    {
        int systemId = 200;
        EventRegistrationRequestData.Builder requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic("test-topic");
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
        EventAdminNamespace eventAdminMessage = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.EventRegistrationRequest)
                .setData(requestMessage.build().toByteString())
                .build();
        TerraHarvestMessage message = createEventAdminMessage(eventAdminMessage);
        TerraHarvestPayload payload = createPayload(eventAdminMessage);
        EventRegistrationRequestData.Builder requestMessage2 = EventRegistrationRequestData.newBuilder()
                .addTopic("test-topic2");
        requestMessage2 = RemoteUtils.appendRequiredFields(requestMessage2, true);
        EventAdminNamespace eventAdminMessage2 = EventAdminNamespace.newBuilder()
                .setType(EventAdminMessageType.EventRegistrationRequest)
                .setData(requestMessage2.build().toByteString())
                .build();
        TerraHarvestMessage message2 = createEventAdminMessage(eventAdminMessage2);
        TerraHarvestPayload payload2 = createPayload(eventAdminMessage2);
        RemoteChannel channel = mock(RemoteChannel.class);
        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.handleMessage(message, payload, channel);
        m_SUT.handleMessage(message2, payload2, channel);
        Map<Integer, RemoteEventRegistration> regsMap = m_SUT.getRemoteEventRegistrations();
        assertThat(regsMap.size(), is(2));
        for (Integer regId : regsMap.keySet())
        {
            RemoteEventRegistration reg = regsMap.get(regId);
            assertThat(reg.getSystemId(), is(systemId));
            if(reg.getServiceRegistration().equals(handler1))
            {
                assertThat(reg.getEventRegistrationRequestData(), is(requestMessage.build()));
            }
            else
            {
                assertThat(reg.getEventRegistrationRequestData(), is(requestMessage2.build()));
            }
            assertThat(m_SUT.getRemoteEventExpirationHours(regId), is(167L));
        }
    }
@ Test public void testGetEventRegistrations ( ) throws UnmarshalException , IOException , ObjectConverterException { int systemId = 200 ; EventRegistrationRequestData . Builder requestMessage = EventRegistrationRequestData . newBuilder ( ) . addTopic ( "test-topic" ) ; requestMessage = RemoteUtils . appendRequiredFields ( requestMessage , false ) ; EventAdminNamespace eventAdminMessage = EventAdminNamespace . newBuilder ( ) . setType ( EventAdminMessageType . EventRegistrationRequest ) . setData ( requestMessage . build ( ) . toByteString ( ) ) . build ( ) ; TerraHarvestMessage message = createEventAdminMessage ( eventAdminMessage ) ; TerraHarvestPayload payload = createPayload ( eventAdminMessage ) ; EventRegistrationRequestData . Builder requestMessage2 = EventRegistrationRequestData . newBuilder ( ) . addTopic ( "test-topic2" ) ; requestMessage2 = RemoteUtils . appendRequiredFields ( requestMessage2 , true ) ; EventAdminNamespace eventAdminMessage2 = EventAdminNamespace . newBuilder ( ) . setType ( EventAdminMessageType . EventRegistrationRequest ) . setData ( requestMessage2 . build ( ) . toByteString ( ) ) . build ( ) ; TerraHarvestMessage message2 = createEventAdminMessage ( eventAdminMessage2 ) ; TerraHarvestPayload payload2 = createPayload ( eventAdminMessage2 ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; 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 . handleMessage ( message , payload , channel ) ; m_SUT . handleMessage ( message2 , payload2 , channel ) ; Map < Integer , RemoteEventRegistration > regsMap = m_SUT . getRemoteEventRegistrations ( ) ; assertThat ( regsMap . size ( ) , is ( 2 ) ) ; for ( Integer regId : regsMap . keySet ( ) ) { RemoteEventRegistration reg = regsMap . get ( regId ) ; assertThat ( reg . getSystemId ( ) , is ( systemId ) ) ; if ( reg . getServiceRegistration ( ) . equals ( handler1 ) ) { assertThat ( reg . getEventRegistrationRequestData ( ) , is ( requestMessage . build ( ) ) ) ; } else { assertThat ( reg . getEventRegistrationRequestData ( ) , is ( requestMessage2 . build ( ) ) ) ; } assertThat ( m_SUT . getRemoteEventExpirationHours ( regId ) , is ( 167L ) ) ; } }
Verify the ability to get the registrations known for a particular system Id.
Verify the ability to get the registrations known for a particular system Id .
//construct message // add required fields //construct message // add required fields // mock the channel the message came from //mocks //service registration mocks //handle messages