mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestBundleManagementMessageService.java
@Test
    public void testGetBundleInfoForMultipleBundles() throws Exception
    {
        //initialize the fake bundles
        setFakeBundles();
        
        GetBundleInfoRequestData request = GetBundleInfoRequestData.newBuilder().
                setBundleDescription(true).
                setBundleLastModified(true).
                setBundleLocation(true).
                setBundleName(true).
                setBundleSymbolicName(true).
                setBundleState(true).
                setBundleVendor(true).
                setBundleVersion(true).
                setPackageExports(true).
                setPackageImports(true).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(3));
        
        for (BundleInfoType type : responseData.getInfoDataList())
        {
            assertThat(type.hasBundleId(), is(true));
            
            assertThat(type.getBundleId(), anyOf(equalTo(1L), equalTo(2L), equalTo(3L)));
            
            if (type.getBundleId() == 1L)
            {
                assertThat(type.getBundleDescription(), is("Like a fine wine."));
                assertThat(type.getBundleLastModified(), is(23L));
                assertThat(type.getBundleLocation(), is("mil.dod.th.when.is.dinner.served"));
                assertThat(type.getBundleName(), is("Who's asking?"));
                assertThat(type.getBundleState(), is(Bundle.ACTIVE));
                assertThat(type.getBundleSymbolicName(), is("Symbolically speaking, bundle"));
                assertThat(type.getBundleVendor(), is("Spaghetti"));
                assertThat(type.getBundleVersion(), is("1.9876"));
                assertThat(type.getPackageExportCount(), is(2));
                assertThat(type.getPackageExportList(), hasItem("com.giraffes.waltz"));
                assertThat(type.getPackageImportCount(), is(2));
                assertThat(type.getPackageImportList(), hasItem("com.elephants.dance"));
            }
            else if (type.getBundleId() == 2L)
            {
                assertThat(type.getBundleDescription(), is("Like a airplane."));
                assertThat(type.getBundleLastModified(), is(42L));
                assertThat(type.getBundleLocation(), is("mil.dod.th.soaring.hawks.2013"));
                assertThat(type.getBundleName(), is("I'm asking?"));
                assertThat(type.getBundleState(), is(Bundle.INSTALLED));
                assertThat(type.getBundleSymbolicName(), is("symbolic name here!"));
                assertThat(type.getBundleVendor(), is("Louie"));
                assertThat(type.getBundleVersion(), is("2.0023"));
                assertThat(type.getPackageExportCount(), is(3));
                assertThat(type.getPackageExportList(), hasItem("com.soaring.hawks"));
                assertThat(type.getPackageImportCount(), is(3));
                assertThat(type.getPackageImportList(), hasItem("com.what.about.it"));
            }
            else if (type.getBundleId() == 3L)
            {
                assertThat(type.getBundleDescription(), is("Like a boat."));
                assertThat(type.getBundleLastModified(), is(22L));
                assertThat(type.getBundleLocation(), is("mil.dod.th.location"));
                assertThat(type.getBundleName(), is("My name"));
                assertThat(type.getBundleState(), is(Bundle.RESOLVED));
                assertThat(type.getBundleSymbolicName(), is("so symbolic man"));
                assertThat(type.getBundleVendor(), is("Peter"));
                assertThat(type.getBundleVersion(), is("1.0003"));
                assertThat(type.getPackageExportCount(), is(0));
                assertThat(type.getPackageImportCount(), is(1));
                assertThat(type.getPackageImportList(), hasItem("com.i.just.want.a.soda"));
            }               
        }
    }
/**
     * Test BundleInfo Request with no id specified returns all known bundles.
     */
