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

        //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).createBaseErrorMessage(eq(message), eq(ErrorCode.INVALID_VALUE), Mockito.anyString());
        verify(m_ResponseWrapper).queue(channel);
        
        //try again mocking exception
        when(m_Context.getBundle(1L)).thenReturn(bundleA);
        request = StartRequestData.newBuilder().setBundleId(1L).build();
        payload = createPayload(request, BundleMessageType.StartRequest);
        message = createTerraHarvestMessage(request, BundleMessageType.StartRequest);
        
        //mock exception
        doThrow(new BundleException("Whammy!")).when(bundleA).start();
        
        // handle the message
        m_SUT.handleMessage(message, payload, channel);
        
        //verify
        ArgumentCaptor<BundleNamespaceErrorData> responseCaptor = ArgumentCaptor.forClass(
            BundleNamespaceErrorData.class);
        verify(m_MessageFactory).createBundleResponseMessage(eq(message), eq(BundleMessageType.BundleNamespaceError),
            responseCaptor.capture());
        verify(m_ResponseWrapper, times(2)).queue(channel);
        BundleNamespaceErrorData error = responseCaptor.getValue();
        assertThat(error.getError(), is(BundleErrorCode.OSGiBundleException));
        verify(bundleA).start();
    }
/**
     * Test the start bundle request.
     * 
     * Verify that in the event that an exception occurs while trying to start the bundle, that the appropriate 
     * response is sent.
     */
Test the start bundle request.

Verify that in the event that an exception occurs while trying to start the bundle, that the appropriate
response is sent.
Test the start bundle request . Verify that in the event that an exception occurs while trying to start the bundle that the appropriate response is sent .
@Test
    public void testStartBundleBad() throws IOException, BundleException
    {
        Bundle bundleA = mock(Bundle.class);
        when(bundleA.getBundleId()).thenReturn(1L);
        StartRequestData request = StartRequestData.newBuilder().setBundleId(9L).build();
        TerraHarvestPayload payload = createPayload(request, BundleMessageType.StartRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, BundleMessageType.StartRequest);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorMessage(eq(message), eq(ErrorCode.INVALID_VALUE), Mockito.anyString());
        verify(m_ResponseWrapper).queue(channel);
        when(m_Context.getBundle(1L)).thenReturn(bundleA);
        request = StartRequestData.newBuilder().setBundleId(1L).build();
        payload = createPayload(request, BundleMessageType.StartRequest);
        message = createTerraHarvestMessage(request, BundleMessageType.StartRequest);
        doThrow(new BundleException("Whammy!")).when(bundleA).start();
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<BundleNamespaceErrorData> responseCaptor = ArgumentCaptor.forClass(
            BundleNamespaceErrorData.class);
        verify(m_MessageFactory).createBundleResponseMessage(eq(message), eq(BundleMessageType.BundleNamespaceError),
            responseCaptor.capture());
        verify(m_ResponseWrapper, times(2)).queue(channel);
        BundleNamespaceErrorData error = responseCaptor.getValue();
        assertThat(error.getError(), is(BundleErrorCode.OSGiBundleException));
        verify(bundleA).start();
    }
@ Test public void testStartBundleBad ( ) throws IOException , BundleException { Bundle bundleA = mock ( Bundle . class ) ; when ( bundleA . getBundleId ( ) ) . thenReturn ( 1L ) ; StartRequestData request = StartRequestData . newBuilder ( ) . setBundleId ( 9L ) . build ( ) ; TerraHarvestPayload payload = createPayload ( request , BundleMessageType . StartRequest ) ; TerraHarvestMessage message = createTerraHarvestMessage ( request , BundleMessageType . StartRequest ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( eq ( message ) , eq ( ErrorCode . INVALID_VALUE ) , Mockito . anyString ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; when ( m_Context . getBundle ( 1L ) ) . thenReturn ( bundleA ) ; request = StartRequestData . newBuilder ( ) . setBundleId ( 1L ) . build ( ) ; payload = createPayload ( request , BundleMessageType . StartRequest ) ; message = createTerraHarvestMessage ( request , BundleMessageType . StartRequest ) ; doThrow ( new BundleException ( "Whammy!" ) ) . when ( bundleA ) . start ( ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < BundleNamespaceErrorData > responseCaptor = ArgumentCaptor . forClass ( BundleNamespaceErrorData . class ) ; verify ( m_MessageFactory ) . createBundleResponseMessage ( eq ( message ) , eq ( BundleMessageType . BundleNamespaceError ) , responseCaptor . capture ( ) ) ; verify ( m_ResponseWrapper , times ( 2 ) ) . queue ( channel ) ; BundleNamespaceErrorData error = responseCaptor . getValue ( ) ; assertThat ( error . getError ( ) , is ( BundleErrorCode . OSGiBundleException ) ) ; verify ( bundleA ) . start ( ) ; }
Test the start bundle request.
Test the start bundle request .
//request //mock the channel the message came from // handle the message //verify //try again mocking exception //mock exception // handle the message //verify