mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestBundleManagementMessageService.java
@Test
    public void testGetBundleNoFieldsRequested() throws Exception
    {
        Bundle bundleA = mock(Bundle.class);
        when(bundleA.getBundleId()).thenReturn(1L);
        
        // mock context lookup
        when(m_Context.getBundle(1L)).thenReturn(bundleA);
        
        //request
        GetBundleInfoRequestData request = GetBundleInfoRequestData.newBuilder().
            setBundleDescription(false).
            setBundleId(1L).
            setBundleLastModified(false).
            setBundleLocation(false).
            setBundleName(false).
            setBundleSymbolicName(false).
            setBundleState(false).
            setBundleVendor(false).
            setBundleVersion(false).
            setPackageExports(false).
            setPackageImports(false).build();
        TerraHarvestPayload payload = createPayload(request, BundleMessageType.GetBundleInfoRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, BundleMessageType.GetBundleInfoRequest);

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

        // handle the message
        m_SUT.handleMessage(message, payload, channel);
        
        //verify
        ArgumentCaptor<GetBundleInfoResponseData> responseCaptor = ArgumentCaptor.forClass(
            GetBundleInfoResponseData.class);
        verify(m_MessageFactory).createBundleResponseMessage(eq(message), eq(BundleMessageType.GetBundleInfoResponse), 
            responseCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);

        // verify event is posted for get bundle info 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.GetBundleInfoRequest.toString()));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
        assertThat((BundleNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
            is(getNamespaceMessage(message)));
        
        //verify data sent back as expected
        GetBundleInfoResponseData responseData = responseCaptor.getValue();
        assertThat(responseData.getInfoDataCount(), is(1));
        
        BundleInfoType type = responseData.getInfoData(0);
        assertThat(type.hasBundleDescription(), is(false));
        assertThat(type.hasBundleLastModified(), is(false));
        assertThat(type.hasBundleLocation(), is(false));
        assertThat(type.hasBundleName(), is(false));
        assertThat(type.hasBundleState(), is(false));
        assertThat(type.hasBundleSymbolicName(), is(false));
        assertThat(type.hasBundleVendor(), is(false));
        assertThat(type.hasBundleVersion(), is(false));
        assertThat(type.getPackageExportCount(), is(0));
        assertThat(type.getPackageImportCount(), is(0));
        assertThat(type.hasBundleId(), is(true));
        assertThat(type.getBundleId(), is(1L));
    }
/**
     * Test get bundle info request.
     * 
     * Verify correct response is sent even if no fields are requested to be returned.
     */
Test get bundle info request.

Verify correct response is sent even if no fields are requested to be returned.
Test get bundle info request . Verify correct response is sent even if no fields are requested to be returned .
@Test
    public void testGetBundleNoFieldsRequested() throws Exception
    {
        Bundle bundleA = mock(Bundle.class);
        when(bundleA.getBundleId()).thenReturn(1L);
        when(m_Context.getBundle(1L)).thenReturn(bundleA);
        GetBundleInfoRequestData request = GetBundleInfoRequestData.newBuilder().
            setBundleDescription(false).
            setBundleId(1L).
            setBundleLastModified(false).
            setBundleLocation(false).
            setBundleName(false).
            setBundleSymbolicName(false).
            setBundleState(false).
            setBundleVendor(false).
            setBundleVersion(false).
            setPackageExports(false).
            setPackageImports(false).build();
        TerraHarvestPayload payload = createPayload(request, BundleMessageType.GetBundleInfoRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, BundleMessageType.GetBundleInfoRequest);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<GetBundleInfoResponseData> responseCaptor = ArgumentCaptor.forClass(
            GetBundleInfoResponseData.class);
        verify(m_MessageFactory).createBundleResponseMessage(eq(message), eq(BundleMessageType.GetBundleInfoResponse), 
            responseCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        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.GetBundleInfoRequest.toString()));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
        assertThat((BundleNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
            is(getNamespaceMessage(message)));
         data sent back as expected
        GetBundleInfoResponseData responseData = responseCaptor.getValue();
        assertThat(responseData.getInfoDataCount(), is(1));
        BundleInfoType type = responseData.getInfoData(0);
        assertThat(type.hasBundleDescription(), is(false));
        assertThat(type.hasBundleLastModified(), is(false));
        assertThat(type.hasBundleLocation(), is(false));
        assertThat(type.hasBundleName(), is(false));
        assertThat(type.hasBundleState(), is(false));
        assertThat(type.hasBundleSymbolicName(), is(false));
        assertThat(type.hasBundleVendor(), is(false));
        assertThat(type.hasBundleVersion(), is(false));
        assertThat(type.getPackageExportCount(), is(0));
        assertThat(type.getPackageImportCount(), is(0));
        assertThat(type.hasBundleId(), is(true));
        assertThat(type.getBundleId(), is(1L));
    }
@ Test public void testGetBundleNoFieldsRequested ( ) throws Exception { Bundle bundleA = mock ( Bundle . class ) ; when ( bundleA . getBundleId ( ) ) . thenReturn ( 1L ) ; when ( m_Context . getBundle ( 1L ) ) . thenReturn ( bundleA ) ; GetBundleInfoRequestData request = GetBundleInfoRequestData . newBuilder ( ) . setBundleDescription ( false ) . setBundleId ( 1L ) . setBundleLastModified ( false ) . setBundleLocation ( false ) . setBundleName ( false ) . setBundleSymbolicName ( false ) . setBundleState ( false ) . setBundleVendor ( false ) . setBundleVersion ( false ) . setPackageExports ( false ) . setPackageImports ( false ) . build ( ) ; TerraHarvestPayload payload = createPayload ( request , BundleMessageType . GetBundleInfoRequest ) ; TerraHarvestMessage message = createTerraHarvestMessage ( request , BundleMessageType . GetBundleInfoRequest ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < GetBundleInfoResponseData > responseCaptor = ArgumentCaptor . forClass ( GetBundleInfoResponseData . class ) ; verify ( m_MessageFactory ) . createBundleResponseMessage ( eq ( message ) , eq ( BundleMessageType . GetBundleInfoResponse ) , responseCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; 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 . GetBundleInfoRequest . toString ( ) ) ) ; assertThat ( ( RemoteChannel ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_CHANNEL ) , is ( channel ) ) ; assertThat ( ( BundleNamespace ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE_MESSAGE ) , is ( getNamespaceMessage ( message ) ) ) ; GetBundleInfoResponseData responseData = responseCaptor . getValue ( ) ; assertThat ( responseData . getInfoDataCount ( ) , is ( 1 ) ) ; BundleInfoType type = responseData . getInfoData ( 0 ) ; assertThat ( type . hasBundleDescription ( ) , is ( false ) ) ; assertThat ( type . hasBundleLastModified ( ) , is ( false ) ) ; assertThat ( type . hasBundleLocation ( ) , is ( false ) ) ; assertThat ( type . hasBundleName ( ) , is ( false ) ) ; assertThat ( type . hasBundleState ( ) , is ( false ) ) ; assertThat ( type . hasBundleSymbolicName ( ) , is ( false ) ) ; assertThat ( type . hasBundleVendor ( ) , is ( false ) ) ; assertThat ( type . hasBundleVersion ( ) , is ( false ) ) ; assertThat ( type . getPackageExportCount ( ) , is ( 0 ) ) ; assertThat ( type . getPackageImportCount ( ) , is ( 0 ) ) ; assertThat ( type . hasBundleId ( ) , is ( true ) ) ; assertThat ( type . getBundleId ( ) , is ( 1L ) ) ; }
Test get bundle info request.
Test get bundle info request .
// mock context lookup //request //mock the channel the message came from // handle the message //verify // verify event is posted for get bundle info request //verify data sent back as expected