Test BundleInfo Request with no id specified returns all known bundles.
Test BundleInfo Request with no id specified returns all known bundles .
@Test
    public void testGetBundleInfoForMultipleBundles() throws Exception
    {
        setFakeBundles();
        GetBundleInfoRequestData request = GetBundleInfoRequestData.newBuilder().
                setBundleDescription(true).
                setBundleLastModified(true).
                setBundleLocation(true).
                setBundleName(true).
                setBundleSymbolicName(true).
                setBundleState(true).
                setBundleVendor(true).
                setBundleVersion(true).
                setPackageExports(true).
                setPackageImports(true).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(3));
        for (BundleInfoType type : responseData.getInfoDataList())
        {
            assertThat(type.hasBundleId(), is(true));
            assertThat(type.getBundleId(), anyOf(equalTo(1L), equalTo(2L), equalTo(3L)));
            if (type.getBundleId() == 1L)
            {
                assertThat(type.getBundleDescription(), is("Like a fine wine."));
                assertThat(type.getBundleLastModified(), is(23L));
                assertThat(type.getBundleLocation(), is("mil.dod.th.when.is.dinner.served"));
                assertThat(type.getBundleName(), is("Who's asking?"));
                assertThat(type.getBundleState(), is(Bundle.ACTIVE));
                assertThat(type.getBundleSymbolicName(), is("Symbolically speaking, bundle"));
                assertThat(type.getBundleVendor(), is("Spaghetti"));
                assertThat(type.getBundleVersion(), is("1.9876"));
                assertThat(type.getPackageExportCount(), is(2));
                assertThat(type.getPackageExportList(), hasItem("com.giraffes.waltz"));
                assertThat(type.getPackageImportCount(), is(2));
                assertThat(type.getPackageImportList(), hasItem("com.elephants.dance"));
            }
            else if (type.getBundleId() == 2L)
            {
                assertThat(type.getBundleDescription(), is("Like a airplane."));
                assertThat(type.getBundleLastModified(), is(42L));
                assertThat(type.getBundleLocation(), is("mil.dod.th.soaring.hawks.2013"));
                assertThat(type.getBundleName(), is("I'm asking?"));
                assertThat(type.getBundleState(), is(Bundle.INSTALLED));
                assertThat(type.getBundleSymbolicName(), is("symbolic name here!"));
                assertThat(type.getBundleVendor(), is("Louie"));
                assertThat(type.getBundleVersion(), is("2.0023"));
                assertThat(type.getPackageExportCount(), is(3));
                assertThat(type.getPackageExportList(), hasItem("com.soaring.hawks"));
                assertThat(type.getPackageImportCount(), is(3));
                assertThat(type.getPackageImportList(), hasItem("com.what.about.it"));
            }
            else if (type.getBundleId() == 3L)
            {
                assertThat(type.getBundleDescription(), is("Like a boat."));
                assertThat(type.getBundleLastModified(), is(22L));
                assertThat(type.getBundleLocation(), is("mil.dod.th.location"));
                assertThat(type.getBundleName(), is("My name"));
                assertThat(type.getBundleState(), is(Bundle.RESOLVED));
                assertThat(type.getBundleSymbolicName(), is("so symbolic man"));
                assertThat(type.getBundleVendor(), is("Peter"));
                assertThat(type.getBundleVersion(), is("1.0003"));
                assertThat(type.getPackageExportCount(), is(0));
                assertThat(type.getPackageImportCount(), is(1));
                assertThat(type.getPackageImportList(), hasItem("com.i.just.want.a.soda"));
            }               
        }
    }
