mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestBundleManagementMessageService.java
@Test
    public void testStopBundle() throws IOException, BundleException
    {
        Bundle bundleA = mock(Bundle.class);
        when(bundleA.getBundleId()).thenReturn(1L);
        
        // mock behavior
        when(m_Context.getBundle(1L)).thenReturn(bundleA);
        
        //request
        StopRequestData request = StopRequestData.newBuilder().setBundleId(1L).build();
        TerraHarvestPayload payload = createPayload(request, BundleMessageType.StopRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, BundleMessageType.StopRequest);

        //mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);

        // handle the message
        m_SUT.handleMessage(message, payload, channel);
        
        //verify
        verify(m_MessageFactory).createBundleResponseMessage(message, BundleMessageType.StopResponse, null);
        verify(m_ResponseWrapper).queue(channel);
        verify(bundleA).stop();
        
        // verify event is posted for stop bundle request
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        assertThat((Integer)postedEvent.getProperty(RemoteConstants.EVENT_PROP_SOURCE_ID), is(0));
        assertThat((Integer)postedEvent.getProperty(RemoteConstants.EVENT_PROP_DEST_ID), is(1));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE), is(Namespace.Bundle.
            toString()));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
            is(BundleMessageType.StopRequest.toString()));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
        assertThat((BundleNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
            is(getNamespaceMessage(message)));
    }
/**
     * Test stop bundle request.
     * 
     * Verify that the correct response is sent.
     */
Test stop bundle request.

Verify that the correct response is sent.
Test stop bundle request . Verify that the correct response is sent .
@Test
    public void testStopBundle() throws IOException, BundleException
    {
        Bundle bundleA = mock(Bundle.class);
        when(bundleA.getBundleId()).thenReturn(1L);
        when(m_Context.getBundle(1L)).thenReturn(bundleA);
        StopRequestData request = StopRequestData.newBuilder().setBundleId(1L).build();
        TerraHarvestPayload payload = createPayload(request, BundleMessageType.StopRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, BundleMessageType.StopRequest);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBundleResponseMessage(message, BundleMessageType.StopResponse, null);
        verify(m_ResponseWrapper).queue(channel);
        verify(bundleA).stop();
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        assertThat((Integer)postedEvent.getProperty(RemoteConstants.EVENT_PROP_SOURCE_ID), is(0));
        assertThat((Integer)postedEvent.getProperty(RemoteConstants.EVENT_PROP_DEST_ID), is(1));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE), is(Namespace.Bundle.
            toString()));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
            is(BundleMessageType.StopRequest.toString()));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
        assertThat((BundleNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
            is(getNamespaceMessage(message)));
    }
@ Test public void testStopBundle ( ) throws IOException , BundleException { Bundle bundleA = mock ( Bundle . class ) ; when ( bundleA . getBundleId ( ) ) . thenReturn ( 1L ) ; when ( m_Context . getBundle ( 1L ) ) . thenReturn ( bundleA ) ; StopRequestData request = StopRequestData . newBuilder ( ) . setBundleId ( 1L ) . build ( ) ; TerraHarvestPayload payload = createPayload ( request , BundleMessageType . StopRequest ) ; TerraHarvestMessage message = createTerraHarvestMessage ( request , BundleMessageType . StopRequest ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createBundleResponseMessage ( message , BundleMessageType . StopResponse , null ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; verify ( bundleA ) . stop ( ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event postedEvent = eventCaptor . getValue ( ) ; assertThat ( postedEvent . getTopic ( ) , is ( RemoteConstants . TOPIC_MESSAGE_RECEIVED ) ) ; assertThat ( ( TerraHarvestMessage ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE ) , is ( message ) ) ; assertThat ( ( Integer ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_SOURCE_ID ) , is ( 0 ) ) ; assertThat ( ( Integer ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_DEST_ID ) , is ( 1 ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE ) , is ( Namespace . Bundle . toString ( ) ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( BundleMessageType . StopRequest . toString ( ) ) ) ; assertThat ( ( RemoteChannel ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_CHANNEL ) , is ( channel ) ) ; assertThat ( ( BundleNamespace ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE_MESSAGE ) , is ( getNamespaceMessage ( message ) ) ) ; }
Test stop bundle request.
Test stop bundle request .
// mock behavior //request //mock the channel the message came from // handle the message //verify // verify event is posted for stop bundle request