mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestBundleManagementMessageService.java
@Test
    public void testUninstallBundle() throws IOException, BundleException
    {
        //request to uninstall bundle that is not in look up
        UninstallRequestData request = UninstallRequestData.newBuilder().setBundleId(2L).build();
        TerraHarvestPayload payload = createPayload(request, BundleMessageType.UninstallRequest);

        TerraHarvestMessage message = createTerraHarvestMessage(request, BundleMessageType.UninstallRequest);

        //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);
        
        //mock bundle to uninstall
        Bundle removeBundle = mock(Bundle.class);
        when(removeBundle.getBundleId()).thenReturn(7L);
        when(m_Context.getBundle(7L)).thenReturn(removeBundle);
        
        //try send message again
        request = UninstallRequestData.newBuilder().setBundleId(7L).build();
        payload = createPayload(request, BundleMessageType.UninstallRequest);
        message = createTerraHarvestMessage(request, BundleMessageType.UninstallRequest);
        
        // handle the message
        m_SUT.handleMessage(message, payload, channel);
        
        //verify
        verify(removeBundle).uninstall();
        verify(m_MessageFactory).createBundleResponseMessage(message, BundleMessageType.UninstallResponse, null);
        //reused channel
        verify(m_ResponseWrapper, times(2)).queue(channel);
        
        //mock exception from bundle while un-installing
        doThrow(new BundleException("The bundle is in a bungle!!")).when(removeBundle).uninstall();
        
        // handle the message
        m_SUT.handleMessage(message, payload, channel);
        
        //verify
        ArgumentCaptor<BundleNamespaceErrorData> responseCaptorError = ArgumentCaptor.forClass(
            BundleNamespaceErrorData.class);
        verify(m_MessageFactory).createBundleResponseMessage(eq(message), eq(BundleMessageType.BundleNamespaceError),
            responseCaptorError.capture());
        //reused channel
        verify(m_ResponseWrapper, times(3)).queue(channel);
        BundleNamespaceErrorData error = responseCaptorError.getValue();
        assertThat(error.getError(), is(BundleErrorCode.OSGiBundleException));
    }
/**
     * Test uninstall bundle request.
     * 
     * Verify correct responses are sent.
     */
Test uninstall bundle request.

Verify correct responses are sent.
Test uninstall bundle request . Verify correct responses are sent .
@Test
    public void testUninstallBundle() throws IOException, BundleException
    {
        UninstallRequestData request = UninstallRequestData.newBuilder().setBundleId(2L).build();
        TerraHarvestPayload payload = createPayload(request, BundleMessageType.UninstallRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, BundleMessageType.UninstallRequest);
        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);
        Bundle removeBundle = mock(Bundle.class);
        when(removeBundle.getBundleId()).thenReturn(7L);
        when(m_Context.getBundle(7L)).thenReturn(removeBundle);
        request = UninstallRequestData.newBuilder().setBundleId(7L).build();
        payload = createPayload(request, BundleMessageType.UninstallRequest);
        message = createTerraHarvestMessage(request, BundleMessageType.UninstallRequest);
        m_SUT.handleMessage(message, payload, channel);
        verify(removeBundle).uninstall();
        verify(m_MessageFactory).createBundleResponseMessage(message, BundleMessageType.UninstallResponse, null);
        verify(m_ResponseWrapper, times(2)).queue(channel);
        doThrow(new BundleException("The bundle is in a bungle!!")).when(removeBundle).uninstall();
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<BundleNamespaceErrorData> responseCaptorError = ArgumentCaptor.forClass(
            BundleNamespaceErrorData.class);
        verify(m_MessageFactory).createBundleResponseMessage(eq(message), eq(BundleMessageType.BundleNamespaceError),
            responseCaptorError.capture());
        verify(m_ResponseWrapper, times(3)).queue(channel);
        BundleNamespaceErrorData error = responseCaptorError.getValue();
        assertThat(error.getError(), is(BundleErrorCode.OSGiBundleException));
    }
@ Test public void testUninstallBundle ( ) throws IOException , BundleException { UninstallRequestData request = UninstallRequestData . newBuilder ( ) . setBundleId ( 2L ) . build ( ) ; TerraHarvestPayload payload = createPayload ( request , BundleMessageType . UninstallRequest ) ; TerraHarvestMessage message = createTerraHarvestMessage ( request , BundleMessageType . UninstallRequest ) ; 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 ) ; Bundle removeBundle = mock ( Bundle . class ) ; when ( removeBundle . getBundleId ( ) ) . thenReturn ( 7L ) ; when ( m_Context . getBundle ( 7L ) ) . thenReturn ( removeBundle ) ; request = UninstallRequestData . newBuilder ( ) . setBundleId ( 7L ) . build ( ) ; payload = createPayload ( request , BundleMessageType . UninstallRequest ) ; message = createTerraHarvestMessage ( request , BundleMessageType . UninstallRequest ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( removeBundle ) . uninstall ( ) ; verify ( m_MessageFactory ) . createBundleResponseMessage ( message , BundleMessageType . UninstallResponse , null ) ; verify ( m_ResponseWrapper , times ( 2 ) ) . queue ( channel ) ; doThrow ( new BundleException ( "The bundle is in a bungle!!" ) ) . when ( removeBundle ) . uninstall ( ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < BundleNamespaceErrorData > responseCaptorError = ArgumentCaptor . forClass ( BundleNamespaceErrorData . class ) ; verify ( m_MessageFactory ) . createBundleResponseMessage ( eq ( message ) , eq ( BundleMessageType . BundleNamespaceError ) , responseCaptorError . capture ( ) ) ; verify ( m_ResponseWrapper , times ( 3 ) ) . queue ( channel ) ; BundleNamespaceErrorData error = responseCaptorError . getValue ( ) ; assertThat ( error . getError ( ) , is ( BundleErrorCode . OSGiBundleException ) ) ; }
Test uninstall bundle request.
Test uninstall bundle request .
//request to uninstall bundle that is not in look up //mock the channel the message came from // handle the message //verify //mock bundle to uninstall //try send message again // handle the message //verify //reused channel //mock exception from bundle while un-installing // handle the message //verify //reused channel