mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestBundleManagementMessageService.java
@Test
    public void testUpdateBundleBad() throws BundleException, IOException
    {
        //mock
        Bundle updateBundle = mock(Bundle.class);
        when(updateBundle.getBundleId()).thenReturn(6L);
        when(m_Context.getBundle(6L)).thenReturn(updateBundle);
        doThrow(new BundleException("High chairs")).when(updateBundle).
            update(Mockito.any(InputStream.class));
        
        //request
        UpdateRequestData request = UpdateRequestData.newBuilder().
            setBundleFile(ByteString.copyFrom(new byte[] { 0, 1, 3, 5, 9, (byte)0xff, 0x3f, 0x56, (byte)0xdd, 18})).
            setBundleId(6L).build();
        TerraHarvestPayload payload = createPayload(request, BundleMessageType.UpdateRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, BundleMessageType.UpdateRequest);

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

        // 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());
        verify(m_ResponseWrapper).queue(channel);
        BundleNamespaceErrorData error = responseCaptorError.getValue();
        assertThat(error.getError(), is(BundleErrorCode.OSGiBundleException));
        
        //try again but this time the bundle won't be found
        request = UpdateRequestData.newBuilder().setBundleId(8L).setBundleFile(ByteString.copyFrom(
            new byte[] { 0, 1, 3, 5, 9, (byte)0xff, 0x3f, 0x56, (byte)0xdd, 18})).build();
        payload = createPayload(request, BundleMessageType.UpdateRequest);
        message = createTerraHarvestMessage(request, BundleMessageType.UpdateRequest);
        
        // handle the message
        m_SUT.handleMessage(message, payload, channel);
        
        //verify
        verify(m_MessageFactory).createBaseErrorMessage(eq(message), eq(ErrorCode.INVALID_VALUE), Mockito.anyString());
        //reused channel
        verify(m_ResponseWrapper, times(2)).queue(channel);
    }
/**
     * Test update bundle request with null bundle and exception.
     * 
     * Verify correct responses are sent.
     */
Test update bundle request with null bundle and exception.

Verify correct responses are sent.
Test update bundle request with null bundle and exception . Verify correct responses are sent .
@Test
    public void testUpdateBundleBad() throws BundleException, IOException
    {
        Bundle updateBundle = mock(Bundle.class);
        when(updateBundle.getBundleId()).thenReturn(6L);
        when(m_Context.getBundle(6L)).thenReturn(updateBundle);
        doThrow(new BundleException("High chairs")).when(updateBundle).
            update(Mockito.any(InputStream.class));
        UpdateRequestData request = UpdateRequestData.newBuilder().
            setBundleFile(ByteString.copyFrom(new byte[] { 0, 1, 3, 5, 9, (byte)0xff, 0x3f, 0x56, (byte)0xdd, 18})).
            setBundleId(6L).build();
        TerraHarvestPayload payload = createPayload(request, BundleMessageType.UpdateRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, BundleMessageType.UpdateRequest);
         the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        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).queue(channel);
        BundleNamespaceErrorData error = responseCaptorError.getValue();
        assertThat(error.getError(), is(BundleErrorCode.OSGiBundleException));
        request = UpdateRequestData.newBuilder().setBundleId(8L).setBundleFile(ByteString.copyFrom(
            new byte[] { 0, 1, 3, 5, 9, (byte)0xff, 0x3f, 0x56, (byte)0xdd, 18})).build();
        payload = createPayload(request, BundleMessageType.UpdateRequest);
        message = createTerraHarvestMessage(request, BundleMessageType.UpdateRequest);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorMessage(eq(message), eq(ErrorCode.INVALID_VALUE), Mockito.anyString());
        verify(m_ResponseWrapper, times(2)).queue(channel);
    }
@ Test public void testUpdateBundleBad ( ) throws BundleException , IOException { Bundle updateBundle = mock ( Bundle . class ) ; when ( updateBundle . getBundleId ( ) ) . thenReturn ( 6L ) ; when ( m_Context . getBundle ( 6L ) ) . thenReturn ( updateBundle ) ; doThrow ( new BundleException ( "High chairs" ) ) . when ( updateBundle ) . update ( Mockito . any ( InputStream . class ) ) ; UpdateRequestData request = UpdateRequestData . newBuilder ( ) . setBundleFile ( ByteString . copyFrom ( new byte [ ] { 0 , 1 , 3 , 5 , 9 , ( byte ) 0xff , 0x3f , 0x56 , ( byte ) 0xdd , 18 } ) ) . setBundleId ( 6L ) . build ( ) ; TerraHarvestPayload payload = createPayload ( request , BundleMessageType . UpdateRequest ) ; TerraHarvestMessage message = createTerraHarvestMessage ( request , BundleMessageType . UpdateRequest ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; 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 ) . queue ( channel ) ; BundleNamespaceErrorData error = responseCaptorError . getValue ( ) ; assertThat ( error . getError ( ) , is ( BundleErrorCode . OSGiBundleException ) ) ; request = UpdateRequestData . newBuilder ( ) . setBundleId ( 8L ) . setBundleFile ( ByteString . copyFrom ( new byte [ ] { 0 , 1 , 3 , 5 , 9 , ( byte ) 0xff , 0x3f , 0x56 , ( byte ) 0xdd , 18 } ) ) . build ( ) ; payload = createPayload ( request , BundleMessageType . UpdateRequest ) ; message = createTerraHarvestMessage ( request , BundleMessageType . UpdateRequest ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( eq ( message ) , eq ( ErrorCode . INVALID_VALUE ) , Mockito . anyString ( ) ) ; verify ( m_ResponseWrapper , times ( 2 ) ) . queue ( channel ) ; }
Test update bundle request with null bundle and exception.
Test update bundle request with null bundle and exception .
//mock //request //mock the channel the message came from // handle the message //verify //try again but this time the bundle won't be found // handle the message //verify //reused channel