mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/base/TestBaseMessageService.java
@Test
    public void testShutdownSystemBundleException() throws BundleException, IOException
    {
        // mock context and activate
        BundleContext context = mock(BundleContext.class);
        Bundle systemBundle = mock(Bundle.class);
        when(context.getBundle(0)).thenReturn(systemBundle); // system bundle is always id 0
        m_SUT.activate(context);
        
        // construct the shutdown system message
        BaseNamespace baseNamespaceMessage = BaseNamespace.newBuilder()
                .setType(BaseMessageType.ShutdownSystem)
                .build();
     
        TerraHarvestPayload payload = createPayload(baseNamespaceMessage);
        TerraHarvestMessage message = createBaseMessage(baseNamespaceMessage);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        doThrow(new BundleException("arghhh bundle exception")).when(systemBundle).stop();
        
        // replay
        m_SUT.handleMessage(message, payload, channel);
        
        // verify system bundle is told to stop which would stop OSGi framework
        verify(systemBundle).stop();
        
        // verify response message is sent back to source requester
        verify(m_MessageFactory).createBaseErrorMessage(eq(message), eq(ErrorCode.INTERNAL_ERROR), 
                Mockito.anyString());
        //once for the initial acknowledgment, and then again for the exception
        verify(m_ResponseWrapper, times(2)).queue(channel);
    }
/**
     * Verify handling of ShutdownSystem with a bundle exception, should queue an error response message.
     */
Verify handling of ShutdownSystem with a bundle exception, should queue an error response message.
Verify handling of ShutdownSystem with a bundle exception should queue an error response message .
@Test
    public void testShutdownSystemBundleException() throws BundleException, IOException
    {
        BundleContext context = mock(BundleContext.class);
        Bundle systemBundle = mock(Bundle.class);
        when(context.getBundle(0)).thenReturn(systemBundle); 
        m_SUT.activate(context);
        BaseNamespace baseNamespaceMessage = BaseNamespace.newBuilder()
                .setType(BaseMessageType.ShutdownSystem)
                .build();
        TerraHarvestPayload payload = createPayload(baseNamespaceMessage);
        TerraHarvestMessage message = createBaseMessage(baseNamespaceMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        doThrow(new BundleException("arghhh bundle exception")).when(systemBundle).stop();
        m_SUT.handleMessage(message, payload, channel);
        verify(systemBundle).stop();
        verify(m_MessageFactory).createBaseErrorMessage(eq(message), eq(ErrorCode.INTERNAL_ERROR), 
                Mockito.anyString());
        verify(m_ResponseWrapper, times(2)).queue(channel);
    }
@ Test public void testShutdownSystemBundleException ( ) throws BundleException , IOException { BundleContext context = mock ( BundleContext . class ) ; Bundle systemBundle = mock ( Bundle . class ) ; when ( context . getBundle ( 0 ) ) . thenReturn ( systemBundle ) ; m_SUT . activate ( context ) ; BaseNamespace baseNamespaceMessage = BaseNamespace . newBuilder ( ) . setType ( BaseMessageType . ShutdownSystem ) . build ( ) ; TerraHarvestPayload payload = createPayload ( baseNamespaceMessage ) ; TerraHarvestMessage message = createBaseMessage ( baseNamespaceMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; doThrow ( new BundleException ( "arghhh bundle exception" ) ) . when ( systemBundle ) . stop ( ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( systemBundle ) . stop ( ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( eq ( message ) , eq ( ErrorCode . INTERNAL_ERROR ) , Mockito . anyString ( ) ) ; verify ( m_ResponseWrapper , times ( 2 ) ) . queue ( channel ) ; }
Verify handling of ShutdownSystem with a bundle exception, should queue an error response message.
Verify handling of ShutdownSystem with a bundle exception should queue an error response message .
// mock context and activate // system bundle is always id 0 // construct the shutdown system message // mock the channel the message came from // replay // verify system bundle is told to stop which would stop OSGi framework // verify response message is sent back to source requester //once for the initial acknowledgment, and then again for the exception