@ Test public void testGetBundleInfoForMultipleBundles ( ) throws Exception { setFakeBundles ( ) ; GetBundleInfoRequestData request = GetBundleInfoRequestData . newBuilder ( ) . setBundleDescription ( true ) . setBundleLastModified ( true ) . setBundleLocation ( true ) . setBundleName ( true ) . setBundleSymbolicName ( true ) . setBundleState ( true ) . setBundleVendor ( true ) . setBundleVersion ( true ) . setPackageExports ( true ) . setPackageImports ( true ) . 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 ( 3 ) ) ; for ( BundleInfoType type : responseData . getInfoDataList ( ) ) { assertThat ( type . hasBundleId ( ) , is ( true ) ) ; assertThat ( type . getBundleId ( ) , anyOf ( equalTo ( 1L ) , equalTo ( 2L ) , equalTo ( 3L ) ) ) ; if ( type . getBundleId ( ) == 1L ) { assertThat ( type . getBundleDescription ( ) , is ( "Like a fine wine." ) ) ; assertThat ( type . getBundleLastModified ( ) , is ( 23L ) ) ; assertThat ( type . getBundleLocation ( ) , is ( "mil.dod.th.when.is.dinner.served" ) ) ; assertThat ( type . getBundleName ( ) , is ( "Who's asking?" ) ) ; assertThat ( type . getBundleState ( ) , is ( Bundle . ACTIVE ) ) ; assertThat ( type . getBundleSymbolicName ( ) , is ( "Symbolically speaking, bundle" ) ) ; assertThat ( type . getBundleVendor ( ) , is ( "Spaghetti" ) ) ; assertThat ( type . getBundleVersion ( ) , is ( "1.9876" ) ) ; assertThat ( type . getPackageExportCount ( ) , is ( 2 ) ) ; assertThat ( type . getPackageExportList ( ) , hasItem ( "com.giraffes.waltz" ) ) ; assertThat ( type . getPackageImportCount ( ) , is ( 2 ) ) ; assertThat ( type . getPackageImportList ( ) , hasItem ( "com.elephants.dance" ) ) ; } else if ( type . getBundleId ( ) == 2L ) { assertThat ( type . getBundleDescription ( ) , is ( "Like a airplane." ) ) ; assertThat ( type . getBundleLastModified ( ) , is ( 42L ) ) ; assertThat ( type . getBundleLocation ( ) , is ( "mil.dod.th.soaring.hawks.2013" ) ) ; assertThat ( type . getBundleName ( ) , is ( "I'm asking?" ) ) ; assertThat ( type . getBundleState ( ) , is ( Bundle . INSTALLED ) ) ; assertThat ( type . getBundleSymbolicName ( ) , is ( "symbolic name here!" ) ) ; assertThat ( type . getBundleVendor ( ) , is ( "Louie" ) ) ; assertThat ( type . getBundleVersion ( ) , is ( "2.0023" ) ) ; assertThat ( type . getPackageExportCount ( ) , is ( 3 ) ) ; assertThat ( type . getPackageExportList ( ) , hasItem ( "com.soaring.hawks" ) ) ; assertThat ( type . getPackageImportCount ( ) , is ( 3 ) ) ; assertThat ( type . getPackageImportList ( ) , hasItem ( "com.what.about.it" ) ) ; } else if ( type . getBundleId ( ) == 3L ) { assertThat ( type . getBundleDescription ( ) , is ( "Like a boat." ) ) ; assertThat ( type . getBundleLastModified ( ) , is ( 22L ) ) ; assertThat ( type . getBundleLocation ( ) , is ( "mil.dod.th.location" ) ) ; assertThat ( type . getBundleName ( ) , is ( "My name" ) ) ; assertThat ( type . getBundleState ( ) , is ( Bundle . RESOLVED ) ) ; assertThat ( type . getBundleSymbolicName ( ) , is ( "so symbolic man" ) ) ; assertThat ( type . getBundleVendor ( ) , is ( "Peter" ) ) ; assertThat ( type . getBundleVersion ( ) , is ( "1.0003" ) ) ; assertThat ( type . getPackageExportCount ( ) , is ( 0 ) ) ; assertThat ( type . getPackageImportCount ( ) , is ( 1 ) ) ; assertThat ( type . getPackageImportList ( ) , hasItem ( "com.i.just.want.a.soda" ) ) ; } } }
Test BundleInfo Request with no id specified returns all known bundles.
Test BundleInfo Request with no id specified returns all known bundles .
//initialize the fake bundles //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